Decoding testet with following compressions for RGB48LE and RGB48BE: LZW, RLE, DEFLATE, NONE
Encoding tested with RGB48LE: PACKBITS, LZW, RAW, DEFLATE
Encoding to RGB48BE is still not supported

thanks ruggles and kshishkov for the help.
Jean
>From 943392225beb8e6eaa61ebe01c54cf48ea48c1dd Mon Sep 17 00:00:00 2001
From: Jean First <[email protected]>
Date: Sat, 24 Sep 2011 00:14:42 +0200
Subject: [PATCH 1/4] increase bit_buffer_size to allow storing tiff header 
encoded with -compression_level 0 (TIFF_RAW)

---
 avconv.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/avconv.c b/avconv.c
index fb744bd..66cbc2b 100644
--- a/avconv.c
+++ b/avconv.c
@@ -2143,7 +2143,7 @@ static int transcode_init(OutputFile *output_files,
         }
         if(codec->codec_type == AVMEDIA_TYPE_VIDEO){
             int size= codec->width * codec->height;
-            bit_buffer_size= FFMAX(bit_buffer_size, 6*size + 200);
+            bit_buffer_size= FFMAX(bit_buffer_size, 6*size + 220);
         }
     }
 
-- 
1.7.4.2

>From 039d9ac487eec34de86ced451880267910eb5dcb Mon Sep 17 00:00:00 2001
From: Jean First <[email protected]>
Date: Sat, 24 Sep 2011 00:19:16 +0200
Subject: [PATCH 2/4] Add decoding of 16 bit tiff files RGB48

---
 libavcodec/tiff.c |   22 ++++++++++++++++++----
 1 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
index ab5f1eb..78d30a7 100644
--- a/libavcodec/tiff.c
+++ b/libavcodec/tiff.c
@@ -572,10 +572,24 @@ static int decode_frame(AVCodecContext *avctx,
         dst = p->data[0];
         soff = s->bpp >> 3;
         ssize = s->width * soff;
-        for(i = 0; i < s->height; i++) {
-            for(j = soff; j < ssize; j++)
-                dst[j] += dst[j - soff];
-            dst += stride;
+        if (s->avctx->pix_fmt == PIX_FMT_RGB48LE) {
+            for (i = 0; i < s->height; i++) {
+                for (j = soff; j < ssize; j += 2)
+                    AV_WL16(dst + j, AV_RL16(dst + j) + AV_RL16(dst + j - 
soff));
+                dst += stride;
+            }
+        } else if (s->avctx->pix_fmt == PIX_FMT_RGB48BE) {
+            for (i = 0; i < s->height; i++) {
+                for (j = soff; j < ssize; j += 2)
+                    AV_WB16(dst + j, AV_RB16(dst + j) + AV_RB16(dst + j - 
soff));
+                dst += stride;
+            }
+        } else {
+            for(i = 0; i < s->height; i++) {
+                for(j = soff; j < ssize; j++)
+                    dst[j] += dst[j - soff];
+                dst += stride;
+            }
         }
     }
 
-- 
1.7.4.2

>From eac0269a6e8e4556032c01caf9cdb3b2d5f632c6 Mon Sep 17 00:00:00 2001
From: Jean First <[email protected]>
Date: Sat, 24 Sep 2011 00:23:03 +0200
Subject: [PATCH 3/4] Add encoding of 16 bit tiff filesi, get rid of the 8k 
limit of stripsize  and initialise a missing s->avctx = avctx

---
 libavcodec/tiffenc.c |   24 +++++++++++++++---------
 1 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/libavcodec/tiffenc.c b/libavcodec/tiffenc.c
index a141a47..cd85b05 100644
--- a/libavcodec/tiffenc.c
+++ b/libavcodec/tiffenc.c
@@ -211,12 +211,13 @@ static int encode_frame(AVCodecContext * avctx, unsigned 
char *buf,
     uint32_t *strip_offsets = NULL;
     int bytes_per_row;
     uint32_t res[2] = { 72, 1 };        // image resolution (72/1)
-    static const uint16_t bpp_tab[] = { 8, 8, 8, 8 };
+    static uint16_t bpp_tab[] = { 8, 8, 8, 8 };
     int ret = -1;
     int is_yuv = 0;
     uint8_t *yuv_line = NULL;
     int shift_h, shift_v;
 
+    s->avctx = avctx;
     s->buf_start = buf;
     s->buf = &ptr;
     s->buf_size = buf_size;
@@ -243,6 +244,14 @@ static int encode_frame(AVCodecContext * avctx, unsigned 
char *buf,
     s->subsampling[1] = 1;
 
     switch (avctx->pix_fmt) {
+    case PIX_FMT_RGB48LE:
+        s->bpp = 48;
+        s->photometric_interpretation = 2;
+        bpp_tab[0] = 16;
+        bpp_tab[1] = 16;
+        bpp_tab[2] = 16;
+        bpp_tab[3] = 16;
+        break;
     case PIX_FMT_RGB24:
         s->bpp = 24;
         s->photometric_interpretation = 2;
@@ -283,13 +292,9 @@ static int encode_frame(AVCodecContext * avctx, unsigned 
char *buf,
         return -1;
     }
     if (!is_yuv)
-        s->bpp_tab_size = (s->bpp >> 3);
+        s->bpp_tab_size = (s->bpp >= 48) ? (s->bpp >> 4) : (s->bpp >> 3);
 
-    if (s->compr == TIFF_DEFLATE || s->compr == TIFF_ADOBE_DEFLATE || s->compr 
== TIFF_LZW)
-        //best choose for DEFLATE
-        s->rps = s->height;
-    else
-        s->rps = FFMAX(8192 / (((s->width * s->bpp) >> 3) + 1), 1);     // 
suggest size of strip
+    s->rps = s->height;
     s->rps = ((s->rps - 1) / s->subsampling[1] + 1) * s->subsampling[1]; // 
round rps up
 
     strips = (s->height - 1) / s->rps + 1;
@@ -450,11 +455,12 @@ AVCodec ff_tiff_encoder = {
     .priv_data_size = sizeof(TiffEncoderContext),
     .encode         = encode_frame,
     .pix_fmts =
-        (const enum PixelFormat[]) {PIX_FMT_RGB24, PIX_FMT_PAL8, PIX_FMT_GRAY8,
+        (const enum PixelFormat[]) {PIX_FMT_RGB24,
+                              PIX_FMT_PAL8, PIX_FMT_GRAY8,
                               PIX_FMT_MONOBLACK, PIX_FMT_MONOWHITE,
                               PIX_FMT_YUV420P, PIX_FMT_YUV422P,
                               PIX_FMT_YUV444P, PIX_FMT_YUV410P,
-                              PIX_FMT_YUV411P,
+                              PIX_FMT_YUV411P, PIX_FMT_RGB48LE,
                               PIX_FMT_NONE},
     .long_name = NULL_IF_CONFIG_SMALL("TIFF image"),
 };
-- 
1.7.4.2

>From 15a24d1273dc9d801c110b20426c67416e3f4e9e Mon Sep 17 00:00:00 2001
From: Jean First <[email protected]>
Date: Sat, 24 Sep 2011 00:32:41 +0200
Subject: [PATCH 4/4] remove some unused variables and some cosmetics do get a 
bit of consistency

---
 libavcodec/tiff.c |   21 +++++++++------------
 1 files changed, 9 insertions(+), 12 deletions(-)

diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
index 78d30a7..d06587f 100644
--- a/libavcodec/tiff.c
+++ b/libavcodec/tiff.c
@@ -568,7 +568,7 @@ static int decode_frame(AVCodecContext *avctx,
             break;
         dst += s->rps * stride;
     }
-    if(s->predictor == 2){
+    if (s->predictor == 2) {
         dst = p->data[0];
         soff = s->bpp >> 3;
         ssize = s->width * soff;
@@ -585,23 +585,20 @@ static int decode_frame(AVCodecContext *avctx,
                 dst += stride;
             }
         } else {
-            for(i = 0; i < s->height; i++) {
-                for(j = soff; j < ssize; j++)
+            for (i = 0; i < s->height; i++) {
+                for (j = soff; j < ssize; j++)
                     dst[j] += dst[j - soff];
                 dst += stride;
             }
         }
     }
 
-    if(s->invert){
-        uint8_t *src;
-        int j;
-
-        src = s->picture.data[0];
-        for(j = 0; j < s->height; j++){
-            for(i = 0; i < s->picture.linesize[0]; i++)
-                src[i] = 255 - src[i];
-            src += s->picture.linesize[0];
+    if (s->invert){
+        dst = s->picture.data[0];
+        for (i = 0; i < s->height; i++) {
+            for (j = 0; j < s->picture.linesize[0]; j++)
+                dst[j] = 255 - src[j];
+            dst += s->picture.linesize[0];
         }
     }
     *picture= *(AVFrame*)&s->picture;
-- 
1.7.4.2

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to