Skip to content

Commit

Permalink
mjpeg: fix fliping with emu edges.
Browse files Browse the repository at this point in the history
Fixes Ticket121

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
  • Loading branch information
michaelni committed Aug 23, 2012
1 parent 628e6d0 commit 168ddcd
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions libavcodec/mjpegdec.c
Expand Up @@ -967,11 +967,6 @@ static int mjpeg_decode_scan(MJpegDecodeContext *s, int nb_components, int Ah,
if (mb_bitmask)
init_get_bits(&mb_bitmask_gb, mb_bitmask, s->mb_width * s->mb_height);

if (s->flipped && s->avctx->flags & CODEC_FLAG_EMU_EDGE) {
av_log(s->avctx, AV_LOG_ERROR,
"Can not flip image with CODEC_FLAG_EMU_EDGE set!\n");
s->flipped = 0;
}
if (s->flipped && s->avctx->lowres) {
av_log(s->avctx, AV_LOG_ERROR, "Can not flip image with lowres\n");
s->flipped = 0;
Expand All @@ -983,7 +978,7 @@ static int mjpeg_decode_scan(MJpegDecodeContext *s, int nb_components, int Ah,
reference_data[c] = reference ? reference->data[c] : NULL;
linesize[c] = s->linesize[c];
s->coefs_finished[c] |= 1;
if (s->flipped) {
if (s->flipped && !(s->avctx->flags & CODEC_FLAG_EMU_EDGE)) {
// picture should be flipped upside-down for this codec
int offset = (linesize[c] * (s->v_scount[i] *
(8 * s->mb_height - ((s->height / s->v_max) & 7)) - 1));
Expand Down Expand Up @@ -1795,6 +1790,29 @@ int ff_mjpeg_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
dst -= s->linesize[s->upscale_v];
}
}
if (s->flipped && (s->avctx->flags & CODEC_FLAG_EMU_EDGE)) {
int hshift, vshift, j;
avcodec_get_chroma_sub_sample(s->avctx->pix_fmt, &hshift, &vshift);
for (index=0; index<4; index++) {
uint8_t *dst = s->picture_ptr->data[index];
int w = s->width;
int h = s->height;
if(index && index<3){
w = -((-w) >> hshift);
h = -((-h) >> vshift);
}
if(dst){
uint8_t *dst2 = dst + s->linesize[index]*(h-1);
for (i=0; i<h/2; i++) {
for (j=0; j<w; j++)
FFSWAP(int, dst[j], dst2[j]);
dst += s->linesize[index];
dst2 -= s->linesize[index];
}
}
}
}

av_log(avctx, AV_LOG_DEBUG, "decode frame unused %td bytes\n",
buf_end - buf_ptr);
// return buf_end - buf_ptr;
Expand Down

0 comments on commit 168ddcd

Please sign in to comment.