65 const int linesize =
frame->linesize[0];
66 uint16_t (*
buffer)[4] =
s->scratch;
67 int left[4], top[4], topleft[4];
70 for (
i = 0;
i < 4;
i++)
73 for (y = 0; y <
height; y++) {
74 const int modified_predictor = y ?
s->pred : 1;
75 const uint8_t *ptr =
frame->data[0] + (linesize * y);
82 for (
i = 0;
i < 4;
i++)
85 for (x = 0; x <
width; x++) {
87 buffer[x][1] = ptr[3 * x + 0] - ptr[3 * x + 1] + 0x100;
88 buffer[x][2] = ptr[3 * x + 2] - ptr[3 * x + 1] + 0x100;
89 buffer[x][0] = (ptr[3 * x + 0] + 2 * ptr[3 * x + 1] + ptr[3 * x + 2]) >> 2;
91 buffer[x][1] = ptr[4 * x + 0] - ptr[4 * x + 1] + 0x100;
92 buffer[x][2] = ptr[4 * x + 2] - ptr[4 * x + 1] + 0x100;
93 buffer[x][0] = (ptr[4 * x + 0] + 2 * ptr[4 * x + 1] + ptr[4 * x + 2]) >> 2;
95 buffer[x][3] = ptr[4 * x + 3];
110 if (
i == 0 ||
i == 3)
127 if (mb_x == 0 || mb_y == 0) {
128 for (
i = 0;
i < 3;
i++) {
130 int x, y,
h, v, linesize;
133 linesize =
frame->linesize[
i];
135 for (y = 0; y < v; y++) {
136 for (x = 0; x <
h; x++) {
139 ptr =
frame->data[
i] + (linesize * (v * mb_y + y)) + (
h * mb_x + x);
140 if (y == 0 && mb_y == 0) {
141 if (x == 0 && mb_x == 0)
146 if (x == 0 && mb_x == 0) {
147 pred = ptr[-linesize];
162 for (
i = 0;
i < 3;
i++) {
164 int x, y,
h, v, linesize;
167 linesize =
frame->linesize[
i];
169 for (y = 0; y < v; y++) {
170 for (x = 0; x <
h; x++) {
173 ptr =
frame->data[
i] + (linesize * (v * mb_y + y)) + (
h * mb_x + x);
190 const int mb_width = (avctx->
width +
s->hsample[0] - 1) /
s->hsample[0];
191 const int mb_height = (avctx->
height +
s->vsample[0] - 1) /
s->vsample[0];
194 for (mb_y = 0; mb_y < mb_height; mb_y++) {
196 mb_width * 4 * 3 *
s->hsample[0] *
s->vsample[0]) {
201 for (mb_x = 0; mb_x < mb_width; mb_x++)
209 const AVFrame *pict,
int *got_packet)
215 const int mb_width = (
width +
s->hsample[0] - 1) /
s->hsample[0];
216 const int mb_height = (
height +
s->vsample[0] - 1) /
s->vsample[0];
218 int ret, header_bits;
226 max_pkt_size += mb_width * mb_height * 3 * 4
227 *
s->hsample[0] *
s->vsample[0];
285 s->huff_code_dc_luminance,
289 s->huff_code_dc_chrominance,
296#define OFFSET(x) offsetof(LJpegEncContext, x)
297#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
308 .class_name =
"ljpeg",
const FFCodec ff_ljpeg_encoder
Libavcodec external API header.
static int BS_FUNC left(const BSCTX *bc)
Return the number of the bits left in a buffer.
#define i(width, name, range_min, range_max)
#define CODEC_PIXFMTS(...)
#define FF_CODEC_ENCODE_CB(func)
#define CODEC_LONG_NAME(str)
int ff_alloc_packet(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
Check AVPacket size and allocate data.
#define FF_INPUT_BUFFER_MIN_SIZE
Used by some encoders as upper bound for the length of headers.
static void predictor(uint8_t *src, ptrdiff_t size)
reference-counted frame API
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
#define LIBAVUTIL_VERSION_INT
FF_VISIBILITY_PUSH_HIDDEN const uint8_t ff_mjpeg_bits_dc_luminance[]
const uint8_t ff_mjpeg_bits_dc_chrominance[]
const uint8_t ff_mjpeg_val_dc[]
static int ljpeg_encode_bgr(AVCodecContext *avctx, PutBitContext *pb, const AVFrame *frame)
static av_cold int ljpeg_encode_close(AVCodecContext *avctx)
static av_cold int ljpeg_encode_init(AVCodecContext *avctx)
static void ljpeg_encode_yuv_mb(LJpegEncContext *s, PutBitContext *pb, const AVFrame *frame, int predictor, int mb_x, int mb_y)
static int ljpeg_encode_yuv(AVCodecContext *avctx, PutBitContext *pb, const AVFrame *frame)
static int ljpeg_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
static const AVClass ljpeg_class
Memory handling functions.
MJPEG encoder and decoder.
#define PREDICT(ret, topleft, top, left, predictor)
void ff_mjpeg_encode_dc(PutBitContext *pb, int val, const uint8_t huff_size[], const uint16_t huff_code[])
void ff_mjpeg_init_hvsample(const AVCodecContext *avctx, int hsample[4], int vsample[4])
void ff_mjpeg_encode_picture_header(AVCodecContext *avctx, PutBitContext *pb, const AVFrame *frame, const struct MJpegContext *m, const uint8_t intra_matrix_permutation[64], int pred, const uint16_t luma_intra_matrix[64], const uint16_t chroma_intra_matrix[64], int use_slices)
int ff_mjpeg_add_icc_profile_size(AVCodecContext *avctx, const AVFrame *frame, size_t *max_pkt_size)
int ff_mjpeg_encode_check_pix_fmt(AVCodecContext *avctx)
void ff_mjpeg_escape_FF(PutBitContext *pb, int start)
void ff_mjpeg_build_huffman_codes(uint8_t *huff_size, uint16_t *huff_code, const uint8_t *bits_table, const uint8_t *val_table)
void ff_mjpeg_encode_picture_trailer(PutBitContext *pb, int header_bits)
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
@ AVCOL_RANGE_JPEG
Full range content.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
static int put_bits_count(PutBitContext *s)
static int put_bytes_left(const PutBitContext *s, int round_up)
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
static int put_bytes_output(const PutBitContext *s)
static const float pred[4]
Describe the class of an AVClass context structure.
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
uint16_t huff_code_dc_chrominance[12]
uint8_t huff_size_dc_luminance[12]
uint8_t huff_size_dc_chrominance[12]
uint16_t huff_code_dc_luminance[12]
#define av_malloc_array(a, b)
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)