31 #define MAX_RLE_BULK 127
33 #define MAX_RLE_REPEAT 128
35 #define MAX_RLE_SKIP 254
85 s->logical_width=avctx->
width;
89 if (avctx->
width % 4) {
93 s->logical_width = avctx->
width / 4;
114 if (!
s->skip_table || !
s->length_table || !
s->rlecode_table) {
119 if (!
s->previous_frame) {
124 s->max_buf_size =
s->logical_width*
s->avctx->height*
s->pixel_size*2
137 int width=
s->logical_width;
143 unsigned int skipcount;
150 int total_repeat_cost;
153 int lowest_bulk_cost;
154 int lowest_bulk_cost_index;
155 int sec_lowest_bulk_cost;
156 int sec_lowest_bulk_cost_index;
162 const uint8_t *prev_line =
s->key_frame ? this_line
163 :
s->previous_frame->data[0]
164 +
line *
s->previous_frame->linesize[0]
167 s->length_table[
width] = 0;
171 lowest_bulk_cost = INT_MAX / 2;
172 lowest_bulk_cost_index =
width;
173 sec_lowest_bulk_cost = INT_MAX / 2;
174 sec_lowest_bulk_cost_index =
width;
176 base_bulk_cost = 1 +
s->pixel_size;
182 this_line -=
s->pixel_size;
183 prev_line -=
s->pixel_size;
188 lowest_bulk_cost = sec_lowest_bulk_cost;
189 lowest_bulk_cost_index = sec_lowest_bulk_cost_index;
191 sec_lowest_bulk_cost = INT_MAX / 2;
192 sec_lowest_bulk_cost_index =
width;
199 sec_lowest_bulk_cost++;
204 prev_bulk_cost =
s->length_table[
i + 1] + base_bulk_cost;
205 if (prev_bulk_cost <= sec_lowest_bulk_cost) {
208 if (prev_bulk_cost <= lowest_bulk_cost) {
213 sec_lowest_bulk_cost = INT_MAX / 2;
215 lowest_bulk_cost = prev_bulk_cost;
216 lowest_bulk_cost_index =
i + 1;
219 sec_lowest_bulk_cost = prev_bulk_cost;
220 sec_lowest_bulk_cost_index =
i + 1;
224 if (!
s->key_frame && !memcmp(this_line, prev_line,
s->pixel_size))
229 total_skip_cost =
s->length_table[
i + skipcount] + 2;
230 s->skip_table[
i] = skipcount;
233 if (
i <
width - 1 && !memcmp(this_line, this_line +
s->pixel_size,
s->pixel_size))
238 total_repeat_cost =
s->length_table[
i + repeatcount] + 1 +
s->pixel_size;
247 if (repeatcount > 1 && (skipcount == 0 || total_repeat_cost < total_skip_cost)) {
249 s->length_table[
i] = total_repeat_cost;
250 s->rlecode_table[
i] = -repeatcount;
252 else if (skipcount > 0) {
254 s->length_table[
i] = total_skip_cost;
255 s->rlecode_table[
i] = 0;
261 s->length_table[
i] = lowest_bulk_cost;
262 s->rlecode_table[
i] = lowest_bulk_cost_index -
i;
267 lowest_bulk_cost +=
s->pixel_size;
268 sec_lowest_bulk_cost +=
s->pixel_size;
279 if (
s->rlecode_table[0] == 0) {
280 bytestream_put_byte(buf,
s->skip_table[0] + 1);
281 i +=
s->skip_table[0];
283 else bytestream_put_byte(buf, 1);
287 rlecode =
s->rlecode_table[
i];
288 bytestream_put_byte(buf, rlecode);
291 bytestream_put_byte(buf,
s->skip_table[
i] + 1);
292 i +=
s->skip_table[
i];
294 else if (rlecode > 0) {
301 for (j = 0; j < rlecode*
s->pixel_size; ++j)
302 bytestream_put_byte(buf, *(this_line +
i*
s->pixel_size + j) ^ 0xff);
313 for (j = 0; j <
s->pixel_size; ++j)
314 bytestream_put_byte(buf, *(this_line +
i*
s->pixel_size + j) ^ 0xff);
321 bytestream_put_byte(buf, -1);
329 int end_line =
s->avctx->height;
333 unsigned line_size =
s->logical_width *
s->pixel_size;
334 for (start_line = 0; start_line <
s->avctx->height; start_line++)
336 s->previous_frame->data[0] + start_line *
s->previous_frame->linesize[0],
340 for (end_line=
s->avctx->height; end_line > start_line; end_line--)
342 s->previous_frame->data[0] + (end_line - 1) *
s->previous_frame->linesize[0],
347 bytestream_put_be32(&buf, 0);
349 if ((start_line == 0 && end_line ==
s->avctx->height) || start_line ==
s->avctx->height)
350 bytestream_put_be16(&buf, 0);
352 bytestream_put_be16(&buf, 8);
353 bytestream_put_be16(&buf, start_line);
354 bytestream_put_be16(&buf, 0);
355 bytestream_put_be16(&buf, end_line - start_line);
356 bytestream_put_be16(&buf, 0);
358 for (
i = start_line;
i < end_line;
i++)
361 bytestream_put_byte(&buf, 0);
362 AV_WB32(orig_buf, buf - orig_buf);
363 return buf - orig_buf;
367 const AVFrame *pict,
int *got_packet)
375 if (avctx->
gop_size == 0 || !
s->previous_frame->data[0] ||
376 (
s->avctx->frame_number % avctx->
gop_size) == 0) {
394 #if FF_API_CODED_FRAME
Libavcodec external API header.
static av_cold int init(AVCodecContext *avctx)
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
void * av_mallocz_array(size_t nmemb, size_t size)
Allocate a memory block for an array with av_mallocz().
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
@ AV_PICTURE_TYPE_I
Intra.
@ AV_PICTURE_TYPE_P
Predicted.
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define FF_DISABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
static enum AVPixelFormat pix_fmts[]
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
@ AV_PIX_FMT_RGB555BE
packed RGB 5:5:5, 16bpp, (msb)1X 5R 5G 5B(lsb), big-endian , X=unused/undefined
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
static av_cold int qtrle_encode_end(AVCodecContext *avctx)
static av_cold int qtrle_encode_init(AVCodecContext *avctx)
#define MAX_RLE_REPEAT
Maximum RLE code for repeat.
static void qtrle_encode_line(QtrleEncContext *s, const AVFrame *p, int line, uint8_t **buf)
Compute the best RLE sequence for a line.
static int qtrle_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
#define MAX_RLE_SKIP
Maximum RLE code for skip.
#define MAX_RLE_BULK
Maximum RLE code for bulk copy.
static int encode_frame(QtrleEncContext *s, const AVFrame *p, uint8_t *buf)
Encode frame including header.
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
attribute_deprecated AVFrame * coded_frame
the picture in the bitstream
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
const char * name
Name of the codec implementation.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int key_frame
1 -> keyframe, 0-> not
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
enum AVPictureType pict_type
Picture type of the frame.
This structure stores compressed data.
int flags
A combination of AV_PKT_FLAG values.
unsigned int max_buf_size
uint8_t * skip_table
Will contain at ith position the number of consecutive pixels equal to the previous frame starting fr...
int * length_table
This array will contain the length of the best rle encoding of the line starting at ith pixel.
signed char * rlecode_table
This array will contain at ith position the value of the best RLE code if the line started at pixel i...
int key_frame
Encoded frame is a key frame.