annotate cscd.c @ 3638:62b3b622f798 libavcodec

Fix A32_BITSTREAM_READER compilation on x86
author aurel
date Sat, 26 Aug 2006 18:12:16 +0000
parents a2f611d6c34d
children c8c591fe26f8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3030
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
1 /*
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
2 * CamStudio decoder
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
3 * Copyright (c) 2006 Reimar Doeffinger
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
4 *
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
9 *
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
13 * Lesser General Public License for more details.
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
14 *
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
3036
0b546eab515d Update licensing information: The FSF changed postal address.
diego
parents: 3034
diff changeset
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
3030
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
18 */
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
19 #include <stdio.h>
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
20 #include <stdlib.h>
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
21
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
22 #include "common.h"
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
23 #include "avcodec.h"
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
24
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
25 #ifdef CONFIG_ZLIB
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
26 #include <zlib.h>
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
27 #endif
3034
d37065d8aeff Our own LZO (1X) implementation, under LGPL and optimized for readability.
reimar
parents: 3030
diff changeset
28 #include "lzo.h"
3030
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
29
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
30 typedef struct {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
31 AVFrame pic;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
32 int linelen, height, bpp;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
33 unsigned int decomp_size;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
34 unsigned char* decomp_buf;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
35 } CamStudioContext;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
36
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
37 static void copy_frame_default(AVFrame *f, uint8_t *src,
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
38 int linelen, int height) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
39 int i;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
40 uint8_t *dst = f->data[0];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
41 dst += (height - 1) * f->linesize[0];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
42 for (i = height; i; i--) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
43 memcpy(dst, src, linelen);
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
44 src += linelen;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
45 dst -= f->linesize[0];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
46 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
47 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
48
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
49 static void add_frame_default(AVFrame *f, uint8_t *src,
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
50 int linelen, int height) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
51 int i, j;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
52 uint8_t *dst = f->data[0];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
53 dst += (height - 1) * f->linesize[0];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
54 for (i = height; i; i--) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
55 for (j = linelen; j; j--)
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
56 *dst++ += *src++;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
57 dst -= f->linesize[0] + linelen;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
58 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
59 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
60
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
61 #ifndef WORDS_BIGENDIAN
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
62 #define copy_frame_16 copy_frame_default
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
63 #define copy_frame_32 copy_frame_default
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
64 #define add_frame_16 add_frame_default
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
65 #define add_frame_32 add_frame_default
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
66 #else
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
67 static void copy_frame_16(AVFrame *f, uint8_t *src,
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
68 int linelen, int height) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
69 int i, j;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
70 uint8_t *dst = f->data[0];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
71 dst += (height - 1) * f->linesize[0];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
72 for (i = height; i; i--) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
73 for (j = linelen / 2; j; j--) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
74 dst[0] = src[1];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
75 dst[1] = src[0];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
76 src += 2;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
77 dst += 2;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
78 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
79 dst -= f->linesize[0] + linelen;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
80 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
81 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
82
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
83 static void copy_frame_32(AVFrame *f, uint8_t *src,
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
84 int linelen, int height) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
85 int i, j;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
86 uint8_t *dst = f->data[0];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
87 dst += (height - 1) * f->linesize[0];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
88 for (i = height; i; i--) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
89 for (j = linelen / 4; j; j--) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
90 dst[0] = src[3];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
91 dst[1] = src[2];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
92 dst[2] = src[1];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
93 dst[3] = src[0];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
94 src += 4;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
95 dst += 4;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
96 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
97 dst -= f->linesize[0] + linelen;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
98 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
99 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
100
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
101 static void add_frame_16(AVFrame *f, uint8_t *src,
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
102 int linelen, int height) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
103 int i, j;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
104 uint8_t *dst = f->data[0];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
105 dst += (height - 1) * f->linesize[0];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
106 for (i = height; i; i--) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
107 for (j = linelen / 2; j; j--) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
108 dst[0] += src[1];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
109 dst[1] += src[0];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
110 src += 2;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
111 dst += 2;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
112 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
113 dst -= f->linesize[0] + linelen;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
114 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
115 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
116
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
117 static void add_frame_32(AVFrame *f, uint8_t *src,
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
118 int linelen, int height) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
119 int i, j;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
120 uint8_t *dst = f->data[0];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
121 dst += (height - 1) * f->linesize[0];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
122 for (i = height; i; i--) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
123 for (j = linelen / 4; j; j--) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
124 dst[0] += src[3];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
125 dst[1] += src[2];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
126 dst[2] += src[1];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
127 dst[3] += src[0];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
128 src += 4;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
129 dst += 4;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
130 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
131 dst -= f->linesize[0] + linelen;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
132 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
133 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
134 #endif
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
135
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
136 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
137 uint8_t *buf, int buf_size) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
138 CamStudioContext *c = (CamStudioContext *)avctx->priv_data;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
139 AVFrame *picture = data;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
140
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
141 if (buf_size < 2) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
142 av_log(avctx, AV_LOG_ERROR, "coded frame too small\n");
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
143 return -1;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
144 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
145
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
146 if (c->pic.data[0])
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
147 avctx->release_buffer(avctx, &c->pic);
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
148 c->pic.reference = 1;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
149 c->pic.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_READABLE |
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
150 FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
151 if (avctx->get_buffer(avctx, &c->pic) < 0) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
152 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
153 return -1;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
154 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
155
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
156 // decompress data
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
157 switch ((buf[0] >> 1) & 7) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
158 case 0: { // lzo compression
3034
d37065d8aeff Our own LZO (1X) implementation, under LGPL and optimized for readability.
reimar
parents: 3030
diff changeset
159 int outlen = c->decomp_size, inlen = buf_size - 2;
d37065d8aeff Our own LZO (1X) implementation, under LGPL and optimized for readability.
reimar
parents: 3030
diff changeset
160 if (lzo1x_decode(c->decomp_buf, &outlen, &buf[2], &inlen))
3030
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
161 av_log(avctx, AV_LOG_ERROR, "error during lzo decompression\n");
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
162 break;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
163 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
164 case 1: { // zlib compression
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
165 #ifdef CONFIG_ZLIB
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
166 unsigned long dlen = c->decomp_size;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
167 if (uncompress(c->decomp_buf, &dlen, &buf[2], buf_size - 2) != Z_OK)
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
168 av_log(avctx, AV_LOG_ERROR, "error during zlib decompression\n");
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
169 break;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
170 #else
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
171 av_log(avctx, AV_LOG_ERROR, "compiled without zlib support\n");
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
172 return -1;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
173 #endif
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
174 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
175 default:
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
176 av_log(avctx, AV_LOG_ERROR, "unknown compression\n");
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
177 return -1;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
178 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
179
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
180 // flip upside down, add difference frame
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
181 if (buf[0] & 1) { // keyframe
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
182 c->pic.pict_type = FF_I_TYPE;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
183 c->pic.key_frame = 1;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
184 switch (c->bpp) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
185 case 16:
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
186 copy_frame_16(&c->pic, c->decomp_buf, c->linelen, c->height);
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
187 break;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
188 case 32:
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
189 copy_frame_32(&c->pic, c->decomp_buf, c->linelen, c->height);
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
190 break;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
191 default:
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
192 copy_frame_default(&c->pic, c->decomp_buf, c->linelen, c->height);
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
193 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
194 } else {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
195 c->pic.pict_type = FF_P_TYPE;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
196 c->pic.key_frame = 0;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
197 switch (c->bpp) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
198 case 16:
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
199 add_frame_16(&c->pic, c->decomp_buf, c->linelen, c->height);
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
200 break;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
201 case 32:
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
202 add_frame_32(&c->pic, c->decomp_buf, c->linelen, c->height);
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
203 break;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
204 default:
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
205 add_frame_default(&c->pic, c->decomp_buf, c->linelen, c->height);
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
206 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
207 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
208
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
209 *picture = c->pic;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
210 *data_size = sizeof(AVFrame);
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
211 return buf_size;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
212 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
213
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
214 static int decode_init(AVCodecContext *avctx) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
215 CamStudioContext *c = (CamStudioContext *)avctx->priv_data;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
216 if (avcodec_check_dimensions(avctx, avctx->height, avctx->width) < 0) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
217 return 1;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
218 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
219 avctx->has_b_frames = 0;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
220 switch (avctx->bits_per_sample) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
221 case 16: avctx->pix_fmt = PIX_FMT_RGB565; break;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
222 case 24: avctx->pix_fmt = PIX_FMT_BGR24; break;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
223 case 32: avctx->pix_fmt = PIX_FMT_RGBA32; break;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
224 default:
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
225 av_log(avctx, AV_LOG_ERROR,
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
226 "CamStudio codec error: unvalid depth %i bpp\n",
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
227 avctx->bits_per_sample);
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
228 return 1;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
229 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
230 c->bpp = avctx->bits_per_sample;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
231 c->pic.data[0] = NULL;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
232 c->linelen = avctx->width * avctx->bits_per_sample / 8;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
233 c->height = avctx->height;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
234 c->decomp_size = c->height * c->linelen;
3060
a2f611d6c34d faster copy functions for lzo decoder that also need padding
reimar
parents: 3036
diff changeset
235 c->decomp_buf = av_malloc(c->decomp_size + LZO_OUTPUT_PADDING);
3030
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
236 if (!c->decomp_buf) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
237 av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n");
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
238 return 1;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
239 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
240 return 0;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
241 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
242
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
243 static int decode_end(AVCodecContext *avctx) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
244 CamStudioContext *c = (CamStudioContext *)avctx->priv_data;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
245 av_freep(&c->decomp_buf);
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
246 if (c->pic.data[0])
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
247 avctx->release_buffer(avctx, &c->pic);
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
248 return 0;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
249 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
250
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
251 AVCodec cscd_decoder = {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
252 "camstudio",
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
253 CODEC_TYPE_VIDEO,
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
254 CODEC_ID_CSCD,
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
255 sizeof(CamStudioContext),
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
256 decode_init,
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
257 NULL,
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
258 decode_end,
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
259 decode_frame,
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
260 CODEC_CAP_DR1,
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
261 };
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
262