Commit a00d4c59 authored by Michael Niedermayer's avatar Michael Niedermayer

Merge commit 'c598b569'

* commit 'c598b569':
  png: K&R formatting cosmetics

Conflicts:
	libavcodec/png.c
	libavcodec/pngdec.c
	libavcodec/pngenc.c
Merged-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parents b361a0bf c598b569
...@@ -85,8 +85,8 @@ static const uint8_t png_pass_dsp_mask[NB_PASSES] = { ...@@ -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, ...@@ -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++) {
...@@ -184,29 +185,35 @@ void ff_add_png_paeth_prediction(uint8_t *dst, uint8_t *src, uint8_t *top, int w ...@@ -184,29 +185,35 @@ 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) \
for(; i <= size - bpp; i+=bpp) {\ b = dst[2]; \
dst[i+0] = r = op(r, src[i+0], last[i+0]);\ if (bpp >= 4) \
if(bpp == 1) continue;\ a = dst[3]; \
dst[i+1] = g = op(g, src[i+1], last[i+1]);\ for (; i <= size - bpp; i += bpp) { \
if(bpp == 2) continue;\ dst[i + 0] = r = op(r, src[i + 0], last[i + 0]); \
dst[i+2] = b = op(b, src[i+2], last[i+2]);\ if (bpp == 1) \
if(bpp == 3) continue;\ continue; \
dst[i+3] = a = op(a, src[i+3], last[i+3]);\ dst[i + 1] = g = op(g, src[i + 1], last[i + 1]); \
}\ if (bpp == 2) \
continue; \
dst[i + 2] = b = op(b, src[i + 2], last[i + 2]); \
if (bpp == 3) \
continue; \
dst[i + 3] = a = op(a, src[i + 3], last[i + 3]); \
} \
} }
#define UNROLL_FILTER(op)\ #define UNROLL_FILTER(op)\
if(bpp == 1) UNROLL1(1, op)\ if (bpp == 1) UNROLL1(1, op)\
else if(bpp == 2) UNROLL1(2, op)\ else if (bpp == 2) UNROLL1(2, op)\
else if(bpp == 3) UNROLL1(3, op)\ else if (bpp == 3) UNROLL1(3, op)\
else if(bpp == 4) UNROLL1(4, op)\ else if (bpp == 4) UNROLL1(4, op)\
for (; i < size; i++) {\ for (; i < size; i++) {\
dst[i] = op(dst[i-bpp], src[i], last[i]);\ dst[i] = op(dst[i - bpp], src[i], last[i]);\
}\ }\
/* NOTE: 'dst' can be equal to 'last' */ /* NOTE: 'dst' can be equal to 'last' */
...@@ -220,18 +227,17 @@ static void png_filter_row(PNGDSPContext *dsp, uint8_t *dst, int filter_type, ...@@ -220,18 +227,17 @@ 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) {
unsigned s = *(int*)(src + i); unsigned s = *(int *)(src + i);
p = ((s & 0x7f7f7f7f) + (p & 0x7f7f7f7f)) ^ ((s ^ p) & 0x80808080); p = ((s & 0x7f7f7f7f) + (p & 0x7f7f7f7f)) ^ ((s ^ p) & 0x80808080);
*(int*)(dst + i) = p; *(int *)(dst + i) = p;
} }
} else { } else {
#define OP_SUB(x,s,l) x+s #define OP_SUB(x, s, l) x + s
UNROLL_FILTER(OP_SUB); UNROLL_FILTER(OP_SUB);
} }
break; break;
...@@ -243,7 +249,7 @@ static void png_filter_row(PNGDSPContext *dsp, uint8_t *dst, int filter_type, ...@@ -243,7 +249,7 @@ static void png_filter_row(PNGDSPContext *dsp, uint8_t *dst, int filter_type,
p = (last[i] >> 1); p = (last[i] >> 1);
dst[i] = p + src[i]; dst[i] = p + src[i];
} }
#define OP_AVG(x,s,l) (((x + l) >> 1) + s) & 0xff #define OP_AVG(x, s, l) (((x + l) >> 1) + s) & 0xff
UNROLL_FILTER(OP_AVG); UNROLL_FILTER(OP_AVG);
break; break;
case PNG_FILTER_VALUE_PAETH: case PNG_FILTER_VALUE_PAETH:
...@@ -252,7 +258,8 @@ static void png_filter_row(PNGDSPContext *dsp, uint8_t *dst, int filter_type, ...@@ -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;
...@@ -269,9 +276,9 @@ static void deloco_ ## NAME(TYPE *dst, int size, int alpha) \ ...@@ -269,9 +276,9 @@ static void deloco_ ## NAME(TYPE *dst, int size, int alpha) \
{ \ { \
int i; \ int i; \
for (i = 0; i < size; i += 3 + alpha) { \ for (i = 0; i < size; i += 3 + alpha) { \
int g = dst [i+1]; \ int g = dst [i + 1]; \
dst[i+0] += g; \ dst[i + 0] += g; \
dst[i+2] += g; \ dst[i + 2] += g; \
} \ } \
} }
...@@ -322,12 +329,12 @@ static void png_handle_row(PNGDecContext *s) ...@@ -322,12 +329,12 @@ 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,
s->last_row, s->pass_row_size, s->bpp); s->last_row, s->pass_row_size, s->bpp);
FFSWAP(uint8_t*, s->last_row, s->tmp_row); FFSWAP(uint8_t *, s->last_row, s->tmp_row);
FFSWAP(unsigned int, s->last_row_size, s->tmp_row_size); FFSWAP(unsigned int, s->last_row_size, s->tmp_row_size);
got_line = 1; got_line = 1;
} }
...@@ -356,7 +363,7 @@ static void png_handle_row(PNGDecContext *s) ...@@ -356,7 +363,7 @@ static void png_handle_row(PNGDecContext *s)
} }
} }
} }
the_end: ; the_end:;
} }
} }
...@@ -382,7 +389,8 @@ static int png_decode_idat(PNGDecContext *s, int length) ...@@ -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;
} }
} }
...@@ -509,7 +517,7 @@ static int decode_frame(AVCodecContext *avctx, ...@@ -509,7 +517,7 @@ static int decode_frame(AVCodecContext *avctx,
void *data, int *got_frame, void *data, int *got_frame,
AVPacket *avpkt) AVPacket *avpkt)
{ {
PNGDecContext * const s = avctx->priv_data; PNGDecContext *const s = avctx->priv_data;
const uint8_t *buf = avpkt->data; const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size; int buf_size = avpkt->size;
AVFrame *p; AVFrame *p;
...@@ -712,9 +720,8 @@ static int decode_frame(AVCodecContext *avctx, ...@@ -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 */
} }
...@@ -755,12 +762,12 @@ static int decode_frame(AVCodecContext *avctx, ...@@ -755,12 +762,12 @@ static int decode_frame(AVCodecContext *avctx,
goto exit_loop; goto exit_loop;
default: default:
/* skip tag */ /* skip tag */
skip_tag: skip_tag:
bytestream2_skip(&s->gb, length + 4); bytestream2_skip(&s->gb, length + 4);
break; break;
} }
} }
exit_loop: exit_loop:
if (s->bits_per_pixel == 1 && s->color_type == PNG_COLOR_TYPE_PALETTE){ if (s->bits_per_pixel == 1 && s->color_type == PNG_COLOR_TYPE_PALETTE){
int i, j, k; int i, j, k;
...@@ -847,9 +854,8 @@ static int decode_frame(AVCodecContext *avctx, ...@@ -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;
} }
...@@ -866,11 +872,11 @@ static int decode_frame(AVCodecContext *avctx, ...@@ -866,11 +872,11 @@ static int decode_frame(AVCodecContext *avctx,
*got_frame = 1; *got_frame = 1;
ret = bytestream2_tell(&s->gb); ret = bytestream2_tell(&s->gb);
the_end: the_end:
inflateEnd(&s->zstream); inflateEnd(&s->zstream);
s->crow_buf = NULL; s->crow_buf = NULL;
return ret; return ret;
fail: fail:
av_dict_free(&metadata); av_dict_free(&metadata);
ff_thread_report_progress(&s->picture, INT_MAX, 0); ff_thread_report_progress(&s->picture, INT_MAX, 0);
ret = AVERROR_INVALIDDATA; ret = AVERROR_INVALIDDATA;
......
...@@ -25,13 +25,13 @@ ...@@ -25,13 +25,13 @@
#include "pngdsp.h" #include "pngdsp.h"
// 0x7f7f7f7f or 0x7f7f7f7f7f7f7f7f or whatever, depending on the cpu's native arithmetic size // 0x7f7f7f7f or 0x7f7f7f7f7f7f7f7f or whatever, depending on the cpu's native arithmetic size
#define pb_7f (~0UL/255 * 0x7f) #define pb_7f (~0UL / 255 * 0x7f)
#define pb_80 (~0UL/255 * 0x80) #define pb_80 (~0UL / 255 * 0x80)
static void add_bytes_l2_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w) static void add_bytes_l2_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w)
{ {
long i; long i;
for (i = 0; i <= w - (int)sizeof(long); i += sizeof(long)) { for (i = 0; i <= w - (int) sizeof(long); i += sizeof(long)) {
long a = *(long *)(src1 + i); long a = *(long *)(src1 + i);
long b = *(long *)(src2 + i); long b = *(long *)(src2 + i);
*(long *)(dst + i) = ((a & pb_7f) + (b & pb_7f)) ^ ((a ^ b) & pb_80); *(long *)(dst + i) = ((a & pb_7f) + (b & pb_7f)) ^ ((a ^ b) & pb_80);
...@@ -45,5 +45,6 @@ av_cold void ff_pngdsp_init(PNGDSPContext *dsp) ...@@ -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);
} }
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment