summaryrefslogtreecommitdiff
path: root/libavcodec/pngenc.c
diff options
context:
space:
mode:
authorDonny Yang <work@kota.moe>2015-04-02 15:09:18 +0000
committerMichael Niedermayer <michaelni@gmx.at>2015-04-02 20:41:51 +0200
commitb0a2aee4089eea8613e4056d9b1a697159899a18 (patch)
treefa814eb3989932bf1aa52ae3aa9eda9f4a7a93c6 /libavcodec/pngenc.c
parent27565ace60d404def06d3a3b82e2e3813ca5a36d (diff)
png: Use libavutil's crc functions instead of zlib's
Signed-off-by: Donny Yang <work@kota.moe> Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/pngenc.c')
-rw-r--r--libavcodec/pngenc.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/libavcodec/pngenc.c b/libavcodec/pngenc.c
index 4349d1aa99..8699b80f99 100644
--- a/libavcodec/pngenc.c
+++ b/libavcodec/pngenc.c
@@ -27,6 +27,7 @@
#include "apng.h"
#include "libavutil/avassert.h"
+#include "libavutil/crc.h"
#include "libavutil/libm.h"
#include "libavutil/opt.h"
#include "libavutil/color_utils.h"
@@ -205,27 +206,28 @@ static uint8_t *png_choose_filter(PNGEncContext *s, uint8_t *dst,
static void png_write_chunk(uint8_t **f, uint32_t tag,
const uint8_t *buf, int length)
{
- uint32_t crc;
+ const AVCRC *crc_table = av_crc_get_table(AV_CRC_32_IEEE_LE);
+ uint32_t crc = ~0U;
uint8_t tagbuf[4];
bytestream_put_be32(f, length);
- crc = crc32(0, Z_NULL, 0);
AV_WL32(tagbuf, tag);
- crc = crc32(crc, tagbuf, 4);
+ crc = av_crc(crc_table, crc, tagbuf, 4);
bytestream_put_be32(f, av_bswap32(tag));
if (length > 0) {
- crc = crc32(crc, buf, length);
+ crc = av_crc(crc_table, crc, buf, length);
memcpy(*f, buf, length);
*f += length;
}
- bytestream_put_be32(f, crc);
+ bytestream_put_be32(f, ~crc);
}
static void png_write_image_data(AVCodecContext *avctx,
const uint8_t *buf, int length)
{
PNGEncContext *s = avctx->priv_data;
- uint32_t crc = crc32(0, Z_NULL, 0);
+ const AVCRC *crc_table = av_crc_get_table(AV_CRC_32_IEEE_LE);
+ uint32_t crc = ~0U;
if (avctx->codec_id == AV_CODEC_ID_PNG || avctx->frame_number == 0)
return png_write_chunk(&s->bytestream, MKTAG('I', 'D', 'A', 'T'), buf, length);
@@ -234,13 +236,13 @@ static void png_write_image_data(AVCodecContext *avctx,
bytestream_put_be32(&s->bytestream, MKBETAG('f', 'd', 'A', 'T'));
bytestream_put_be32(&s->bytestream, s->sequence_number);
- crc = crc32(crc, s->bytestream - 8, 8);
+ crc = av_crc(crc_table, crc, s->bytestream - 8, 8);
- crc = crc32(crc, buf, length);
+ crc = av_crc(crc_table, crc, buf, length);
memcpy(s->bytestream, buf, length);
s->bytestream += length;
- bytestream_put_be32(&s->bytestream, crc);
+ bytestream_put_be32(&s->bytestream, ~crc);
++s->sequence_number;
}
@@ -536,7 +538,7 @@ static int encode_apng(AVCodecContext *avctx, AVPacket *pkt,
uint8_t buf[26];
if (avctx->codec_id == AV_CODEC_ID_APNG && s->color_type == PNG_COLOR_TYPE_PALETTE) {
- uint32_t checksum = crc32(crc32(0, Z_NULL, 0), pict->data[1], 256 * sizeof(uint32_t));
+ uint32_t checksum = ~av_crc(av_crc_get_table(AV_CRC_32_IEEE_LE), ~0U, pict->data[1], 256 * sizeof(uint32_t));
if (avctx->frame_number == 0) {
s->palette_checksum = checksum;