mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-02-04 06:08:26 +02:00
Merge commit 'c598b569fb3d1f4b6c4868fe64f6989254df5186'
* commit 'c598b569fb3d1f4b6c4868fe64f6989254df5186': png: K&R formatting cosmetics Conflicts: libavcodec/png.c libavcodec/pngdec.c libavcodec/pngenc.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
commit
a00d4c5956
@ -85,8 +85,8 @@ static const uint8_t png_pass_dsp_mask[NB_PASSES] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* NOTE: we try to construct a good looking image at each pass. width
|
/* NOTE: we try to construct a good looking image at each pass. width
|
||||||
is the original image width. We also do pixel format conversion at
|
* is the original image width. We also do pixel format conversion at
|
||||||
this stage */
|
* this stage */
|
||||||
static void png_put_interlaced_row(uint8_t *dst, int width,
|
static void png_put_interlaced_row(uint8_t *dst, int width,
|
||||||
int bits_per_pixel, int pass,
|
int bits_per_pixel, int pass,
|
||||||
int color_type, const uint8_t *src)
|
int color_type, const uint8_t *src)
|
||||||
@ -157,7 +157,8 @@ static void png_put_interlaced_row(uint8_t *dst, int width,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ff_add_png_paeth_prediction(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp)
|
void ff_add_png_paeth_prediction(uint8_t *dst, uint8_t *src, uint8_t *top,
|
||||||
|
int w, int bpp)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < w; i++) {
|
for (i = 0; i < w; i++) {
|
||||||
@ -186,16 +187,22 @@ void ff_add_png_paeth_prediction(uint8_t *dst, uint8_t *src, uint8_t *top, int w
|
|||||||
|
|
||||||
#define UNROLL1(bpp, op) { \
|
#define UNROLL1(bpp, op) { \
|
||||||
r = dst[0]; \
|
r = dst[0]; \
|
||||||
if(bpp >= 2) g = dst[1];\
|
if (bpp >= 2) \
|
||||||
if(bpp >= 3) b = dst[2];\
|
g = dst[1]; \
|
||||||
if(bpp >= 4) a = dst[3];\
|
if (bpp >= 3) \
|
||||||
|
b = dst[2]; \
|
||||||
|
if (bpp >= 4) \
|
||||||
|
a = dst[3]; \
|
||||||
for (; i <= size - bpp; i += bpp) { \
|
for (; i <= size - bpp; i += bpp) { \
|
||||||
dst[i + 0] = r = op(r, src[i + 0], last[i + 0]); \
|
dst[i + 0] = r = op(r, src[i + 0], last[i + 0]); \
|
||||||
if(bpp == 1) continue;\
|
if (bpp == 1) \
|
||||||
|
continue; \
|
||||||
dst[i + 1] = g = op(g, src[i + 1], last[i + 1]); \
|
dst[i + 1] = g = op(g, src[i + 1], last[i + 1]); \
|
||||||
if(bpp == 2) continue;\
|
if (bpp == 2) \
|
||||||
|
continue; \
|
||||||
dst[i + 2] = b = op(b, src[i + 2], last[i + 2]); \
|
dst[i + 2] = b = op(b, src[i + 2], last[i + 2]); \
|
||||||
if(bpp == 3) continue;\
|
if (bpp == 3) \
|
||||||
|
continue; \
|
||||||
dst[i + 3] = a = op(a, src[i + 3], last[i + 3]); \
|
dst[i + 3] = a = op(a, src[i + 3], last[i + 3]); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
@ -220,9 +227,8 @@ static void png_filter_row(PNGDSPContext *dsp, uint8_t *dst, int filter_type,
|
|||||||
memcpy(dst, src, size);
|
memcpy(dst, src, size);
|
||||||
break;
|
break;
|
||||||
case PNG_FILTER_VALUE_SUB:
|
case PNG_FILTER_VALUE_SUB:
|
||||||
for (i = 0; i < bpp; i++) {
|
for (i = 0; i < bpp; i++)
|
||||||
dst[i] = src[i];
|
dst[i] = src[i];
|
||||||
}
|
|
||||||
if (bpp == 4) {
|
if (bpp == 4) {
|
||||||
p = *(int *)dst;
|
p = *(int *)dst;
|
||||||
for (; i < size; i += bpp) {
|
for (; i < size; i += bpp) {
|
||||||
@ -252,7 +258,8 @@ static void png_filter_row(PNGDSPContext *dsp, uint8_t *dst, int filter_type,
|
|||||||
dst[i] = p + src[i];
|
dst[i] = p + src[i];
|
||||||
}
|
}
|
||||||
if (bpp > 2 && size > 4) {
|
if (bpp > 2 && size > 4) {
|
||||||
// would write off the end of the array if we let it process the last pixel with bpp=3
|
/* would write off the end of the array if we let it process
|
||||||
|
* the last pixel with bpp=3 */
|
||||||
int w = bpp == 4 ? size : size - 3;
|
int w = bpp == 4 ? size : size - 3;
|
||||||
dsp->add_paeth_prediction(dst + i, src + i, last + i, w - i, bpp);
|
dsp->add_paeth_prediction(dst + i, src + i, last + i, w - i, bpp);
|
||||||
i = w;
|
i = w;
|
||||||
@ -322,7 +329,7 @@ static void png_handle_row(PNGDecContext *s)
|
|||||||
ptr = s->image_buf + s->image_linesize * s->y;
|
ptr = s->image_buf + s->image_linesize * s->y;
|
||||||
if ((ff_png_pass_ymask[s->pass] << (s->y & 7)) & 0x80) {
|
if ((ff_png_pass_ymask[s->pass] << (s->y & 7)) & 0x80) {
|
||||||
/* if we already read one row, it is time to stop to
|
/* if we already read one row, it is time to stop to
|
||||||
wait for the next one */
|
* wait for the next one */
|
||||||
if (got_line)
|
if (got_line)
|
||||||
break;
|
break;
|
||||||
png_filter_row(&s->dsp, s->tmp_row, s->crow_buf[0], s->crow_buf + 1,
|
png_filter_row(&s->dsp, s->tmp_row, s->crow_buf[0], s->crow_buf + 1,
|
||||||
@ -382,7 +389,8 @@ static int png_decode_idat(PNGDecContext *s, int length)
|
|||||||
s->zstream.next_out = s->crow_buf;
|
s->zstream.next_out = s->crow_buf;
|
||||||
}
|
}
|
||||||
if (ret == Z_STREAM_END && s->zstream.avail_in > 0) {
|
if (ret == Z_STREAM_END && s->zstream.avail_in > 0) {
|
||||||
av_log(NULL, AV_LOG_WARNING, "%d undecompressed bytes left in buffer\n", s->zstream.avail_in);
|
av_log(NULL, AV_LOG_WARNING,
|
||||||
|
"%d undecompressed bytes left in buffer\n", s->zstream.avail_in);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -712,9 +720,8 @@ static int decode_frame(AVCodecContext *avctx,
|
|||||||
b = bytestream2_get_byte(&s->gb);
|
b = bytestream2_get_byte(&s->gb);
|
||||||
s->palette[i] = (0xFFU << 24) | (r << 16) | (g << 8) | b;
|
s->palette[i] = (0xFFU << 24) | (r << 16) | (g << 8) | b;
|
||||||
}
|
}
|
||||||
for (; i < 256; i++) {
|
for (; i < 256; i++)
|
||||||
s->palette[i] = (0xFFU << 24);
|
s->palette[i] = (0xFFU << 24);
|
||||||
}
|
|
||||||
s->state |= PNG_PLTE;
|
s->state |= PNG_PLTE;
|
||||||
bytestream2_skip(&s->gb, 4); /* crc */
|
bytestream2_skip(&s->gb, 4); /* crc */
|
||||||
}
|
}
|
||||||
@ -847,9 +854,8 @@ static int decode_frame(AVCodecContext *avctx,
|
|||||||
|
|
||||||
ff_thread_await_progress(&s->last_picture, INT_MAX, 0);
|
ff_thread_await_progress(&s->last_picture, INT_MAX, 0);
|
||||||
for (j = 0; j < s->height; j++) {
|
for (j = 0; j < s->height; j++) {
|
||||||
for (i = 0; i < s->width * s->bpp; i++) {
|
for (i = 0; i < s->width * s->bpp; i++)
|
||||||
pd[i] += pd_last[i];
|
pd[i] += pd_last[i];
|
||||||
}
|
|
||||||
pd += s->image_linesize;
|
pd += s->image_linesize;
|
||||||
pd_last += s->image_linesize;
|
pd_last += s->image_linesize;
|
||||||
}
|
}
|
||||||
|
@ -45,5 +45,6 @@ av_cold void ff_pngdsp_init(PNGDSPContext *dsp)
|
|||||||
dsp->add_bytes_l2 = add_bytes_l2_c;
|
dsp->add_bytes_l2 = add_bytes_l2_c;
|
||||||
dsp->add_paeth_prediction = ff_add_png_paeth_prediction;
|
dsp->add_paeth_prediction = ff_add_png_paeth_prediction;
|
||||||
|
|
||||||
if (ARCH_X86) ff_pngdsp_init_x86(dsp);
|
if (ARCH_X86)
|
||||||
|
ff_pngdsp_init_x86(dsp);
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
* License along with FFmpeg; if not, write to the Free Software
|
* License along with FFmpeg; if not, write to the Free Software
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "avcodec.h"
|
#include "avcodec.h"
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
#include "bytestream.h"
|
#include "bytestream.h"
|
||||||
@ -86,7 +87,8 @@ static void png_get_interlaced_row(uint8_t *dst, int row_size,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sub_png_paeth_prediction(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp)
|
static void sub_png_paeth_prediction(uint8_t *dst, uint8_t *src, uint8_t *top,
|
||||||
|
int w, int bpp)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < w; i++) {
|
for (i = 0; i < w; i++) {
|
||||||
@ -220,7 +222,8 @@ static int png_write_row(PNGEncContext *s, const uint8_t *data, int size)
|
|||||||
return -1;
|
return -1;
|
||||||
if (s->zstream.avail_out == 0) {
|
if (s->zstream.avail_out == 0) {
|
||||||
if (s->bytestream_end - s->bytestream > IOBUF_SIZE + 100)
|
if (s->bytestream_end - s->bytestream > IOBUF_SIZE + 100)
|
||||||
png_write_chunk(&s->bytestream, MKTAG('I', 'D', 'A', 'T'), s->buf, IOBUF_SIZE);
|
png_write_chunk(&s->bytestream,
|
||||||
|
MKTAG('I', 'D', 'A', 'T'), s->buf, IOBUF_SIZE);
|
||||||
s->zstream.avail_out = IOBUF_SIZE;
|
s->zstream.avail_out = IOBUF_SIZE;
|
||||||
s->zstream.next_out = s->buf;
|
s->zstream.next_out = s->buf;
|
||||||
}
|
}
|
||||||
@ -237,8 +240,8 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
|||||||
int bits_per_pixel, pass_row_size, enc_row_size;
|
int bits_per_pixel, pass_row_size, enc_row_size;
|
||||||
int64_t max_packet_size;
|
int64_t max_packet_size;
|
||||||
int compression_level;
|
int compression_level;
|
||||||
uint8_t *ptr, *top;
|
uint8_t *ptr, *top, *crow_buf, *crow;
|
||||||
uint8_t *crow_base = NULL, *crow_buf, *crow;
|
uint8_t *crow_base = NULL;
|
||||||
uint8_t *progressive_buf = NULL;
|
uint8_t *progressive_buf = NULL;
|
||||||
uint8_t *top_buf = NULL;
|
uint8_t *top_buf = NULL;
|
||||||
|
|
||||||
@ -289,9 +292,9 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
|||||||
s->zstream.zalloc = ff_png_zalloc;
|
s->zstream.zalloc = ff_png_zalloc;
|
||||||
s->zstream.zfree = ff_png_zfree;
|
s->zstream.zfree = ff_png_zfree;
|
||||||
s->zstream.opaque = NULL;
|
s->zstream.opaque = NULL;
|
||||||
compression_level = avctx->compression_level == FF_COMPRESSION_DEFAULT ?
|
compression_level = avctx->compression_level == FF_COMPRESSION_DEFAULT
|
||||||
Z_DEFAULT_COMPRESSION :
|
? Z_DEFAULT_COMPRESSION
|
||||||
av_clip(avctx->compression_level, 0, 9);
|
: av_clip(avctx->compression_level, 0, 9);
|
||||||
ret = deflateInit2(&s->zstream, compression_level,
|
ret = deflateInit2(&s->zstream, compression_level,
|
||||||
Z_DEFLATED, 15, 8, Z_DEFAULT_STRATEGY);
|
Z_DEFLATED, 15, 8, Z_DEFAULT_STRATEGY);
|
||||||
if (ret != Z_OK)
|
if (ret != Z_OK)
|
||||||
@ -313,7 +316,8 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
|||||||
crow_base = av_malloc((row_size + 32) << (s->filter_type == PNG_FILTER_VALUE_MIXED));
|
crow_base = av_malloc((row_size + 32) << (s->filter_type == PNG_FILTER_VALUE_MIXED));
|
||||||
if (!crow_base)
|
if (!crow_base)
|
||||||
goto fail;
|
goto fail;
|
||||||
crow_buf = crow_base + 15; // pixel data should be aligned, but there's a control byte before it
|
// pixel data should be aligned, but there's a control byte before it
|
||||||
|
crow_buf = crow_base + 15;
|
||||||
if (is_progressive) {
|
if (is_progressive) {
|
||||||
progressive_buf = av_malloc(row_size + 1);
|
progressive_buf = av_malloc(row_size + 1);
|
||||||
if (!progressive_buf)
|
if (!progressive_buf)
|
||||||
@ -369,9 +373,11 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
|||||||
*alpha_ptr++ = alpha;
|
*alpha_ptr++ = alpha;
|
||||||
bytestream_put_be24(&ptr, v);
|
bytestream_put_be24(&ptr, v);
|
||||||
}
|
}
|
||||||
png_write_chunk(&s->bytestream, MKTAG('P', 'L', 'T', 'E'), s->buf, 256 * 3);
|
png_write_chunk(&s->bytestream,
|
||||||
|
MKTAG('P', 'L', 'T', 'E'), s->buf, 256 * 3);
|
||||||
if (has_alpha) {
|
if (has_alpha) {
|
||||||
png_write_chunk(&s->bytestream, MKTAG('t', 'R', 'N', 'S'), s->buf + 256 * 3, 256);
|
png_write_chunk(&s->bytestream,
|
||||||
|
MKTAG('t', 'R', 'N', 'S'), s->buf + 256 * 3, 256);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -383,29 +389,30 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
|||||||
|
|
||||||
for (pass = 0; pass < NB_PASSES; pass++) {
|
for (pass = 0; pass < NB_PASSES; pass++) {
|
||||||
/* NOTE: a pass is completely omitted if no pixels would be
|
/* NOTE: a pass is completely omitted if no pixels would be
|
||||||
output */
|
* output */
|
||||||
pass_row_size = ff_png_pass_row_size(pass, bits_per_pixel, avctx->width);
|
pass_row_size = ff_png_pass_row_size(pass, bits_per_pixel, avctx->width);
|
||||||
if (pass_row_size > 0) {
|
if (pass_row_size > 0) {
|
||||||
top = NULL;
|
top = NULL;
|
||||||
for(y = 0; y < avctx->height; y++) {
|
for (y = 0; y < avctx->height; y++)
|
||||||
if ((ff_png_pass_ymask[pass] << (y & 7)) & 0x80) {
|
if ((ff_png_pass_ymask[pass] << (y & 7)) & 0x80) {
|
||||||
ptr = p->data[0] + y * p->linesize[0];
|
ptr = p->data[0] + y * p->linesize[0];
|
||||||
FFSWAP(uint8_t *, progressive_buf, top_buf);
|
FFSWAP(uint8_t *, progressive_buf, top_buf);
|
||||||
png_get_interlaced_row(progressive_buf, pass_row_size,
|
png_get_interlaced_row(progressive_buf, pass_row_size,
|
||||||
bits_per_pixel, pass,
|
bits_per_pixel, pass,
|
||||||
ptr, avctx->width);
|
ptr, avctx->width);
|
||||||
crow = png_choose_filter(s, crow_buf, progressive_buf, top, pass_row_size, bits_per_pixel>>3);
|
crow = png_choose_filter(s, crow_buf, progressive_buf,
|
||||||
|
top, pass_row_size, bits_per_pixel >> 3);
|
||||||
png_write_row(s, crow, pass_row_size + 1);
|
png_write_row(s, crow, pass_row_size + 1);
|
||||||
top = progressive_buf;
|
top = progressive_buf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
top = NULL;
|
top = NULL;
|
||||||
for (y = 0; y < avctx->height; y++) {
|
for (y = 0; y < avctx->height; y++) {
|
||||||
ptr = p->data[0] + y * p->linesize[0];
|
ptr = p->data[0] + y * p->linesize[0];
|
||||||
crow = png_choose_filter(s, crow_buf, ptr, top, row_size, bits_per_pixel>>3);
|
crow = png_choose_filter(s, crow_buf, ptr, top,
|
||||||
|
row_size, bits_per_pixel >> 3);
|
||||||
png_write_row(s, crow, row_size + 1);
|
png_write_row(s, crow, row_size + 1);
|
||||||
top = ptr;
|
top = ptr;
|
||||||
}
|
}
|
||||||
@ -444,7 +451,8 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
|||||||
goto the_end;
|
goto the_end;
|
||||||
}
|
}
|
||||||
|
|
||||||
static av_cold int png_enc_init(AVCodecContext *avctx){
|
static av_cold int png_enc_init(AVCodecContext *avctx)
|
||||||
|
{
|
||||||
PNGEncContext *s = avctx->priv_data;
|
PNGEncContext *s = avctx->priv_data;
|
||||||
|
|
||||||
switch (avctx->pix_fmt) {
|
switch (avctx->pix_fmt) {
|
||||||
@ -473,7 +481,9 @@ static av_cold int png_enc_init(AVCodecContext *avctx){
|
|||||||
|
|
||||||
ff_dsputil_init(&s->dsp, avctx);
|
ff_dsputil_init(&s->dsp, avctx);
|
||||||
|
|
||||||
s->filter_type = av_clip(avctx->prediction_method, PNG_FILTER_VALUE_NONE, PNG_FILTER_VALUE_MIXED);
|
s->filter_type = av_clip(avctx->prediction_method,
|
||||||
|
PNG_FILTER_VALUE_NONE,
|
||||||
|
PNG_FILTER_VALUE_MIXED);
|
||||||
if (avctx->pix_fmt == AV_PIX_FMT_MONOBLACK)
|
if (avctx->pix_fmt == AV_PIX_FMT_MONOBLACK)
|
||||||
s->filter_type = PNG_FILTER_VALUE_NONE;
|
s->filter_type = PNG_FILTER_VALUE_NONE;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user