farbfeld

suckless image format with conversion tools
git clone git://git.suckless.org/farbfeld
Log | Files | Refs | README | LICENSE

commit e9feca5c2bda05b9a356617868fd4b08ec903d0d
parent 291e677210c6c2c1d1eba2f0ba2243806ef63b07
Author: FRIGN <dev@frign.de>
Date:   Wed, 20 Jan 2016 22:31:25 +0100

Use linear RGB

Makes things a lot easier for image manipulation algorithms which
can be expected to be applied to farbfeld data.

Diffstat:
MFORMAT | 27+++++++++++++++------------
Mff2png.c | 23+++++++++++++----------
Mjpg2ff.c | 10+++++-----
Mpng2ff.c | 10+++++-----
4 files changed, 38 insertions(+), 32 deletions(-)

diff --git a/FORMAT b/FORMAT @@ -1,15 +1,18 @@ FARBFELD IMAGE FORMAT SPECIFICATION - +--------+-------------------------------------------------------+ - | Bytes | Description | - +--------+-------------------------------------------------------+ - | 8 | "farbfeld" magic value | - +--------+-------------------------------------------------------+ - | 4 | 32-Bit BE unsigned integer (width) | - +--------+-------------------------------------------------------+ - | 4 | 32-Bit BE unsigned integer (height) | - +--------+-------------------------------------------------------+ - | [2222] | 4*16-Bit BE unsigned integers [RGBA] / pixel | - | | pixels in rows, ProPhoto RGB, not alpha-premultiplied | - +--------+-------------------------------------------------------+ + +--------+-----------------------------------------------+ + | Bytes | Description | + +--------+-----------------------------------------------+ + | 8 | "farbfeld" magic value | + +--------+-----------------------------------------------+ + | 4 | 32-Bit BE unsigned integer (width) | + +--------+-----------------------------------------------+ + | 4 | 32-Bit BE unsigned integer (height) | + +--------+-----------------------------------------------+ + | [2222] | 4*16-Bit BE unsigned integers [RGBA] / pixel | + | | - pixels in rows | + | | - linear ROMM RGB (ISO 22028-2:2013) | + | | (= linear ProPhoto RGB = Melissa RGB) | + | | - no alpha premultiplication | + +--------+-----------------------------------------------+ diff --git a/ff2png.c b/ff2png.c @@ -14,7 +14,7 @@ static char *argv0; -/* ProPhoto RGB */ +/* ROMM RGB primaries (ISO 22028-2:2013) */ static cmsCIExyYTRIPLE primaries = { /* x, y, Y */ { 0.7347, 0.2653, 0.288040 }, /* red */ @@ -34,8 +34,8 @@ main(int argc, char *argv[]) { cmsContext icc_context; cmsHPROFILE out_prof; - cmsMLU *mlu1, *mlu2; - cmsToneCurve *gamma18, *out_curve[3]; + cmsMLU *mlu1, *mlu2, *mlu3; + cmsToneCurve *gamma10, *out_curve[3]; png_structp pngs; png_infop pngi; size_t png_row_len, j; @@ -62,25 +62,27 @@ main(int argc, char *argv[]) width = ntohl(*((uint32_t *)(hdr + 8))); height = ntohl(*((uint32_t *)(hdr + 12))); - /* icc profile (ProPhoto RGB) */ + /* icc profile (linear ROMM RGB (ISO 22028-2:2013)) */ if (!(icc_context = cmsCreateContext(NULL, NULL))) goto lcmserr; - if (!(gamma18 = cmsBuildGamma(icc_context, 1.8))) + if (!(gamma10 = cmsBuildGamma(icc_context, 1.0))) goto lcmserr; - out_curve[0] = out_curve[1] = out_curve[2] = gamma18; + out_curve[0] = out_curve[1] = out_curve[2] = gamma10; if (!(out_prof = cmsCreateRGBProfileTHR(icc_context, cmsD50_xyY(), &primaries, out_curve))) goto lcmserr; cmsSetHeaderFlags(out_prof, cmsEmbeddedProfileTrue | cmsUseAnywhere); cmsSetHeaderRenderingIntent(out_prof, INTENT_RELATIVE_COLORIMETRIC); cmsSetDeviceClass(out_prof, cmsSigColorSpaceClass); - if (!(mlu1 = cmsMLUalloc(NULL, 1)) || !(mlu2 = cmsMLUalloc(NULL, 1))) + if (!(mlu1 = cmsMLUalloc(NULL, 1)) || !(mlu2 = cmsMLUalloc(NULL, 1)) || + !(mlu3 = cmsMLUalloc(NULL, 1))) goto lcmserr; cmsMLUsetASCII(mlu1, "en", "US", "Public Domain"); cmsWriteTag(out_prof, cmsSigCopyrightTag, mlu1); - cmsMLUsetASCII(mlu2, "en", "US", "ProPhoto RGB"); - cmsWriteTag(out_prof, cmsSigProfileDescriptionTag, mlu2); + cmsMLUsetASCII(mlu2, "en", "US", "aka Linear ProPhoto RGB, Melissa RGB"); cmsWriteTag(out_prof, cmsSigDeviceModelDescTag, mlu2); + cmsMLUsetASCII(mlu3, "en", "US", "Linear ROMM RGB (ISO 22028-2:2013)"); + cmsWriteTag(out_prof, cmsSigProfileDescriptionTag, mlu3); cmsSaveProfileToMem(out_prof, NULL, &icclen); if (!(icc = malloc(icclen))) { fprintf(stderr, "%s: malloc: out of memory\n", argv0); @@ -101,7 +103,8 @@ main(int argc, char *argv[]) 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_set_iCCP(pngs, pngi, "Linear ROMM RGB (ISO 22028-2:2013)", 0, + icc, icclen); png_write_info(pngs, pngi); /* write rows */ diff --git a/jpg2ff.c b/jpg2ff.c @@ -12,7 +12,7 @@ static char *argv0; -/* ProPhoto RGB */ +/* ROMM RGB primaries (ISO 22028-2:2013) */ static cmsCIExyYTRIPLE primaries = { /* x, y, Y */ { 0.7347, 0.2653, 0.288040 }, /* red */ @@ -33,7 +33,7 @@ main(int argc, char *argv[]) { cmsHPROFILE in_profile = NULL, out_profile; cmsHTRANSFORM transform; - cmsToneCurve *gamma18, *out_curves[3]; + cmsToneCurve *gamma10, *out_curves[3]; struct jpeg_decompress_struct cinfo; jpeg_saved_marker_ptr marker; struct jpeg_error_mgr jerr; @@ -97,12 +97,12 @@ main(int argc, char *argv[]) return 1; } - /* icc profile (output ProPhoto RGB) */ + /* icc profile (output linear ROMM RGB (ISO 22028-2:2013)) */ if (!in_profile && !(in_profile = cmsCreate_sRGBProfile())) goto lcmserr; - if (!(gamma18 = cmsBuildGamma(NULL, 1.8))) + if (!(gamma10 = cmsBuildGamma(NULL, 1.0))) goto lcmserr; - out_curves[0] = out_curves[1] = out_curves[2] = gamma18; + out_curves[0] = out_curves[1] = out_curves[2] = gamma10; if (!(out_profile = cmsCreateRGBProfile(cmsD50_xyY(), &primaries, out_curves))) goto lcmserr; diff --git a/png2ff.c b/png2ff.c @@ -12,7 +12,7 @@ static char *argv0; -/* ProPhoto RGB */ +/* ROMM RGB primaries (ISO 22028-2:2013) */ static cmsCIExyYTRIPLE primaries = { /* x, y, Y */ { 0.7347, 0.2653, 0.288040 }, /* red */ @@ -32,7 +32,7 @@ main(int argc, char *argv[]) { cmsHPROFILE in_prof, out_prof; cmsHTRANSFORM trans; - cmsToneCurve *gamma18, *out_curves[3]; + cmsToneCurve *gamma10, *out_curves[3]; png_structp pngs; png_infop pngi; int icc_compression; @@ -70,7 +70,7 @@ main(int argc, char *argv[]) height = png_get_image_height(pngs, pngi); png_row_p = png_get_rows(pngs, pngi); - /* icc profile (output ProPhoto RGB) */ + /* icc profile (output linear ROMM RGB (ISO 22028-2:2013)) */ if (png_get_valid(pngs, pngi, PNG_INFO_iCCP)) { png_get_iCCP(pngs, pngi, &icc_name, &icc_compression, &icc_data, &icc_len); @@ -81,9 +81,9 @@ main(int argc, char *argv[]) if (!(in_prof = cmsCreate_sRGBProfile())) goto lcmserr; } - if (!(gamma18 = cmsBuildGamma(NULL, 1.8))) + if (!(gamma10 = cmsBuildGamma(NULL, 1.0))) goto lcmserr; - out_curves[0] = out_curves[1] = out_curves[2] = gamma18; + out_curves[0] = out_curves[1] = out_curves[2] = gamma10; if (!(out_prof = cmsCreateRGBProfile(cmsD50_xyY(), &primaries, out_curves))) goto lcmserr;