3 #include "colormodels.h"
4 #include "funcprotos.h"
10 unsigned char *work_buffer
;
12 unsigned char *output_temp
;
13 } quicktime_rle_codec_t
;
16 static int delete_codec(quicktime_video_map_t
*vtrack
)
18 quicktime_rle_codec_t
*codec
;
19 codec
= ((quicktime_codec_t
*)vtrack
->codec
)->priv
;
20 if(codec
->work_buffer
) free(codec
->work_buffer
);
21 if(codec
->output_temp
) free(codec
->output_temp
);
25 static int reads_colormodel(quicktime_t
*file
,
29 return (colormodel
== BC_RGB888
);
32 static int source_cmodel(quicktime_t
*file
, int track
)
34 int depth
= quicktime_video_depth(file
, track
);
43 static int decode(quicktime_t
*file
, unsigned char **row_pointers
, int track
)
45 quicktime_video_map_t
*vtrack
= &(file
->vtracks
[track
]);
46 quicktime_trak_t
*trak
= vtrack
->track
;
47 quicktime_rle_codec_t
*codec
= ((quicktime_codec_t
*)vtrack
->codec
)->priv
;
48 int depth
= quicktime_video_depth(file
, track
);
49 int width
= trak
->tkhd
.track_width
;
50 int height
= trak
->tkhd
.track_height
;
59 unsigned char *row_ptr
;
61 unsigned char *buffer_end
;
65 unsigned char **temp_rows
= malloc(sizeof(unsigned char*) * height
);
66 int cmodel
= source_cmodel(file
, track
);
69 quicktime_set_video_position(file
, vtrack
->current_position
, track
);
70 size
= quicktime_frame_size(file
, vtrack
->current_position
, track
);
71 row_bytes
= depth
/ 8 * width
;
72 pixel_size
= depth
/ 8;
74 if(size
<= 8) return 0;
75 if(codec
->buffer_size
< size
&& codec
->work_buffer
)
77 free(codec
->work_buffer
);
78 codec
->work_buffer
= 0;
80 if(!codec
->work_buffer
)
82 codec
->work_buffer
= malloc(size
);
83 codec
->buffer_size
= size
;
86 if(!quicktime_read_data(file
,
91 ptr
= codec
->work_buffer
;
92 buffer_end
= ptr
+ size
;
98 header
= (ptr
[0] << 8) | ptr
[1];
101 // Incremental change
104 start_line
= (ptr
[0] << 8) | ptr
[1];
106 total_lines
= (ptr
[0] << 8) | ptr
[1];
113 total_lines
= height
;
117 if(cmodel
!= file
->color_model
||
120 file
->in_w
!= width
||
121 file
->in_h
!= height
||
122 file
->out_w
!= width
||
123 file
->out_h
!= height
)
128 if(!codec
->output_temp
)
129 codec
->output_temp
= calloc(1, height
* row_bytes
);
130 row_ptr
= codec
->output_temp
+ start_line
* row_bytes
;
131 for(i
= 0; i
< height
; i
++)
132 temp_rows
[i
] = codec
->output_temp
+ i
* row_bytes
;
136 row_ptr
= row_pointers
[start_line
];
137 for(i
= 0; i
< height
; i
++)
138 temp_rows
[i
] = row_pointers
[i
];
147 pixel
= row_ptr
+ (skip
- 1) * pixel_size
;
149 while(ptr
< buffer_end
&&
150 (code
= (char)*ptr
++) != -1)
155 pixel
+= (*ptr
++ - 1) * pixel_size
;
158 // Run length encoded
185 row_ptr
+= row_bytes
;
193 cmodel_transfer(row_pointers
,
223 void quicktime_init_codec_rle(quicktime_video_map_t
*vtrack
)
225 quicktime_codec_t
*codec_base
= (quicktime_codec_t
*)vtrack
->codec
;
226 quicktime_rle_codec_t
*codec
;
227 codec_base
->priv
= calloc(1, sizeof(quicktime_rle_codec_t
));
228 codec_base
->delete_vcodec
= delete_codec
;
229 codec_base
->decode_video
= decode
;
230 codec_base
->reads_colormodel
= reads_colormodel
;
231 codec_base
->fourcc
= "rle ";
232 codec_base
->title
= "RLE";
233 codec_base
->desc
= "Run length encoding";
235 codec
= (quicktime_rle_codec_t
*)codec_base
->priv
;