]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/tiffenc.c
imgconvert: cosmetics: Reshuffle defines to reduce ifdeffery
[ffmpeg] / libavcodec / tiffenc.c
index 4cbc51746d1ea2331154aae2b9e2863a0a71aeda..f450edb10f38433d4e7c90192b3abf6eae67d889 100644 (file)
@@ -56,7 +56,7 @@ typedef struct TiffEncoderContext {
     unsigned int bpp;                       ///< bits per pixel
     int compr;                              ///< compression level
     int bpp_tab_size;                       ///< bpp_tab size
-    int photometric_interpretation;         ///< photometric interpretation
+    enum TiffPhotometric photometric_interpretation;  ///< photometric interpretation
     int strips;                             ///< number of strips
     int rps;                                ///< row per strip
     uint8_t entries[TIFF_MAX_ENTRY * 12];   ///< entries in header
@@ -218,6 +218,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
     int is_yuv = 0;
     uint8_t *yuv_line = NULL;
     int shift_h, shift_v;
+    int packet_size;
     const AVPixFmtDescriptor *pfd;
 
     s->avctx = avctx;
@@ -230,29 +231,30 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
     switch (avctx->pix_fmt) {
     case AV_PIX_FMT_RGB48LE:
     case AV_PIX_FMT_GRAY16LE:
+    case AV_PIX_FMT_RGBA:
     case AV_PIX_FMT_RGB24:
     case AV_PIX_FMT_GRAY8:
     case AV_PIX_FMT_PAL8:
         pfd    = av_pix_fmt_desc_get(avctx->pix_fmt);
         s->bpp = av_get_bits_per_pixel(pfd);
         if (pfd->flags & AV_PIX_FMT_FLAG_PAL)
-            s->photometric_interpretation = 3;
+            s->photometric_interpretation = TIFF_PHOTOMETRIC_PALETTE;
         else if (pfd->flags & AV_PIX_FMT_FLAG_RGB)
-            s->photometric_interpretation = 2;
+            s->photometric_interpretation = TIFF_PHOTOMETRIC_RGB;
         else
-            s->photometric_interpretation = 1;
+            s->photometric_interpretation = TIFF_PHOTOMETRIC_BLACK_IS_ZERO;
         s->bpp_tab_size = pfd->nb_components;
         for (i = 0; i < s->bpp_tab_size; i++)
             bpp_tab[i] = s->bpp / s->bpp_tab_size;
         break;
     case AV_PIX_FMT_MONOBLACK:
         s->bpp                        = 1;
-        s->photometric_interpretation = 1;
+        s->photometric_interpretation = TIFF_PHOTOMETRIC_BLACK_IS_ZERO;
         s->bpp_tab_size               = 0;
         break;
     case AV_PIX_FMT_MONOWHITE:
         s->bpp                        = 1;
-        s->photometric_interpretation = 0;
+        s->photometric_interpretation = TIFF_PHOTOMETRIC_WHITE_IS_ZERO;
         s->bpp_tab_size               = 0;
         break;
     case AV_PIX_FMT_YUV420P:
@@ -261,7 +263,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
     case AV_PIX_FMT_YUV410P:
     case AV_PIX_FMT_YUV411P:
         av_pix_fmt_get_chroma_sub_sample(avctx->pix_fmt, &shift_h, &shift_v);
-        s->photometric_interpretation = 6;
+        s->photometric_interpretation = TIFF_PHOTOMETRIC_YCBCR;
         s->bpp                        = 8 + (16 >> (shift_h + shift_v));
         s->subsampling[0]             = 1 << shift_h;
         s->subsampling[1]             = 1 << shift_v;
@@ -287,10 +289,11 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
 
     strips = (s->height - 1) / s->rps + 1;
 
+    packet_size = avctx->height * ((avctx->width * s->bpp + 7) >> 3) * 2 +
+                  avctx->height * 4 + FF_MIN_BUFFER_SIZE;
+
     if (!pkt->data &&
-        (ret = av_new_packet(pkt,
-                             avctx->width * avctx->height * s->bpp * 2 +
-                             avctx->height * 4 + FF_MIN_BUFFER_SIZE)) < 0) {
+        (ret = av_new_packet(pkt, packet_size)) < 0) {
         av_log(avctx, AV_LOG_ERROR, "Error getting output packet.\n");
         return ret;
     }
@@ -409,9 +412,9 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
     if (s->bpp_tab_size)
         add_entry(s, TIFF_BPP, TIFF_SHORT, s->bpp_tab_size, bpp_tab);
 
-    add_entry1(s, TIFF_COMPR,      TIFF_SHORT, s->compr);
-    add_entry1(s, TIFF_INVERT,     TIFF_SHORT, s->photometric_interpretation);
-    add_entry(s,  TIFF_STRIP_OFFS, TIFF_LONG,  strips, strip_offsets);
+    add_entry1(s, TIFF_COMPR,       TIFF_SHORT, s->compr);
+    add_entry1(s, TIFF_PHOTOMETRIC, TIFF_SHORT, s->photometric_interpretation);
+    add_entry(s,  TIFF_STRIP_OFFS,  TIFF_LONG,  strips, strip_offsets);
 
     if (s->bpp_tab_size)
         add_entry1(s, TIFF_SAMPLES_PER_PIXEL, TIFF_SHORT, s->bpp_tab_size);
@@ -513,6 +516,7 @@ AVCodec ff_tiff_encoder = {
     .encode2        = encode_frame,
     .pix_fmts       = (const enum AVPixelFormat[]) {
         AV_PIX_FMT_RGB24, AV_PIX_FMT_RGB48LE, AV_PIX_FMT_PAL8,
+        AV_PIX_FMT_RGBA,
         AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY16LE,
         AV_PIX_FMT_MONOBLACK, AV_PIX_FMT_MONOWHITE,
         AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV444P,