Commit 2bb78759 authored by Baptiste Coudurier's avatar Baptiste Coudurier
Browse files

mjpeg 4:2:2 encoding support

Originally committed as revision 6550 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 938dd846
......@@ -613,7 +613,7 @@ static void encode_block(MpegEncContext *s, DCTELEM *block, int n)
uint16_t *huff_code_ac;
/* DC coef */
component = (n <= 3 ? 0 : n - 4 + 1);
component = (n <= 3 ? 0 : (n&1) + 1);
dc = block[0]; /* overflow is impossible */
val = dc - s->last_dc[component];
if (n < 4) {
......@@ -666,9 +666,16 @@ void mjpeg_encode_mb(MpegEncContext *s,
DCTELEM block[6][64])
{
int i;
for(i=0;i<6;i++) {
for(i=0;i<5;i++) {
encode_block(s, block[i], i);
}
if (s->chroma_format == CHROMA_420) {
encode_block(s, block[5], 5);
} else {
encode_block(s, block[6], 6);
encode_block(s, block[5], 5);
encode_block(s, block[7], 7);
}
}
static int encode_picture_lossless(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
......@@ -1103,7 +1110,7 @@ static int mjpeg_decode_dht(MJpegDecodeContext *s)
static int mjpeg_decode_sof(MJpegDecodeContext *s)
{
int len, nb_components, i, width, height;
int len, nb_components, i, width, height, pix_fmt_id;
/* XXX: verify len field validity */
len = get_bits(&s->gb, 16);
......@@ -1188,8 +1195,13 @@ static int mjpeg_decode_sof(MJpegDecodeContext *s)
return 0;
/* XXX: not complete test ! */
switch((s->h_count[0] << 4) | s->v_count[0]) {
case 0x11:
pix_fmt_id = (s->h_count[0] << 20) | (s->v_count[0] << 16) |
(s->h_count[1] << 12) | (s->v_count[1] << 8) |
(s->h_count[2] << 4) | s->v_count[2];
dprintf("pix fmt id %x\n", pix_fmt_id);
switch(pix_fmt_id){
case 0x222222:
case 0x111111:
if(s->rgb){
s->avctx->pix_fmt = PIX_FMT_RGBA32;
}else if(s->nb_components==3)
......@@ -1197,11 +1209,12 @@ static int mjpeg_decode_sof(MJpegDecodeContext *s)
else
s->avctx->pix_fmt = PIX_FMT_GRAY8;
break;
case 0x21:
case 0x211111:
case 0x221212:
s->avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV422P : PIX_FMT_YUVJ422P;
break;
default:
case 0x22:
case 0x221111:
s->avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV420P : PIX_FMT_YUVJ420P;
break;
}
......
......@@ -940,7 +940,8 @@ int MPV_encode_init(AVCodecContext *avctx)
break;
case CODEC_ID_LJPEG:
case CODEC_ID_MJPEG:
if(avctx->pix_fmt != PIX_FMT_YUVJ420P && (avctx->pix_fmt != PIX_FMT_YUV420P || avctx->strict_std_compliance>FF_COMPLIANCE_INOFFICIAL)){
if(avctx->pix_fmt != PIX_FMT_YUVJ420P && avctx->pix_fmt != PIX_FMT_YUVJ422P &&
((avctx->pix_fmt != PIX_FMT_YUV420P && avctx->pix_fmt != PIX_FMT_YUV422P) || avctx->strict_std_compliance>FF_COMPLIANCE_INOFFICIAL)){
av_log(avctx, AV_LOG_ERROR, "colorspace not supported in jpeg\n");
return -1;
}
......@@ -1182,12 +1183,12 @@ int MPV_encode_init(AVCodecContext *avctx)
s->intra_only = 1; /* force intra only for jpeg */
s->mjpeg_write_tables = avctx->codec->id != CODEC_ID_JPEGLS;
s->mjpeg_data_only_frames = 0; /* write all the needed headers */
s->mjpeg_vsample[0] = 1<<chroma_v_shift;
s->mjpeg_vsample[1] = 1;
s->mjpeg_vsample[2] = 1;
s->mjpeg_hsample[0] = 1<<chroma_h_shift;
s->mjpeg_hsample[1] = 1;
s->mjpeg_hsample[2] = 1;
s->mjpeg_vsample[0] = 2;
s->mjpeg_vsample[1] = 2>>chroma_v_shift;
s->mjpeg_vsample[2] = 2>>chroma_v_shift;
s->mjpeg_hsample[0] = 2;
s->mjpeg_hsample[1] = 2>>chroma_h_shift;
s->mjpeg_hsample[2] = 2>>chroma_h_shift;
if (mjpeg_init(s) < 0)
return -1;
avctx->delay=0;
......@@ -6842,7 +6843,7 @@ AVCodec mjpeg_encoder = {
MPV_encode_init,
MPV_encode_picture,
MPV_encode_end,
.pix_fmts= (enum PixelFormat[]){PIX_FMT_YUVJ420P, -1},
.pix_fmts= (enum PixelFormat[]){PIX_FMT_YUVJ420P, PIX_FMT_YUVJ422P, -1},
};
#endif //CONFIG_ENCODERS
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment