@@ -967,11 +967,6 @@ static int mjpeg_decode_scan(MJpegDecodeContext *s, int nb_components, int Ah,
967967 if (mb_bitmask )
968968 init_get_bits (& mb_bitmask_gb , mb_bitmask , s -> mb_width * s -> mb_height );
969969
970- if (s -> flipped && s -> avctx -> flags & CODEC_FLAG_EMU_EDGE ) {
971- av_log (s -> avctx , AV_LOG_ERROR ,
972- "Can not flip image with CODEC_FLAG_EMU_EDGE set!\n" );
973- s -> flipped = 0 ;
974- }
975970 if (s -> flipped && s -> avctx -> lowres ) {
976971 av_log (s -> avctx , AV_LOG_ERROR , "Can not flip image with lowres\n" );
977972 s -> flipped = 0 ;
@@ -983,7 +978,7 @@ static int mjpeg_decode_scan(MJpegDecodeContext *s, int nb_components, int Ah,
983978 reference_data [c ] = reference ? reference -> data [c ] : NULL ;
984979 linesize [c ] = s -> linesize [c ];
985980 s -> coefs_finished [c ] |= 1 ;
986- if (s -> flipped ) {
981+ if (s -> flipped && !( s -> avctx -> flags & CODEC_FLAG_EMU_EDGE ) ) {
987982 // picture should be flipped upside-down for this codec
988983 int offset = (linesize [c ] * (s -> v_scount [i ] *
989984 (8 * s -> mb_height - ((s -> height / s -> v_max ) & 7 )) - 1 ));
@@ -1795,6 +1790,29 @@ int ff_mjpeg_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
17951790 dst -= s -> linesize [s -> upscale_v ];
17961791 }
17971792 }
1793+ if (s -> flipped && (s -> avctx -> flags & CODEC_FLAG_EMU_EDGE )) {
1794+ int hshift , vshift , j ;
1795+ avcodec_get_chroma_sub_sample (s -> avctx -> pix_fmt , & hshift , & vshift );
1796+ for (index = 0 ; index < 4 ; index ++ ) {
1797+ uint8_t * dst = s -> picture_ptr -> data [index ];
1798+ int w = s -> width ;
1799+ int h = s -> height ;
1800+ if (index && index < 3 ){
1801+ w = - ((- w ) >> hshift );
1802+ h = - ((- h ) >> vshift );
1803+ }
1804+ if (dst ){
1805+ uint8_t * dst2 = dst + s -> linesize [index ]* (h - 1 );
1806+ for (i = 0 ; i < h /2 ; i ++ ) {
1807+ for (j = 0 ; j < w ; j ++ )
1808+ FFSWAP (int , dst [j ], dst2 [j ]);
1809+ dst += s -> linesize [index ];
1810+ dst2 -= s -> linesize [index ];
1811+ }
1812+ }
1813+ }
1814+ }
1815+
17981816 av_log (avctx , AV_LOG_DEBUG , "decode frame unused %td bytes\n" ,
17991817 buf_end - buf_ptr );
18001818// return buf_end - buf_ptr;
0 commit comments