summaryrefslogtreecommitdiff
path: root/libavcodec/tiffenc.c
diff options
context:
space:
mode:
Diffstat (limited to 'libavcodec/tiffenc.c')
-rw-r--r--libavcodec/tiffenc.c58
1 files changed, 39 insertions, 19 deletions
diff --git a/libavcodec/tiffenc.c b/libavcodec/tiffenc.c
index 7504216f0a..d7165dc4ef 100644
--- a/libavcodec/tiffenc.c
+++ b/libavcodec/tiffenc.c
@@ -2,20 +2,20 @@
* TIFF image encoder
* Copyright (c) 2007 Bartlomiej Wolowiec
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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 Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -29,9 +29,11 @@
#include "libavutil/opt.h"
#include "avcodec.h"
+#include "internal.h"
#if CONFIG_ZLIB
#include <zlib.h>
#endif
+#include "libavutil/opt.h"
#include "bytestream.h"
#include "tiff.h"
#include "rle.h"
@@ -65,6 +67,7 @@ typedef struct TiffEncoderContext {
int buf_size; ///< buffer size
uint16_t subsampling[2]; ///< YUV subsampling factors
struct LZWEncodeState *lzws; ///< LZW Encode state
+ uint32_t dpi; ///< image resolution in DPI
} TiffEncoderContext;
@@ -212,9 +215,9 @@ static int encode_frame(AVCodecContext * avctx, AVPacket *pkt,
uint32_t *strip_sizes = NULL;
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 };
- int ret;
+ uint32_t res[2] = { s->dpi, 1 }; // image resolution (72/1)
+ 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;
@@ -232,6 +235,26 @@ static int encode_frame(AVCodecContext * avctx, AVPacket *pkt,
s->subsampling[1] = 1;
switch (avctx->pix_fmt) {
+ case PIX_FMT_RGBA64LE:
+ s->bpp = 64;
+ s->photometric_interpretation = 2;
+ bpp_tab[0] = 16;
+ bpp_tab[1] = 16;
+ bpp_tab[2] = 16;
+ bpp_tab[3] = 16;
+ break;
+ 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_RGBA:
+ s->bpp = 32;
+ s->photometric_interpretation = 2;
+ break;
case PIX_FMT_RGB24:
s->bpp = 24;
s->photometric_interpretation = 2;
@@ -245,12 +268,10 @@ static int encode_frame(AVCodecContext * avctx, AVPacket *pkt,
s->photometric_interpretation = 3;
break;
case PIX_FMT_MONOBLACK:
- s->bpp = 1;
- s->photometric_interpretation = 1;
- break;
case PIX_FMT_MONOWHITE:
s->bpp = 1;
- s->photometric_interpretation = 0;
+ s->photometric_interpretation = avctx->pix_fmt == PIX_FMT_MONOBLACK;
+ bpp_tab[0] = 1;
break;
case PIX_FMT_YUV420P:
case PIX_FMT_YUV422P:
@@ -272,7 +293,7 @@ static int encode_frame(AVCodecContext * avctx, AVPacket *pkt,
return -1;
}
if (!is_yuv)
- s->bpp_tab_size = (s->bpp >> 3);
+ s->bpp_tab_size = (s->bpp >= 48) ? ((s->bpp + 7) >> 4):((s->bpp + 7) >> 3);
if (s->compr == TIFF_DEFLATE || s->compr == TIFF_ADOBE_DEFLATE || s->compr == TIFF_LZW)
//best choose for DEFLATE
@@ -283,12 +304,9 @@ static int encode_frame(AVCodecContext * avctx, AVPacket *pkt,
strips = (s->height - 1) / s->rps + 1;
- if (!pkt->data &&
- (ret = av_new_packet(pkt, avctx->width * avctx->height * s->bpp * 2 +
- avctx->height * 4 + FF_MIN_BUFFER_SIZE)) < 0) {
- av_log(avctx, AV_LOG_ERROR, "Error getting output packet.\n");
+ if ((ret = ff_alloc_packet2(avctx, pkt, avctx->width * avctx->height * s->bpp * 2 +
+ avctx->height * 4 + FF_MIN_BUFFER_SIZE)) < 0)
return ret;
- }
ptr = pkt->data;
s->buf_start = pkt->data;
s->buf = &ptr;
@@ -443,12 +461,13 @@ fail:
av_free(strip_sizes);
av_free(strip_offsets);
av_free(yuv_line);
- return ret;
+ return ret < 0 ? ret : 0;
}
#define OFFSET(x) offsetof(TiffEncoderContext, x)
#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
static const AVOption options[] = {
+ {"dpi", "set the image resolution (in dpi)", OFFSET(dpi), AV_OPT_TYPE_INT, {.dbl = 72}, 1, 0x10000, AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_ENCODING_PARAM},
{ "compression_algo", NULL, OFFSET(compr), AV_OPT_TYPE_INT, {TIFF_PACKBITS}, TIFF_RAW, TIFF_DEFLATE, VE, "compression_algo" },
{ "packbits", NULL, 0, AV_OPT_TYPE_CONST, {TIFF_PACKBITS}, 0, 0, VE, "compression_algo" },
{ "raw", NULL, 0, AV_OPT_TYPE_CONST, {TIFF_RAW}, 0, 0, VE, "compression_algo" },
@@ -476,7 +495,8 @@ AVCodec ff_tiff_encoder = {
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_YUV410P, PIX_FMT_YUV411P, PIX_FMT_RGB48LE,
+ PIX_FMT_RGBA, PIX_FMT_RGBA64LE,
PIX_FMT_NONE
},
.long_name = NULL_IF_CONFIG_SMALL("TIFF image"),