summaryrefslogtreecommitdiff
path: root/libavcodec/tiff.c
diff options
context:
space:
mode:
authorLuca Barbato <lu_zero@gentoo.org>2013-06-03 03:58:17 +0200
committerLuca Barbato <lu_zero@gentoo.org>2013-06-07 17:23:53 +0200
commit016c5b066de08a93a5f6b5beb0ef377356b35cde (patch)
tree662f6b86b30f791fb8b21556fd1dd72266da800f /libavcodec/tiff.c
parent103937681d7e6afd3e8caf8937272575e450fb55 (diff)
tiff: refactor fax support in a separate function
Diffstat (limited to 'libavcodec/tiff.c')
-rw-r--r--libavcodec/tiff.c65
1 files changed, 33 insertions, 32 deletions
diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
index e4ea0ba7ce..2471f33ec6 100644
--- a/libavcodec/tiff.c
+++ b/libavcodec/tiff.c
@@ -142,6 +142,38 @@ static int tiff_unpack_zlib(TiffContext *s, uint8_t *dst, int stride,
}
#endif
+
+static int tiff_unpack_fax(TiffContext *s, uint8_t *dst, int stride,
+ const uint8_t *src, int size, int lines)
+{
+ int i, ret = 0;
+ uint8_t *src2 = av_malloc((unsigned)size +
+ FF_INPUT_BUFFER_PADDING_SIZE);
+
+ if (!src2) {
+ av_log(s->avctx, AV_LOG_ERROR,
+ "Error allocating temporary buffer\n");
+ return AVERROR(ENOMEM);
+ }
+ if (s->fax_opts & 2) {
+ av_log(s->avctx, AV_LOG_ERROR,
+ "Uncompressed fax mode is not supported (yet)\n");
+ av_free(src2);
+ return AVERROR_INVALIDDATA;
+ }
+ if (!s->fill_order) {
+ memcpy(src2, src, size);
+ } else {
+ for (i = 0; i < size; i++)
+ src2[i] = ff_reverse[src[i]];
+ }
+ memset(src2 + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
+ ret = ff_ccitt_unpack(s->avctx, src2, size, dst, lines, stride,
+ s->compr, s->fax_opts);
+ av_free(src2);
+ return ret;
+}
+
static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride,
const uint8_t *src, int size, int lines)
{
@@ -171,38 +203,7 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride,
if (s->compr == TIFF_CCITT_RLE ||
s->compr == TIFF_G3 ||
s->compr == TIFF_G4) {
- int i, ret = 0;
- uint8_t *src2 = av_malloc((unsigned)size +
- FF_INPUT_BUFFER_PADDING_SIZE);
-
- if (!src2) {
- av_log(s->avctx, AV_LOG_ERROR,
- "Error allocating temporary buffer\n");
- return AVERROR(ENOMEM);
- }
- if (s->fax_opts & 2) {
- av_log(s->avctx, AV_LOG_ERROR,
- "Uncompressed fax mode is not supported (yet)\n");
- av_free(src2);
- return AVERROR_INVALIDDATA;
- }
- if (!s->fill_order) {
- memcpy(src2, src, size);
- } else {
- for (i = 0; i < size; i++)
- src2[i] = ff_reverse[src[i]];
- }
- memset(src2 + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
- switch (s->compr) {
- case TIFF_CCITT_RLE:
- case TIFF_G3:
- case TIFF_G4:
- ret = ff_ccitt_unpack(s->avctx, src2, size, dst, lines, stride,
- s->compr, s->fax_opts);
- break;
- }
- av_free(src2);
- return ret;
+ return tiff_unpack_fax(s, dst, stride, src, size, lines);
}
for (line = 0; line < lines; line++) {
if (src - ssrc > size) {