[hackers] [farbfeld] Remove more png cruft from code || FRIGN

From: <git_AT_suckless.org>
Date: Tue, 19 Jan 2016 23:17:47 +0100 (CET)

commit 2ea5274584f8f38a8bd49271ad7aebed5d3afec3
Author: FRIGN <dev_AT_frign.de>
AuthorDate: Tue Jan 19 23:17:27 2016 +0100
Commit: FRIGN <dev_AT_frign.de>
CommitDate: Tue Jan 19 23:17:27 2016 +0100

    Remove more png cruft from code
    
    No need for these shitty png-types.

diff --git a/ff2png.c b/ff2png.c
index 94a6b95..9f562b8 100644
--- a/ff2png.c
+++ b/ff2png.c
_AT_@ -23,7 +23,7 @@ static cmsCIExyYTRIPLE primaries = {
 };
 
 void
-pngerr(png_structp png_struct_p, png_const_charp msg)
+pngerr(png_structp pngs, const char *msg)
 {
         fprintf(stderr, "%s: libpng: %s\n", argv0, msg);
         exit(1);
_AT_@ -33,14 +33,13 @@ int
 main(int argc, char *argv[])
 {
         cmsContext icc_context;
- cmsHPROFILE out_profile;
+ cmsHPROFILE out_prof;
         cmsMLU *mlu1, *mlu2;
- cmsToneCurve *gamma18, *out_curves[3];
- png_structp png_struct_p;
- png_infop png_info_p;
- png_size_t png_row_len, j;
- png_uint_32 width, height, i;
- uint32_t icclen;
+ cmsToneCurve *gamma18, *out_curve[3];
+ png_structp pngs;
+ png_infop pngi;
+ size_t png_row_len, j;
+ uint32_t icclen, width, height, i;
         uint16_t tmp16, *png_row;
         uint8_t hdr[16], *icc;
 
_AT_@ -68,42 +67,42 @@ main(int argc, char *argv[])
                 goto lcmserr;
         if (!(gamma18 = cmsBuildGamma(icc_context, 1.8)))
                 goto lcmserr;
- out_curves[0] = out_curves[1] = out_curves[2] = gamma18;
- if (!(out_profile = cmsCreateRGBProfileTHR(icc_context, cmsD50_xyY(),
- &primaries, out_curves)))
+ out_curve[0] = out_curve[1] = out_curve[2] = gamma18;
+ if (!(out_prof = cmsCreateRGBProfileTHR(icc_context, cmsD50_xyY(),
+ &primaries, out_curve)))
                 goto lcmserr;
- cmsSetHeaderFlags(out_profile, cmsEmbeddedProfileTrue | cmsUseAnywhere);
- cmsSetHeaderRenderingIntent(out_profile, INTENT_RELATIVE_COLORIMETRIC);
- cmsSetDeviceClass(out_profile, cmsSigColorSpaceClass);
+ cmsSetHeaderFlags(out_prof, cmsEmbeddedProfileTrue | cmsUseAnywhere);
+ cmsSetHeaderRenderingIntent(out_prof, INTENT_RELATIVE_COLORIMETRIC);
+ cmsSetDeviceClass(out_prof, cmsSigColorSpaceClass);
         if (!(mlu1 = cmsMLUalloc(NULL, 1)) || !(mlu2 = cmsMLUalloc(NULL, 1)))
                 goto lcmserr;
         cmsMLUsetASCII(mlu1, "en", "US", "Public Domain");
- cmsWriteTag(out_profile, cmsSigCopyrightTag, mlu1);
+ cmsWriteTag(out_prof, cmsSigCopyrightTag, mlu1);
         cmsMLUsetASCII(mlu2, "en", "US", "ProPhoto RGB");
- cmsWriteTag(out_profile, cmsSigProfileDescriptionTag, mlu2);
- cmsWriteTag(out_profile, cmsSigDeviceModelDescTag, mlu2);
- cmsSaveProfileToMem(out_profile, NULL, &icclen);
+ cmsWriteTag(out_prof, cmsSigProfileDescriptionTag, mlu2);
+ cmsWriteTag(out_prof, cmsSigDeviceModelDescTag, mlu2);
+ cmsSaveProfileToMem(out_prof, NULL, &icclen);
         if (!(icc = malloc(icclen))) {
                 fprintf(stderr, "%s: malloc: out of memory\n", argv0);
                 return 1;
         }
- cmsSaveProfileToMem(out_profile, icc, &icclen);
+ cmsSaveProfileToMem(out_prof, icc, &icclen);
 
         /* load png */
- png_struct_p = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL,
- pngerr, NULL);
- png_info_p = png_create_info_struct(png_struct_p);
+ pngs = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, pngerr,
+ NULL);
+ pngi = png_create_info_struct(pngs);
 
- if (!png_struct_p || !png_info_p) {
+ if (!pngs || !pngi) {
                 fprintf(stderr, "%s: failed to initialize libpng\n", argv0);
                 return 1;
         }
- png_init_io(png_struct_p, stdout);
- png_set_IHDR(png_struct_p, png_info_p, width, height, 16,
- PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE,
- PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
- png_set_iCCP(png_struct_p, png_info_p, "ProPhoto RGB", 0, icc, icclen);
- png_write_info(png_struct_p, png_info_p);
+ png_init_io(pngs, stdout);
+ png_set_IHDR(pngs, pngi, width, height, 16, PNG_COLOR_TYPE_RGB_ALPHA,
+ PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE,
+ PNG_FILTER_TYPE_BASE);
+ png_set_iCCP(pngs, pngi, "ProPhoto RGB", 0, icc, icclen);
+ png_write_info(pngs, pngi);
 
         /* write rows */
         png_row_len = strlen("RGBA") * width * sizeof(uint16_t);
_AT_@ -119,10 +118,10 @@ main(int argc, char *argv[])
                         }
                         png_row[j] = tmp16;
                 }
- png_write_row(png_struct_p, (uint8_t *)png_row);
+ png_write_row(pngs, (uint8_t *)png_row);
         }
- png_write_end(png_struct_p, NULL);
- png_destroy_write_struct(&png_struct_p, NULL);
+ png_write_end(pngs, NULL);
+ png_destroy_write_struct(&pngs, NULL);
 
         return 0;
 lcmserr:
diff --git a/png2ff.c b/png2ff.c
index 97bcdce..6750b6b 100644
--- a/png2ff.c
+++ b/png2ff.c
_AT_@ -21,7 +21,7 @@ static cmsCIExyYTRIPLE primaries = {
 };
 
 void
-pngerr(png_structp png_struct_p, png_const_charp msg)
+pngerr(png_structp pngs, const char *msg)
 {
         fprintf(stderr, "%s: libpng: %s\n", argv0, msg);
         exit(1);
_AT_@ -30,16 +30,16 @@ pngerr(png_structp png_struct_p, png_const_charp msg)
 int
 main(int argc, char *argv[])
 {
- cmsHPROFILE in_profile, out_profile;
- cmsHTRANSFORM transform;
+ cmsHPROFILE in_prof, out_prof;
+ cmsHTRANSFORM trans;
         cmsToneCurve *gamma18, *out_curves[3];
- png_structp png_struct_p;
- png_infop png_info_p;
- png_bytep *png_row_p, icc_data;
- png_charp icc_name;
+ png_structp pngs;
+ png_infop pngi;
+ int icc_compression;
         uint32_t width, height, icc_len, outrowlen, tmp32, r, i;
         uint16_t *inrow, *outrow;
- int icc_compression;
+ uint8_t **png_row_p, *icc_data;
+ char *icc_name;
 
         argv0 = argv[0], argc--, argv++;
 
_AT_@ -49,46 +49,46 @@ main(int argc, char *argv[])
         }
 
         /* load png */
- png_struct_p = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL,
- pngerr, NULL);
- png_info_p = png_create_info_struct(png_struct_p);
+ pngs = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, pngerr,
+ NULL);
+ pngi = png_create_info_struct(pngs);
 
- if (!png_struct_p || !png_info_p) {
+ if (!pngs || !pngi) {
                 fprintf(stderr, "%s: failed to initialize libpng\n", argv0);
                 return 1;
         }
- png_init_io(png_struct_p, stdin);
- if (png_get_valid(png_struct_p, png_info_p, PNG_INFO_tRNS))
- png_set_tRNS_to_alpha(png_struct_p);
- png_set_add_alpha(png_struct_p, 255*257, PNG_FILLER_AFTER);
- png_set_expand_gray_1_2_4_to_8(png_struct_p);
- png_set_gray_to_rgb(png_struct_p);
- png_set_packing(png_struct_p);
- png_read_png(png_struct_p, png_info_p, PNG_TRANSFORM_PACKING |
+ png_init_io(pngs, stdin);
+ if (png_get_valid(pngs, pngi, PNG_INFO_tRNS))
+ png_set_tRNS_to_alpha(pngs);
+ png_set_add_alpha(pngs, 255*257, PNG_FILLER_AFTER);
+ png_set_expand_gray_1_2_4_to_8(pngs);
+ png_set_gray_to_rgb(pngs);
+ png_set_packing(pngs);
+ png_read_png(pngs, pngi, PNG_TRANSFORM_PACKING |
                      PNG_TRANSFORM_EXPAND, NULL);
- width = png_get_image_width(png_struct_p, png_info_p);
- height = png_get_image_height(png_struct_p, png_info_p);
- png_row_p = png_get_rows(png_struct_p, png_info_p);
+ width = png_get_image_width(pngs, pngi);
+ height = png_get_image_height(pngs, pngi);
+ png_row_p = png_get_rows(pngs, pngi);
 
         /* icc profile (output ProPhoto RGB) */
- if (png_get_valid(png_struct_p, png_info_p, PNG_INFO_iCCP)) {
- png_get_iCCP(png_struct_p, png_info_p, &icc_name,
+ if (png_get_valid(pngs, pngi, PNG_INFO_iCCP)) {
+ png_get_iCCP(pngs, pngi, &icc_name,
                              &icc_compression, &icc_data, &icc_len);
- if (!(in_profile = cmsOpenProfileFromMem(icc_data,
+ if (!(in_prof = cmsOpenProfileFromMem(icc_data,
                                                          icc_len)))
                         goto lcmserr;
         } else {
- if (!(in_profile = cmsCreate_sRGBProfile()))
+ if (!(in_prof = cmsCreate_sRGBProfile()))
                         goto lcmserr;
         }
         if (!(gamma18 = cmsBuildGamma(NULL, 1.8)))
                 goto lcmserr;
         out_curves[0] = out_curves[1] = out_curves[2] = gamma18;
- if (!(out_profile = cmsCreateRGBProfile(cmsD50_xyY(), &primaries,
+ if (!(out_prof = cmsCreateRGBProfile(cmsD50_xyY(), &primaries,
                                                 out_curves)))
                 goto lcmserr;
 
- /* allocate row buffer */
+ /* allocate output row buffer */
         outrowlen = width * strlen("RGBA");
         if (!(outrow = malloc(outrowlen * sizeof(uint16_t)))) {
                 fprintf(stderr, "%s: malloc: out of memory\n", argv0);
_AT_@ -105,14 +105,15 @@ main(int argc, char *argv[])
                 goto writerr;
 
         /* write data */
- switch(png_get_bit_depth(png_struct_p, png_info_p)) {
+ switch(png_get_bit_depth(pngs, pngi)) {
         case 8:
- if (!(transform = cmsCreateTransform(in_profile,
- TYPE_RGBA_8, out_profile, TYPE_RGBA_16,
- INTENT_RELATIVE_COLORIMETRIC, 0)))
+ if (!(trans = cmsCreateTransform(in_prof, TYPE_RGBA_8,
+ out_prof, TYPE_RGBA_16,
+ INTENT_RELATIVE_COLORIMETRIC,
+ 0)))
                         goto lcmserr;
                 for (r = 0; r < height; ++r) {
- cmsDoTransform(transform, png_row_p[r], outrow, width);
+ cmsDoTransform(trans, png_row_p[r], outrow, width);
                         for (i = 0; i < outrowlen; i++) {
                                 /* re-add alpha */
                                 if (i >= 3 && (i - 3) % 4 == 0)
_AT_@ -126,9 +127,10 @@ main(int argc, char *argv[])
                 }
                 break;
         case 16:
- if (!(transform = cmsCreateTransform(in_profile,
- TYPE_RGBA_16, out_profile, TYPE_RGBA_16,
- INTENT_RELATIVE_COLORIMETRIC, 0)))
+ if (!(trans = cmsCreateTransform(in_prof, TYPE_RGBA_16,
+ out_prof, TYPE_RGBA_16,
+ INTENT_RELATIVE_COLORIMETRIC,
+ 0)))
                         goto lcmserr;
                 for (r = 0; r < height; ++r) {
                         inrow = (uint16_t *)png_row_p[r];
_AT_@ -136,7 +138,7 @@ main(int argc, char *argv[])
                                 /* swap endianness to LE */
                                 inrow[i] = ntohs(inrow[i]);
                         }
- cmsDoTransform(transform, png_row_p[r], outrow, width);
+ cmsDoTransform(trans, png_row_p[r], outrow, width);
                         for (i = 0; i < outrowlen; ++i) {
                                 /* re-add alpha */
                                 if (i >= 3 && (i - 3) % 4 == 0)
_AT_@ -154,7 +156,7 @@ main(int argc, char *argv[])
                 return 1;
         }
 
- png_destroy_read_struct(&png_struct_p, &png_info_p, NULL);
+ png_destroy_read_struct(&pngs, &pngi, NULL);
 
         return 0;
 writerr:
Received on Tue Jan 19 2016 - 23:17:47 CET

This archive was generated by hypermail 2.3.0 : Tue Jan 19 2016 - 23:24:14 CET