Go to the documentation of this file.
32 #define MAX_RLE_BULK 127
34 #define MAX_RLE_REPEAT 128
36 #define MAX_RLE_SKIP 254
86 s->logical_width=avctx->
width;
90 if (avctx->
width % 4) {
94 s->logical_width = avctx->
width / 4;
114 s->length_table =
av_calloc(
s->logical_width + 1,
sizeof(*
s->length_table));
115 if (!
s->skip_table || !
s->length_table || !
s->rlecode_table) {
120 if (!
s->previous_frame) {
125 s->max_buf_size =
s->logical_width*
s->avctx->height*
s->pixel_size*2
138 int width=
s->logical_width;
144 unsigned int skipcount;
151 int total_repeat_cost;
154 int lowest_bulk_cost;
155 int lowest_bulk_cost_index;
156 int sec_lowest_bulk_cost;
157 int sec_lowest_bulk_cost_index;
163 const uint8_t *prev_line =
s->key_frame ? this_line
164 :
s->previous_frame->data[0]
165 +
line *
s->previous_frame->linesize[0]
168 s->length_table[
width] = 0;
172 lowest_bulk_cost = INT_MAX / 2;
173 lowest_bulk_cost_index =
width;
174 sec_lowest_bulk_cost = INT_MAX / 2;
175 sec_lowest_bulk_cost_index =
width;
177 base_bulk_cost = 1 +
s->pixel_size;
183 this_line -=
s->pixel_size;
184 prev_line -=
s->pixel_size;
189 lowest_bulk_cost = sec_lowest_bulk_cost;
190 lowest_bulk_cost_index = sec_lowest_bulk_cost_index;
192 sec_lowest_bulk_cost = INT_MAX / 2;
193 sec_lowest_bulk_cost_index =
width;
200 sec_lowest_bulk_cost++;
205 prev_bulk_cost =
s->length_table[
i + 1] + base_bulk_cost;
206 if (prev_bulk_cost <= sec_lowest_bulk_cost) {
209 if (prev_bulk_cost <= lowest_bulk_cost) {
214 sec_lowest_bulk_cost = INT_MAX / 2;
216 lowest_bulk_cost = prev_bulk_cost;
217 lowest_bulk_cost_index =
i + 1;
220 sec_lowest_bulk_cost = prev_bulk_cost;
221 sec_lowest_bulk_cost_index =
i + 1;
225 if (!
s->key_frame && !memcmp(this_line, prev_line,
s->pixel_size))
230 total_skip_cost =
s->length_table[
i + skipcount] + 2;
231 s->skip_table[
i] = skipcount;
234 if (
i <
width - 1 && !memcmp(this_line, this_line +
s->pixel_size,
s->pixel_size))
239 total_repeat_cost =
s->length_table[
i + repeatcount] + 1 +
s->pixel_size;
248 if (repeatcount > 1 && (skipcount == 0 || total_repeat_cost < total_skip_cost)) {
250 s->length_table[
i] = total_repeat_cost;
251 s->rlecode_table[
i] = -repeatcount;
253 else if (skipcount > 0) {
255 s->length_table[
i] = total_skip_cost;
256 s->rlecode_table[
i] = 0;
262 s->length_table[
i] = lowest_bulk_cost;
263 s->rlecode_table[
i] = lowest_bulk_cost_index -
i;
268 lowest_bulk_cost +=
s->pixel_size;
269 sec_lowest_bulk_cost +=
s->pixel_size;
280 if (
s->rlecode_table[0] == 0) {
281 bytestream_put_byte(buf,
s->skip_table[0] + 1);
282 i +=
s->skip_table[0];
284 else bytestream_put_byte(buf, 1);
288 rlecode =
s->rlecode_table[
i];
289 bytestream_put_byte(buf, rlecode);
292 bytestream_put_byte(buf,
s->skip_table[
i] + 1);
293 i +=
s->skip_table[
i];
295 else if (rlecode > 0) {
302 for (j = 0; j < rlecode*
s->pixel_size; ++j)
303 bytestream_put_byte(buf, *(this_line +
i*
s->pixel_size + j) ^ 0xff);
314 for (j = 0; j <
s->pixel_size; ++j)
315 bytestream_put_byte(buf, *(this_line +
i*
s->pixel_size + j) ^ 0xff);
322 bytestream_put_byte(buf, -1);
330 int end_line =
s->avctx->height;
331 uint8_t *orig_buf = buf;
334 unsigned line_size =
s->logical_width *
s->pixel_size;
335 for (start_line = 0; start_line <
s->avctx->height; start_line++)
337 s->previous_frame->data[0] + start_line *
s->previous_frame->linesize[0],
341 for (end_line=
s->avctx->height; end_line > start_line; end_line--)
343 s->previous_frame->data[0] + (end_line - 1) *
s->previous_frame->linesize[0],
348 bytestream_put_be32(&buf, 0);
350 if ((start_line == 0 && end_line ==
s->avctx->height) || start_line ==
s->avctx->height)
351 bytestream_put_be16(&buf, 0);
353 bytestream_put_be16(&buf, 8);
354 bytestream_put_be16(&buf, start_line);
355 bytestream_put_be16(&buf, 0);
356 bytestream_put_be16(&buf, end_line - start_line);
357 bytestream_put_be16(&buf, 0);
359 for (
i = start_line;
i < end_line;
i++)
362 bytestream_put_byte(&buf, 0);
363 AV_WB32(orig_buf, buf - orig_buf);
364 return buf - orig_buf;
368 const AVFrame *pict,
int *got_packet)
376 if (avctx->
gop_size == 0 || !
s->previous_frame->data[0] ||
377 (
s->avctx->frame_number % avctx->
gop_size) == 0) {
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
AVPixelFormat
Pixel format.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
#define MAX_RLE_BULK
Maximum RLE code for bulk copy.
int * length_table
This array will contain the length of the best rle encoding of the line starting at ith pixel.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
This structure describes decoded (raw) audio or video data.
static av_cold int qtrle_encode_end(AVCodecContext *avctx)
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
@ AV_PIX_FMT_RGB555BE
packed RGB 5:5:5, 16bpp, (msb)1X 5R 5G 5B(lsb), big-endian , X=unused/undefined
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
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.
static void qtrle_encode_line(QtrleEncContext *s, const AVFrame *p, int line, uint8_t **buf)
Compute the best RLE sequence for a line.
static enum AVPixelFormat pix_fmts[]
#define MAX_RLE_SKIP
Maximum RLE code for skip.
int key_frame
Encoded frame is a key frame.
uint8_t * skip_table
Will contain at ith position the number of consecutive pixels equal to the previous frame starting fr...
const AVCodec ff_qtrle_encoder
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
#define MAX_RLE_REPEAT
Maximum RLE code for repeat.
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
static int encode_frame(QtrleEncContext *s, const AVFrame *p, uint8_t *buf)
Encode frame including header.
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 flags
A combination of AV_PKT_FLAG values.
unsigned int max_buf_size
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
#define i(width, name, range_min, range_max)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
const char * name
Name of the codec implementation.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
void * av_calloc(size_t nmemb, size_t size)
main external API structure.
static int qtrle_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
static av_cold int qtrle_encode_init(AVCodecContext *avctx)
This structure stores compressed data.
int width
picture width / height.
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
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...
int ff_alloc_packet(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
Check AVPacket size and allocate data.