68 const int linesize = frame->
linesize[0];
71 int left[3], top[3], topleft[3];
74 for (i = 0; i < 3; i++)
75 buffer[0][i] = 1 << (9 - 1);
77 for (y = 0; y <
height; y++) {
78 const int modified_predictor = y ? predictor : 1;
86 for (i = 0; i < 3; i++)
87 top[i]= left[i]= topleft[i]=
buffer[0][i];
89 for (x = 0; x <
width; x++) {
91 buffer[x][1] = ptr[3 * x + 0] - ptr[3 * x + 1] + 0x100;
92 buffer[x][2] = ptr[3 * x + 2] - ptr[3 * x + 1] + 0x100;
93 buffer[x][0] = (ptr[3 * x + 0] + 2 * ptr[3 * x + 1] + ptr[3 * x + 2]) >> 2;
95 buffer[x][1] = ptr[4 * x + 0] - ptr[4 * x + 1] + 0x100;
96 buffer[x][2] = ptr[4 * x + 2] - ptr[4 * x + 1] + 0x100;
97 buffer[x][0] = (ptr[4 * x + 0] + 2 * ptr[4 * x + 1] + ptr[4 * x + 2]) >> 2;
100 for (i = 0; i < 3; i++) {
103 PREDICT(pred, topleft[i], top[i], left[i], modified_predictor);
110 diff = ((left[i] - pred + 0x100) & 0x1FF) - 0x100;
129 if (mb_x == 0 || mb_y == 0) {
130 for (i = 0; i < 3; i++) {
132 int x,
y,
h,
v, linesize;
137 for (y = 0; y <
v; y++) {
138 for (x = 0; x <
h; x++) {
141 ptr = frame->
data[i] + (linesize * (v * mb_y +
y)) + (h * mb_x + x);
142 if (y == 0 && mb_y == 0) {
143 if (x == 0 && mb_x == 0)
148 if (x == 0 && mb_x == 0) {
149 pred = ptr[-linesize];
151 PREDICT(pred, ptr[-linesize - 1], ptr[-linesize],
164 for (i = 0; i < 3; i++) {
166 int x,
y,
h,
v, linesize;
171 for (y = 0; y <
v; y++) {
172 for (x = 0; x <
h; x++) {
175 ptr = frame->
data[i] + (linesize * (v * mb_y +
y)) + (h * mb_x + x);
176 PREDICT(pred, ptr[-linesize - 1], ptr[-linesize], ptr[-1], predictor);
197 for (mb_y = 0; mb_y < mb_height; mb_y++) {
204 for (mb_x = 0; mb_x < mb_width; mb_x++)
212 const AVFrame *pict,
int *got_packet)
219 const int mb_height = (height + s->
vsample[0] - 1) / s->
vsample[0];
221 int ret, header_bits;
226 max_pkt_size += width * height * 3 * 4;
228 max_pkt_size += mb_width * mb_height * 3 * 4
283 "Limited range YUV is non-standard, set strict_std_compliance to "
284 "at least unofficial to use it.\n");
288 #if FF_API_CODED_FRAME
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
static av_cold int init(AVCodecContext *avctx)
enum AVColorRange color_range
MPEG vs JPEG YUV range.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
void ff_mjpeg_encode_picture_header(AVCodecContext *avctx, PutBitContext *pb, ScanTable *intra_scantable, uint16_t luma_intra_matrix[64], uint16_t chroma_intra_matrix[64])
MJPEG encoder and decoder.
#define AV_CODEC_CAP_INTRA_ONLY
Codec is intra only.
uint8_t huff_size_dc_chrominance[12]
void ff_mjpeg_build_huffman_codes(uint8_t *huff_size, uint16_t *huff_code, const uint8_t *bits_table, const uint8_t *val_table)
const uint8_t avpriv_mjpeg_bits_dc_luminance[17]
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
#define AV_INPUT_BUFFER_MIN_SIZE
minimum encoding buffer size Used to avoid some checks during header writing.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
#define PREDICT(ret, topleft, top, left, predictor)
static void predictor(uint8_t *src, int size)
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.
const uint8_t avpriv_mjpeg_bits_dc_chrominance[17]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
const char * name
Name of the codec implementation.
void ff_mjpeg_encode_picture_trailer(PutBitContext *pb, int header_bits)
Libavcodec external API header.
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
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)
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)
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
int width
picture width / height.
static av_cold int ljpeg_encode_close(AVCodecContext *avctx)
uint16_t huff_code_dc_chrominance[12]
void ff_mjpeg_escape_FF(PutBitContext *pb, int start)
uint8_t idct_permutation[64]
IDCT input permutation.
packed RGB 8:8:8, 24bpp, BGRBGR...
static const float pred[4]
#define FF_COMPLIANCE_UNOFFICIAL
Allow unofficial extensions.
void ff_mjpeg_encode_dc(PutBitContext *pb, int val, uint8_t *huff_size, uint16_t *huff_code)
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
main external API structure.
const uint8_t avpriv_mjpeg_val_dc[12]
void ff_mjpeg_init_hvsample(AVCodecContext *avctx, int hsample[3], int vsample[3])
BYTE int const BYTE int int int height
const uint8_t ff_zigzag_direct[64]
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
static enum AVPixelFormat pix_fmts[]
static int ljpeg_encode_yuv(AVCodecContext *avctx, PutBitContext *pb, const AVFrame *frame)
static int ljpeg_encode_bgr(AVCodecContext *avctx, PutBitContext *pb, const AVFrame *frame)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
the normal 219*2^(n-8) "MPEG" YUV ranges
uint16_t huff_code_dc_luminance[12]
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
#define FF_DISABLE_DEPRECATION_WARNINGS
common internal api header.
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]
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
attribute_deprecated AVFrame * coded_frame
the picture in the bitstream
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
static av_always_inline int diff(const uint32_t a, const uint32_t b)
av_cold void ff_init_scantable(uint8_t *permutation, ScanTable *st, const uint8_t *src_scantable)
static void ljpeg_encode_yuv_mb(LJpegEncContext *s, PutBitContext *pb, const AVFrame *frame, int predictor, int mb_x, int mb_y)
av_cold void ff_idctdsp_init(IDCTDSPContext *c, AVCodecContext *avctx)
#define FF_ENABLE_DEPRECATION_WARNINGS
int key_frame
1 -> keyframe, 0-> not
#define av_malloc_array(a, b)
AVPixelFormat
Pixel format.
This structure stores compressed data.
int strict_std_compliance
strictly follow the standard (MPEG4, ...).