00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "libavutil/imgutils.h"
00025 #include "avcodec.h"
00026 #include "bytestream.h"
00027 #include "png.h"
00028
00029
00030
00031
00032
00033 #include <zlib.h>
00034
00035
00036 static const uint8_t png_pass_dsp_ymask[NB_PASSES] = {
00037 0xff, 0xff, 0x0f, 0xcc, 0x33, 0xff, 0x55,
00038 };
00039
00040
00041 static const uint8_t png_pass_dsp_mask[NB_PASSES] = {
00042 0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff
00043 };
00044
00045
00046
00047
00048 static void png_put_interlaced_row(uint8_t *dst, int width,
00049 int bits_per_pixel, int pass,
00050 int color_type, const uint8_t *src)
00051 {
00052 int x, mask, dsp_mask, j, src_x, b, bpp;
00053 uint8_t *d;
00054 const uint8_t *s;
00055
00056 mask = ff_png_pass_mask[pass];
00057 dsp_mask = png_pass_dsp_mask[pass];
00058 switch(bits_per_pixel) {
00059 case 1:
00060 src_x = 0;
00061 for(x = 0; x < width; x++) {
00062 j = (x & 7);
00063 if ((dsp_mask << j) & 0x80) {
00064 b = (src[src_x >> 3] >> (7 - (src_x & 7))) & 1;
00065 dst[x >> 3] &= 0xFF7F>>j;
00066 dst[x >> 3] |= b << (7 - j);
00067 }
00068 if ((mask << j) & 0x80)
00069 src_x++;
00070 }
00071 break;
00072 case 2:
00073 src_x = 0;
00074 for(x = 0; x < width; x++) {
00075 int j2 = 2*(x&3);
00076 j = (x & 7);
00077 if ((dsp_mask << j) & 0x80) {
00078 b = (src[src_x >> 2] >> (6 - 2*(src_x & 3))) & 3;
00079 dst[x >> 2] &= 0xFF3F>>j2;
00080 dst[x >> 2] |= b << (6 - j2);
00081 }
00082 if ((mask << j) & 0x80)
00083 src_x++;
00084 }
00085 break;
00086 case 4:
00087 src_x = 0;
00088 for(x = 0; x < width; x++) {
00089 int j2 = 4*(x&1);
00090 j = (x & 7);
00091 if ((dsp_mask << j) & 0x80) {
00092 b = (src[src_x >> 1] >> (4 - 4*(src_x & 1))) & 15;
00093 dst[x >> 1] &= 0xFF0F>>j2;
00094 dst[x >> 1] |= b << (4 - j2);
00095 }
00096 if ((mask << j) & 0x80)
00097 src_x++;
00098 }
00099 break;
00100 default:
00101 bpp = bits_per_pixel >> 3;
00102 d = dst;
00103 s = src;
00104 if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
00105 for(x = 0; x < width; x++) {
00106 j = x & 7;
00107 if ((dsp_mask << j) & 0x80) {
00108 *(uint32_t *)d = (s[3] << 24) | (s[0] << 16) | (s[1] << 8) | s[2];
00109 }
00110 d += bpp;
00111 if ((mask << j) & 0x80)
00112 s += bpp;
00113 }
00114 } else {
00115 for(x = 0; x < width; x++) {
00116 j = x & 7;
00117 if ((dsp_mask << j) & 0x80) {
00118 memcpy(d, s, bpp);
00119 }
00120 d += bpp;
00121 if ((mask << j) & 0x80)
00122 s += bpp;
00123 }
00124 }
00125 break;
00126 }
00127 }
00128
00129
00130 #define pb_7f (~0UL/255 * 0x7f)
00131 #define pb_80 (~0UL/255 * 0x80)
00132
00133 static void add_bytes_l2_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w)
00134 {
00135 long i;
00136 for(i=0; i<=w-sizeof(long); i+=sizeof(long)){
00137 long a = *(long*)(src1+i);
00138 long b = *(long*)(src2+i);
00139 *(long*)(dst+i) = ((a&pb_7f) + (b&pb_7f)) ^ ((a^b)&pb_80);
00140 }
00141 for(; i<w; i++)
00142 dst[i] = src1[i]+src2[i];
00143 }
00144
00145 static void add_paeth_prediction_c(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp)
00146 {
00147 int i;
00148 for(i = 0; i < w; i++) {
00149 int a, b, c, p, pa, pb, pc;
00150
00151 a = dst[i - bpp];
00152 b = top[i];
00153 c = top[i - bpp];
00154
00155 p = b - c;
00156 pc = a - c;
00157
00158 pa = abs(p);
00159 pb = abs(pc);
00160 pc = abs(p + pc);
00161
00162 if (pa <= pb && pa <= pc)
00163 p = a;
00164 else if (pb <= pc)
00165 p = b;
00166 else
00167 p = c;
00168 dst[i] = p + src[i];
00169 }
00170 }
00171
00172 #define UNROLL1(bpp, op) {\
00173 r = dst[0];\
00174 if(bpp >= 2) g = dst[1];\
00175 if(bpp >= 3) b = dst[2];\
00176 if(bpp >= 4) a = dst[3];\
00177 for(; i < size; i+=bpp) {\
00178 dst[i+0] = r = op(r, src[i+0], last[i+0]);\
00179 if(bpp == 1) continue;\
00180 dst[i+1] = g = op(g, src[i+1], last[i+1]);\
00181 if(bpp == 2) continue;\
00182 dst[i+2] = b = op(b, src[i+2], last[i+2]);\
00183 if(bpp == 3) continue;\
00184 dst[i+3] = a = op(a, src[i+3], last[i+3]);\
00185 }\
00186 }
00187
00188 #define UNROLL_FILTER(op)\
00189 if(bpp == 1) UNROLL1(1, op)\
00190 else if(bpp == 2) UNROLL1(2, op)\
00191 else if(bpp == 3) UNROLL1(3, op)\
00192 else if(bpp == 4) UNROLL1(4, op)\
00193 else {\
00194 for (; i < size; i += bpp) {\
00195 int j;\
00196 for (j = 0; j < bpp; j++)\
00197 dst[i+j] = op(dst[i+j-bpp], src[i+j], last[i+j]);\
00198 }\
00199 }
00200
00201
00202 static void png_filter_row(PNGDecContext *s, uint8_t *dst, int filter_type,
00203 uint8_t *src, uint8_t *last, int size, int bpp)
00204 {
00205 int i, p, r, g, b, a;
00206
00207 switch(filter_type) {
00208 case PNG_FILTER_VALUE_NONE:
00209 memcpy(dst, src, size);
00210 break;
00211 case PNG_FILTER_VALUE_SUB:
00212 for(i = 0; i < bpp; i++) {
00213 dst[i] = src[i];
00214 }
00215 if(bpp == 4) {
00216 p = *(int*)dst;
00217 for(; i < size; i+=bpp) {
00218 int s = *(int*)(src+i);
00219 p = ((s&0x7f7f7f7f) + (p&0x7f7f7f7f)) ^ ((s^p)&0x80808080);
00220 *(int*)(dst+i) = p;
00221 }
00222 } else {
00223 #define OP_SUB(x,s,l) x+s
00224 UNROLL_FILTER(OP_SUB);
00225 }
00226 break;
00227 case PNG_FILTER_VALUE_UP:
00228 s->add_bytes_l2(dst, src, last, size);
00229 break;
00230 case PNG_FILTER_VALUE_AVG:
00231 for(i = 0; i < bpp; i++) {
00232 p = (last[i] >> 1);
00233 dst[i] = p + src[i];
00234 }
00235 #define OP_AVG(x,s,l) (((x + l) >> 1) + s) & 0xff
00236 UNROLL_FILTER(OP_AVG);
00237 break;
00238 case PNG_FILTER_VALUE_PAETH:
00239 for(i = 0; i < bpp; i++) {
00240 p = last[i];
00241 dst[i] = p + src[i];
00242 }
00243 if(bpp > 1 && size > 4) {
00244
00245 int w = bpp==4 ? size : size-3;
00246 s->add_paeth_prediction(dst+i, src+i, last+i, w-i, bpp);
00247 i = w;
00248 }
00249 add_paeth_prediction_c(dst+i, src+i, last+i, size-i, bpp);
00250 break;
00251 }
00252 }
00253
00254 static av_always_inline void convert_to_rgb32_loco(uint8_t *dst, const uint8_t *src, int width, int loco)
00255 {
00256 int j;
00257 unsigned int r, g, b, a;
00258
00259 for(j = 0;j < width; j++) {
00260 r = src[0];
00261 g = src[1];
00262 b = src[2];
00263 a = src[3];
00264 if(loco) {
00265 r = (r+g)&0xff;
00266 b = (b+g)&0xff;
00267 }
00268 *(uint32_t *)dst = (a << 24) | (r << 16) | (g << 8) | b;
00269 dst += 4;
00270 src += 4;
00271 }
00272 }
00273
00274 static void convert_to_rgb32(uint8_t *dst, const uint8_t *src, int width, int loco)
00275 {
00276 if(loco)
00277 convert_to_rgb32_loco(dst, src, width, 1);
00278 else
00279 convert_to_rgb32_loco(dst, src, width, 0);
00280 }
00281
00282 static void deloco_rgb24(uint8_t *dst, int size)
00283 {
00284 int i;
00285 for(i=0; i<size; i+=3) {
00286 int g = dst[i+1];
00287 dst[i+0] += g;
00288 dst[i+2] += g;
00289 }
00290 }
00291
00292
00293 static void png_handle_row(PNGDecContext *s)
00294 {
00295 uint8_t *ptr, *last_row;
00296 int got_line;
00297
00298 if (!s->interlace_type) {
00299 ptr = s->image_buf + s->image_linesize * s->y;
00300
00301 if (s->color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
00302 png_filter_row(s, s->tmp_row, s->crow_buf[0], s->crow_buf + 1,
00303 s->last_row, s->row_size, s->bpp);
00304 convert_to_rgb32(ptr, s->tmp_row, s->width, s->filter_type == PNG_FILTER_TYPE_LOCO);
00305 FFSWAP(uint8_t*, s->last_row, s->tmp_row);
00306 } else {
00307
00308 if (s->y == 0)
00309 last_row = s->last_row;
00310 else
00311 last_row = ptr - s->image_linesize;
00312
00313 png_filter_row(s, ptr, s->crow_buf[0], s->crow_buf + 1,
00314 last_row, s->row_size, s->bpp);
00315 }
00316
00317 if (s->filter_type == PNG_FILTER_TYPE_LOCO &&
00318 s->color_type == PNG_COLOR_TYPE_RGB && s->y > 0)
00319 deloco_rgb24(ptr - s->image_linesize, s->row_size);
00320 s->y++;
00321 if (s->y == s->height) {
00322 s->state |= PNG_ALLIMAGE;
00323 if (s->filter_type == PNG_FILTER_TYPE_LOCO &&
00324 s->color_type == PNG_COLOR_TYPE_RGB)
00325 deloco_rgb24(ptr, s->row_size);
00326 }
00327 } else {
00328 got_line = 0;
00329 for(;;) {
00330 ptr = s->image_buf + s->image_linesize * s->y;
00331 if ((ff_png_pass_ymask[s->pass] << (s->y & 7)) & 0x80) {
00332
00333
00334 if (got_line)
00335 break;
00336 png_filter_row(s, s->tmp_row, s->crow_buf[0], s->crow_buf + 1,
00337 s->last_row, s->pass_row_size, s->bpp);
00338 FFSWAP(uint8_t*, s->last_row, s->tmp_row);
00339 got_line = 1;
00340 }
00341 if ((png_pass_dsp_ymask[s->pass] << (s->y & 7)) & 0x80) {
00342
00343 png_put_interlaced_row(ptr, s->width, s->bits_per_pixel, s->pass,
00344 s->color_type, s->last_row);
00345 }
00346 s->y++;
00347 if (s->y == s->height) {
00348 memset(s->last_row, 0, s->row_size);
00349 for(;;) {
00350 if (s->pass == NB_PASSES - 1) {
00351 s->state |= PNG_ALLIMAGE;
00352 goto the_end;
00353 } else {
00354 s->pass++;
00355 s->y = 0;
00356 s->pass_row_size = ff_png_pass_row_size(s->pass,
00357 s->bits_per_pixel,
00358 s->width);
00359 s->crow_size = s->pass_row_size + 1;
00360 if (s->pass_row_size != 0)
00361 break;
00362
00363 }
00364 }
00365 }
00366 }
00367 the_end: ;
00368 }
00369 }
00370
00371 static int png_decode_idat(PNGDecContext *s, int length)
00372 {
00373 int ret;
00374 s->zstream.avail_in = length;
00375 s->zstream.next_in = s->bytestream;
00376 s->bytestream += length;
00377
00378 if(s->bytestream > s->bytestream_end)
00379 return -1;
00380
00381
00382 while (s->zstream.avail_in > 0) {
00383 ret = inflate(&s->zstream, Z_PARTIAL_FLUSH);
00384 if (ret != Z_OK && ret != Z_STREAM_END) {
00385 return -1;
00386 }
00387 if (s->zstream.avail_out == 0) {
00388 if (!(s->state & PNG_ALLIMAGE)) {
00389 png_handle_row(s);
00390 }
00391 s->zstream.avail_out = s->crow_size;
00392 s->zstream.next_out = s->crow_buf;
00393 }
00394 }
00395 return 0;
00396 }
00397
00398 static int decode_frame(AVCodecContext *avctx,
00399 void *data, int *data_size,
00400 AVPacket *avpkt)
00401 {
00402 const uint8_t *buf = avpkt->data;
00403 int buf_size = avpkt->size;
00404 PNGDecContext * const s = avctx->priv_data;
00405 AVFrame *picture = data;
00406 AVFrame *p;
00407 uint8_t *crow_buf_base = NULL;
00408 uint32_t tag, length;
00409 int ret;
00410
00411 FFSWAP(AVFrame *, s->current_picture, s->last_picture);
00412 avctx->coded_frame= s->current_picture;
00413 p = s->current_picture;
00414
00415 s->bytestream_start=
00416 s->bytestream= buf;
00417 s->bytestream_end= buf + buf_size;
00418
00419
00420 if (memcmp(s->bytestream, ff_pngsig, 8) != 0 &&
00421 memcmp(s->bytestream, ff_mngsig, 8) != 0)
00422 return -1;
00423 s->bytestream+= 8;
00424 s->y=
00425 s->state=0;
00426
00427
00428 s->zstream.zalloc = ff_png_zalloc;
00429 s->zstream.zfree = ff_png_zfree;
00430 s->zstream.opaque = NULL;
00431 ret = inflateInit(&s->zstream);
00432 if (ret != Z_OK)
00433 return -1;
00434 for(;;) {
00435 int tag32;
00436 if (s->bytestream >= s->bytestream_end)
00437 goto fail;
00438 length = bytestream_get_be32(&s->bytestream);
00439 if (length > 0x7fffffff)
00440 goto fail;
00441 tag32 = bytestream_get_be32(&s->bytestream);
00442 tag = av_bswap32(tag32);
00443 av_dlog(avctx, "png: tag=%c%c%c%c length=%u\n",
00444 (tag & 0xff),
00445 ((tag >> 8) & 0xff),
00446 ((tag >> 16) & 0xff),
00447 ((tag >> 24) & 0xff), length);
00448 switch(tag) {
00449 case MKTAG('I', 'H', 'D', 'R'):
00450 if (length != 13)
00451 goto fail;
00452 s->width = bytestream_get_be32(&s->bytestream);
00453 s->height = bytestream_get_be32(&s->bytestream);
00454 if(av_image_check_size(s->width, s->height, 0, avctx)){
00455 s->width= s->height= 0;
00456 goto fail;
00457 }
00458 s->bit_depth = *s->bytestream++;
00459 s->color_type = *s->bytestream++;
00460 s->compression_type = *s->bytestream++;
00461 s->filter_type = *s->bytestream++;
00462 s->interlace_type = *s->bytestream++;
00463 s->bytestream += 4;
00464 s->state |= PNG_IHDR;
00465 av_dlog(avctx, "width=%d height=%d depth=%d color_type=%d compression_type=%d filter_type=%d interlace_type=%d\n",
00466 s->width, s->height, s->bit_depth, s->color_type,
00467 s->compression_type, s->filter_type, s->interlace_type);
00468 break;
00469 case MKTAG('I', 'D', 'A', 'T'):
00470 if (!(s->state & PNG_IHDR))
00471 goto fail;
00472 if (!(s->state & PNG_IDAT)) {
00473
00474 avctx->width = s->width;
00475 avctx->height = s->height;
00476
00477 s->channels = ff_png_get_nb_channels(s->color_type);
00478 s->bits_per_pixel = s->bit_depth * s->channels;
00479 s->bpp = (s->bits_per_pixel + 7) >> 3;
00480 s->row_size = (avctx->width * s->bits_per_pixel + 7) >> 3;
00481
00482 if (s->bit_depth == 8 &&
00483 s->color_type == PNG_COLOR_TYPE_RGB) {
00484 avctx->pix_fmt = PIX_FMT_RGB24;
00485 } else if (s->bit_depth == 8 &&
00486 s->color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
00487 avctx->pix_fmt = PIX_FMT_RGB32;
00488 } else if (s->bit_depth == 8 &&
00489 s->color_type == PNG_COLOR_TYPE_GRAY) {
00490 avctx->pix_fmt = PIX_FMT_GRAY8;
00491 } else if (s->bit_depth == 16 &&
00492 s->color_type == PNG_COLOR_TYPE_GRAY) {
00493 avctx->pix_fmt = PIX_FMT_GRAY16BE;
00494 } else if (s->bit_depth == 16 &&
00495 s->color_type == PNG_COLOR_TYPE_RGB) {
00496 avctx->pix_fmt = PIX_FMT_RGB48BE;
00497 } else if (s->bit_depth == 1) {
00498 avctx->pix_fmt = PIX_FMT_MONOBLACK;
00499 } else if (s->color_type == PNG_COLOR_TYPE_PALETTE) {
00500 avctx->pix_fmt = PIX_FMT_PAL8;
00501 } else if (s->bit_depth == 8 &&
00502 s->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
00503 avctx->pix_fmt = PIX_FMT_GRAY8A;
00504 } else {
00505 goto fail;
00506 }
00507 if(p->data[0])
00508 avctx->release_buffer(avctx, p);
00509
00510 p->reference= 3;
00511 if(avctx->get_buffer(avctx, p) < 0){
00512 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
00513 goto fail;
00514 }
00515 p->pict_type= AV_PICTURE_TYPE_I;
00516 p->key_frame= 1;
00517 p->interlaced_frame = !!s->interlace_type;
00518
00519
00520 if (!s->interlace_type) {
00521 s->crow_size = s->row_size + 1;
00522 } else {
00523 s->pass = 0;
00524 s->pass_row_size = ff_png_pass_row_size(s->pass,
00525 s->bits_per_pixel,
00526 s->width);
00527 s->crow_size = s->pass_row_size + 1;
00528 }
00529 av_dlog(avctx, "row_size=%d crow_size =%d\n",
00530 s->row_size, s->crow_size);
00531 s->image_buf = p->data[0];
00532 s->image_linesize = p->linesize[0];
00533
00534 if (avctx->pix_fmt == PIX_FMT_PAL8)
00535 memcpy(p->data[1], s->palette, 256 * sizeof(uint32_t));
00536
00537 s->last_row = av_mallocz(s->row_size);
00538 if (!s->last_row)
00539 goto fail;
00540 if (s->interlace_type ||
00541 s->color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
00542 s->tmp_row = av_malloc(s->row_size);
00543 if (!s->tmp_row)
00544 goto fail;
00545 }
00546
00547 crow_buf_base = av_malloc(s->row_size + 16);
00548 if (!crow_buf_base)
00549 goto fail;
00550
00551
00552 s->crow_buf = crow_buf_base + 15;
00553 s->zstream.avail_out = s->crow_size;
00554 s->zstream.next_out = s->crow_buf;
00555 }
00556 s->state |= PNG_IDAT;
00557 if (png_decode_idat(s, length) < 0)
00558 goto fail;
00559 s->bytestream += 4;
00560 break;
00561 case MKTAG('P', 'L', 'T', 'E'):
00562 {
00563 int n, i, r, g, b;
00564
00565 if ((length % 3) != 0 || length > 256 * 3)
00566 goto skip_tag;
00567
00568 n = length / 3;
00569 for(i=0;i<n;i++) {
00570 r = *s->bytestream++;
00571 g = *s->bytestream++;
00572 b = *s->bytestream++;
00573 s->palette[i] = (0xff << 24) | (r << 16) | (g << 8) | b;
00574 }
00575 for(;i<256;i++) {
00576 s->palette[i] = (0xff << 24);
00577 }
00578 s->state |= PNG_PLTE;
00579 s->bytestream += 4;
00580 }
00581 break;
00582 case MKTAG('t', 'R', 'N', 'S'):
00583 {
00584 int v, i;
00585
00586
00587 if (s->color_type != PNG_COLOR_TYPE_PALETTE ||
00588 length > 256 ||
00589 !(s->state & PNG_PLTE))
00590 goto skip_tag;
00591 for(i=0;i<length;i++) {
00592 v = *s->bytestream++;
00593 s->palette[i] = (s->palette[i] & 0x00ffffff) | (v << 24);
00594 }
00595 s->bytestream += 4;
00596 }
00597 break;
00598 case MKTAG('I', 'E', 'N', 'D'):
00599 if (!(s->state & PNG_ALLIMAGE))
00600 goto fail;
00601 s->bytestream += 4;
00602 goto exit_loop;
00603 default:
00604
00605 skip_tag:
00606 s->bytestream += length + 4;
00607 break;
00608 }
00609 }
00610 exit_loop:
00611
00612 if(s->bits_per_pixel == 2){
00613 int i, j;
00614 uint8_t *pd = s->current_picture->data[0];
00615 for(j=0; j < s->height; j++) {
00616 for(i=s->width/4-1; i>=0; i--) {
00617 pd[4*i+3]= pd[i] &3;
00618 pd[4*i+2]= (pd[i]>>2)&3;
00619 pd[4*i+1]= (pd[i]>>4)&3;
00620 pd[4*i+0]= pd[i]>>6;
00621 }
00622 pd += s->image_linesize;
00623 }
00624 }
00625 if(s->bits_per_pixel == 4){
00626 int i, j;
00627 uint8_t *pd = s->current_picture->data[0];
00628 for(j=0; j < s->height; j++) {
00629 for(i=s->width/2-1; i>=0; i--) {
00630 pd[2*i+1]= pd[i]&15;
00631 pd[2*i+0]= pd[i]>>4;
00632 }
00633 pd += s->image_linesize;
00634 }
00635 }
00636
00637
00638 if(s->last_picture->data[0] != NULL) {
00639 if(!(avpkt->flags & AV_PKT_FLAG_KEY)) {
00640 int i, j;
00641 uint8_t *pd = s->current_picture->data[0];
00642 uint8_t *pd_last = s->last_picture->data[0];
00643
00644 for(j=0; j < s->height; j++) {
00645 for(i=0; i < s->width * s->bpp; i++) {
00646 pd[i] += pd_last[i];
00647 }
00648 pd += s->image_linesize;
00649 pd_last += s->image_linesize;
00650 }
00651 }
00652 }
00653
00654 *picture= *s->current_picture;
00655 *data_size = sizeof(AVFrame);
00656
00657 ret = s->bytestream - s->bytestream_start;
00658 the_end:
00659 inflateEnd(&s->zstream);
00660 av_free(crow_buf_base);
00661 s->crow_buf = NULL;
00662 av_freep(&s->last_row);
00663 av_freep(&s->tmp_row);
00664 return ret;
00665 fail:
00666 ret = -1;
00667 goto the_end;
00668 }
00669
00670 static av_cold int png_dec_init(AVCodecContext *avctx)
00671 {
00672 PNGDecContext *s = avctx->priv_data;
00673
00674 s->current_picture = &s->picture1;
00675 s->last_picture = &s->picture2;
00676 avcodec_get_frame_defaults(&s->picture1);
00677 avcodec_get_frame_defaults(&s->picture2);
00678
00679 #if HAVE_MMX
00680 ff_png_init_mmx(s);
00681 #endif
00682
00683 if (!s->add_paeth_prediction)
00684 s->add_paeth_prediction = add_paeth_prediction_c;
00685 if (!s->add_bytes_l2)
00686 s->add_bytes_l2 = add_bytes_l2_c;
00687
00688 return 0;
00689 }
00690
00691 static av_cold int png_dec_end(AVCodecContext *avctx)
00692 {
00693 PNGDecContext *s = avctx->priv_data;
00694
00695 if (s->picture1.data[0])
00696 avctx->release_buffer(avctx, &s->picture1);
00697 if (s->picture2.data[0])
00698 avctx->release_buffer(avctx, &s->picture2);
00699
00700 return 0;
00701 }
00702
00703 AVCodec ff_png_decoder = {
00704 .name = "png",
00705 .type = AVMEDIA_TYPE_VIDEO,
00706 .id = CODEC_ID_PNG,
00707 .priv_data_size = sizeof(PNGDecContext),
00708 .init = png_dec_init,
00709 .close = png_dec_end,
00710 .decode = decode_frame,
00711 .capabilities = CODEC_CAP_DR1 ,
00712 .long_name = NULL_IF_CONFIG_SMALL("PNG image"),
00713 };