annotate pngdec.c @ 6385:40fbc878ce3f libavcodec

pseudo-simd add_bytes and diff_bytes 2x faster than scalar in 32bit, 4x faster in 64bit (as opposed to 8x in mmx)
author lorenm
date Thu, 21 Feb 2008 07:54:46 +0000
parents 0a403ade8c81
children 1a9af4a496f2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
1 /*
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
2 * PNG image format
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
3 * Copyright (c) 2003 Fabrice Bellard.
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
4 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3777
diff changeset
5 * This file is part of FFmpeg.
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3777
diff changeset
6 *
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3777
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3777
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
11 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3777
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
15 * Lesser General Public License for more details.
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
16 *
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3777
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
3036
0b546eab515d Update licensing information: The FSF changed postal address.
diego
parents: 2967
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
20 */
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
21 #include "avcodec.h"
5067
6166fbf375cc Remove duplicate bytestream functions
ramiro
parents: 4515
diff changeset
22 #include "bytestream.h"
5337
26f4095e35d2 separate en/decoder specific parts from png.c
mru
parents: 5097
diff changeset
23 #include "png.h"
6384
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
24 #include "dsputil.h"
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
25
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
26 /* TODO:
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
27 * - add 2, 4 and 16 bit depth support
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
28 */
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
29
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
30 #include <zlib.h>
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
31
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
32 //#define DEBUG
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
33
5339
a8c48a070cff hardly anything in PNGContext is shared; split it
mru
parents: 5337
diff changeset
34 typedef struct PNGDecContext {
6384
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
35 DSPContext dsp;
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
36
6245
michael
parents: 5355
diff changeset
37 const uint8_t *bytestream;
michael
parents: 5355
diff changeset
38 const uint8_t *bytestream_start;
michael
parents: 5355
diff changeset
39 const uint8_t *bytestream_end;
5339
a8c48a070cff hardly anything in PNGContext is shared; split it
mru
parents: 5337
diff changeset
40 AVFrame picture;
a8c48a070cff hardly anything in PNGContext is shared; split it
mru
parents: 5337
diff changeset
41
a8c48a070cff hardly anything in PNGContext is shared; split it
mru
parents: 5337
diff changeset
42 int state;
a8c48a070cff hardly anything in PNGContext is shared; split it
mru
parents: 5337
diff changeset
43 int width, height;
a8c48a070cff hardly anything in PNGContext is shared; split it
mru
parents: 5337
diff changeset
44 int bit_depth;
a8c48a070cff hardly anything in PNGContext is shared; split it
mru
parents: 5337
diff changeset
45 int color_type;
a8c48a070cff hardly anything in PNGContext is shared; split it
mru
parents: 5337
diff changeset
46 int compression_type;
a8c48a070cff hardly anything in PNGContext is shared; split it
mru
parents: 5337
diff changeset
47 int interlace_type;
a8c48a070cff hardly anything in PNGContext is shared; split it
mru
parents: 5337
diff changeset
48 int filter_type;
a8c48a070cff hardly anything in PNGContext is shared; split it
mru
parents: 5337
diff changeset
49 int channels;
a8c48a070cff hardly anything in PNGContext is shared; split it
mru
parents: 5337
diff changeset
50 int bits_per_pixel;
a8c48a070cff hardly anything in PNGContext is shared; split it
mru
parents: 5337
diff changeset
51 int bpp;
a8c48a070cff hardly anything in PNGContext is shared; split it
mru
parents: 5337
diff changeset
52
a8c48a070cff hardly anything in PNGContext is shared; split it
mru
parents: 5337
diff changeset
53 uint8_t *image_buf;
a8c48a070cff hardly anything in PNGContext is shared; split it
mru
parents: 5337
diff changeset
54 int image_linesize;
a8c48a070cff hardly anything in PNGContext is shared; split it
mru
parents: 5337
diff changeset
55 uint32_t palette[256];
a8c48a070cff hardly anything in PNGContext is shared; split it
mru
parents: 5337
diff changeset
56 uint8_t *crow_buf;
a8c48a070cff hardly anything in PNGContext is shared; split it
mru
parents: 5337
diff changeset
57 uint8_t *last_row;
a8c48a070cff hardly anything in PNGContext is shared; split it
mru
parents: 5337
diff changeset
58 uint8_t *tmp_row;
a8c48a070cff hardly anything in PNGContext is shared; split it
mru
parents: 5337
diff changeset
59 int pass;
a8c48a070cff hardly anything in PNGContext is shared; split it
mru
parents: 5337
diff changeset
60 int crow_size; /* compressed row size (include filter type) */
a8c48a070cff hardly anything in PNGContext is shared; split it
mru
parents: 5337
diff changeset
61 int row_size; /* decompressed row size */
a8c48a070cff hardly anything in PNGContext is shared; split it
mru
parents: 5337
diff changeset
62 int pass_row_size; /* decompress row size of the current pass */
a8c48a070cff hardly anything in PNGContext is shared; split it
mru
parents: 5337
diff changeset
63 int y;
a8c48a070cff hardly anything in PNGContext is shared; split it
mru
parents: 5337
diff changeset
64 z_stream zstream;
a8c48a070cff hardly anything in PNGContext is shared; split it
mru
parents: 5337
diff changeset
65 } PNGDecContext;
a8c48a070cff hardly anything in PNGContext is shared; split it
mru
parents: 5337
diff changeset
66
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
67 /* Mask to determine which y pixels can be written in a pass */
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
68 static const uint8_t png_pass_dsp_ymask[NB_PASSES] = {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
69 0xff, 0xff, 0x0f, 0xcc, 0x33, 0xff, 0x55,
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
70 };
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
71
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
72 /* Mask to determine which pixels to overwrite while displaying */
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2661
diff changeset
73 static const uint8_t png_pass_dsp_mask[NB_PASSES] = {
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
74 0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
75 };
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
76
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
77 /* NOTE: we try to construct a good looking image at each pass. width
5355
45d083bbbbe7 typo fixes
diego
parents: 5339
diff changeset
78 is the original image width. We also do pixel format conversion at
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
79 this stage */
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2661
diff changeset
80 static void png_put_interlaced_row(uint8_t *dst, int width,
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2661
diff changeset
81 int bits_per_pixel, int pass,
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
82 int color_type, const uint8_t *src)
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
83 {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
84 int x, mask, dsp_mask, j, src_x, b, bpp;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
85 uint8_t *d;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
86 const uint8_t *s;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2661
diff changeset
87
5337
26f4095e35d2 separate en/decoder specific parts from png.c
mru
parents: 5097
diff changeset
88 mask = ff_png_pass_mask[pass];
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
89 dsp_mask = png_pass_dsp_mask[pass];
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
90 switch(bits_per_pixel) {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
91 case 1:
5097
e9a0c447dc73 spelling
diego
parents: 5089
diff changeset
92 /* we must initialize the line to zero before writing to it */
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
93 if (pass == 0)
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
94 memset(dst, 0, (width + 7) >> 3);
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
95 src_x = 0;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
96 for(x = 0; x < width; x++) {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
97 j = (x & 7);
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
98 if ((dsp_mask << j) & 0x80) {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
99 b = (src[src_x >> 3] >> (7 - (src_x & 7))) & 1;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
100 dst[x >> 3] |= b << (7 - j);
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
101 }
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
102 if ((mask << j) & 0x80)
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
103 src_x++;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
104 }
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
105 break;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
106 default:
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
107 bpp = bits_per_pixel >> 3;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
108 d = dst;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
109 s = src;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
110 if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
111 for(x = 0; x < width; x++) {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
112 j = x & 7;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
113 if ((dsp_mask << j) & 0x80) {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
114 *(uint32_t *)d = (s[3] << 24) | (s[0] << 16) | (s[1] << 8) | s[2];
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
115 }
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
116 d += bpp;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
117 if ((mask << j) & 0x80)
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
118 s += bpp;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
119 }
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
120 } else {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
121 for(x = 0; x < width; x++) {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
122 j = x & 7;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
123 if ((dsp_mask << j) & 0x80) {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
124 memcpy(d, s, bpp);
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
125 }
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
126 d += bpp;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
127 if ((mask << j) & 0x80)
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
128 s += bpp;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
129 }
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
130 }
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
131 break;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
132 }
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
133 }
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
134
6384
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
135 void ff_add_png_paeth_prediction(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp)
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
136 {
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
137 int i;
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
138 for(i = 0; i < w; i++) {
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
139 int a, b, c, p, pa, pb, pc;
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
140
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
141 a = dst[i - bpp];
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
142 b = top[i];
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
143 c = top[i - bpp];
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
144
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
145 p = b - c;
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
146 pc = a - c;
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
147
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
148 pa = abs(p);
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
149 pb = abs(pc);
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
150 pc = abs(p + pc);
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
151
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
152 if (pa <= pb && pa <= pc)
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
153 p = a;
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
154 else if (pb <= pc)
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
155 p = b;
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
156 else
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
157 p = c;
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
158 dst[i] = p + src[i];
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
159 }
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
160 }
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
161
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
162 #define UNROLL1(bpp, op) {\
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
163 r = dst[0];\
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
164 if(bpp >= 2) g = dst[1];\
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
165 if(bpp >= 3) b = dst[2];\
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
166 if(bpp >= 4) a = dst[3];\
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
167 for(; i < size; i+=bpp) {\
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
168 dst[i+0] = r = op(r, src[i+0], last[i+0]);\
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
169 if(bpp == 1) continue;\
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
170 dst[i+1] = g = op(g, src[i+1], last[i+1]);\
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
171 if(bpp == 2) continue;\
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
172 dst[i+2] = b = op(b, src[i+2], last[i+2]);\
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
173 if(bpp == 3) continue;\
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
174 dst[i+3] = a = op(a, src[i+3], last[i+3]);\
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
175 }\
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
176 }
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
177
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
178 #define UNROLL_FILTER(op)\
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
179 if(bpp == 1) UNROLL1(1, op)\
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
180 else if(bpp == 2) UNROLL1(2, op)\
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
181 else if(bpp == 3) UNROLL1(3, op)\
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
182 else if(bpp == 4) UNROLL1(4, op)\
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
183
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
184 /* NOTE: 'dst' can be equal to 'last' */
6384
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
185 static void png_filter_row(DSPContext *dsp, uint8_t *dst, int filter_type,
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
186 uint8_t *src, uint8_t *last, int size, int bpp)
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
187 {
6384
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
188 int i, p, r, g, b, a;
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
189
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
190 switch(filter_type) {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
191 case PNG_FILTER_VALUE_NONE:
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
192 memcpy(dst, src, size);
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
193 break;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
194 case PNG_FILTER_VALUE_SUB:
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
195 for(i = 0; i < bpp; i++) {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
196 dst[i] = src[i];
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
197 }
6384
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
198 if(bpp == 4) {
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
199 p = *(int*)dst;
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
200 for(; i < size; i+=bpp) {
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
201 int s = *(int*)(src+i);
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
202 p = ((s&0x7f7f7f7f) + (p&0x7f7f7f7f)) ^ ((s^p)&0x80808080);
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
203 *(int*)(dst+i) = p;
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
204 }
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
205 } else {
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
206 #define OP_SUB(x,s,l) x+s
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
207 UNROLL_FILTER(OP_SUB);
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
208 }
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
209 break;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
210 case PNG_FILTER_VALUE_UP:
6384
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
211 dsp->add_bytes_l2(dst, src, last, size);
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
212 break;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
213 case PNG_FILTER_VALUE_AVG:
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
214 for(i = 0; i < bpp; i++) {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
215 p = (last[i] >> 1);
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
216 dst[i] = p + src[i];
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
217 }
6384
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
218 #define OP_AVG(x,s,l) (((x + l) >> 1) + s) & 0xff
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
219 UNROLL_FILTER(OP_AVG);
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
220 break;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
221 case PNG_FILTER_VALUE_PAETH:
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
222 for(i = 0; i < bpp; i++) {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
223 p = last[i];
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
224 dst[i] = p + src[i];
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
225 }
6384
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
226 if(bpp > 1 && size > 4) {
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
227 // would write off the end of the array if we let it process the last pixel with bpp=3
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
228 int w = bpp==4 ? size : size-3;
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
229 dsp->add_png_paeth_prediction(dst+i, src+i, last+i, w-i, bpp);
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
230 i = w;
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
231 }
6384
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
232 ff_add_png_paeth_prediction(dst+i, src+i, last+i, size-i, bpp);
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
233 break;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
234 }
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
235 }
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
236
4515
a2b14c6fccfd consistency renaming: rgba32 --> rgb32
diego
parents: 4494
diff changeset
237 static void convert_to_rgb32(uint8_t *dst, const uint8_t *src, int width)
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
238 {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
239 int j;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
240 unsigned int r, g, b, a;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
241
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
242 for(j = 0;j < width; j++) {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
243 r = src[0];
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
244 g = src[1];
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
245 b = src[2];
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
246 a = src[3];
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
247 *(uint32_t *)dst = (a << 24) | (r << 16) | (g << 8) | b;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
248 dst += 4;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
249 src += 4;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
250 }
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
251 }
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
252
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
253 /* process exactly one decompressed row */
5339
a8c48a070cff hardly anything in PNGContext is shared; split it
mru
parents: 5337
diff changeset
254 static void png_handle_row(PNGDecContext *s)
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
255 {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
256 uint8_t *ptr, *last_row;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
257 int got_line;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2661
diff changeset
258
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
259 if (!s->interlace_type) {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
260 ptr = s->image_buf + s->image_linesize * s->y;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
261 /* need to swap bytes correctly for RGB_ALPHA */
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
262 if (s->color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
6384
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
263 png_filter_row(&s->dsp, s->tmp_row, s->crow_buf[0], s->crow_buf + 1,
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
264 s->last_row, s->row_size, s->bpp);
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
265 memcpy(s->last_row, s->tmp_row, s->row_size);
4515
a2b14c6fccfd consistency renaming: rgba32 --> rgb32
diego
parents: 4494
diff changeset
266 convert_to_rgb32(ptr, s->tmp_row, s->width);
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
267 } else {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
268 /* in normal case, we avoid one copy */
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
269 if (s->y == 0)
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
270 last_row = s->last_row;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
271 else
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
272 last_row = ptr - s->image_linesize;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2661
diff changeset
273
6384
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
274 png_filter_row(&s->dsp, ptr, s->crow_buf[0], s->crow_buf + 1,
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
275 last_row, s->row_size, s->bpp);
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
276 }
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
277 s->y++;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
278 if (s->y == s->height) {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
279 s->state |= PNG_ALLIMAGE;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
280 }
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
281 } else {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
282 got_line = 0;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
283 for(;;) {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
284 ptr = s->image_buf + s->image_linesize * s->y;
5337
26f4095e35d2 separate en/decoder specific parts from png.c
mru
parents: 5097
diff changeset
285 if ((ff_png_pass_ymask[s->pass] << (s->y & 7)) & 0x80) {
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
286 /* if we already read one row, it is time to stop to
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
287 wait for the next one */
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
288 if (got_line)
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
289 break;
6384
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
290 png_filter_row(&s->dsp, s->tmp_row, s->crow_buf[0], s->crow_buf + 1,
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
291 s->last_row, s->pass_row_size, s->bpp);
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
292 memcpy(s->last_row, s->tmp_row, s->pass_row_size);
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
293 got_line = 1;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
294 }
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
295 if ((png_pass_dsp_ymask[s->pass] << (s->y & 7)) & 0x80) {
4515
a2b14c6fccfd consistency renaming: rgba32 --> rgb32
diego
parents: 4494
diff changeset
296 /* NOTE: RGB32 is handled directly in png_put_interlaced_row */
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2661
diff changeset
297 png_put_interlaced_row(ptr, s->width, s->bits_per_pixel, s->pass,
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
298 s->color_type, s->last_row);
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
299 }
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
300 s->y++;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
301 if (s->y == s->height) {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
302 for(;;) {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
303 if (s->pass == NB_PASSES - 1) {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
304 s->state |= PNG_ALLIMAGE;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
305 goto the_end;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
306 } else {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
307 s->pass++;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
308 s->y = 0;
5337
26f4095e35d2 separate en/decoder specific parts from png.c
mru
parents: 5097
diff changeset
309 s->pass_row_size = ff_png_pass_row_size(s->pass,
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2661
diff changeset
310 s->bits_per_pixel,
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
311 s->width);
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
312 s->crow_size = s->pass_row_size + 1;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
313 if (s->pass_row_size != 0)
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
314 break;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
315 /* skip pass if empty row */
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
316 }
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
317 }
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
318 }
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
319 }
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
320 the_end: ;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
321 }
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
322 }
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
323
5339
a8c48a070cff hardly anything in PNGContext is shared; split it
mru
parents: 5337
diff changeset
324 static int png_decode_idat(PNGDecContext *s, int length)
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
325 {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
326 int ret;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
327 s->zstream.avail_in = length;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
328 s->zstream.next_in = s->bytestream;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
329 s->bytestream += length;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2661
diff changeset
330
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
331 if(s->bytestream > s->bytestream_end)
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
332 return -1;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
333
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
334 /* decode one line if possible */
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
335 while (s->zstream.avail_in > 0) {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
336 ret = inflate(&s->zstream, Z_PARTIAL_FLUSH);
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
337 if (ret != Z_OK && ret != Z_STREAM_END) {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
338 return -1;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
339 }
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
340 if (s->zstream.avail_out == 0) {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
341 if (!(s->state & PNG_ALLIMAGE)) {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
342 png_handle_row(s);
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
343 }
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
344 s->zstream.avail_out = s->crow_size;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
345 s->zstream.next_out = s->crow_buf;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
346 }
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
347 }
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
348 return 0;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
349 }
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
350
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2661
diff changeset
351 static int decode_frame(AVCodecContext *avctx,
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
352 void *data, int *data_size,
6245
michael
parents: 5355
diff changeset
353 const uint8_t *buf, int buf_size)
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
354 {
5339
a8c48a070cff hardly anything in PNGContext is shared; split it
mru
parents: 5337
diff changeset
355 PNGDecContext * const s = avctx->priv_data;
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
356 AVFrame *picture = data;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
357 AVFrame * const p= (AVFrame*)&s->picture;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
358 uint32_t tag, length;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
359 int ret, crc;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
360
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
361 s->bytestream_start=
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
362 s->bytestream= buf;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
363 s->bytestream_end= buf + buf_size;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
364
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
365 /* check signature */
5337
26f4095e35d2 separate en/decoder specific parts from png.c
mru
parents: 5097
diff changeset
366 if (memcmp(s->bytestream, ff_pngsig, 8) != 0)
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
367 return -1;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
368 s->bytestream+= 8;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
369 s->y=
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
370 s->state=0;
5339
a8c48a070cff hardly anything in PNGContext is shared; split it
mru
parents: 5337
diff changeset
371 // memset(s, 0, sizeof(PNGDecContext));
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
372 /* init the zlib */
5337
26f4095e35d2 separate en/decoder specific parts from png.c
mru
parents: 5097
diff changeset
373 s->zstream.zalloc = ff_png_zalloc;
26f4095e35d2 separate en/decoder specific parts from png.c
mru
parents: 5097
diff changeset
374 s->zstream.zfree = ff_png_zfree;
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
375 s->zstream.opaque = NULL;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
376 ret = inflateInit(&s->zstream);
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
377 if (ret != Z_OK)
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
378 return -1;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
379 for(;;) {
2347
c6280d48be02 When bswap_32 is a macro, png images fail to decode properly, patch by (Milan Cutka <cutka>at<szm>dot<sk>)
michael
parents: 2342
diff changeset
380 int tag32;
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
381 if (s->bytestream >= s->bytestream_end)
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
382 goto fail;
5067
6166fbf375cc Remove duplicate bytestream functions
ramiro
parents: 4515
diff changeset
383 length = bytestream_get_be32(&s->bytestream);
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
384 if (length > 0x7fffffff)
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
385 goto fail;
5067
6166fbf375cc Remove duplicate bytestream functions
ramiro
parents: 4515
diff changeset
386 tag32 = bytestream_get_be32(&s->bytestream);
2347
c6280d48be02 When bswap_32 is a macro, png images fail to decode properly, patch by (Milan Cutka <cutka>at<szm>dot<sk>)
michael
parents: 2342
diff changeset
387 tag = bswap_32(tag32);
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
388 #ifdef DEBUG
3177
8d1b2cc2a75b (f)printf --> av_log conversion
diego
parents: 3036
diff changeset
389 av_log(avctx, AV_LOG_DEBUG, "png: tag=%c%c%c%c length=%u\n",
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
390 (tag & 0xff),
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
391 ((tag >> 8) & 0xff),
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
392 ((tag >> 16) & 0xff),
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
393 ((tag >> 24) & 0xff), length);
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
394 #endif
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
395 switch(tag) {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
396 case MKTAG('I', 'H', 'D', 'R'):
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
397 if (length != 13)
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
398 goto fail;
5067
6166fbf375cc Remove duplicate bytestream functions
ramiro
parents: 4515
diff changeset
399 s->width = bytestream_get_be32(&s->bytestream);
6166fbf375cc Remove duplicate bytestream functions
ramiro
parents: 4515
diff changeset
400 s->height = bytestream_get_be32(&s->bytestream);
2422
18b8b2dcc037 various security fixes and precautionary checks
michael
parents: 2347
diff changeset
401 if(avcodec_check_dimensions(avctx, s->width, s->height)){
18b8b2dcc037 various security fixes and precautionary checks
michael
parents: 2347
diff changeset
402 s->width= s->height= 0;
18b8b2dcc037 various security fixes and precautionary checks
michael
parents: 2347
diff changeset
403 goto fail;
18b8b2dcc037 various security fixes and precautionary checks
michael
parents: 2347
diff changeset
404 }
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
405 s->bit_depth = *s->bytestream++;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
406 s->color_type = *s->bytestream++;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
407 s->compression_type = *s->bytestream++;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
408 s->filter_type = *s->bytestream++;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
409 s->interlace_type = *s->bytestream++;
5067
6166fbf375cc Remove duplicate bytestream functions
ramiro
parents: 4515
diff changeset
410 crc = bytestream_get_be32(&s->bytestream);
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
411 s->state |= PNG_IHDR;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
412 #ifdef DEBUG
3177
8d1b2cc2a75b (f)printf --> av_log conversion
diego
parents: 3036
diff changeset
413 av_log(avctx, AV_LOG_DEBUG, "width=%d height=%d depth=%d color_type=%d compression_type=%d filter_type=%d interlace_type=%d\n",
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2661
diff changeset
414 s->width, s->height, s->bit_depth, s->color_type,
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
415 s->compression_type, s->filter_type, s->interlace_type);
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
416 #endif
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
417 break;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
418 case MKTAG('I', 'D', 'A', 'T'):
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
419 if (!(s->state & PNG_IHDR))
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
420 goto fail;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
421 if (!(s->state & PNG_IDAT)) {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
422 /* init image info */
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
423 avctx->width = s->width;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
424 avctx->height = s->height;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
425
5337
26f4095e35d2 separate en/decoder specific parts from png.c
mru
parents: 5097
diff changeset
426 s->channels = ff_png_get_nb_channels(s->color_type);
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
427 s->bits_per_pixel = s->bit_depth * s->channels;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
428 s->bpp = (s->bits_per_pixel + 7) >> 3;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
429 s->row_size = (avctx->width * s->bits_per_pixel + 7) >> 3;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
430
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2661
diff changeset
431 if (s->bit_depth == 8 &&
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
432 s->color_type == PNG_COLOR_TYPE_RGB) {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
433 avctx->pix_fmt = PIX_FMT_RGB24;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2661
diff changeset
434 } else if (s->bit_depth == 8 &&
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
435 s->color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
4494
ce643a22f049 Replace deprecated PIX_FMT names by the newer variants.
diego
parents: 4379
diff changeset
436 avctx->pix_fmt = PIX_FMT_RGB32;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2661
diff changeset
437 } else if (s->bit_depth == 8 &&
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
438 s->color_type == PNG_COLOR_TYPE_GRAY) {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
439 avctx->pix_fmt = PIX_FMT_GRAY8;
4067
8ab58b7bc06b PNG 16-bit gray decoding support
kostya
parents: 4018
diff changeset
440 } else if (s->bit_depth == 16 &&
8ab58b7bc06b PNG 16-bit gray decoding support
kostya
parents: 4018
diff changeset
441 s->color_type == PNG_COLOR_TYPE_GRAY) {
8ab58b7bc06b PNG 16-bit gray decoding support
kostya
parents: 4018
diff changeset
442 avctx->pix_fmt = PIX_FMT_GRAY16BE;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2661
diff changeset
443 } else if (s->bit_depth == 1 &&
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
444 s->color_type == PNG_COLOR_TYPE_GRAY) {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
445 avctx->pix_fmt = PIX_FMT_MONOBLACK;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
446 } else if (s->color_type == PNG_COLOR_TYPE_PALETTE) {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
447 avctx->pix_fmt = PIX_FMT_PAL8;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
448 } else {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
449 goto fail;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
450 }
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
451 if(p->data[0])
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
452 avctx->release_buffer(avctx, p);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2661
diff changeset
453
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
454 p->reference= 0;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
455 if(avctx->get_buffer(avctx, p) < 0){
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
456 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
457 goto fail;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
458 }
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
459 p->pict_type= FF_I_TYPE;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
460 p->key_frame= 1;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
461 p->interlaced_frame = !!s->interlace_type;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
462
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
463 /* compute the compressed row size */
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
464 if (!s->interlace_type) {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
465 s->crow_size = s->row_size + 1;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
466 } else {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
467 s->pass = 0;
5337
26f4095e35d2 separate en/decoder specific parts from png.c
mru
parents: 5097
diff changeset
468 s->pass_row_size = ff_png_pass_row_size(s->pass,
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2661
diff changeset
469 s->bits_per_pixel,
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
470 s->width);
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
471 s->crow_size = s->pass_row_size + 1;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
472 }
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
473 #ifdef DEBUG
3177
8d1b2cc2a75b (f)printf --> av_log conversion
diego
parents: 3036
diff changeset
474 av_log(avctx, AV_LOG_DEBUG, "row_size=%d crow_size =%d\n",
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
475 s->row_size, s->crow_size);
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
476 #endif
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
477 s->image_buf = p->data[0];
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
478 s->image_linesize = p->linesize[0];
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
479 /* copy the palette if needed */
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
480 if (s->color_type == PNG_COLOR_TYPE_PALETTE)
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
481 memcpy(p->data[1], s->palette, 256 * sizeof(uint32_t));
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
482 /* empty row is used if differencing to the first row */
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
483 s->last_row = av_mallocz(s->row_size);
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
484 if (!s->last_row)
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
485 goto fail;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
486 if (s->interlace_type ||
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
487 s->color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
488 s->tmp_row = av_malloc(s->row_size);
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
489 if (!s->tmp_row)
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
490 goto fail;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
491 }
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
492 /* compressed row */
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
493 s->crow_buf = av_malloc(s->row_size + 1);
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
494 if (!s->crow_buf)
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
495 goto fail;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
496 s->zstream.avail_out = s->crow_size;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
497 s->zstream.next_out = s->crow_buf;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
498 }
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
499 s->state |= PNG_IDAT;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
500 if (png_decode_idat(s, length) < 0)
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
501 goto fail;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
502 /* skip crc */
5067
6166fbf375cc Remove duplicate bytestream functions
ramiro
parents: 4515
diff changeset
503 crc = bytestream_get_be32(&s->bytestream);
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
504 break;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
505 case MKTAG('P', 'L', 'T', 'E'):
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
506 {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
507 int n, i, r, g, b;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2661
diff changeset
508
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
509 if ((length % 3) != 0 || length > 256 * 3)
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
510 goto skip_tag;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
511 /* read the palette */
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
512 n = length / 3;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
513 for(i=0;i<n;i++) {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
514 r = *s->bytestream++;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
515 g = *s->bytestream++;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
516 b = *s->bytestream++;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
517 s->palette[i] = (0xff << 24) | (r << 16) | (g << 8) | b;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
518 }
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
519 for(;i<256;i++) {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
520 s->palette[i] = (0xff << 24);
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
521 }
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
522 s->state |= PNG_PLTE;
5067
6166fbf375cc Remove duplicate bytestream functions
ramiro
parents: 4515
diff changeset
523 crc = bytestream_get_be32(&s->bytestream);
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
524 }
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
525 break;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
526 case MKTAG('t', 'R', 'N', 'S'):
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
527 {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
528 int v, i;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
529
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
530 /* read the transparency. XXX: Only palette mode supported */
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
531 if (s->color_type != PNG_COLOR_TYPE_PALETTE ||
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
532 length > 256 ||
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
533 !(s->state & PNG_PLTE))
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
534 goto skip_tag;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
535 for(i=0;i<length;i++) {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
536 v = *s->bytestream++;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
537 s->palette[i] = (s->palette[i] & 0x00ffffff) | (v << 24);
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
538 }
5067
6166fbf375cc Remove duplicate bytestream functions
ramiro
parents: 4515
diff changeset
539 crc = bytestream_get_be32(&s->bytestream);
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
540 }
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
541 break;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
542 case MKTAG('I', 'E', 'N', 'D'):
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
543 if (!(s->state & PNG_ALLIMAGE))
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
544 goto fail;
5067
6166fbf375cc Remove duplicate bytestream functions
ramiro
parents: 4515
diff changeset
545 crc = bytestream_get_be32(&s->bytestream);
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
546 goto exit_loop;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
547 default:
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
548 /* skip tag */
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
549 skip_tag:
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
550 s->bytestream += length + 4;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
551 break;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
552 }
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
553 }
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
554 exit_loop:
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
555 *picture= *(AVFrame*)&s->picture;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
556 *data_size = sizeof(AVPicture);
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
557
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
558 ret = s->bytestream - s->bytestream_start;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
559 the_end:
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
560 inflateEnd(&s->zstream);
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
561 av_freep(&s->crow_buf);
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
562 av_freep(&s->last_row);
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
563 av_freep(&s->tmp_row);
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
564 return ret;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
565 fail:
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
566 ret = -1;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
567 goto the_end;
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
568 }
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
569
5339
a8c48a070cff hardly anything in PNGContext is shared; split it
mru
parents: 5337
diff changeset
570 static int png_dec_init(AVCodecContext *avctx){
a8c48a070cff hardly anything in PNGContext is shared; split it
mru
parents: 5337
diff changeset
571 PNGDecContext *s = avctx->priv_data;
a8c48a070cff hardly anything in PNGContext is shared; split it
mru
parents: 5337
diff changeset
572
a8c48a070cff hardly anything in PNGContext is shared; split it
mru
parents: 5337
diff changeset
573 avcodec_get_frame_defaults((AVFrame*)&s->picture);
a8c48a070cff hardly anything in PNGContext is shared; split it
mru
parents: 5337
diff changeset
574 avctx->coded_frame= (AVFrame*)&s->picture;
6384
0a403ade8c81 simd and unroll png_filter_row
lorenm
parents: 6245
diff changeset
575 dsputil_init(&s->dsp, avctx);
5339
a8c48a070cff hardly anything in PNGContext is shared; split it
mru
parents: 5337
diff changeset
576
a8c48a070cff hardly anything in PNGContext is shared; split it
mru
parents: 5337
diff changeset
577 return 0;
a8c48a070cff hardly anything in PNGContext is shared; split it
mru
parents: 5337
diff changeset
578 }
a8c48a070cff hardly anything in PNGContext is shared; split it
mru
parents: 5337
diff changeset
579
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
580 AVCodec png_decoder = {
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
581 "png",
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
582 CODEC_TYPE_VIDEO,
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
583 CODEC_ID_PNG,
5339
a8c48a070cff hardly anything in PNGContext is shared; split it
mru
parents: 5337
diff changeset
584 sizeof(PNGDecContext),
a8c48a070cff hardly anything in PNGContext is shared; split it
mru
parents: 5337
diff changeset
585 png_dec_init,
2342
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
586 NULL,
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
587 NULL, //decode_end,
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
588 decode_frame,
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
589 0 /*CODEC_CAP_DR1*/ /*| CODEC_CAP_DRAW_HORIZ_BAND*/,
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
590 NULL
8b6668325ff8 porting png support from -f image to -f image2
michael
parents:
diff changeset
591 };