Mercurial > hg > forks > libbpg
changeset 5:524eae707ba4
Cosmetics: Remove trailing whitespace.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 07 Dec 2016 10:38:38 +0200 |
parents | bbd61622856a |
children | 690bf78c1ce9 |
files | bpgdec.c bpgenc.c bpgview.c |
diffstat | 3 files changed, 159 insertions(+), 159 deletions(-) [+] |
line wrap: on
line diff
--- a/bpgdec.c Wed Dec 07 10:37:38 2016 +0200 +++ b/bpgdec.c Wed Dec 07 10:38:38 2016 +0200 @@ -45,7 +45,7 @@ uint8_t *rgb_line; bpg_decoder_get_info(img, img_info); - + w = img_info->width; h = img_info->height; @@ -56,9 +56,9 @@ fprintf(stderr, "%s: I/O error\n", filename); exit(1); } - + fprintf(f, "P6\n%d %d\n%d\n", w, h, 255); - + bpg_decoder_start(img, BPG_OUTPUT_FORMAT_RGB24); for (y = 0; y < h; y++) { bpg_decoder_get_line(img, rgb_line); @@ -124,7 +124,7 @@ color_type = PNG_COLOR_TYPE_RGB_ALPHA; else color_type = PNG_COLOR_TYPE_RGB; - + png_set_IHDR(png_ptr, info_ptr, img_info->width, img_info->height, bit_depth, color_type, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); @@ -136,7 +136,7 @@ png_set_swap(png_ptr); } #endif - + if (bit_depth == 16) { if (img_info->has_alpha) out_fmt = BPG_OUTPUT_FORMAT_RGBA64; @@ -148,7 +148,7 @@ else out_fmt = BPG_OUTPUT_FORMAT_RGB24; } - + bpg_decoder_start(img, out_fmt); bpp = (3 + img_info->has_alpha) * (bit_depth / 8); @@ -158,9 +158,9 @@ png_write_row(png_ptr, row_pointer); } png_free(png_ptr, row_pointer); - + png_write_end(png_ptr, NULL); - + png_destroy_write_struct(&png_ptr, &info_ptr); fclose(f); @@ -197,7 +197,7 @@ "Thumbnail", "Animation control", }; - + f = fopen(filename, "rb"); if (!f) { fprintf(stderr, "Could not open %s\n", filename); @@ -230,7 +230,7 @@ printf(" w_plane=%d", p->has_w_plane); } if (p->has_alpha) { - printf(" alpha=%d premul=%d", + printf(" alpha=%d premul=%d", p->has_alpha, p->premultiplied_alpha); } printf(" format=%s limited_range=%d bit_depth=%d animation=%d\n", @@ -238,7 +238,7 @@ p->limited_range, p->bit_depth, p->has_animation); - + if (first_md) { const char *tag_name; printf("Extension data:\n"); @@ -272,7 +272,7 @@ uint8_t *buf; int buf_len, bit_depth, c, show_info; const char *outfilename, *filename, *p; - + outfilename = "out.png"; bit_depth = 8; show_info = 0; @@ -324,7 +324,7 @@ fprintf(stderr, "Error while reading file\n"); exit(1); } - + fclose(f); img = bpg_decoder_open(); @@ -342,7 +342,7 @@ if (p && strcasecmp(p, "ppm") != 0) { png_save(img, outfilename, bit_depth); - } else + } else #endif { ppm_save(img, outfilename);
--- a/bpgenc.c Wed Dec 07 10:37:38 2016 +0200 +++ b/bpgenc.c Wed Dec 07 10:38:38 2016 +0200 @@ -77,7 +77,7 @@ int c_center; } ColorConvertState; -static void convert_init(ColorConvertState *s, int in_bit_depth, +static void convert_init(ColorConvertState *s, int in_bit_depth, int out_bit_depth, BPGColorSpaceEnum color_space, int limited_range) { @@ -92,9 +92,9 @@ mult = (double)out_pixel_max * (1 << c_shift) / (double)in_pixel_max; // printf("mult=%f c_shift=%d\n", mult, c_shift); if (limited_range) { - mult_y = (double)(219 << (out_bit_depth - 8)) * (1 << c_shift) / + mult_y = (double)(219 << (out_bit_depth - 8)) * (1 << c_shift) / (double)in_pixel_max; - mult_c = (double)(224 << (out_bit_depth - 8)) * (1 << c_shift) / + mult_c = (double)(224 << (out_bit_depth - 8)) * (1 << c_shift) / (double)in_pixel_max; } else { mult_y = mult; @@ -105,12 +105,12 @@ k_r = 0.299; k_b = 0.114; goto convert_ycc; - + case BPG_CS_YCbCr_BT709: - k_r = 0.2126; + k_r = 0.2126; k_b = 0.0722; goto convert_ycc; - + case BPG_CS_YCbCr_BT2020: k_r = 0.2627; k_b = 0.0593; @@ -124,7 +124,7 @@ rgb_to_ycc[6] = 0.5; rgb_to_ycc[7] = -0.5 * (1 - k_r - k_b) / (1 - k_r); rgb_to_ycc[8] = -0.5 * k_b / (1 - k_r); - + for(i = 0; i < 3; i++) s->rgb_to_ycc[i] = lrint(rgb_to_ycc[i] * mult_y); for(i = 3; i < 9; i++) @@ -183,9 +183,9 @@ b = src[2]; y_ptr[i] = clamp_pix((c0 * r + c1 * g + c2 * b + y_offset) >> shift, pixel_max); - cb_ptr[i] = clamp_pix(((c3 * r + c4 * g + c5 * b + + cb_ptr[i] = clamp_pix(((c3 * r + c4 * g + c5 * b + rnd) >> shift) + center, pixel_max); - cr_ptr[i] = clamp_pix(((c6 * r + c7 * g + c8 * b + + cr_ptr[i] = clamp_pix(((c6 * r + c7 * g + c8 * b + rnd) >> shift) + center, pixel_max); src += incr; } @@ -234,7 +234,7 @@ t1 = c_0_5 * g; t2 = c_0_25 * (r + b); y_ptr[i] = clamp_pix((t1 + t2 + y_offset) >> shift, pixel_max); - cb_ptr[i] = clamp_pix(((t1 - t2 + rnd) >> shift) + center, + cb_ptr[i] = clamp_pix(((t1 - t2 + rnd) >> shift) + center, pixel_max); cr_ptr[i] = clamp_pix(((c_0_5 * (r - b) + rnd) >> shift) + center, pixel_max); @@ -275,7 +275,7 @@ /* 16 bit input */ -static void rgb48_to_ycc(ColorConvertState *s, +static void rgb48_to_ycc(ColorConvertState *s, PIXEL *y_ptr, PIXEL *cb_ptr, PIXEL *cr_ptr, const void *src1, int n, int incr) { @@ -303,15 +303,15 @@ b = src[2]; y_ptr[i] = clamp_pix((c0 * r + c1 * g + c2 * b + y_offset) >> shift, pixel_max); - cb_ptr[i] = clamp_pix(((c3 * r + c4 * g + c5 * b + + cb_ptr[i] = clamp_pix(((c3 * r + c4 * g + c5 * b + rnd) >> shift) + center, pixel_max); - cr_ptr[i] = clamp_pix(((c6 * r + c7 * g + c8 * b + + cr_ptr[i] = clamp_pix(((c6 * r + c7 * g + c8 * b + rnd) >> shift) + center, pixel_max); src += incr; } } -static void rgb48_to_ycgco(ColorConvertState *s, +static void rgb48_to_ycgco(ColorConvertState *s, PIXEL *y_ptr, PIXEL *cb_ptr, PIXEL *cr_ptr, const void *src1, int n, int incr) { @@ -333,7 +333,7 @@ t1 = c_0_5 * g; t2 = c_0_25 * (r + b); y_ptr[i] = clamp_pix((t1 + t2 + y_offset) >> shift, pixel_max); - cb_ptr[i] = clamp_pix(((t1 - t2 + rnd) >> shift) + center, + cb_ptr[i] = clamp_pix(((t1 - t2 + rnd) >> shift) + center, pixel_max); cr_ptr[i] = clamp_pix(((c_0_5 * (r - b) + rnd) >> shift) + center, pixel_max); @@ -342,7 +342,7 @@ } /* Note: use for alpha/W so no limited range */ -static void gray16_to_gray(ColorConvertState *s, +static void gray16_to_gray(ColorConvertState *s, PIXEL *y_ptr, const uint16_t *src, int n, int incr) { int i, g, c, shift, rnd; @@ -357,7 +357,7 @@ } } -static void luma16_to_gray(ColorConvertState *s, +static void luma16_to_gray(ColorConvertState *s, PIXEL *y_ptr, const uint16_t *src, int n, int incr) { int i, g, c, shift, rnd; @@ -372,7 +372,7 @@ } } -static void rgb48_to_rgb(ColorConvertState *s, +static void rgb48_to_rgb(ColorConvertState *s, PIXEL *y_ptr, PIXEL *cb_ptr, PIXEL *cr_ptr, const void *src1, int n, int incr) { @@ -383,7 +383,7 @@ luma16_to_gray(s, cr_ptr, src + 0, n, incr); } -typedef void RGBConvertFunc(ColorConvertState *s, +typedef void RGBConvertFunc(ColorConvertState *s, PIXEL *y_ptr, PIXEL *cb_ptr, PIXEL *cr_ptr, const void *src, int n, int incr); @@ -403,7 +403,7 @@ rgb48_to_ycc, } }; - + /* val = 1.0 - val */ static void gray_one_minus(ColorConvertState *s, PIXEL *y_ptr, int n) { @@ -461,10 +461,10 @@ pixel_max = (1 << bit_depth) - 1; n2 = (n + 1) / 2; for(i = 0; i < n2; i++) { - dst[i] = clamp_pix(((src[-7] + src[7]) * DP0C7 + - (src[-5] + src[5]) * DP0C5 + - (src[-3] + src[3]) * DP0C3 + - (src[-1] + src[1]) * DP0C1 + + dst[i] = clamp_pix(((src[-7] + src[7]) * DP0C7 + + (src[-5] + src[5]) * DP0C5 + + (src[-3] + src[3]) * DP0C3 + + (src[-1] + src[1]) * DP0C1 + src[0] * DP0C0 + 64) >> 7, pixel_max); src += 2; } @@ -478,10 +478,10 @@ rnd = 1 << (shift - 1); n2 = (n + 1) / 2; for(i = 0; i < n2; i++) { - dst[i] = ((src[-7] + src[7]) * DP0C7 + - (src[-5] + src[5]) * DP0C5 + - (src[-3] + src[3]) * DP0C3 + - (src[-1] + src[1]) * DP0C1 + + dst[i] = ((src[-7] + src[7]) * DP0C7 + + (src[-5] + src[5]) * DP0C5 + + (src[-3] + src[3]) * DP0C3 + + (src[-1] + src[1]) * DP0C1 + src[0] * DP0C0 + rnd) >> shift; src += 2; } @@ -495,10 +495,10 @@ pixel_max = (1 << bit_depth) - 1; n2 = (n + 1) / 2; for(i = 0; i < n2; i++) { - dst[i] = clamp_pix(((src[-4] + src[5]) * DP1C4 + - (src[-3] + src[4]) * DP1C3 + - (src[-2] + src[3]) * DP1C2 + - (src[-1] + src[2]) * DP1C1 + + dst[i] = clamp_pix(((src[-4] + src[5]) * DP1C4 + + (src[-3] + src[4]) * DP1C3 + + (src[-2] + src[3]) * DP1C2 + + (src[-1] + src[2]) * DP1C1 + (src[0] + src[1]) * DP1C0 + 64) >> 7, pixel_max); src += 2; } @@ -512,10 +512,10 @@ rnd = 1 << (shift - 1); n2 = (n + 1) / 2; for(i = 0; i < n2; i++) { - dst[i] = ((src[-4] + src[5]) * DP1C4 + - (src[-3] + src[4]) * DP1C3 + - (src[-2] + src[3]) * DP1C2 + - (src[-1] + src[2]) * DP1C1 + + dst[i] = ((src[-4] + src[5]) * DP1C4 + + (src[-3] + src[4]) * DP1C3 + + (src[-2] + src[3]) * DP1C2 + + (src[-1] + src[2]) * DP1C1 + (src[0] + src[1]) * DP1C0 + rnd) >> shift; src += 2; } @@ -526,7 +526,7 @@ PIXEL *src1, v; int d, i; - if (phase == 0) + if (phase == 0) d = DP0TAPS2; else d = DP1TAPS2; @@ -553,7 +553,7 @@ PIXEL v; int d, i; - if (phase == 0) + if (phase == 0) d = DP0TAPS2; else d = DP1TAPS2; @@ -569,7 +569,7 @@ decimate2p0_simple16(dst, src1 + d, n, bit_depth); else decimate2p1_simple16(dst, src1 + d, n, bit_depth); - + } static void decimate2_v(PIXEL *dst, int16_t **src, int pos, int n, @@ -598,28 +598,28 @@ src4 = src[pos]; pos = add_mod_int(pos, 1, DP1TAPS); src5 = src[pos]; - + shift = 21 - bit_depth; offset = 1 << (shift - 1); pixel_max = (1 << bit_depth) - 1; for(i = 0; i < n; i++) { - dst[i] = clamp_pix(((srcm4[i] + src5[i]) * DP1C4 + - (srcm3[i] + src4[i]) * DP1C3 + - (srcm2[i] + src3[i]) * DP1C2 + - (srcm1[i] + src2[i]) * DP1C1 + + dst[i] = clamp_pix(((srcm4[i] + src5[i]) * DP1C4 + + (srcm3[i] + src4[i]) * DP1C3 + + (srcm2[i] + src3[i]) * DP1C2 + + (srcm1[i] + src2[i]) * DP1C1 + (src0[i] + src1[i]) * DP1C0 + offset) >> shift, pixel_max); } } /* Note: we do the horizontal decimation first to use less CPU cache */ static void decimate2_hv(uint8_t *dst, int dst_linesize, - uint8_t *src, int src_linesize, + uint8_t *src, int src_linesize, int w, int h, int bit_depth, int h_phase) { PIXEL *buf1; int16_t *buf2[DP1TAPS]; int w2, pos, i, y, y1, y2; - + w2 = (w + 1) / 2; buf1 = malloc(sizeof(PIXEL) * (w + 2 * DTAPS_MAX)); @@ -692,7 +692,7 @@ img = malloc(sizeof(Image)); memset(img, 0, sizeof(*img)); - + img->w = w; img->h = h; img->format = format; @@ -713,7 +713,7 @@ /* multiple of 16 pixels to add borders */ w1 = (w1 + (W_PAD - 1)) & ~(W_PAD - 1); h1 = (h1 + (W_PAD - 1)) & ~(W_PAD - 1); - + linesize = w1 << img->pixel_shift; img->data[i] = malloc(linesize * h1); img->linesize[i] = linesize; @@ -802,7 +802,7 @@ return; w1 = (img->w + cb_size - 1) & ~(cb_size - 1); h1 = (img->h + cb_size - 1) & ~(cb_size - 1); - + if (img->format == BPG_FORMAT_GRAY) c_count = 1; else @@ -810,11 +810,11 @@ if (img->has_alpha) c_count++; for(c_idx = 0; c_idx < c_count; c_idx++) { - if (img->format == BPG_FORMAT_420 && + if (img->format == BPG_FORMAT_420 && (c_idx == 1 || c_idx == 2)) { h_shift = 1; v_shift = 1; - } else if (img->format == BPG_FORMAT_422 && + } else if (img->format == BPG_FORMAT_422 && (c_idx == 1 || c_idx == 2)) { h_shift = 1; v_shift = 0; @@ -1009,28 +1009,28 @@ BPGImageFormatEnum format; ColorConvertState cvt_s, *cvt = &cvt_s; BPGMetaData *md, **plast_md, *first_md; - + png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if (png_ptr == NULL) { return NULL; } - + info_ptr = png_create_info_struct(png_ptr); if (info_ptr == NULL) { png_destroy_read_struct(&png_ptr, NULL, NULL); return NULL; } - + if (setjmp(png_jmpbuf(png_ptr))) { png_destroy_read_struct(&png_ptr, &info_ptr, NULL); return NULL; } - + png_init_io(png_ptr, f); - + png_read_info(png_ptr, info_ptr); - + bit_depth = png_get_bit_depth(png_ptr, info_ptr); color_type = png_get_color_type(png_ptr, info_ptr); @@ -1062,7 +1062,7 @@ } else { format = BPG_FORMAT_444; } - + has_alpha = (color_type == PNG_COLOR_TYPE_GRAY_ALPHA || color_type == PNG_COLOR_TYPE_RGB_ALPHA); @@ -1091,9 +1091,9 @@ for (y = 0; y < img->h; y++) { rows[y] = malloc(linesize); } - + png_read_image(png_ptr, rows); - + convert_init(cvt, bit_depth, out_bit_depth, color_space, limited_range); if (format != BPG_FORMAT_GRAY) { @@ -1102,7 +1102,7 @@ idx = (bit_depth == 16); convert_func = rgb_to_cs[idx][color_space]; - + for (y = 0; y < img->h; y++) { convert_func(cvt, (PIXEL *)(img->data[0] + y * img->linesize[0]), (PIXEL *)(img->data[1] + y * img->linesize[1]), @@ -1144,9 +1144,9 @@ free(rows[y]); } free(rows); - + png_read_end(png_ptr, info_ptr); - + /* get the ICC profile if present */ first_md = NULL; plast_md = &first_md; @@ -1155,9 +1155,9 @@ int comp_type; png_bytep iccp_buf; png_uint_32 iccp_buf_len; - + if (png_get_iCCP(png_ptr, info_ptr, - &name, &comp_type, &iccp_buf, &iccp_buf_len) == + &name, &comp_type, &iccp_buf, &iccp_buf_len) == PNG_INFO_iCCP) { md = bpg_md_alloc(BPG_EXTENSION_TAG_ICCP); md->buf_len = iccp_buf_len; @@ -1169,7 +1169,7 @@ } png_destroy_read_struct(&png_ptr, &info_ptr, NULL); - + *pmd = first_md; return img; } @@ -1183,7 +1183,7 @@ BPGMetaData *md, **plast_md, *first_md; int has_exif, has_xmp, l, iccp_chunk_count, i; jpeg_saved_marker_ptr iccp_chunks[256]; - + iccp_chunk_count = 0; has_exif = 0; has_xmp = 0; @@ -1191,7 +1191,7 @@ plast_md = &first_md; for (marker = first_marker; marker != NULL; marker = marker->next) { #if 0 - printf("marker=APP%d len=%d\n", + printf("marker=APP%d len=%d\n", marker->marker - JPEG_APP0, marker->data_length); #endif if (!has_exif && marker->marker == JPEG_APP0 + 1 && @@ -1207,7 +1207,7 @@ has_exif = 1; } else if (!has_xmp && marker->marker == JPEG_APP0 + 1 && marker->data_length > sizeof(app1_xmp) && - !memcmp(marker->data, app1_xmp, sizeof(app1_xmp)) && + !memcmp(marker->data, app1_xmp, sizeof(app1_xmp)) && !has_xmp) { md = bpg_md_alloc(BPG_EXTENSION_TAG_XMP); l = sizeof(app1_xmp); @@ -1224,7 +1224,7 @@ l = sizeof(app2_iccp); chunk_index = marker->data[l]; chunk_count = marker->data[l]; - if (chunk_index == 0 || chunk_count == 0) + if (chunk_index == 0 || chunk_count == 0) continue; if (iccp_chunk_count == 0) { iccp_chunk_count = chunk_count; @@ -1269,7 +1269,7 @@ return first_md; } -Image *read_jpeg(BPGMetaData **pmd, FILE *f, +Image *read_jpeg(BPGMetaData **pmd, FILE *f, int out_bit_depth) { struct jpeg_decompress_struct cinfo; @@ -1290,12 +1290,12 @@ jpeg_save_markers(&cinfo, JPEG_APP0 + 2, 65535); jpeg_stdio_src(&cinfo, f); - + jpeg_read_header(&cinfo, TRUE); - + cinfo.raw_data_out = TRUE; cinfo.do_fancy_upsampling = TRUE; - + w = cinfo.image_width; h = cinfo.image_height; @@ -1405,7 +1405,7 @@ plane_idx[2] = 2; } plane_idx[3] = 3; - + if (cinfo.raw_data_out) { JSAMPROW rows[4][16]; JSAMPROW *plane_pointer[4]; @@ -1433,11 +1433,11 @@ } plane_pointer[c_idx] = rows[c_idx]; } - + while (cinfo.output_scanline < cinfo.output_height) { y = cinfo.output_scanline; jpeg_read_raw_data(&cinfo, plane_pointer, y_h); - + for(c_idx = 0; c_idx < cinfo.num_components; c_idx++) { if (c_idx == 1 || c_idx == 2) { h1 = c_h; @@ -1451,7 +1451,7 @@ idx = plane_idx[c_idx]; for(i = 0; i < h1; i++) { PIXEL *ptr; - ptr = (PIXEL *)(img->data[idx] + + ptr = (PIXEL *)(img->data[idx] + img->linesize[idx] * (y1 + i)); gray8_to_gray(cvt, ptr, rows[c_idx][i], w1, 1); if (color_space == BPG_CS_YCbCr && has_w_plane) { @@ -1465,7 +1465,7 @@ } } } - + for(c_idx = 0; c_idx < cinfo.num_components; c_idx++) { if (c_idx == 1 || c_idx == 2) { h1 = c_h; @@ -1490,19 +1490,19 @@ for(c_idx = 0; c_idx < c_count; c_idx++) { idx = plane_idx[c_idx]; - gray8_to_gray(cvt, (PIXEL *)(img->data[idx] + + gray8_to_gray(cvt, (PIXEL *)(img->data[idx] + img->linesize[idx] * y), buf + c_idx, w, c_count); } } free(buf); } - + first_md = jpeg_get_metadata(cinfo.marker_list); the_end: jpeg_finish_decompress(&cinfo); - + jpeg_destroy_decompress(&cinfo); *pmd = first_md; return img; @@ -1557,7 +1557,7 @@ for(i = 0; i < c_count; i++) { get_plane_res(img, &c_w, &c_h, i); for(y = 0; y < c_h; y++) { - fwrite(img->data[i] + y * img->linesize[i], + fwrite(img->data[i] + y * img->linesize[i], 1, c_w << img->pixel_shift, f); } } @@ -1611,7 +1611,7 @@ } /* return the position of the end of the NAL or -1 if error */ -static int extract_nal(uint8_t **pnal_buf, int *pnal_len, +static int extract_nal(uint8_t **pnal_buf, int *pnal_len, const uint8_t *buf, int buf_len) { int idx, start, end, len; @@ -1626,7 +1626,7 @@ else start = 4; len = end - start; - + nal_buf = malloc(len); nal_len = 0; idx = start; @@ -1652,7 +1652,7 @@ { uint8_t *p = *pp; int i, j; - + for(i = 1; i < 5; i++) { if (v < (1 << (7 * i))) break; @@ -1690,7 +1690,7 @@ p = s->idx >> 3; if ((p + 3) < s->buf_len) { - v = (buf[p] << 24) | (buf[p + 1] << 16) | + v = (buf[p] << 24) | (buf[p + 1] << 16) | (buf[p + 2] << 8) | buf[p + 3]; } else { v = 0; @@ -1804,7 +1804,7 @@ if (new_size < size) new_size = size; new_buf = realloc(s->buf, new_size); - if (!new_buf) + if (!new_buf) return -1; s->buf = new_buf; s->size = new_size; @@ -1927,12 +1927,12 @@ get_ue_golomb(gb); /* max_dec_pic_buffering */ get_ue_golomb(gb); /* num_reorder_pics */ get_ue_golomb(gb); /* max_latency_increase */ - + log2_min_cb_size = get_ue_golomb(gb) + 3; log2_diff_max_min_coding_block_size = get_ue_golomb(gb); log2_min_tb_size = get_ue_golomb(gb) + 2; log2_diff_max_min_transform_block_size = get_ue_golomb(gb); - + max_transform_hierarchy_depth_inter = get_ue_golomb(gb); max_transform_hierarchy_depth_intra = get_ue_golomb(gb); if (max_transform_hierarchy_depth_inter != max_transform_hierarchy_depth_intra) { @@ -1987,11 +1987,11 @@ if (sar_present) { sar_idx = get_bits(gb, 8); if (sar_idx == 255) { - skip_bits(gb, 16); /* sar_num */ - skip_bits(gb, 16); /* sar_den */ + skip_bits(gb, 16); /* sar_num */ + skip_bits(gb, 16); /* sar_den */ } } - + overscan_info_present_flag = get_bits(gb, 1); if (overscan_info_present_flag) { skip_bits(gb, 1); /* overscan_appropriate_flag */ @@ -2053,9 +2053,9 @@ } if (sps_range_extension_flag) { sps_range_extension_flags = get_bits(gb, 9); - if (sps_range_extension_flags & ((1 << (8 - 3)) | - (1 << (8 - 4)) | - (1 << (8 - 6)) | + if (sps_range_extension_flags & ((1 << (8 - 3)) | + (1 << (8 - 4)) | + (1 << (8 - 6)) | (1 << (8 - 8)))) { fprintf(stderr, "unsupported range extensions (0x%x)\n", sps_range_extension_flags); @@ -2067,7 +2067,7 @@ /* build the modified SPS */ msps_buf = malloc(nal_len + 32); memset(msps_buf, 0, nal_len + 16); - + init_put_bits(pb, msps_buf); put_ue_golomb(pb, log2_min_cb_size - 3); put_ue_golomb(pb, log2_diff_max_min_coding_block_size); @@ -2103,7 +2103,7 @@ memcpy(p, msps_buf, msps_buf_len); p += msps_buf_len; - + out_buf_len = p - out_buf; free(msps_buf); free(nal_buf); @@ -2141,7 +2141,7 @@ return 0; } -static int build_modified_hevc(uint8_t **pout_buf, +static int build_modified_hevc(uint8_t **pout_buf, const uint8_t *cbuf, int cbuf_len, const uint8_t *abuf, int abuf_len, const uint16_t *frame_duration_tab, @@ -2151,9 +2151,9 @@ uint8_t *msps; const uint8_t *nal_buf; int msps_len, cidx, aidx, is_alpha, nal_len, first_nal, start, l, frame_num; - + dyn_buf_init(out_buf); - + /* add alpha MSPS */ aidx = 0; /* avoids warning */ if (abuf) { @@ -2166,7 +2166,7 @@ out_buf->len += msps_len; free(msps); } - + /* add color MSPS */ cidx = build_modified_sps(&msps, &msps_len, cbuf, cbuf_len); if (cidx < 0) @@ -2198,7 +2198,7 @@ goto fail; cidx += nal_len; } else { - if (aidx >= abuf_len) + if (aidx >= abuf_len) break; nal_buf = abuf + aidx; nal_len = find_nal_end(nal_buf, abuf_len - aidx); @@ -2212,7 +2212,7 @@ int nut; /* add SEI NAL for the frame duration (animation case) */ nut = (nal_buf[start] >> 1) & 0x3f; - if ((nut <= 9 || (nut >= 16 && nut <= 21)) && + if ((nut <= 9 || (nut >= 16 && nut <= 21)) && start + 2 < nal_len && (nal_buf[start + 2] & 0x80)) { int frame_ticks; assert(frame_num < frame_count); @@ -2372,13 +2372,13 @@ return s; } -void bpg_encoder_set_extension_data(BPGEncoderContext *s, +void bpg_encoder_set_extension_data(BPGEncoderContext *s, BPGMetaData *md) { s->first_md = md; } -static int bpg_encoder_encode_trailer(BPGEncoderContext *s, +static int bpg_encoder_encode_trailer(BPGEncoderContext *s, BPGEncoderWriteFunc *write_func, void *opaque) { @@ -2391,7 +2391,7 @@ exit(1); } s->enc_ctx = NULL; - + alpha_buf = NULL; alpha_buf_len = 0; if (s->alpha_enc_ctx) { @@ -2402,7 +2402,7 @@ } s->alpha_enc_ctx = NULL; } - + hevc_buf = NULL; hevc_buf_len = build_modified_hevc(&hevc_buf, out_buf, out_buf_len, alpha_buf, alpha_buf_len, @@ -2413,7 +2413,7 @@ } free(out_buf); free(alpha_buf); - + if (write_func(opaque, hevc_buf, hevc_buf_len) != hevc_buf_len) { fprintf(stderr, "Error while writing HEVC data\n"); exit(1); @@ -2469,7 +2469,7 @@ img_alpha->pixel_shift = img->pixel_shift; img_alpha->data[0] = img->data[c_idx]; img_alpha->linesize[0] = img->linesize[c_idx]; - + img->data[c_idx] = NULL; img->has_alpha = 0; } else { @@ -2508,7 +2508,7 @@ if (img_alpha) image_convert16to8(img_alpha); } - + if (s->frame_count == 0) { memset(ep, 0, sizeof(*ep)); ep->qp = p->qp; @@ -2534,7 +2534,7 @@ else ep->qp = p->alpha_qp; ep->chroma_format = 0; - + s->alpha_enc_ctx = s->encoder->open(ep); if (!s->alpha_enc_ctx) { fprintf(stderr, "Error while opening alpha encoder\n"); @@ -2565,7 +2565,7 @@ BPGMetaData *md1; int max_len; uint8_t *q; - + max_len = 0; for(md1 = s->first_md; md1 != NULL; md1 = md1->next) { max_len += md1->buf_len + 5 * 2; @@ -2579,19 +2579,19 @@ q += md1->buf_len; } extension_buf_len = q - extension_buf; - + bpg_md_free(s->first_md); s->first_md = NULL; } - + { uint8_t img_header[128], *q; int v, has_alpha, has_extension, alpha2_flag, alpha1_flag, format; - + has_alpha = (img_alpha != NULL); has_extension = (extension_buf_len > 0); - - + + if (has_alpha) { if (img->has_w_plane) { alpha1_flag = 0; @@ -2604,7 +2604,7 @@ alpha1_flag = 0; alpha2_flag = 0; } - + q = img_header; *q++ = (IMAGE_HEADER_MAGIC >> 24) & 0xff; *q++ = (IMAGE_HEADER_MAGIC >> 16) & 0xff; @@ -2625,14 +2625,14 @@ *q++ = v; put_ue(&q, width); put_ue(&q, height); - + put_ue(&q, 0); /* zero length means up to the end of the file */ if (has_extension) { put_ue(&q, extension_buf_len); /* extension data length */ } - + write_func(opaque, img_header, q - img_header); - + if (has_extension) { if (write_func(opaque, extension_buf, extension_buf_len) != extension_buf_len) { fprintf(stderr, "Error while writing extension data\n"); @@ -2648,18 +2648,18 @@ s->frame_duration_tab_size = (s->frame_duration_tab_size * 3) / 2; if (s->frame_duration_tab_size < (s->frame_count + 1)) s->frame_duration_tab_size = (s->frame_count + 1); - s->frame_duration_tab = realloc(s->frame_duration_tab, + s->frame_duration_tab = realloc(s->frame_duration_tab, sizeof(s->frame_duration_tab) * s->frame_duration_tab_size); } s->frame_duration_tab[s->frame_count] = s->frame_ticks; s->encoder->encode(s->enc_ctx, img); - + if (img_alpha) { s->encoder->encode(s->alpha_enc_ctx, img_alpha); image_free(img_alpha); } - + s->frame_count++; if (!p->animated) @@ -2711,7 +2711,7 @@ } snprintf(q, buf + buf_size - q, "%0*u", l, n); q += strlen(q); - + } else { add_char: if ((q - buf) < buf_size - 1) @@ -2733,14 +2733,14 @@ strcat(hevc_encoders, " "); strcat(hevc_encoders, hevc_encoder_name[i]); } - + printf("BPG Image Encoder version " CONFIG_BPG_VERSION "\n" - "usage: bpgenc [options] infile.[jpg|png]\n" + "usage: bpgenc [options] infile.[jpg|png|tiff]\n" "\n" "Main options:\n" "-h show the full help (including the advanced options)\n" "-o outfile set output filename (default = %s)\n" - "-q qp set quantizer parameter (smaller gives better quality,\n" + "-q qp set quantizer parameter (smaller gives better quality,\n" " range: 0-51, default = %d)\n" "-f cfmt set the preferred chroma format (420, 422, 444,\n" " default=420)\n" @@ -2812,7 +2812,7 @@ limited_range = 0; premultiplied_alpha = 0; frame_delay_file = NULL; - + for(;;) { c = getopt_long_only(argc, argv, "q:o:hf:c:vm:b:e:a", long_opts, &option_index); if (c == -1) @@ -2952,7 +2952,7 @@ } } - if (optind >= argc) + if (optind >= argc) help(0); infilename = argv[optind]; @@ -3010,10 +3010,10 @@ frame_ticks = 1; } } - + if (p->verbose) printf("Encoding '%s' ticks=%d\n", filename, frame_ticks); - + if (keep_metadata && first_frame) { bpg_encoder_set_extension_data(enc_ctx, md); } else { @@ -3036,22 +3036,22 @@ fprintf(stderr, "Could not read '%s'\n", infilename); exit(1); } - + if (!keep_metadata && md) { bpg_md_free(md); md = NULL; } - + bpg_encoder_set_extension_data(enc_ctx, md); - + bpg_encoder_encode(enc_ctx, img, my_write_func, f); image_free(img); } fclose(f); - + bpg_encoder_close(enc_ctx); - + bpg_encoder_param_free(p); return 0;
--- a/bpgview.c Wed Dec 07 10:37:38 2016 +0200 +++ b/bpgview.c Wed Dec 07 10:38:38 2016 +0200 @@ -96,12 +96,12 @@ return NULL; if (fread(buf, 1, len, f) != len) return NULL; - + frames = NULL; frame_count = 0; s = bpg_decoder_open(); - if (bpg_decoder_decode(s, buf, len) < 0) + if (bpg_decoder_decode(s, buf, len) < 0) goto fail; bpg_decoder_get_info(s, bi); #if SDL_BYTEORDER == SDL_BIG_ENDIAN @@ -122,9 +122,9 @@ frames = realloc(frames, sizeof(frames[0]) * (frame_count + 1)); img = SDL_CreateRGBSurface(SDL_HWSURFACE, bi->width, bi->height, 32, rmask, gmask, bmask, amask); - if (!img) + if (!img) goto fail; - + SDL_LockSurface(img); for(y = 0; y < bi->height; y++) { bpg_decoder_get_line(s, (uint8_t *)img->pixels + y * img->pitch); @@ -155,7 +155,7 @@ SDL_RemoveTimer(dc->frame_timer_id); dc->frame_timer_id = 0; } - dc->frame_timer_id = + dc->frame_timer_id = SDL_AddTimer(dc->frames[dc->frame_index].delay, timer_cb, NULL); } @@ -201,7 +201,7 @@ SDL_RemoveTimer(dc->frame_timer_id); dc->frame_timer_id = 0; } - + dc->frame_count = frame_count; dc->frames = frames; dc->frame_index = 0; @@ -531,7 +531,7 @@ break; } } - done: + done: SDL_FreeSurface(dc->screen); return 0;