OSDN Git Service

Merge remote-tracking branch 'qatar/master'
authorMichael Niedermayer <michaelni@gmx.at>
Thu, 23 Feb 2012 01:33:21 +0000 (02:33 +0100)
committerMichael Niedermayer <michaelni@gmx.at>
Thu, 23 Feb 2012 03:31:55 +0000 (04:31 +0100)
* qatar/master:
  dxva2: don't check for DXVA_PictureParameters->wDecodedPictureIndex
  img2: split muxer and demuxer into separate files
  rm: prevent infinite loops for index parsing.
  aac: fix infinite loop on end-of-frame with sequence of 1-bits.
  mov: Add more HDV and XDCAM FourCCs.
  lavf: don't set AVCodecContext.has_b_frames in compute_pkt_fields().
  rmdec: when using INT4 deinterleaving, error out if sub_packet_h <= 1.
  cdxl: correctly synchronize video timestamps to audio
  mlpdec_parser: fix a few channel layouts.
  Add channel names to channel_names[] array for channels added in b2890f5
  movenc: Buffer the mdat for the initial moov fragment, too
  flvdec: Ignore the index if the ignidx flag is set
  flvdec: Fix indentation
  movdec: Don't parse all fragments if ignidx is set
  movdec: Restart parsing root-level atoms at the right spot
  prores: use natural integer type for the codebook index
  mov: Add support for MPEG2 HDV 720p24 (hdv4)
  swscale: K&R formatting cosmetics (part I)
  swscale: variable declaration and placement cosmetics

Conflicts:
configure
libavcodec/aacdec.c
libavcodec/mlp_parser.c
libavformat/flvdec.c
libavformat/img2.c
libavformat/isom.h
libavformat/mov.c
libavformat/movenc.c
libswscale/rgb2rgb.c
libswscale/rgb2rgb_template.c
libswscale/yuv2rgb.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
20 files changed:
1  2 
libavcodec/aacdec.c
libavcodec/mlp_parser.c
libavcodec/proresdec_lgpl.c
libavcodec/proresenc_kostya.c
libavformat/Makefile
libavformat/flvdec.c
libavformat/img2.c
libavformat/img2dec.c
libavformat/img2enc.c
libavformat/isom.c
libavformat/isom.h
libavformat/mov.c
libavformat/movenc.c
libavformat/movenc.h
libavformat/rmdec.c
libavutil/audioconvert.c
libswscale/options.c
libswscale/rgb2rgb.c
libswscale/rgb2rgb_template.c
libswscale/yuv2rgb.c

Simple merge
@@@ -82,9 -82,9 +82,9 @@@ static const uint64_t thd_layout[13] = 
      AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER, // LRc
      AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT,                       // LRrs
      AV_CH_BACK_CENTER,                                      // Cs
 -    AV_CH_TOP_BACK_CENTER,                                  // Ts
 -    AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT,                       // LRsd
 +    AV_CH_TOP_CENTER,                                       // Ts
 +    AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT,                       // LRsd - TODO: Surround Direct
-     AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER, // LRw  - TODO: Wide
+     AV_CH_WIDE_LEFT|AV_CH_WIDE_RIGHT,                       // LRw
      AV_CH_TOP_FRONT_CENTER,                                 // Cvh
      AV_CH_LOW_FREQUENCY                                     // LFE2
  };
@@@ -107,9 -107,10 +107,10 @@@ static int truehd_channels(int chanmap
      return channels;
  }
  
 -static uint64_t truehd_layout(int chanmap)
 +uint64_t ff_truehd_layout(int chanmap)
  {
-     int layout = 0, i;
+     int i;
+     uint64_t layout = 0;
  
      for (i = 0; i < 13; i++)
          layout |= thd_layout[i] * ((chanmap >> i) & 1);
Simple merge
Simple merge
@@@ -115,14 -104,12 +115,14 @@@ OBJS-$(CONFIG_H263_MUXER
  OBJS-$(CONFIG_H264_DEMUXER)              += h264dec.o rawdec.o
  OBJS-$(CONFIG_H264_MUXER)                += rawenc.o
  OBJS-$(CONFIG_HLS_DEMUXER)               += hls.o
 +OBJS-$(CONFIG_ICO_DEMUXER)               += icodec.o
  OBJS-$(CONFIG_IDCIN_DEMUXER)             += idcin.o
 +OBJS-$(CONFIG_IDF_DEMUXER)               += bintext.o
  OBJS-$(CONFIG_IFF_DEMUXER)               += iff.o
- OBJS-$(CONFIG_IMAGE2_DEMUXER)            += img2.o
- OBJS-$(CONFIG_IMAGE2_MUXER)              += img2.o
- OBJS-$(CONFIG_IMAGE2PIPE_DEMUXER)        += img2.o
- OBJS-$(CONFIG_IMAGE2PIPE_MUXER)          += img2.o
+ OBJS-$(CONFIG_IMAGE2_DEMUXER)            += img2dec.o img2.o
+ OBJS-$(CONFIG_IMAGE2_MUXER)              += img2enc.o img2.o
+ OBJS-$(CONFIG_IMAGE2PIPE_DEMUXER)        += img2dec.o img2.o
+ OBJS-$(CONFIG_IMAGE2PIPE_MUXER)          += img2enc.o img2.o
  OBJS-$(CONFIG_INGENIENT_DEMUXER)         += ingenientdec.o rawdec.o
  OBJS-$(CONFIG_IPMOVIE_DEMUXER)           += ipmovie.o
  OBJS-$(CONFIG_ISS_DEMUXER)               += iss.o
@@@ -149,9 -157,11 +149,12 @@@ static int parse_keyframes_index(AVForm
          return 0;
      }
  
+     if (s->flags & AVFMT_FLAG_IGNIDX)
+         return 0;
      while (avio_tell(ioc) < max_pos - 2 && amf_get_string(ioc, str_val, sizeof(str_val)) > 0) {
 -        int64_t* current_array;
 +        int64_t** current_array;
 +        unsigned int arraylen;
  
          // Expect array object in context
          if (avio_r8(ioc) != AMF_DATA_TYPE_ARRAY)
          }
      }
  
 -    if (!ret && timeslen == fileposlen)
 -        for (i = 0; i < fileposlen; i++)
 +    if (timeslen == fileposlen && fileposlen>1 && max_pos <= filepositions[0]) {
 +        int64_t dts, size0, size1;
 +        avio_seek(ioc, filepositions[1]-4, SEEK_SET);
 +        size0 = avio_rb32(ioc);
 +                avio_r8(ioc);
 +        size1 = avio_rb24(ioc);
 +        dts   = avio_rb24(ioc);
 +        dts  |= avio_r8(ioc) << 24;
 +        if (size0 > filepositions[1] || FFABS(dts - times[1]*1000)>5000/*arbitraray threshold to detect invalid index*/)
 +            goto invalid;
-          for(i = 0; i < timeslen; i++)
-              av_add_index_entry(vstream, filepositions[i], times[i]*1000, 0, 0, AVINDEX_KEYFRAME);
++        for(i = 0; i < timeslen; i++)
+             av_add_index_entry(vstream, filepositions[i], times[i]*1000,
+                                0, 0, AVINDEX_KEYFRAME);
 -    else
 +    } else {
 +invalid:
          av_log(s, AV_LOG_WARNING, "Invalid keyframes object, skipping.\n");
 +    }
  
  finish:
      av_freep(&times);
Simple merge
index 0000000,b4b9723..e8b695f
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,322 +1,327 @@@
 - * This file is part of Libav.
+ /*
+  * Image format
+  * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
+  * Copyright (c) 2004 Michael Niedermayer
+  *
 - * Libav is free software; you can redistribute it and/or
++ * This file is part of FFmpeg.
+  *
 - * Libav is distributed in the hope that it will be useful,
++ * FFmpeg is free software; you can redistribute it and/or
+  * modify it under the terms of the GNU Lesser General Public
+  * License as published by the Free Software Foundation; either
+  * version 2.1 of the License, or (at your option) any later version.
+  *
 - * License along with Libav; if not, write to the Free Software
++ * FFmpeg is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
 -            if(codec->codec_id != CODEC_ID_RAWVIDEO)
++ * License along with FFmpeg; if not, write to the Free Software
+  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+  */
+ #include "libavutil/avstring.h"
+ #include "libavutil/log.h"
+ #include "libavutil/opt.h"
+ #include "libavutil/pixdesc.h"
+ #include "libavutil/parseutils.h"
+ #include "avformat.h"
+ #include "internal.h"
+ typedef struct {
+     const AVClass *class;  /**< Class for private options. */
+     int img_first;
+     int img_last;
+     int img_number;
+     int img_count;
+     int is_pipe;
++    int split_planes;       /**< use independent file for each Y, U, V plane */
+     char path[1024];
+     char *pixel_format;     /**< Set by a private option. */
+     char *video_size;       /**< Set by a private option. */
+     char *framerate;        /**< Set by a private option. */
+     int loop;
+ } VideoDemuxData;
+ static const int sizes[][2] = {
+     { 640, 480 },
+     { 720, 480 },
+     { 720, 576 },
+     { 352, 288 },
+     { 352, 240 },
+     { 160, 128 },
+     { 512, 384 },
+     { 640, 352 },
+     { 640, 240 },
+ };
+ static int infer_size(int *width_ptr, int *height_ptr, int size)
+ {
+     int i;
+     for(i=0;i<FF_ARRAY_ELEMS(sizes);i++) {
+         if ((sizes[i][0] * sizes[i][1]) == size) {
+             *width_ptr = sizes[i][0];
+             *height_ptr = sizes[i][1];
+             return 0;
+         }
+     }
+     return -1;
+ }
+ /* return -1 if no image found */
+ static int find_image_range(int *pfirst_index, int *plast_index,
+                             const char *path)
+ {
+     char buf[1024];
+     int range, last_index, range1, first_index;
+     /* find the first image */
+     for(first_index = 0; first_index < 5; first_index++) {
+         if (av_get_frame_filename(buf, sizeof(buf), path, first_index) < 0){
+             *pfirst_index =
+             *plast_index = 1;
+             if (avio_check(buf, AVIO_FLAG_READ) > 0)
+                 return 0;
+             return -1;
+         }
+         if (avio_check(buf, AVIO_FLAG_READ) > 0)
+             break;
+     }
+     if (first_index == 5)
+         goto fail;
+     /* find the last image */
+     last_index = first_index;
+     for(;;) {
+         range = 0;
+         for(;;) {
+             if (!range)
+                 range1 = 1;
+             else
+                 range1 = 2 * range;
+             if (av_get_frame_filename(buf, sizeof(buf), path,
+                                       last_index + range1) < 0)
+                 goto fail;
+             if (avio_check(buf, AVIO_FLAG_READ) <= 0)
+                 break;
+             range = range1;
+             /* just in case... */
+             if (range >= (1 << 30))
+                 goto fail;
+         }
+         /* we are sure than image last_index + range exists */
+         if (!range)
+             break;
+         last_index += range;
+     }
+     *pfirst_index = first_index;
+     *plast_index = last_index;
+     return 0;
+  fail:
+     return -1;
+ }
+ static int read_probe(AVProbeData *p)
+ {
+     if (p->filename && ff_guess_image2_codec(p->filename)) {
+         if (av_filename_number_test(p->filename))
+             return AVPROBE_SCORE_MAX;
+         else
+             return AVPROBE_SCORE_MAX/2;
+     }
+     return 0;
+ }
+ static int read_header(AVFormatContext *s1)
+ {
+     VideoDemuxData *s = s1->priv_data;
+     int first_index, last_index, ret = 0;
+     int width = 0, height = 0;
+     AVStream *st;
+     enum PixelFormat pix_fmt = PIX_FMT_NONE;
+     AVRational framerate;
+     s1->ctx_flags |= AVFMTCTX_NOHEADER;
+     st = avformat_new_stream(s1, NULL);
+     if (!st) {
+         return AVERROR(ENOMEM);
+     }
+     if (s->pixel_format && (pix_fmt = av_get_pix_fmt(s->pixel_format)) == PIX_FMT_NONE) {
+         av_log(s1, AV_LOG_ERROR, "No such pixel format: %s.\n", s->pixel_format);
+         return AVERROR(EINVAL);
+     }
+     if (s->video_size && (ret = av_parse_video_size(&width, &height, s->video_size)) < 0) {
+         av_log(s, AV_LOG_ERROR, "Could not parse video size: %s.\n", s->video_size);
+         return ret;
+     }
+     if ((ret = av_parse_video_rate(&framerate, s->framerate)) < 0) {
+         av_log(s, AV_LOG_ERROR, "Could not parse framerate: %s.\n", s->framerate);
+         return ret;
+     }
+     av_strlcpy(s->path, s1->filename, sizeof(s->path));
+     s->img_number = 0;
+     s->img_count = 0;
+     /* find format */
+     if (s1->iformat->flags & AVFMT_NOFILE)
+         s->is_pipe = 0;
+     else{
+         s->is_pipe = 1;
+         st->need_parsing = AVSTREAM_PARSE_FULL;
+     }
+     avpriv_set_pts_info(st, 60, framerate.den, framerate.num);
+     if (width && height) {
+         st->codec->width  = width;
+         st->codec->height = height;
+     }
+     if (!s->is_pipe) {
+         if (find_image_range(&first_index, &last_index, s->path) < 0)
+             return AVERROR(ENOENT);
+         s->img_first = first_index;
+         s->img_last = last_index;
+         s->img_number = first_index;
+         /* compute duration */
+         st->start_time = 0;
+         st->duration = last_index - first_index + 1;
+     }
+     if(s1->video_codec_id){
+         st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
+         st->codec->codec_id = s1->video_codec_id;
+     }else if(s1->audio_codec_id){
+         st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
+         st->codec->codec_id = s1->audio_codec_id;
+     }else{
++        const char *str= strrchr(s->path, '.');
++        s->split_planes = str && !av_strcasecmp(str + 1, "y");
+         st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
+         st->codec->codec_id = ff_guess_image2_codec(s->path);
++        if (st->codec->codec_id == CODEC_ID_LJPEG)
++            st->codec->codec_id = CODEC_ID_MJPEG;
+     }
+     if(st->codec->codec_type == AVMEDIA_TYPE_VIDEO && pix_fmt != PIX_FMT_NONE)
+         st->codec->pix_fmt = pix_fmt;
+     return 0;
+ }
+ static int read_packet(AVFormatContext *s1, AVPacket *pkt)
+ {
+     VideoDemuxData *s = s1->priv_data;
+     char filename[1024];
+     int i;
+     int size[3]={0}, ret[3]={0};
+     AVIOContext *f[3];
+     AVCodecContext *codec= s1->streams[0]->codec;
+     if (!s->is_pipe) {
+         /* loop over input */
+         if (s->loop && s->img_number > s->img_last) {
+             s->img_number = s->img_first;
+         }
+         if (s->img_number > s->img_last)
+             return AVERROR_EOF;
+         if (av_get_frame_filename(filename, sizeof(filename),
+                                   s->path, s->img_number)<0 && s->img_number > 1)
+             return AVERROR(EIO);
+         for(i=0; i<3; i++){
+             if (avio_open2(&f[i], filename, AVIO_FLAG_READ,
+                            &s1->interrupt_callback, NULL) < 0) {
+                 if(i==1)
+                     break;
+                 av_log(s1, AV_LOG_ERROR, "Could not open file : %s\n",filename);
+                 return AVERROR(EIO);
+             }
+             size[i]= avio_size(f[i]);
 -        if (f[0]->eof_reached)
++            if(!s->split_planes)
+                 break;
+             filename[ strlen(filename) - 1 ]= 'U' + i;
+         }
+         if(codec->codec_id == CODEC_ID_RAWVIDEO && !codec->width)
+             infer_size(&codec->width, &codec->height, size[0]);
+     } else {
+         f[0] = s1->pb;
++        if (url_feof(f[0]))
+             return AVERROR(EIO);
+         size[0]= 4096;
+     }
+     av_new_packet(pkt, size[0] + size[1] + size[2]);
+     pkt->stream_index = 0;
+     pkt->flags |= AV_PKT_FLAG_KEY;
+     pkt->size= 0;
+     for(i=0; i<3; i++){
+         if(size[i]){
+             ret[i]= avio_read(f[i], pkt->data + pkt->size, size[i]);
+             if (!s->is_pipe)
+                 avio_close(f[i]);
+             if(ret[i]>0)
+                 pkt->size += ret[i];
+         }
+     }
+     if (ret[0] <= 0 || ret[1]<0 || ret[2]<0) {
+         av_free_packet(pkt);
+         return AVERROR(EIO); /* signal EOF */
+     } else {
+         s->img_count++;
+         s->img_number++;
+         return 0;
+     }
+ }
+ #define OFFSET(x) offsetof(VideoDemuxData, x)
+ #define DEC AV_OPT_FLAG_DECODING_PARAM
+ static const AVOption options[] = {
+     { "pixel_format", "", OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
+     { "video_size",   "", OFFSET(video_size),   AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
+     { "framerate",    "", OFFSET(framerate),    AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0, DEC },
+     { "loop",         "", OFFSET(loop),         AV_OPT_TYPE_INT,    {.dbl = 0},    0, 1, DEC },
+     { NULL },
+ };
+ #if CONFIG_IMAGE2_DEMUXER
+ static const AVClass img2_class = {
+     .class_name = "image2 demuxer",
+     .item_name  = av_default_item_name,
+     .option     = options,
+     .version    = LIBAVUTIL_VERSION_INT,
+ };
+ AVInputFormat ff_image2_demuxer = {
+     .name           = "image2",
+     .long_name      = NULL_IF_CONFIG_SMALL("image2 sequence"),
+     .priv_data_size = sizeof(VideoDemuxData),
+     .read_probe     = read_probe,
+     .read_header    = read_header,
+     .read_packet    = read_packet,
+     .flags          = AVFMT_NOFILE,
+     .priv_class     = &img2_class,
+ };
+ #endif
+ #if CONFIG_IMAGE2PIPE_DEMUXER
+ static const AVClass img2pipe_class = {
+     .class_name = "image2pipe demuxer",
+     .item_name  = av_default_item_name,
+     .option     = options,
+     .version    = LIBAVUTIL_VERSION_INT,
+ };
+ AVInputFormat ff_image2pipe_demuxer = {
+     .name           = "image2pipe",
+     .long_name      = NULL_IF_CONFIG_SMALL("piped image2 sequence"),
+     .priv_data_size = sizeof(VideoDemuxData),
+     .read_header    = read_header,
+     .read_packet    = read_packet,
+     .priv_class     = &img2pipe_class,
+ };
+ #endif
index 0000000,8fbe37e..9b4b30e
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,151 +1,175 @@@
 - * This file is part of Libav.
+ /*
+  * Image format
+  * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
+  * Copyright (c) 2004 Michael Niedermayer
+  *
 - * Libav is free software; you can redistribute it and/or
++ * This file is part of FFmpeg.
+  *
 - * Libav is distributed in the hope that it will be useful,
++ * FFmpeg is free software; you can redistribute it and/or
+  * modify it under the terms of the GNU Lesser General Public
+  * License as published by the Free Software Foundation; either
+  * version 2.1 of the License, or (at your option) any later version.
+  *
 - * License along with Libav; if not, write to the Free Software
++ * FFmpeg is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
 -                                  img->path, img->img_number) < 0 && img->img_number>1) {
++ * License along with FFmpeg; if not, write to the Free Software
+  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+  */
+ #include "libavutil/intreadwrite.h"
+ #include "libavutil/avstring.h"
+ #include "libavutil/log.h"
++#include "libavutil/opt.h"
+ #include "avformat.h"
+ #include "avio_internal.h"
+ #include "internal.h"
+ typedef struct {
++    const AVClass *class;  /**< Class for private options. */
+     int img_number;
+     int is_pipe;
++    int split_planes;       /**< use independent file for each Y, U, V plane */
+     char path[1024];
++    int updatefirst;
+ } VideoMuxData;
+ static int write_header(AVFormatContext *s)
+ {
+     VideoMuxData *img = s->priv_data;
++    const char *str;
+     img->img_number = 1;
+     av_strlcpy(img->path, s->filename, sizeof(img->path));
+     /* find format */
+     if (s->oformat->flags & AVFMT_NOFILE)
+         img->is_pipe = 0;
+     else
+         img->is_pipe = 1;
++    str = strrchr(img->path, '.');
++    img->split_planes = str && !av_strcasecmp(str + 1, "y");
+     return 0;
+ }
+ static int write_packet(AVFormatContext *s, AVPacket *pkt)
+ {
+     VideoMuxData *img = s->priv_data;
+     AVIOContext *pb[3];
+     char filename[1024];
+     AVCodecContext *codec= s->streams[ pkt->stream_index ]->codec;
+     int i;
+     if (!img->is_pipe) {
+         if (av_get_frame_filename(filename, sizeof(filename),
 -            return AVERROR(EIO);
++                                  img->path, img->img_number) < 0 && img->img_number>1 && !img->updatefirst) {
+             av_log(s, AV_LOG_ERROR,
+                    "Could not get frame filename number %d from pattern '%s'\n",
+                    img->img_number, img->path);
 -            if(codec->codec_id != CODEC_ID_RAWVIDEO)
++            return AVERROR(EINVAL);
+         }
+         for(i=0; i<3; i++){
+             if (avio_open2(&pb[i], filename, AVIO_FLAG_WRITE,
+                            &s->interrupt_callback, NULL) < 0) {
+                 av_log(s, AV_LOG_ERROR, "Could not open file : %s\n",filename);
+                 return AVERROR(EIO);
+             }
 -    if(codec->codec_id == CODEC_ID_RAWVIDEO){
++            if(!img->split_planes)
+                 break;
+             filename[ strlen(filename) - 1 ]= 'U' + i;
+         }
+     } else {
+         pb[0] = s->pb;
+     }
 -                av_log(s, AV_LOG_ERROR, "malformed JPEG 2000 codestream\n");
++    if(img->split_planes){
+         int ysize = codec->width * codec->height;
+         avio_write(pb[0], pkt->data        , ysize);
+         avio_write(pb[1], pkt->data + ysize, (pkt->size - ysize)/2);
+         avio_write(pb[2], pkt->data + ysize +(pkt->size - ysize)/2, (pkt->size - ysize)/2);
+         avio_flush(pb[1]);
+         avio_flush(pb[2]);
+         avio_close(pb[1]);
+         avio_close(pb[2]);
+     }else{
+         if(ff_guess_image2_codec(s->filename) == CODEC_ID_JPEG2000){
+             AVStream *st = s->streams[0];
+             if(st->codec->extradata_size > 8 &&
+                AV_RL32(st->codec->extradata+4) == MKTAG('j','p','2','h')){
+                 if(pkt->size < 8 || AV_RL32(pkt->data+4) != MKTAG('j','p','2','c'))
+                     goto error;
+                 avio_wb32(pb[0], 12);
+                 ffio_wfourcc(pb[0], "jP  ");
+                 avio_wb32(pb[0], 0x0D0A870A); // signature
+                 avio_wb32(pb[0], 20);
+                 ffio_wfourcc(pb[0], "ftyp");
+                 ffio_wfourcc(pb[0], "jp2 ");
+                 avio_wb32(pb[0], 0);
+                 ffio_wfourcc(pb[0], "jp2 ");
+                 avio_write(pb[0], st->codec->extradata, st->codec->extradata_size);
++            }else if(pkt->size >= 8 && AV_RB32(pkt->data) == 0xFF4FFF51){
++                //jpeg2000 codestream
+             }else if(pkt->size < 8 ||
+                      (!st->codec->extradata_size &&
+                       AV_RL32(pkt->data+4) != MKTAG('j','P',' ',' '))){ // signature
+             error:
 -    .extensions     = "bmp,dpx,jpeg,jpg,ljpg,pam,pbm,pcx,pgm,pgmyuv,png,"
 -                      "ppm,sgi,tga,tif,tiff,jp2,xwd,sun,ras,rs,im1,im8,im24,"
++                av_log(s, AV_LOG_ERROR, "malformed JPEG 2000 codestream %X\n", AV_RB32(pkt->data));
+                 return -1;
+             }
+         }
+         avio_write(pb[0], pkt->data, pkt->size);
+     }
+     avio_flush(pb[0]);
+     if (!img->is_pipe) {
+         avio_close(pb[0]);
+     }
+     img->img_number++;
+     return 0;
+ }
++#define OFFSET(x) offsetof(VideoMuxData, x)
++#define ENC AV_OPT_FLAG_ENCODING_PARAM
++static const AVOption muxoptions[] = {
++    { "updatefirst",  "", OFFSET(updatefirst),  AV_OPT_TYPE_INT,    {.dbl = 0},    0, 1, ENC },
++    { NULL },
++};
++
++
+ #if CONFIG_IMAGE2_MUXER
++static const AVClass img2mux_class = {
++    .class_name = "image2 muxer",
++    .item_name  = av_default_item_name,
++    .option     = muxoptions,
++    .version    = LIBAVUTIL_VERSION_INT,
++};
+ AVOutputFormat ff_image2_muxer = {
+     .name           = "image2",
+     .long_name      = NULL_IF_CONFIG_SMALL("image2 sequence"),
 -    .flags          = AVFMT_NOTIMESTAMPS | AVFMT_NODIMENSIONS | AVFMT_NOFILE
++    .extensions     = "bmp,dpx,jls,jpeg,jpg,ljpg,pam,pbm,pcx,pgm,pgmyuv,png,"
++                      "ppm,sgi,tga,tif,tiff,jp2,j2c,xwd,sun,ras,rs,im1,im8,im24,"
+                       "sunras",
+     .priv_data_size = sizeof(VideoMuxData),
+     .video_codec    = CODEC_ID_MJPEG,
+     .write_header   = write_header,
+     .write_packet   = write_packet,
++    .flags          = AVFMT_NOTIMESTAMPS | AVFMT_NODIMENSIONS | AVFMT_NOFILE,
++    .priv_class     = &img2mux_class,
+ };
+ #endif
+ #if CONFIG_IMAGE2PIPE_MUXER
+ AVOutputFormat ff_image2pipe_muxer = {
+     .name           = "image2pipe",
+     .long_name      = NULL_IF_CONFIG_SMALL("piped image2 sequence"),
+     .priv_data_size = sizeof(VideoMuxData),
+     .video_codec    = CODEC_ID_MJPEG,
+     .write_header   = write_header,
+     .write_packet   = write_packet,
+     .flags          = AVFMT_NOTIMESTAMPS | AVFMT_NODIMENSIONS
+ };
+ #endif
Simple merge
@@@ -147,7 -143,7 +147,8 @@@ typedef struct MOVContext 
      unsigned trex_count;
      int itunes_metadata;  ///< metadata are itunes style
      int chapter_track;
 +    int use_absolute_path;
+     int64_t next_root_atom; ///< offset of the next root atom
  } MOVContext;
  
  int ff_mp4_read_descr_len(AVIOContext *pb);
@@@ -2821,9 -2671,12 +2825,12 @@@ static int mov_read_packet(AVFormatCont
      sample = mov_find_next_sample(s, &st);
      if (!sample) {
          mov->found_mdat = 0;
-         if (s->pb->seekable||
-             mov_read_default(mov, s->pb, (MOVAtom){ AV_RL32("root"), INT64_MAX }) < 0 ||
+         if (!mov->next_root_atom)
+             return AVERROR_EOF;
+         avio_seek(s->pb, mov->next_root_atom, SEEK_SET);
+         mov->next_root_atom = 0;
+         if (mov_read_default(mov, s->pb, (MOVAtom){ AV_RL32("root"), INT64_MAX }) < 0 ||
 -            s->pb->eof_reached)
 +            url_feof(s->pb))
              return AVERROR_EOF;
          av_dlog(s, "read fragments, offset 0x%"PRIx64"\n", avio_tell(s->pb));
          goto retry;
@@@ -94,14 -93,12 +94,14 @@@ static int mov_write_stco_tag(AVIOConte
      } else
          ffio_wfourcc(pb, "stco");
      avio_wb32(pb, 0); /* version & flags */
 -    avio_wb32(pb, track->entry); /* entry count */
 +    avio_wb32(pb, track->chunkCount); /* entry count */
      for (i=0; i<track->entry; i++) {
 +        if(!track->cluster[i].chunkNum)
 +            continue;
          if(mode64 == 1)
-             avio_wb64(pb, track->cluster[i].pos);
+             avio_wb64(pb, track->cluster[i].pos + track->data_offset);
          else
-             avio_wb32(pb, track->cluster[i].pos);
+             avio_wb32(pb, track->cluster[i].pos + track->data_offset);
      }
      return update_size(pb, pos);
  }
@@@ -2030,27 -1996,6 +2030,29 @@@ static int mov_write_uuidusmt_tag(AVIOC
      return 0;
  }
  
 +static void build_chunks(MOVTrack *trk)
 +{
 +    int i;
 +    MOVIentry *chunk= &trk->cluster[0];
 +    uint64_t chunkSize = chunk->size;
 +    chunk->chunkNum= 1;
++    if (trk->chunkCount)
++        return;
 +    trk->chunkCount= 1;
 +    for(i=1; i<trk->entry; i++){
 +        if(chunk->pos + chunkSize == trk->cluster[i].pos &&
 +            chunkSize + trk->cluster[i].size < (1<<20)){
 +            chunkSize             += trk->cluster[i].size;
 +            chunk->samples_in_chunk += trk->cluster[i].entries;
 +        }else{
 +            trk->cluster[i].chunkNum = chunk->chunkNum+1;
 +            chunk=&trk->cluster[i];
 +            chunkSize = chunk->size;
 +            trk->chunkCount++;
 +        }
 +    }
 +}
 +
  static int mov_write_moov_tag(AVIOContext *pb, MOVMuxContext *mov,
                                AVFormatContext *s)
  {
@@@ -3181,23 -3149,11 +3216,16 @@@ static int mov_write_header(AVFormatCon
                              FF_MOV_FLAG_FRAG_CUSTOM)) &&
              !mov->max_fragment_duration && !mov->max_fragment_size)
              mov->max_fragment_duration = 5000000;
-         mov->flags |= FF_MOV_FLAG_EMPTY_MOOV | FF_MOV_FLAG_SEPARATE_MOOF;
+         mov->flags |= FF_MOV_FLAG_EMPTY_MOOV | FF_MOV_FLAG_SEPARATE_MOOF |
+                       FF_MOV_FLAG_FRAGMENT;
      }
  
-     /* Set the FRAGMENT flag if any of the fragmentation methods are
-      * enabled. */
-     if (mov->max_fragment_duration || mov->max_fragment_size ||
-         mov->flags & (FF_MOV_FLAG_EMPTY_MOOV |
-                       FF_MOV_FLAG_FRAG_KEYFRAME |
-                       FF_MOV_FLAG_FRAG_CUSTOM))
-         mov->flags |= FF_MOV_FLAG_FRAGMENT;
-     if (!(mov->flags & FF_MOV_FLAG_EMPTY_MOOV))
 +    if(mov->reserved_moov_size){
 +        mov->reserved_moov_pos= avio_tell(pb);
 +        avio_skip(pb, mov->reserved_moov_size);
 +    }
 +
+     if (!(mov->flags & FF_MOV_FLAG_FRAGMENT))
          mov_write_mdat_tag(pb, mov);
  
      if (t = av_dict_get(s->metadata, "creation_time", NULL, 0))
Simple merge
Simple merge
Simple merge
Simple merge
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
 - * License along with Libav; if not, write to the Free Software
 + * License along with FFmpeg; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  #include <inttypes.h>
- #include "config.h"
  #include "libavutil/bswap.h"
+ #include "config.h"
  #include "rgb2rgb.h"
  #include "swscale.h"
  #include "swscale_internal.h"
@@@ -162,22 -172,21 +172,21 @@@ void rgb24to32(const uint8_t *src, uint
  
  void rgb16tobgr32(const uint8_t *src, uint8_t *dst, int src_size)
  {
-     const uint16_t *end;
-     uint8_t *d = dst;
-     const uint16_t *s = (const uint16_t *)src;
-     end = s + src_size/2;
+     uint8_t *d          = dst;
+     const uint16_t *s   = (const uint16_t *)src;
+     const uint16_t *end = s + src_size / 2;
      while (s < end) {
-         register uint16_t bgr;
-         bgr = *s++;
+         register uint16_t bgr = *s++;
  #if HAVE_BIGENDIAN
          *d++ = 255;
-         *d++ = ((bgr&0x1F)<<3) | ((bgr&0x1F)>>2);
-         *d++ = ((bgr&0x7E0)>>3) | ((bgr&0x7E0)>>9);
 -        *d++ = (bgr & 0x1F)   << 3;
 -        *d++ = (bgr & 0x7E0)  >> 3;
 -        *d++ = (bgr & 0xF800) >> 8;
++        *d++ = ((bgr&0x001F)<<3) | ((bgr&0x001F)>> 2);
++        *d++ = ((bgr&0x07E0)>>3) | ((bgr&0x07E0)>> 9);
 +        *d++ = ((bgr&0xF800)>>8) | ((bgr&0xF800)>>13);
  #else
 -        *d++ = (bgr & 0xF800) >> 8;
 -        *d++ = (bgr & 0x7E0)  >> 3;
 -        *d++ = (bgr & 0x1F)   << 3;
 +        *d++ = ((bgr&0xF800)>>8) | ((bgr&0xF800)>>13);
-         *d++ = ((bgr&0x7E0)>>3) | ((bgr&0x7E0)>>9);
-         *d++ = ((bgr&0x1F)<<3) | ((bgr&0x1F)>>2);
++        *d++ = ((bgr&0x07E0)>>3) | ((bgr&0x07E0)>> 9);
++        *d++ = ((bgr&0x001F)<<3) | ((bgr&0x001F)>> 2);
          *d++ = 255;
  #endif
      }
@@@ -204,16 -213,15 +213,15 @@@ void rgb12to15(const uint8_t *src, uint
  
  void rgb16to24(const uint8_t *src, uint8_t *dst, int src_size)
  {
-     const uint16_t *end;
-     uint8_t *d = dst;
-     const uint16_t *s = (const uint16_t *)src;
-     end = s + src_size/2;
+     uint8_t *d          = dst;
+     const uint16_t *s   = (const uint16_t *)src;
+     const uint16_t *end = s + src_size / 2;
      while (s < end) {
-         register uint16_t bgr;
-         bgr = *s++;
+         register uint16_t bgr = *s++;
 -        *d++ = (bgr & 0xF800) >> 8;
 -        *d++ = (bgr & 0x7E0)  >> 3;
 -        *d++ = (bgr & 0x1F)   << 3;
 +        *d++ = ((bgr&0xF800)>>8) | ((bgr&0xF800)>>13);
-         *d++ = ((bgr&0x7E0)>>3) | ((bgr&0x7E0)>>9);
-         *d++ = ((bgr&0x1F)<<3) | ((bgr&0x1F)>>2);
++        *d++ = ((bgr&0x07E0)>>3) | ((bgr&0x07E0)>> 9);
++        *d++ = ((bgr&0x001F)<<3) | ((bgr&0x001F)>> 2);
      }
  }
  
@@@ -241,22 -247,21 +247,21 @@@ void rgb16tobgr15(const uint8_t *src, u
  
  void rgb15tobgr32(const uint8_t *src, uint8_t *dst, int src_size)
  {
-     const uint16_t *end;
-     uint8_t *d = dst;
-     const uint16_t *s = (const uint16_t *)src;
-     end = s + src_size/2;
+     uint8_t *d          = dst;
+     const uint16_t *s   = (const uint16_t *)src;
+     const uint16_t *end = s + src_size / 2;
      while (s < end) {
-         register uint16_t bgr;
-         bgr = *s++;
+         register uint16_t bgr = *s++;
  #if HAVE_BIGENDIAN
          *d++ = 255;
-         *d++ = ((bgr&0x1F)<<3) | ((bgr&0x1F)>>2);
-         *d++ = ((bgr&0x3E0)>>2) | ((bgr&0x3E0)>>7);
 -        *d++ = (bgr & 0x1F)   << 3;
 -        *d++ = (bgr & 0x3E0)  >> 2;
 -        *d++ = (bgr & 0x7C00) >> 7;
++        *d++ = ((bgr&0x001F)<<3) | ((bgr&0x001F)>> 2);
++        *d++ = ((bgr&0x03E0)>>2) | ((bgr&0x03E0)>> 7);
 +        *d++ = ((bgr&0x7C00)>>7) | ((bgr&0x7C00)>>12);
  #else
 -        *d++ = (bgr & 0x7C00) >> 7;
 -        *d++ = (bgr & 0x3E0)  >> 2;
 -        *d++ = (bgr & 0x1F)   << 3;
 +        *d++ = ((bgr&0x7C00)>>7) | ((bgr&0x7C00)>>12);
-         *d++ = ((bgr&0x3E0)>>2) | ((bgr&0x3E0)>>7);
-         *d++ = ((bgr&0x1F)<<3) | ((bgr&0x1F)>>2);
++        *d++ = ((bgr&0x03E0)>>2) | ((bgr&0x03E0)>> 7);
++        *d++ = ((bgr&0x001F)<<3) | ((bgr&0x001F)>> 2);
          *d++ = 255;
  #endif
      }
  
  void rgb15to24(const uint8_t *src, uint8_t *dst, int src_size)
  {
-     const uint16_t *end;
-     uint8_t *d = dst;
-     const uint16_t *s = (const uint16_t *)src;
-     end = s + src_size/2;
+     uint8_t *d          = dst;
+     const uint16_t *s   = (const uint16_t *)src;
+     const uint16_t *end = s + src_size / 2;
      while (s < end) {
-         register uint16_t bgr;
-         bgr = *s++;
+         register uint16_t bgr = *s++;
 -        *d++ = (bgr & 0x7C00) >> 7;
 -        *d++ = (bgr & 0x3E0)  >> 2;
 -        *d++ = (bgr & 0x1F)   << 3;
 +        *d++ = ((bgr&0x7C00)>>7) | ((bgr&0x7C00)>>12);
-         *d++ = ((bgr&0x3E0)>>2) | ((bgr&0x3E0)>>7);
-         *d++ = ((bgr&0x1F)<<3) | ((bgr&0x1F)>>2);
++        *d++ = ((bgr&0x03E0)>>2) | ((bgr&0x03E0)>> 7);
++        *d++ = ((bgr&0x001F)<<3) | ((bgr&0x001F)>> 2);
      }
  }
  
@@@ -314,12 -314,26 +314,14 @@@ void rgb12tobgr12(const uint8_t *src, u
      }
  }
  
 -void bgr8torgb8(const uint8_t *src, uint8_t *dst, int src_size)
 -{
 -    int i, num_pixels = src_size;
 -
 -    for (i = 0; i < num_pixels; i++) {
 -        register uint8_t rgb = src[i];
 -        unsigned r           = (rgb & 0x07);
 -        unsigned g           = (rgb & 0x38) >> 3;
 -        unsigned b           = (rgb & 0xC0) >> 6;
 -        dst[i]               = ((b << 1) & 0x07) | ((g & 0x07) << 3) | ((r & 0x03) << 6);
 -    }
 -}
  #define DEFINE_SHUFFLE_BYTES(a, b, c, d)                                \
- void shuffle_bytes_##a##b##c##d(const uint8_t *src, uint8_t *dst, int src_size) \
+ void shuffle_bytes_ ## a ## b ## c ## d(const uint8_t *src,             \
+                                         uint8_t *dst, int src_size)     \
  {                                                                       \
-     int i;                                                             \
+     int i;                                                              \
                                                                          \
-     for (i = 0; i < src_size; i+=4) {                                   \
+     for (i = 0; i < src_size; i += 4) {                                 \
          dst[i + 0] = src[i + a];                                        \
          dst[i + 1] = src[i + b];                                        \
          dst[i + 2] = src[i + c];                                        \
@@@ -227,54 -238,74 +238,53 @@@ static inline void rgb24to15_c(const ui
      }
  }
  
- static inline void rgb15tobgr24_c(const uint8_t *src, uint8_t *dst, int src_size)
 -/*
 - * I use less accurate approximation here by simply left-shifting the input
 - * value and filling the low order bits with zeroes. This method improves PNG
 - * compression but this scheme cannot reproduce white exactly, since it does
 - * not generate an all-ones maximum value; the net effect is to darken the
 - * image slightly.
 - *
 - * The better method should be "left bit replication":
 - *
 - *  4 3 2 1 0
 - *  ---------
 - *  1 1 0 1 1
 - *
 - *  7 6 5 4 3  2 1 0
 - *  ----------------
 - *  1 1 0 1 1  1 1 0
 - *  |=======|  |===|
 - *      |      leftmost bits repeated to fill open bits
 - *      |
 - *  original bits
 - */
+ static inline void rgb15tobgr24_c(const uint8_t *src, uint8_t *dst,
+                                   int src_size)
  {
-     const uint16_t *end;
-     uint8_t *d = dst;
-     const uint16_t *s = (const uint16_t*)src;
-     end = s + src_size/2;
+     uint8_t *d          = dst;
+     const uint16_t *s   = (const uint16_t *)src;
+     const uint16_t *end = s + src_size / 2;
      while (s < end) {
-         register uint16_t bgr;
-         bgr = *s++;
-         *d++ = ((bgr&0x1F)<<3) | ((bgr&0x1F)>>2);
-         *d++ = ((bgr&0x3E0)>>2) | ((bgr&0x3E0)>>7);
+         register uint16_t bgr = *s++;
 -        *d++ = (bgr & 0x1F)   << 3;
 -        *d++ = (bgr & 0x3E0)  >> 2;
 -        *d++ = (bgr & 0x7C00) >> 7;
++        *d++ = ((bgr&0x001F)<<3) | ((bgr&0x001F)>> 2);
++        *d++ = ((bgr&0x03E0)>>2) | ((bgr&0x03E0)>> 7);
 +        *d++ = ((bgr&0x7C00)>>7) | ((bgr&0x7C00)>>12);
      }
  }
  
- static inline void rgb16tobgr24_c(const uint8_t *src, uint8_t *dst, int src_size)
+ static inline void rgb16tobgr24_c(const uint8_t *src, uint8_t *dst,
+                                   int src_size)
  {
-     const uint16_t *end;
-     uint8_t *d = (uint8_t *)dst;
-     const uint16_t *s = (const uint16_t *)src;
-     end = s + src_size/2;
+     uint8_t *d          = (uint8_t *)dst;
+     const uint16_t *s   = (const uint16_t *)src;
+     const uint16_t *end = s + src_size / 2;
      while (s < end) {
-         register uint16_t bgr;
-         bgr = *s++;
-         *d++ = ((bgr&0x1F)<<3) | ((bgr&0x1F)>>2);
-         *d++ = ((bgr&0x7E0)>>3) | ((bgr&0x7E0)>>9);
+         register uint16_t bgr = *s++;
 -        *d++ = (bgr & 0x1F)   << 3;
 -        *d++ = (bgr & 0x7E0)  >> 3;
 -        *d++ = (bgr & 0xF800) >> 8;
++        *d++ = ((bgr&0x001F)<<3) | ((bgr&0x001F)>> 2);
++        *d++ = ((bgr&0x07E0)>>3) | ((bgr&0x07E0)>> 9);
 +        *d++ = ((bgr&0xF800)>>8) | ((bgr&0xF800)>>13);
      }
  }
  
  static inline void rgb15to32_c(const uint8_t *src, uint8_t *dst, int src_size)
  {
-     const uint16_t *end;
-     uint8_t *d = dst;
-     const uint16_t *s = (const uint16_t *)src;
-     end = s + src_size/2;
+     uint8_t *d          = dst;
+     const uint16_t *s   = (const uint16_t *)src;
+     const uint16_t *end = s + src_size / 2;
      while (s < end) {
-         register uint16_t bgr;
-         bgr = *s++;
+         register uint16_t bgr = *s++;
  #if HAVE_BIGENDIAN
          *d++ = 255;
 -        *d++ = (bgr & 0x7C00) >> 7;
 -        *d++ = (bgr & 0x3E0)  >> 2;
 -        *d++ = (bgr & 0x1F)   << 3;
 +        *d++ = ((bgr&0x7C00)>>7) | ((bgr&0x7C00)>>12);
-         *d++ = ((bgr&0x3E0)>>2) | ((bgr&0x3E0)>>7);
-         *d++ = ((bgr&0x1F)<<3) | ((bgr&0x1F)>>2);
++        *d++ = ((bgr&0x03E0)>>2) | ((bgr&0x03E0)>> 7);
++        *d++ = ((bgr&0x001F)<<3) | ((bgr&0x001F)>> 2);
  #else
-         *d++ = ((bgr&0x1F)<<3) | ((bgr&0x1F)>>2);
-         *d++ = ((bgr&0x3E0)>>2) | ((bgr&0x3E0)>>7);
 -        *d++ = (bgr & 0x1F)   << 3;
 -        *d++ = (bgr & 0x3E0)  >> 2;
 -        *d++ = (bgr & 0x7C00) >> 7;
++        *d++ = ((bgr&0x001F)<<3) | ((bgr&0x001F)>> 2);
++        *d++ = ((bgr&0x03E0)>>2) | ((bgr&0x03E0)>> 7);
 +        *d++ = ((bgr&0x7C00)>>7) | ((bgr&0x7C00)>>12);
          *d++ = 255;
  #endif
      }
  
  static inline void rgb16to32_c(const uint8_t *src, uint8_t *dst, int src_size)
  {
-     const uint16_t *end;
-     uint8_t *d = dst;
-     const uint16_t *s = (const uint16_t*)src;
-     end = s + src_size/2;
+     uint8_t *d          = dst;
+     const uint16_t *s   = (const uint16_t *)src;
+     const uint16_t *end = s + src_size / 2;
      while (s < end) {
-         register uint16_t bgr;
-         bgr = *s++;
+         register uint16_t bgr = *s++;
  #if HAVE_BIGENDIAN
          *d++ = 255;
 -        *d++ = (bgr & 0xF800) >> 8;
 -        *d++ = (bgr & 0x7E0)  >> 3;
 -        *d++ = (bgr & 0x1F)   << 3;
 +        *d++ = ((bgr&0xF800)>>8) | ((bgr&0xF800)>>13);
-         *d++ = ((bgr&0x7E0)>>3) | ((bgr&0x7E0)>>9);
-         *d++ = ((bgr&0x1F)<<3) | ((bgr&0x1F)>>2);
++        *d++ = ((bgr&0x07E0)>>3) | ((bgr&0x07E0)>> 9);
++        *d++ = ((bgr&0x001F)<<3) | ((bgr&0x001F)>> 2);
  #else
-         *d++ = ((bgr&0x1F)<<3) | ((bgr&0x1F)>>2);
-         *d++ = ((bgr&0x7E0)>>3) | ((bgr&0x7E0)>>9);
 -        *d++ = (bgr & 0x1F)   << 3;
 -        *d++ = (bgr & 0x7E0)  >> 3;
 -        *d++ = (bgr & 0xF800) >> 8;
++        *d++ = ((bgr&0x001F)<<3) | ((bgr&0x001F)>> 2);
++        *d++ = ((bgr&0x07E0)>>3) | ((bgr&0x07E0)>> 9);
 +        *d++ = ((bgr&0xF800)>>8) | ((bgr&0xF800)>>13);
          *d++ = 255;
  #endif
      }
@@@ -637,24 -665,21 +644,24 @@@ void rgb24toyv12_c(const uint8_t *src, 
          ydst += lumStride;
          src  += srcStride;
  
-         if(y+1 == height)
++        if (y+1 == height)
 +            break;
 +
-         for (i=0; i<chromWidth; i++) {
-             unsigned int b = src[6*i+0];
-             unsigned int g = src[6*i+1];
-             unsigned int r = src[6*i+2];
+         for (i = 0; i < chromWidth; i++) {
+             unsigned int b = src[6 * i + 0];
+             unsigned int g = src[6 * i + 1];
+             unsigned int r = src[6 * i + 2];
  
-             unsigned int Y  =  ((RY*r + GY*g + BY*b)>>RGB2YUV_SHIFT) + 16;
+             unsigned int Y = ((RY * r + GY * g + BY * b) >> RGB2YUV_SHIFT) + 16;
  
-             ydst[2*i]     = Y;
+             ydst[2 * i] = Y;
  
-             b = src[6*i+3];
-             g = src[6*i+4];
-             r = src[6*i+5];
+             b = src[6 * i + 3];
+             g = src[6 * i + 4];
+             r = src[6 * i + 5];
  
-             Y  =  ((RY*r + GY*g + BY*b)>>RGB2YUV_SHIFT) + 16;
-             ydst[2*i+1]     = Y;
+             Y = ((RY * r + GY * g + BY * b) >> RGB2YUV_SHIFT) + 16;
+             ydst[2 * i + 1] = Y;
          }
          udst += chromStride;
          vdst += chromStride;
@@@ -32,9 -34,6 +34,7 @@@
  #include "rgb2rgb.h"
  #include "swscale.h"
  #include "swscale_internal.h"
- #include "libavutil/cpu.h"
- #include "libavutil/bswap.h"
 +#include "libavutil/pixdesc.h"
  
  extern const uint8_t dither_4x4_16[4][8];
  extern const uint8_t dither_8x8_32[8][8];
@@@ -62,102 -61,111 +62,111 @@@ const int *sws_getCoefficients(int colo
  #define LOADCHROMA(i)                               \
      U = pu[i];                                      \
      V = pv[i];                                      \
 -    r = (void *)c->table_rV[V];                     \
 -    g = (void *)(c->table_gU[U] + c->table_gV[V]);  \
 -    b = (void *)c->table_bU[U];
 +    r = (void *)c->table_rV[V+YUVRGB_TABLE_HEADROOM];                     \
 +    g = (void *)(c->table_gU[U+YUVRGB_TABLE_HEADROOM] + c->table_gV[V+YUVRGB_TABLE_HEADROOM]);  \
 +    b = (void *)c->table_bU[U+YUVRGB_TABLE_HEADROOM];
  
- #define PUTRGB(dst,src,i)            \
-     Y = src[2*i];                    \
-     dst[2*i  ] = r[Y] + g[Y] + b[Y]; \
-     Y = src[2*i+1];                  \
-     dst[2*i+1] = r[Y] + g[Y] + b[Y];
- #define PUTRGB24(dst,src,i)                                  \
-     Y = src[2*i];                                            \
-     dst[6*i+0] = r[Y]; dst[6*i+1] = g[Y]; dst[6*i+2] = b[Y]; \
-     Y = src[2*i+1];                                          \
-     dst[6*i+3] = r[Y]; dst[6*i+4] = g[Y]; dst[6*i+5] = b[Y];
- #define PUTBGR24(dst,src,i)                                  \
-     Y = src[2*i];                                            \
-     dst[6*i+0] = b[Y]; dst[6*i+1] = g[Y]; dst[6*i+2] = r[Y]; \
-     Y = src[2*i+1];                                          \
-     dst[6*i+3] = b[Y]; dst[6*i+4] = g[Y]; dst[6*i+5] = r[Y];
- #define PUTRGBA(dst,ysrc,asrc,i,s)                      \
-     Y = ysrc[2*i];                                      \
-     dst[2*i  ] = r[Y] + g[Y] + b[Y] + (asrc[2*i  ]<<s); \
-     Y = ysrc[2*i+1];                                    \
-     dst[2*i+1] = r[Y] + g[Y] + b[Y] + (asrc[2*i+1]<<s);
- #define PUTRGB48(dst,src,i)             \
-     Y = src[2*i];                       \
-     dst[12*i+ 0] = dst[12*i+ 1] = r[Y]; \
-     dst[12*i+ 2] = dst[12*i+ 3] = g[Y]; \
-     dst[12*i+ 4] = dst[12*i+ 5] = b[Y]; \
-     Y = src[2*i+1];                     \
-     dst[12*i+ 6] = dst[12*i+ 7] = r[Y]; \
-     dst[12*i+ 8] = dst[12*i+ 9] = g[Y]; \
-     dst[12*i+10] = dst[12*i+11] = b[Y];
- #define PUTBGR48(dst,src,i)             \
-     Y = src[2*i];                       \
-     dst[12*i+ 0] = dst[12*i+ 1] = b[Y]; \
-     dst[12*i+ 2] = dst[12*i+ 3] = g[Y]; \
-     dst[12*i+ 4] = dst[12*i+ 5] = r[Y]; \
-     Y = src[2*i+1];                     \
-     dst[12*i+ 6] = dst[12*i+ 7] = b[Y]; \
-     dst[12*i+ 8] = dst[12*i+ 9] = g[Y]; \
-     dst[12*i+10] = dst[12*i+11] = r[Y];
- #define YUV2RGBFUNC(func_name, dst_type, alpha) \
- static int func_name(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, \
-                      int srcSliceH, uint8_t* dst[], int dstStride[]) \
- {\
-     int y;\
- \
-     if (!alpha && c->srcFormat == PIX_FMT_YUV422P) {\
-         srcStride[1] *= 2;\
-         srcStride[2] *= 2;\
-     }\
-     for (y=0; y<srcSliceH; y+=2) {\
-         dst_type *dst_1 = (dst_type*)(dst[0] + (y+srcSliceY  )*dstStride[0]);\
-         dst_type *dst_2 = (dst_type*)(dst[0] + (y+srcSliceY+1)*dstStride[0]);\
-         dst_type av_unused *r, *b;\
-         dst_type *g;\
-         const uint8_t *py_1 = src[0] + y*srcStride[0];\
-         const uint8_t *py_2 = py_1 + srcStride[0];\
-         const uint8_t *pu = src[1] + (y>>1)*srcStride[1];\
-         const uint8_t *pv = src[2] + (y>>1)*srcStride[2];\
-         const uint8_t av_unused *pa_1, *pa_2;\
-         unsigned int h_size = c->dstW>>3;\
-         if (alpha) {\
-             pa_1 = src[3] + y*srcStride[3];\
-             pa_2 = pa_1 + srcStride[3];\
-         }\
-         while (h_size--) {\
-             int av_unused U, V;\
-             int Y;\
- #define ENDYUV2RGBLINE(dst_delta)\
-             pu += 4;\
-             pv += 4;\
-             py_1 += 8;\
-             py_2 += 8;\
-             dst_1 += dst_delta;\
-             dst_2 += dst_delta;\
-         }\
-         if (c->dstW & 4) {\
-             int av_unused Y, U, V;\
- #define ENDYUV2RGBFUNC()\
-         }\
-     }\
-     return srcSliceH;\
- }
+ #define PUTRGB(dst, src, i)                         \
+     Y              = src[2 * i];                    \
+     dst[2 * i]     = r[Y] + g[Y] + b[Y];            \
+     Y              = src[2 * i + 1];                \
+     dst[2 * i + 1] = r[Y] + g[Y] + b[Y];
+ #define PUTRGB24(dst, src, i)                       \
+     Y              = src[2 * i];                    \
+     dst[6 * i + 0] = r[Y];                          \
+     dst[6 * i + 1] = g[Y];                          \
+     dst[6 * i + 2] = b[Y];                          \
+     Y              = src[2 * i + 1];                \
+     dst[6 * i + 3] = r[Y];                          \
+     dst[6 * i + 4] = g[Y];                          \
+     dst[6 * i + 5] = b[Y];
+ #define PUTBGR24(dst, src, i)                       \
+     Y              = src[2 * i];                    \
+     dst[6 * i + 0] = b[Y];                          \
+     dst[6 * i + 1] = g[Y];                          \
+     dst[6 * i + 2] = r[Y];                          \
+     Y              = src[2 * i + 1];                \
+     dst[6 * i + 3] = b[Y];                          \
+     dst[6 * i + 4] = g[Y];                          \
+     dst[6 * i + 5] = r[Y];
+ #define PUTRGBA(dst, ysrc, asrc, i, s)                                  \
+     Y              = ysrc[2 * i];                                       \
+     dst[2 * i]     = r[Y] + g[Y] + b[Y] + (asrc[2 * i]     << s);       \
+     Y              = ysrc[2 * i + 1];                                   \
+     dst[2 * i + 1] = r[Y] + g[Y] + b[Y] + (asrc[2 * i + 1] << s);
+ #define PUTRGB48(dst, src, i)                       \
+     Y                = src[ 2 * i];                 \
+     dst[12 * i +  0] = dst[12 * i +  1] = r[Y];     \
+     dst[12 * i +  2] = dst[12 * i +  3] = g[Y];     \
+     dst[12 * i +  4] = dst[12 * i +  5] = b[Y];     \
+     Y                = src[ 2 * i + 1];             \
+     dst[12 * i +  6] = dst[12 * i +  7] = r[Y];     \
+     dst[12 * i +  8] = dst[12 * i +  9] = g[Y];     \
+     dst[12 * i + 10] = dst[12 * i + 11] = b[Y];
+ #define PUTBGR48(dst, src, i)                       \
+     Y                = src[2 * i];                  \
+     dst[12 * i +  0] = dst[12 * i +  1] = b[Y];     \
+     dst[12 * i +  2] = dst[12 * i +  3] = g[Y];     \
+     dst[12 * i +  4] = dst[12 * i +  5] = r[Y];     \
+     Y                = src[2  * i +  1];            \
+     dst[12 * i +  6] = dst[12 * i +  7] = b[Y];     \
+     dst[12 * i +  8] = dst[12 * i +  9] = g[Y];     \
+     dst[12 * i + 10] = dst[12 * i + 11] = r[Y];
+ #define YUV2RGBFUNC(func_name, dst_type, alpha)                             \
+     static int func_name(SwsContext *c, const uint8_t *src[],               \
+                          int srcStride[], int srcSliceY, int srcSliceH,     \
+                          uint8_t *dst[], int dstStride[])                   \
+     {                                                                       \
+         int y;                                                              \
+                                                                             \
+         if (!alpha && c->srcFormat == PIX_FMT_YUV422P) {                    \
+             srcStride[1] *= 2;                                              \
+             srcStride[2] *= 2;                                              \
+         }                                                                   \
+         for (y = 0; y < srcSliceH; y += 2) {                                \
+             dst_type *dst_1 =                                               \
+                 (dst_type *)(dst[0] + (y + srcSliceY)     * dstStride[0]);  \
+             dst_type *dst_2 =                                               \
+                 (dst_type *)(dst[0] + (y + srcSliceY + 1) * dstStride[0]);  \
+             dst_type av_unused *r, *g, *b;                                  \
+             const uint8_t *py_1 = src[0] +  y       * srcStride[0];         \
+             const uint8_t *py_2 = py_1   +            srcStride[0];         \
+             const uint8_t *pu   = src[1] + (y >> 1) * srcStride[1];         \
+             const uint8_t *pv   = src[2] + (y >> 1) * srcStride[2];         \
+             const uint8_t av_unused *pa_1, *pa_2;                           \
+             unsigned int h_size = c->dstW >> 3;                             \
+             if (alpha) {                                                    \
+                 pa_1 = src[3] + y * srcStride[3];                           \
+                 pa_2 = pa_1   +     srcStride[3];                           \
+             }                                                               \
+             while (h_size--) {                                              \
+                 int av_unused U, V, Y;                                      \
+ #define ENDYUV2RGBLINE(dst_delta)                   \
+     pu    += 4;                                     \
+     pv    += 4;                                     \
+     py_1  += 8;                                     \
+     py_2  += 8;                                     \
+     dst_1 += dst_delta;                             \
+     dst_2 += dst_delta;                             \
+     }                                               \
+     if (c->dstW & 4) {                              \
+         int av_unused Y, U, V;                      \
+ #define ENDYUV2RGBFUNC()                            \
+             }                                       \
+         }                                           \
+         return srcSliceH;                           \
+     }
  
- #define CLOSEYUV2RGBFUNC(dst_delta)\
-     ENDYUV2RGBLINE(dst_delta)\
+ #define CLOSEYUV2RGBFUNC(dst_delta)                 \
+     ENDYUV2RGBLINE(dst_delta)                       \
      ENDYUV2RGBFUNC()
  
  YUV2RGBFUNC(yuv2rgb_c_48, uint8_t, 0)
@@@ -477,30 -503,30 +504,30 @@@ YUV2RGBFUNC(yuv2rgb_c_4b_ordered_dither
  CLOSEYUV2RGBFUNC(8)
  
  YUV2RGBFUNC(yuv2rgb_c_1_ordered_dither, uint8_t, 0)
-         const uint8_t *d128 = dither_8x8_220[y&7];
-         char out_1 = 0, out_2 = 0;
-         g= c->table_gU[128 + YUVRGB_TABLE_HEADROOM] + c->table_gV[128 + YUVRGB_TABLE_HEADROOM];
+     const uint8_t *d128 = dither_8x8_220[y & 7];
+     char out_1 = 0, out_2 = 0;
 -    g = c->table_gU[128] + c->table_gV[128];
++    g = c->table_gU[128 + YUVRGB_TABLE_HEADROOM] + c->table_gV[128 + YUVRGB_TABLE_HEADROOM];
  
- #define PUTRGB1(out,src,i,o)    \
-     Y = src[2*i];               \
-     out+= out + g[Y+d128[0+o]]; \
-     Y = src[2*i+1];             \
-     out+= out + g[Y+d128[1+o]];
+ #define PUTRGB1(out, src, i, o)                     \
+     Y    = src[2 * i];                              \
+     out += out + g[Y + d128[0 + o]];                \
+     Y    = src[2 * i + 1];                          \
+     out += out + g[Y + d128[1 + o]];
  
-     PUTRGB1(out_1,py_1,0,0);
-     PUTRGB1(out_2,py_2,0,0+8);
+     PUTRGB1(out_1, py_1, 0, 0);
+     PUTRGB1(out_2, py_2, 0, 0 + 8);
  
-     PUTRGB1(out_2,py_2,1,2+8);
-     PUTRGB1(out_1,py_1,1,2);
+     PUTRGB1(out_2, py_2, 1, 2 + 8);
+     PUTRGB1(out_1, py_1, 1, 2);
  
-     PUTRGB1(out_1,py_1,2,4);
-     PUTRGB1(out_2,py_2,2,4+8);
+     PUTRGB1(out_1, py_1, 2, 4);
+     PUTRGB1(out_2, py_2, 2, 4 + 8);
  
-     PUTRGB1(out_2,py_2,3,6+8);
-     PUTRGB1(out_1,py_1,3,6);
+     PUTRGB1(out_2, py_2, 3, 6 + 8);
+     PUTRGB1(out_1, py_1, 3, 6);
  
-     dst_1[0]= out_1;
-     dst_2[0]= out_2;
+     dst_1[0] = out_1;
+     dst_2[0] = out_2;
  CLOSEYUV2RGBFUNC(1)
  
  SwsFunc ff_yuv2rgb_get_func_ptr(SwsContext *c)
      if (t)
          return t;
  
-     av_log(c, AV_LOG_WARNING, "No accelerated colorspace conversion found from %s to %s.\n",
+     av_log(c, AV_LOG_WARNING,
+            "No accelerated colorspace conversion found from %s to %s.\n",
 -           sws_format_name(c->srcFormat), sws_format_name(c->dstFormat));
 +           av_get_pix_fmt_name(c->srcFormat), av_get_pix_fmt_name(c->dstFormat));
  
      switch (c->dstFormat) {
      case PIX_FMT_BGR48BE:
-     case PIX_FMT_BGR48LE:    return yuv2rgb_c_bgr48;
+     case PIX_FMT_BGR48LE:
+         return yuv2rgb_c_bgr48;
      case PIX_FMT_RGB48BE:
-     case PIX_FMT_RGB48LE:    return yuv2rgb_c_48;
+     case PIX_FMT_RGB48LE:
+         return yuv2rgb_c_48;
      case PIX_FMT_ARGB:
-     case PIX_FMT_ABGR:       if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) return yuva2argb_c;
+     case PIX_FMT_ABGR:
 -        if (CONFIG_SWSCALE_ALPHA && c->srcFormat == PIX_FMT_YUVA420P)
++        if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat))
+             return yuva2argb_c;
      case PIX_FMT_RGBA:
-     case PIX_FMT_BGRA:       return (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) ? yuva2rgba_c : yuv2rgb_c_32;
-     case PIX_FMT_RGB24:      return yuv2rgb_c_24_rgb;
-     case PIX_FMT_BGR24:      return yuv2rgb_c_24_bgr;
+     case PIX_FMT_BGRA:
 -        if (CONFIG_SWSCALE_ALPHA && c->srcFormat == PIX_FMT_YUVA420P)
 -            return yuva2rgba_c;
 -        else
 -            return yuv2rgb_c_32;
++        return (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) ? yuva2rgba_c : yuv2rgb_c_32;
+     case PIX_FMT_RGB24:
+         return yuv2rgb_c_24_rgb;
+     case PIX_FMT_BGR24:
+         return yuv2rgb_c_24_bgr;
      case PIX_FMT_RGB565:
      case PIX_FMT_BGR565:
      case PIX_FMT_RGB555:
      return NULL;
  }
  
- static void fill_table(uint8_t* table[256 + 2*YUVRGB_TABLE_HEADROOM], const int elemsize, const int inc, void *y_tab)
 -static void fill_table(uint8_t *table[256], const int elemsize,
++static void fill_table(uint8_t* table[256 + 2*YUVRGB_TABLE_HEADROOM], const int elemsize,
+                        const int inc, void *y_tab)
  {
      int i;
 -    int64_t cb       = 0;
      uint8_t *y_table = y_tab;
  
      y_table -= elemsize * (inc >> 9);
      }
  }
  
 -static void fill_gv_table(int table[256], const int elemsize, const int inc)
 +static void fill_gv_table(int table[256 + 2*YUVRGB_TABLE_HEADROOM], const int elemsize, const int inc)
  {
      int i;
-     int off = -(inc >> 9);
 -    int64_t cb = 0;
+     int off    = -(inc >> 9);
  
 -    for (i = 0; i < 256; i++) {
 +    for (i = 0; i < 256 + 2*YUVRGB_TABLE_HEADROOM; i++) {
 +        int64_t cb = av_clip(i-YUVRGB_TABLE_HEADROOM, 0, 255)*inc;
          table[i] = elemsize * (off + (cb >> 16));
 -        cb      += inc;
      }
  }