summaryrefslogtreecommitdiff
path: root/jpg2ff.c
diff options
context:
space:
mode:
authorFRIGN <dev@frign.de>2016-01-29 23:34:24 +0100
committerFRIGN <dev@frign.de>2016-01-29 23:34:24 +0100
commitdd22f4087d5e7420929575d1bbaf767d76395e9c (patch)
treedae372e3a7fe4ee92177d291842b6e1dee44137b /jpg2ff.c
parente9feca5c2bda05b9a356617868fd4b08ec903d0d (diff)
Back to the roots.
Talking with even more people and weighing the benefits, I've made the decision to remove color spaces from farbfeld again (as it currently is handled in version 1) and recommend sRGB, not force it. Thing is the following: We are not ready yet for this step. Neither the people working with the images nor the hardware to display extended colors. Using greater colorspaces also removes the "hackability" of farbfeld. As it was previously possible to easily create gradients in plain C, you have to keep multiple things in mind with linear ProPhoto RGB. The first thing is that not all colors are "real", and there are imaginary colors. This doesn't happen with sRGB because all the colors it describes are "real". The second thing is the linear gamma curve, which makes the gradients look perceptually inconsistent. In the interest of creating a good and simple interchange format, we can't only weigh in points of professionals. This little excursion has shown that aiming for the 99% is still the way to go. And as often as you could repeat that sRGB will meet its fate in the future when screens become better, it is surprising how badly the industry has caught up to it. I also must honestly say that we can't solve the color space issue using RGB and should look at other formats to explore (CIELUV, CIELAB), which I will probably give a talk about at slcon3. Before releasing version 2, my aim is to make the I/O a bit more effective (as far as possible) so it's even easier to use. I know people will be pissed off, but fuck it, I'm the maintainer! Live with it.
Diffstat (limited to 'jpg2ff.c')
-rw-r--r--jpg2ff.c69
1 files changed, 4 insertions, 65 deletions
diff --git a/jpg2ff.c b/jpg2ff.c
index cdf5d56..7a25f03 100644
--- a/jpg2ff.c
+++ b/jpg2ff.c
@@ -8,18 +8,9 @@
#include <string.h>
#include <jpeglib.h>
-#include <lcms2.h>
static char *argv0;
-/* ROMM RGB primaries (ISO 22028-2:2013) */
-static cmsCIExyYTRIPLE primaries = {
- /* x, y, Y */
- { 0.7347, 0.2653, 0.288040 }, /* red */
- { 0.1596, 0.8404, 0.711874 }, /* green */
- { 0.0366, 0.0001, 0.000086 }, /* blue */
-};
-
METHODDEF(void)
jpeg_error(j_common_ptr cinfo)
{
@@ -31,11 +22,7 @@ jpeg_error(j_common_ptr cinfo)
int
main(int argc, char *argv[])
{
- cmsHPROFILE in_profile = NULL, out_profile;
- cmsHTRANSFORM transform;
- cmsToneCurve *gamma10, *out_curves[3];
struct jpeg_decompress_struct cinfo;
- jpeg_saved_marker_ptr marker;
struct jpeg_error_mgr jerr;
uint32_t width, height, val_be;
uint16_t *ff_row;
@@ -55,9 +42,6 @@ main(int argc, char *argv[])
jpeg_create_decompress(&cinfo);
- jpeg_save_markers(&cinfo, JPEG_APP0 + 1, 0xffff); /* exif data */
- jpeg_save_markers(&cinfo, JPEG_APP0 + 2, 0xffff); /* icc data */
-
jpeg_stdio_src(&cinfo, stdin);
jpeg_read_header(&cinfo, TRUE);
@@ -68,23 +52,6 @@ main(int argc, char *argv[])
cinfo.output_components = 3; /* color components per pixel */
cinfo.out_color_space = JCS_RGB; /* input color space */
- /* extract metadata */
- marker = cinfo.marker_list;
- for(; marker; marker = marker->next) {
- if (!marker->data || !marker->data_length)
- continue;
- if (marker->marker == JPEG_APP0 + 1) {
- /* exif data marker */
- /* todo: Should we handle icc data from exif? */
- } else if (marker->marker == JPEG_APP0 + 2) {
- /* icc data marker */
- if (!(in_profile = cmsOpenProfileFromMem(
- marker->data + 14,
- marker->data_length - 14)))
- goto lcmserr;
- }
- }
-
jpeg_start_decompress(&cinfo);
jpeg_row_len = width * cinfo.output_components;
@@ -97,20 +64,6 @@ main(int argc, char *argv[])
return 1;
}
- /* icc profile (output linear ROMM RGB (ISO 22028-2:2013)) */
- if (!in_profile && !(in_profile = cmsCreate_sRGBProfile()))
- goto lcmserr;
- if (!(gamma10 = cmsBuildGamma(NULL, 1.0)))
- goto lcmserr;
- out_curves[0] = out_curves[1] = out_curves[2] = gamma10;
- if (!(out_profile = cmsCreateRGBProfile(cmsD50_xyY(), &primaries,
- out_curves)))
- goto lcmserr;
- if (!(transform = cmsCreateTransform(in_profile, TYPE_RGBA_16,
- out_profile, TYPE_RGBA_16,
- INTENT_RELATIVE_COLORIMETRIC, 0)))
- goto lcmserr;
-
/* write header */
fprintf(stdout, "farbfeld");
val_be = htonl(width);
@@ -127,20 +80,10 @@ main(int argc, char *argv[])
jpeg_read_scanlines(&cinfo, buffer, 1);
for (i = 0, dx = 0, sx = 0; i < width; i++, sx += 3, dx += 4) {
- ff_row[dx] = buffer[0][sx] * 257;
- ff_row[dx+1] = buffer[0][sx+1] * 257;
- ff_row[dx+2] = buffer[0][sx+2] * 257;
- ff_row[dx+3] = 65535;
- }
-
- cmsDoTransform(transform, ff_row, ff_row, ff_row_len / 4);
-
- for (i = 0; i < ff_row_len; i++) {
- /* re-add alpha */
- if (i >= 3 && (i - 3) % 4 == 0)
- ff_row[i] = 65535;
- /* swap endianness to BE */
- ff_row[i] = htons(ff_row[i]);
+ ff_row[dx] = htons(buffer[0][sx] * 257);
+ ff_row[dx+1] = htons(buffer[0][sx+1] * 257);
+ ff_row[dx+2] = htons(buffer[0][sx+2] * 257);
+ ff_row[dx+3] = htons(65535);
}
/* write data */
@@ -156,8 +99,4 @@ writerr:
perror(NULL);
return 1;
-lcmserr:
- fprintf(stderr, "%s: lcms error\n", argv0);
-
- return 1;
}