Browse code

Merge commit '4a0918cae6394e503b17c71f8f171b4a795eb849'

* commit '4a0918cae6394e503b17c71f8f171b4a795eb849':
sgienc: Support encoding high bit depth images with RLE

Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>

Hendrik Leppkes authored on 2015/11/29 23:49:31
Showing 2 changed files
... ...
@@ -36,6 +36,7 @@ version <next>:
36 36
 - IVR demuxer
37 37
 - compensationdelay filter
38 38
 - acompressor filter
39
+- support encoding 16-bit RLE SGI images
39 40
 
40 41
 
41 42
 version 2.8:
... ...
@@ -46,7 +46,10 @@ static int sgi_rle_encode(PutByteContext *pbc, const uint8_t *src,
46 46
     int val, count, x, start = bytestream2_tell_p(pbc);
47 47
     void (*bytestream2_put)(PutByteContext *, unsigned int);
48 48
 
49
-    bytestream2_put = bytestream2_put_byte;
49
+    if (bpp == 1)
50
+        bytestream2_put = bytestream2_put_byte;
51
+    else
52
+        bytestream2_put = bytestream2_put_be16;
50 53
 
51 54
     for (x = 0; x < w; x += count) {
52 55
         /* see if we can encode the next set of pixels with RLE */
... ...
@@ -55,7 +58,7 @@ static int sgi_rle_encode(PutByteContext *pbc, const uint8_t *src,
55 55
             if (bytestream2_get_bytes_left_p(pbc) < bpp * 2)
56 56
                 return AVERROR_INVALIDDATA;
57 57
 
58
-            val = *src;
58
+            val = bpp == 1 ? *src : AV_RB16(src);
59 59
             bytestream2_put(pbc, count);
60 60
             bytestream2_put(pbc, val);
61 61
         } else {
... ...
@@ -67,7 +70,7 @@ static int sgi_rle_encode(PutByteContext *pbc, const uint8_t *src,
67 67
 
68 68
             bytestream2_put(pbc, count + 0x80);
69 69
             for (i = 0; i < count; i++) {
70
-                val = src[i];
70
+                val = bpp == 1 ? src[i] : AV_RB16(src + i * bpp);
71 71
                 bytestream2_put(pbc, val);
72 72
             }
73 73
         }
... ...
@@ -117,7 +120,6 @@ FF_ENABLE_DEPRECATION_WARNINGS
117 117
     case AV_PIX_FMT_GRAY16LE:
118 118
         put_be = !HAVE_BIGENDIAN;
119 119
     case AV_PIX_FMT_GRAY16BE:
120
-        avctx->coder_type = FF_CODER_TYPE_RAW;
121 120
         bytes_per_channel = 2;
122 121
         pixmax = 0xFFFF;
123 122
         dimension = SGI_SINGLE_CHAN;
... ...
@@ -126,7 +128,6 @@ FF_ENABLE_DEPRECATION_WARNINGS
126 126
     case AV_PIX_FMT_RGB48LE:
127 127
         put_be = !HAVE_BIGENDIAN;
128 128
     case AV_PIX_FMT_RGB48BE:
129
-        avctx->coder_type = FF_CODER_TYPE_RAW;
130 129
         bytes_per_channel = 2;
131 130
         pixmax = 0xFFFF;
132 131
         dimension = SGI_MULTI_CHAN;
... ...
@@ -135,7 +136,6 @@ FF_ENABLE_DEPRECATION_WARNINGS
135 135
     case AV_PIX_FMT_RGBA64LE:
136 136
         put_be = !HAVE_BIGENDIAN;
137 137
     case AV_PIX_FMT_RGBA64BE:
138
-        avctx->coder_type = FF_CODER_TYPE_RAW;
139 138
         bytes_per_channel = 2;
140 139
         pixmax = 0xFFFF;
141 140
         dimension = SGI_MULTI_CHAN;
... ...
@@ -191,19 +191,20 @@ FF_ENABLE_DEPRECATION_WARNINGS
191 191
         bytestream2_skip_p(&pbc, tablesize);
192 192
 
193 193
         /* Make an intermediate consecutive buffer. */
194
-        if (!(encode_buf = av_malloc(width)))
194
+        if (!(encode_buf = av_malloc(width * bytes_per_channel)))
195 195
             return AVERROR(ENOMEM);
196 196
 
197 197
         for (z = 0; z < depth; z++) {
198
-            in_buf = p->data[0] + p->linesize[0] * (height - 1) + z;
198
+            in_buf = p->data[0] + p->linesize[0] * (height - 1) + z * bytes_per_channel;
199 199
 
200 200
             for (y = 0; y < height; y++) {
201 201
                 bytestream2_put_be32(&taboff_pcb, bytestream2_tell_p(&pbc));
202 202
 
203
-                for (x = 0; x < width; x++)
203
+                for (x = 0; x < width * bytes_per_channel; x += bytes_per_channel)
204 204
                     encode_buf[x] = in_buf[depth * x];
205 205
 
206
-                length = sgi_rle_encode(&pbc, encode_buf, width, 1);
206
+                length = sgi_rle_encode(&pbc, encode_buf, width,
207
+                                        bytes_per_channel);
207 208
                 if (length < 1) {
208 209
                     av_free(encode_buf);
209 210
                     return -1;