66 const int linesize = frame->
linesize[0];
69 int left[3], top[3], topleft[3];
72 for (i = 0; i < 3; i++)
73 buffer[0][i] = 1 << (9 - 1);
75 for (y = 0; y <
height; y++) {
76 const int modified_predictor = y ? predictor : 1;
84 for (i = 0; i < 3; i++)
85 top[i]= left[i]= topleft[i]=
buffer[0][i];
87 for (x = 0; x <
width; x++) {
88 buffer[x][1] = ptr[3 * x + 0] - ptr[3 * x + 1] + 0x100;
89 buffer[x][2] = ptr[3 * x + 2] - ptr[3 * x + 1] + 0x100;
90 buffer[x][0] = (ptr[3 * x + 0] + 2 * ptr[3 * x + 1] + ptr[3 * x + 2]) >> 2;
92 for (i = 0; i < 3; i++) {
95 PREDICT(pred, topleft[i], top[i], left[i], modified_predictor);
102 diff = ((left[i] - pred + 0x100) & 0x1FF) - 0x100;
116 const AVFrame *frame,
int predictor,
121 if (mb_x == 0 || mb_y == 0) {
122 for (i = 0; i < 3; i++) {
124 int x, y, h, v, linesize;
129 for (y = 0; y < v; y++) {
130 for (x = 0; x < h; x++) {
133 ptr = frame->
data[i] + (linesize * (v * mb_y + y)) + (h * mb_x + x);
134 if (y == 0 && mb_y == 0) {
135 if (x == 0 && mb_x == 0)
140 if (x == 0 && mb_x == 0) {
141 pred = ptr[-linesize];
143 PREDICT(pred, ptr[-linesize - 1], ptr[-linesize],
156 for (i = 0; i < 3; i++) {
158 int x, y, h, v, linesize;
163 for (y = 0; y < v; y++) {
164 for (x = 0; x < h; x++) {
167 ptr = frame->
data[i] + (linesize * (v * mb_y + y)) + (h * mb_x + x);
168 PREDICT(pred, ptr[-linesize - 1], ptr[-linesize], ptr[-1], predictor);
189 for (mb_y = 0; mb_y < mb_height; mb_y++) {
196 for (mb_x = 0; mb_x < mb_width; mb_x++)
204 const AVFrame *pict,
int *got_packet)
211 const int mb_height = (height + s->
vsample[0] - 1) / s->
vsample[0];
213 int ret, header_bits;
216 max_pkt_size += width * height * 3 * 3;
218 max_pkt_size += mb_width * mb_height * 3 * 4
222 av_log(avctx,
AV_LOG_ERROR,
"Error getting output packet of size %d.\n", max_pkt_size);
265 int chroma_v_shift, chroma_h_shift;
272 "Limited range YUV is non-standard, set strict_std_compliance to "
273 "at least unofficial to use it.\n");
298 s->
vsample[1] = 2 >> chroma_v_shift;
299 s->
vsample[2] = 2 >> chroma_v_shift;
301 s->
hsample[1] = 2 >> chroma_h_shift;
302 s->
hsample[2] = 2 >> chroma_h_shift;
av_cold void ff_dsputil_init(DSPContext *c, AVCodecContext *avctx)
This structure describes decoded (raw) audio or video data.
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
memory handling functions
AVFrame * coded_frame
the picture in the bitstream
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
const uint8_t avpriv_mjpeg_bits_dc_chrominance[17]
MJPEG encoder and decoder.
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
uint8_t huff_size_dc_chrominance[12]
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
void ff_mjpeg_build_huffman_codes(uint8_t *huff_size, uint16_t *huff_code, const uint8_t *bits_table, const uint8_t *val_table)
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV422P and setting color_...
uint8_t idct_permutation[64]
idct input permutation.
#define FF_COMPLIANCE_UNOFFICIAL
Allow unofficial extensions.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
#define PREDICT(ret, topleft, top, left, predictor)
int width
width and height of the video frame
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static uint8_t * put_bits_ptr(PutBitContext *s)
Return the pointer to the byte where the bitstream writer will put the next bit.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void ff_mjpeg_encode_picture_trailer(PutBitContext *pb, int header_bits)
void av_log(void *avcl, int level, const char *fmt,...)
const char * name
Name of the codec implementation.
int flags
A combination of AV_PKT_FLAG values.
reference-counted frame API
static int put_bits_count(PutBitContext *s)
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
void ff_mjpeg_encode_picture_header(AVCodecContext *avctx, PutBitContext *pb, ScanTable *intra_scantable, uint16_t intra_matrix[64])
static int ljpeg_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
enum AVPictureType pict_type
Picture type of the frame.
static av_cold int ljpeg_encode_init(AVCodecContext *avctx)
#define FF_MIN_BUFFER_SIZE
minimum encoding buffer size Used to avoid some checks during header writing.
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV420P and setting color_...
int width
picture width / height.
static av_cold int ljpeg_encode_close(AVCodecContext *avctx)
void ff_mjpeg_encode_dc(PutBitContext *pb, int val, uint8_t *huff_size, uint16_t *huff_code)
const uint8_t avpriv_mjpeg_bits_dc_luminance[17]
const uint8_t avpriv_mjpeg_val_dc[12]
uint16_t huff_code_dc_chrominance[12]
int ff_alloc_packet(AVPacket *avpkt, int size)
Check AVPacket size and/or allocate data.
packed RGB 8:8:8, 24bpp, BGRBGR...
static const float pred[4]
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
main external API structure.
static void close(AVCodecParserContext *s)
av_cold void ff_init_scantable(uint8_t *permutation, ScanTable *st, const uint8_t *src_scantable)
static int ljpeg_encode_yuv(AVCodecContext *avctx, PutBitContext *pb, const AVFrame *frame)
static int ljpeg_encode_bgr(AVCodecContext *avctx, PutBitContext *pb, const AVFrame *frame)
static void * av_malloc_array(size_t nmemb, size_t size)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
uint16_t huff_code_dc_luminance[12]
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
common internal api header.
const uint8_t ff_zigzag_direct[64]
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
int prediction_method
prediction method (needed for huffyuv)
uint8_t huff_size_dc_luminance[12]
FF_ENABLE_DEPRECATION_WARNINGS int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
Utility function to access log2_chroma_w log2_chroma_h from the pixel format AVPixFmtDescriptor.
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV444P and setting color_...
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
static av_cold int init(AVCodecParserContext *s)
static void ljpeg_encode_yuv_mb(LJpegEncContext *s, PutBitContext *pb, const AVFrame *frame, int predictor, int mb_x, int mb_y)
int key_frame
1 -> keyframe, 0-> not
AVPixelFormat
Pixel format.
This structure stores compressed data.
int strict_std_compliance
strictly follow the standard (MPEG4, ...).