summaryrefslogtreecommitdiff
path: root/libavcodec/mjpegenc_common.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michael@niedermayer.cc>2015-09-11 13:28:16 +0200
committerMichael Niedermayer <michael@niedermayer.cc>2015-09-11 13:45:29 +0200
commit8b72f6d50ba8cc43a45f1ffd9f9f4176addfa18c (patch)
tree42c46ae17f67bb671e744c162a069bba6984af1c /libavcodec/mjpegenc_common.c
parent055e56e9f76da3298f1b59bf5ea46f570e844600 (diff)
downloadffmpeg-8b72f6d50ba8cc43a45f1ffd9f9f4176addfa18c.tar.gz
avcodec/ljpegenc: Fix encoding RGBA LJPEG
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Diffstat (limited to 'libavcodec/mjpegenc_common.c')
-rw-r--r--libavcodec/mjpegenc_common.c28
1 files changed, 22 insertions, 6 deletions
diff --git a/libavcodec/mjpegenc_common.c b/libavcodec/mjpegenc_common.c
index 64e14253eb..d1d4cfb40a 100644
--- a/libavcodec/mjpegenc_common.c
+++ b/libavcodec/mjpegenc_common.c
@@ -159,7 +159,7 @@ static void jpeg_put_comments(AVCodecContext *avctx, PutBitContext *p)
}
}
-void ff_mjpeg_init_hvsample(AVCodecContext *avctx, int hsample[3], int vsample[3])
+void ff_mjpeg_init_hvsample(AVCodecContext *avctx, int hsample[4], int vsample[4])
{
int chroma_h_shift, chroma_v_shift;
@@ -171,7 +171,8 @@ void ff_mjpeg_init_hvsample(AVCodecContext *avctx, int hsample[3], int vsample[3
|| avctx->pix_fmt == AV_PIX_FMT_BGR24)) {
vsample[0] = hsample[0] =
vsample[1] = hsample[1] =
- vsample[2] = hsample[2] = 1;
+ vsample[2] = hsample[2] =
+ vsample[3] = hsample[3] = 1;
} else if (avctx->pix_fmt == AV_PIX_FMT_YUV444P || avctx->pix_fmt == AV_PIX_FMT_YUVJ444P) {
vsample[0] = vsample[1] = vsample[2] = 2;
hsample[0] = hsample[1] = hsample[2] = 1;
@@ -191,8 +192,9 @@ void ff_mjpeg_encode_picture_header(AVCodecContext *avctx, PutBitContext *pb,
uint16_t chroma_intra_matrix[64])
{
const int lossless = avctx->codec_id != AV_CODEC_ID_MJPEG && avctx->codec_id != AV_CODEC_ID_AMV;
- int hsample[3], vsample[3];
+ int hsample[4], vsample[4];
int i;
+ int components = 3 + (avctx->pix_fmt == AV_PIX_FMT_BGRA);
int chroma_matrix = !!memcmp(luma_intra_matrix,
chroma_intra_matrix,
sizeof(luma_intra_matrix[0])*64);
@@ -223,7 +225,7 @@ void ff_mjpeg_encode_picture_header(AVCodecContext *avctx, PutBitContext *pb,
put_bits(pb, 8, 8); /* 8 bits/component */
put_bits(pb, 16, avctx->height);
put_bits(pb, 16, avctx->width);
- put_bits(pb, 8, 3); /* 3 components */
+ put_bits(pb, 8, components); /* 3 or 4 components */
/* Y component */
put_bits(pb, 8, 1); /* component number */
@@ -243,10 +245,17 @@ void ff_mjpeg_encode_picture_header(AVCodecContext *avctx, PutBitContext *pb,
put_bits(pb, 4, vsample[2]); /* V factor */
put_bits(pb, 8, lossless ? 0 : chroma_matrix); /* select matrix */
+ if (components == 4) {
+ put_bits(pb, 8, 4); /* component number */
+ put_bits(pb, 4, hsample[3]); /* H factor */
+ put_bits(pb, 4, vsample[3]); /* V factor */
+ put_bits(pb, 8, 0); /* select matrix */
+ }
+
/* scan header */
put_marker(pb, SOS);
- put_bits(pb, 16, 12); /* length */
- put_bits(pb, 8, 3); /* 3 components */
+ put_bits(pb, 16, 6 + 2*components); /* length */
+ put_bits(pb, 8, components); /* 3 components */
/* Y component */
put_bits(pb, 8, 1); /* index */
@@ -263,6 +272,13 @@ void ff_mjpeg_encode_picture_header(AVCodecContext *avctx, PutBitContext *pb,
put_bits(pb, 4, 1); /* DC huffman table index */
put_bits(pb, 4, lossless ? 0 : 1); /* AC huffman table index */
+ if (components == 4) {
+ /* Alpha component */
+ put_bits(pb, 8, 4); /* index */
+ put_bits(pb, 4, 0); /* DC huffman table index */
+ put_bits(pb, 4, 0); /* AC huffman table index */
+ }
+
put_bits(pb, 8, lossless ? avctx->prediction_method + 1 : 0); /* Ss (not used) */
switch (avctx->codec_id) {