]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/pcxenc.c
hevc: ppc: Add HEVC 4x4 IDCT for PowerPC
[ffmpeg] / libavcodec / pcxenc.c
index e01727f3e7c8671aef9f21123ad15456d6dc2632..7fc0d9cc76a869d6dca9b49629fae96cefa5731e 100644 (file)
@@ -2,45 +2,44 @@
  * PC Paintbrush PCX (.pcx) image encoder
  * Copyright (c) 2009 Daniel Verkamp <daniel at drv.nu>
  *
- * This file is part of FFmpeg.
+ * This file is part of Libav.
  *
- * FFmpeg is free software; you can redistribute it and/or
+ * Libav 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.
  *
- * FFmpeg is distributed in the hope that it will be useful,
+ * Libav 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 FFmpeg; if not, write to the Free Software
+ * License along with Libav; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 /**
- * PCX image encoder
  * @file
+ * PCX image encoder
  * @author Daniel Verkamp
- * @sa http://www.qzx.com/pc-gpe/pcx.txt
+ * @see http://www.qzx.com/pc-gpe/pcx.txt
  */
 
 #include "avcodec.h"
 #include "bytestream.h"
-
-typedef struct PCXContext {
-    AVFrame picture;
-} PCXContext;
+#include "internal.h"
 
 static const uint32_t monoblack_pal[16] = { 0x000000, 0xFFFFFF };
 
 static av_cold int pcx_encode_init(AVCodecContext *avctx)
 {
-    PCXContext *s = avctx->priv_data;
-
-    avcodec_get_frame_defaults(&s->picture);
-    avctx->coded_frame = &s->picture;
+#if FF_API_CODED_FRAME
+FF_DISABLE_DEPRECATION_WARNINGS
+    avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
+    avctx->coded_frame->key_frame = 1;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 
     return 0;
 }
@@ -63,7 +62,7 @@ static int pcx_rle_encode(      uint8_t *dst, int dst_size,
 
     // check worst-case upper bound on dst_size
     if (dst_size < 2LL * src_plane_size * nplanes || src_plane_size <= 0)
-        return -1;
+        return AVERROR(EINVAL);
 
     for (p = 0; p < nplanes; p++) {
         int count = 1;
@@ -95,55 +94,57 @@ static int pcx_rle_encode(      uint8_t *dst, int dst_size,
     return dst - dst_start;
 }
 
-static int pcx_encode_frame(AVCodecContext *avctx,
-                            unsigned char *buf, int buf_size, void *data)
+static int pcx_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
+                            const AVFrame *frame, int *got_packet)
 {
-    PCXContext *s = avctx->priv_data;
-    AVFrame *const pict = &s->picture;
-    const uint8_t *buf_start = buf;
-    const uint8_t *buf_end   = buf + buf_size;
+    const uint8_t *buf_end;
+    uint8_t *buf;
 
-    int bpp, nplanes, i, y, line_bytes, written;
+    int bpp, nplanes, i, y, line_bytes, written, ret, max_pkt_size;
     const uint32_t *pal = NULL;
     const uint8_t *src;
 
-    *pict = *(AVFrame *)data;
-    pict->pict_type = FF_I_TYPE;
-    pict->key_frame = 1;
-
     if (avctx->width > 65535 || avctx->height > 65535) {
         av_log(avctx, AV_LOG_ERROR, "image dimensions do not fit in 16 bits\n");
-        return -1;
+        return AVERROR(EINVAL);
     }
 
     switch (avctx->pix_fmt) {
-    case PIX_FMT_RGB24:
+    case AV_PIX_FMT_RGB24:
         bpp = 8;
         nplanes = 3;
         break;
-    case PIX_FMT_RGB8:
-    case PIX_FMT_BGR8:
-    case PIX_FMT_RGB4_BYTE:
-    case PIX_FMT_BGR4_BYTE:
-    case PIX_FMT_GRAY8:
-    case PIX_FMT_PAL8:
+    case AV_PIX_FMT_RGB8:
+    case AV_PIX_FMT_BGR8:
+    case AV_PIX_FMT_RGB4_BYTE:
+    case AV_PIX_FMT_BGR4_BYTE:
+    case AV_PIX_FMT_GRAY8:
+    case AV_PIX_FMT_PAL8:
         bpp = 8;
         nplanes = 1;
-        pal = (uint32_t *)pict->data[1];
+        pal = (uint32_t *)frame->data[1];
         break;
-    case PIX_FMT_MONOBLACK:
+    case AV_PIX_FMT_MONOBLACK:
         bpp = 1;
         nplanes = 1;
         pal = monoblack_pal;
         break;
     default:
         av_log(avctx, AV_LOG_ERROR, "unsupported pixfmt\n");
-        return -1;
+        return AVERROR(EINVAL);
     }
 
     line_bytes = (avctx->width * bpp + 7) >> 3;
     line_bytes = (line_bytes + 1) & ~1;
 
+    max_pkt_size = 128 + avctx->height * 2 * line_bytes * nplanes + (pal ? 256*3 + 1 : 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);
+        return ret;
+    }
+    buf     = pkt->data;
+    buf_end = pkt->data + pkt->size;
+
     bytestream_put_byte(&buf, 10);                  // manufacturer
     bytestream_put_byte(&buf, 5);                   // version
     bytestream_put_byte(&buf, 1);                   // encoding
@@ -160,25 +161,25 @@ static int pcx_encode_frame(AVCodecContext *avctx,
     bytestream_put_byte(&buf, nplanes);             // number of planes
     bytestream_put_le16(&buf, line_bytes);          // scanline plane size in bytes
 
-    while (buf - buf_start < 128)
+    while (buf - pkt->data < 128)
         *buf++= 0;
 
-    src = pict->data[0];
+    src = frame->data[0];
 
     for (y = 0; y < avctx->height; y++) {
         if ((written = pcx_rle_encode(buf, buf_end - buf,
                                       src, line_bytes, nplanes)) < 0) {
             av_log(avctx, AV_LOG_ERROR, "buffer too small\n");
-            return -1;
+            return AVERROR_BUG;
         }
         buf += written;
-        src += pict->linesize[0];
+        src += frame->linesize[0];
     }
 
     if (nplanes == 1 && bpp == 8) {
         if (buf_end - buf < 257) {
             av_log(avctx, AV_LOG_ERROR, "buffer too small\n");
-            return -1;
+            return AVERROR_BUG;
         }
         bytestream_put_byte(&buf, 12);
         for (i = 0; i < 256; i++) {
@@ -186,21 +187,25 @@ static int pcx_encode_frame(AVCodecContext *avctx,
         }
     }
 
-    return buf - buf_start;
+    pkt->size   = buf - pkt->data;
+    pkt->flags |= AV_PKT_FLAG_KEY;
+    *got_packet = 1;
+
+    return 0;
 }
 
-AVCodec pcx_encoder = {
-    "pcx",
-    AVMEDIA_TYPE_VIDEO,
-    CODEC_ID_PCX,
-    sizeof(PCXContext),
-    pcx_encode_init,
-    pcx_encode_frame,
-    NULL,
-    .pix_fmts = (const enum PixelFormat[]){
-        PIX_FMT_RGB24,
-        PIX_FMT_RGB8, PIX_FMT_BGR8, PIX_FMT_RGB4_BYTE, PIX_FMT_BGR4_BYTE, PIX_FMT_GRAY8, PIX_FMT_PAL8,
-        PIX_FMT_MONOBLACK,
-        PIX_FMT_NONE},
-    .long_name = NULL_IF_CONFIG_SMALL("PC Paintbrush PCX image"),
+AVCodec ff_pcx_encoder = {
+    .name           = "pcx",
+    .long_name      = NULL_IF_CONFIG_SMALL("PC Paintbrush PCX image"),
+    .type           = AVMEDIA_TYPE_VIDEO,
+    .id             = AV_CODEC_ID_PCX,
+    .init           = pcx_encode_init,
+    .encode2        = pcx_encode_frame,
+    .pix_fmts       = (const enum AVPixelFormat[]){
+        AV_PIX_FMT_RGB24,
+        AV_PIX_FMT_RGB8, AV_PIX_FMT_BGR8, AV_PIX_FMT_RGB4_BYTE, AV_PIX_FMT_BGR4_BYTE,
+        AV_PIX_FMT_GRAY8, AV_PIX_FMT_PAL8,
+        AV_PIX_FMT_MONOBLACK,
+        AV_PIX_FMT_NONE
+    },
 };