1 /*
2 * TechSmith Camtasia decoder
3 * Copyright (c) 2004 Konstantin Shishkov
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * TechSmith Camtasia decoder
25 *
26 * Fourcc: TSCC
27 *
28 * Codec is very simple:
29 * it codes picture (picture difference, really)
30 * with algorithm almost identical to Windows RLE8,
31 * only without padding and with greater pixel sizes,
32 * then this coded picture is packed with ZLib
33 *
34 * Supports: BGR8,BGR555,BGR24 - only BGR8 and BGR555 tested
35 */
36
37 #include <stdio.h>
38 #include <stdlib.h>
39
43
44 #include <zlib.h>
45
46 typedef struct TsccContext {
47
50
51 // Bits per pixel
53 // Decompressed data size
55 // Decompression buffer
60
63
66 {
68 int buf_size = avpkt->
size;
71 int ret;
72
74 return ret;
75
76 ret = inflateReset(&c->
zstream);
77 if (ret != Z_OK) {
80 }
86 // Z_DATA_ERROR means empty picture
87 if ((ret != Z_OK) && (ret != Z_STREAM_END) && (ret != Z_DATA_ERROR)) {
90 }
91
92
93 if (ret != Z_DATA_ERROR) {
97 }
98
99 /* make the palette available on the way out */
103
107 } else if (pal) {
109 }
111 }
112
114 return ret;
115 *got_frame = 1;
116
117 /* always report that the buffer was completely consumed */
118 return buf_size;
119 }
120
122 {
124 int zret; // Zlib return code
125
127
129
130 // Needed if zlib unused or init aborted before inflateInit
131 memset(&c->
zstream, 0,
sizeof(z_stream));
135 case 24:
137 break;
141 }
143 // buffer size for RLE 'best' case when 2-byte code precedes each pixel and there may be padding after it too
145
146 /* Allocate decompression buffer */
151 }
152 }
153
157 zret = inflateInit(&c->
zstream);
158 if (zret != Z_OK) {
161 }
162
164
165 return 0;
166 }
167
169 {
171
174
176
177 return 0;
178 }
179
190 };
This structure describes decoded (raw) audio or video data.
int ff_msrle_decode(AVCodecContext *avctx, AVFrame *pic, int depth, GetByteContext *gb)
Decode stream in MS RLE format into frame.
ptrdiff_t const GLvoid * data
static av_cold int init(AVCodecContext *avctx)
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
unsigned char * decomp_buf
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame)
Identical in function to av_frame_make_writable(), except it uses ff_get_buffer() to allocate the buf...
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
8 bits with AV_PIX_FMT_RGB32 palette
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
static av_cold int decode_init(AVCodecContext *avctx)
static void inflate(uint8_t *dst, const uint8_t *p1, int width, int threshold, const uint8_t *coordinates[], int coord)
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
An AV_PKT_DATA_PALETTE side data packet contains exactly AVPALETTE_SIZE bytes worth of palette...
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, int *size)
Get side information from packet.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
const char * name
Name of the codec implementation.
int width
picture width / height.
packed RGB 8:8:8, 24bpp, BGRBGR...
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Libavcodec external API header.
main external API structure.
int palette_has_changed
Tell user application that palette has changed from previous frame.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
common internal api header.
#define AV_PIX_FMT_RGB555
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
static av_cold int decode_end(AVCodecContext *avctx)
This structure stores compressed data.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
#define AV_PIX_FMT_0RGB32