Merge commit '0cdbc4d39394965bd8712395b19160da8f3fe144'
authorMichael Niedermayer <michaelni@gmx.at>
Fri, 6 Dec 2013 12:38:17 +0000 (13:38 +0100)
committerMichael Niedermayer <michaelni@gmx.at>
Fri, 6 Dec 2013 12:38:30 +0000 (13:38 +0100)
* commit '0cdbc4d39394965bd8712395b19160da8f3fe144':
  ljpegenc: rename the encoding function.

Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
libavcodec/ljpegenc.c

diff --combined libavcodec/ljpegenc.c
@@@ -8,20 -8,20 +8,20 @@@
   * aspecting, new decode_frame mechanism and apple mjpeg-b support
   *                                  by Alex Beregszaszi
   *
 - * This file is part of Libav.
 + * This file is part of FFmpeg.
   *
 - * Libav is free software; you can redistribute it and/or
 + * 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.
   *
 - * Libav is distributed in the hope that it will be useful,
 + * 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
 - * 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
   */
  
@@@ -57,8 -57,8 +57,8 @@@ typedef struct LJpegEncContext 
      uint16_t (*scratch)[4];
  } LJpegEncContext;
  
- static int encode_picture_lossless(AVCodecContext *avctx, AVPacket *pkt,
-                                    const AVFrame *pict, int *got_packet)
+ static int ljpeg_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
+                               const AVFrame *pict, int *got_packet)
  {
      LJpegEncContext *s = avctx->priv_data;
      PutBitContext pb;
      int max_pkt_size = FF_MIN_BUFFER_SIZE;
      int ret, header_bits;
  
 -    if (avctx->pix_fmt == AV_PIX_FMT_BGRA)
 +    if(    avctx->pix_fmt == AV_PIX_FMT_BGR0
 +        || avctx->pix_fmt == AV_PIX_FMT_BGRA
 +        || avctx->pix_fmt == AV_PIX_FMT_BGR24)
          max_pkt_size += width * height * 3 * 4;
      else {
          max_pkt_size += mb_width * mb_height * 3 * 4
                          * s->hsample[0] * s->vsample[0];
      }
 -    if ((ret = ff_alloc_packet(pkt, max_pkt_size)) < 0) {
 -        av_log(avctx, AV_LOG_ERROR, "Error getting output packet of size %d.\n", max_pkt_size);
 +
 +    if ((ret = ff_alloc_packet2(avctx, pkt, max_pkt_size)) < 0)
          return ret;
 -    }
  
      init_put_bits(&pb, pkt->data, pkt->size);
  
@@@ -89,9 -88,7 +89,9 @@@
  
      header_bits = put_bits_count(&pb);
  
 -    if(avctx->pix_fmt == AV_PIX_FMT_BGRA){
 +    if(    avctx->pix_fmt == AV_PIX_FMT_BGR0
 +        || avctx->pix_fmt == AV_PIX_FMT_BGRA
 +        || avctx->pix_fmt == AV_PIX_FMT_BGR24){
          int x, y, i;
          const int linesize = pict->linesize[0];
          uint16_t (*buffer)[4] = s->scratch;
                  top[i]= left[i]= topleft[i]= buffer[0][i];
              }
              for(x = 0; x < width; x++) {
 +                if(avctx->pix_fmt == AV_PIX_FMT_BGR24){
 +                    buffer[x][1] = ptr[3*x+0] - ptr[3*x+1] + 0x100;
 +                    buffer[x][2] = ptr[3*x+2] - ptr[3*x+1] + 0x100;
 +                    buffer[x][0] = (ptr[3*x+0] + 2*ptr[3*x+1] + ptr[3*x+2])>>2;
 +                }else{
                  buffer[x][1] = ptr[4*x+0] - ptr[4*x+1] + 0x100;
                  buffer[x][2] = ptr[4*x+2] - ptr[4*x+1] + 0x100;
                  buffer[x][0] = (ptr[4*x+0] + 2*ptr[4*x+1] + ptr[4*x+2])>>2;
 +                }
  
                  for(i=0;i<3;i++) {
                      int pred, diff;
  
      emms_c();
  
 +    ff_mjpeg_escape_FF(&pb, header_bits >> 3);
      ff_mjpeg_encode_picture_trailer(&pb, header_bits);
  
      flush_put_bits(&pb);
@@@ -267,15 -257,10 +267,15 @@@ static av_cold int ljpeg_encode_init(AV
      av_pix_fmt_get_chroma_sub_sample(avctx->pix_fmt, &chroma_h_shift,
                                       &chroma_v_shift);
  
 -    if (avctx->pix_fmt   == AV_PIX_FMT_BGRA) {
 +    if (   avctx->pix_fmt == AV_PIX_FMT_BGR0
 +        || avctx->pix_fmt == AV_PIX_FMT_BGRA
 +        || avctx->pix_fmt == AV_PIX_FMT_BGR24) {
          s->vsample[0] = s->hsample[0] =
          s->vsample[1] = s->hsample[1] =
          s->vsample[2] = s->hsample[2] = 1;
 +    } else if (avctx->pix_fmt == AV_PIX_FMT_YUV444P || avctx->pix_fmt == AV_PIX_FMT_YUVJ444P) {
 +        s->vsample[0] = s->vsample[1] = s->vsample[2] = 2;
 +        s->hsample[0] = s->hsample[1] = s->hsample[2] = 1;
      } else {
          s->vsample[0] = 2;
          s->vsample[1] = 2 >> chroma_v_shift;
@@@ -304,11 -289,14 +304,11 @@@ AVCodec ff_ljpeg_encoder = 
      .id             = AV_CODEC_ID_LJPEG,
      .priv_data_size = sizeof(LJpegEncContext),
      .init           = ljpeg_encode_init,
-     .encode2        = encode_picture_lossless,
+     .encode2        = ljpeg_encode_frame,
      .close          = ljpeg_encode_close,
 -    .pix_fmts       = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUVJ420P,
 -                                                    AV_PIX_FMT_YUVJ422P,
 -                                                    AV_PIX_FMT_YUVJ444P,
 -                                                    AV_PIX_FMT_BGRA,
 -                                                    AV_PIX_FMT_YUV420P,
 -                                                    AV_PIX_FMT_YUV422P,
 -                                                    AV_PIX_FMT_YUVJ444P,
 -                                                    AV_PIX_FMT_NONE },
 +    .pix_fmts       = (const enum AVPixelFormat[]){
 +        AV_PIX_FMT_BGR24   , AV_PIX_FMT_BGRA    , AV_PIX_FMT_BGR0,
 +        AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVJ422P,
 +        AV_PIX_FMT_YUV420P , AV_PIX_FMT_YUV444P , AV_PIX_FMT_YUV422P,
 +        AV_PIX_FMT_NONE},
  };