|
shun-iwasawa |
82a8f5 |
/*
|
|
shun-iwasawa |
82a8f5 |
* cmyk.h
|
|
shun-iwasawa |
82a8f5 |
*
|
|
shun-iwasawa |
82a8f5 |
* Copyright (C) 2017-2018, D. R. Commander.
|
|
shun-iwasawa |
82a8f5 |
* For conditions of distribution and use, see the accompanying README.ijg
|
|
shun-iwasawa |
82a8f5 |
* file.
|
|
shun-iwasawa |
82a8f5 |
*
|
|
shun-iwasawa |
82a8f5 |
* This file contains convenience functions for performing quick & dirty
|
|
shun-iwasawa |
82a8f5 |
* CMYK<->RGB conversion. This algorithm is suitable for testing purposes
|
|
shun-iwasawa |
82a8f5 |
* only. Properly converting between CMYK and RGB requires a color management
|
|
shun-iwasawa |
82a8f5 |
* system.
|
|
shun-iwasawa |
82a8f5 |
*/
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
#ifndef CMYK_H
|
|
shun-iwasawa |
82a8f5 |
#define CMYK_H
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
#include <jinclude.h></jinclude.h>
|
|
shun-iwasawa |
82a8f5 |
#define JPEG_INTERNALS
|
|
shun-iwasawa |
82a8f5 |
#include <jpeglib.h></jpeglib.h>
|
|
shun-iwasawa |
82a8f5 |
#include "jconfigint.h"
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
/* Fully reversible */
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
INLINE
|
|
shun-iwasawa |
82a8f5 |
LOCAL(void)
|
|
shun-iwasawa |
82a8f5 |
rgb_to_cmyk(JSAMPLE r, JSAMPLE g, JSAMPLE b, JSAMPLE *c, JSAMPLE *m,
|
|
shun-iwasawa |
82a8f5 |
JSAMPLE *y, JSAMPLE *k)
|
|
shun-iwasawa |
82a8f5 |
{
|
|
shun-iwasawa |
82a8f5 |
double ctmp = 1.0 - ((double)r / 255.0);
|
|
shun-iwasawa |
82a8f5 |
double mtmp = 1.0 - ((double)g / 255.0);
|
|
shun-iwasawa |
82a8f5 |
double ytmp = 1.0 - ((double)b / 255.0);
|
|
shun-iwasawa |
82a8f5 |
double ktmp = MIN(MIN(ctmp, mtmp), ytmp);
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
if (ktmp == 1.0) ctmp = mtmp = ytmp = 0.0;
|
|
shun-iwasawa |
82a8f5 |
else {
|
|
shun-iwasawa |
82a8f5 |
ctmp = (ctmp - ktmp) / (1.0 - ktmp);
|
|
shun-iwasawa |
82a8f5 |
mtmp = (mtmp - ktmp) / (1.0 - ktmp);
|
|
shun-iwasawa |
82a8f5 |
ytmp = (ytmp - ktmp) / (1.0 - ktmp);
|
|
shun-iwasawa |
82a8f5 |
}
|
|
shun-iwasawa |
82a8f5 |
*c = (JSAMPLE)(255.0 - ctmp * 255.0 + 0.5);
|
|
shun-iwasawa |
82a8f5 |
*m = (JSAMPLE)(255.0 - mtmp * 255.0 + 0.5);
|
|
shun-iwasawa |
82a8f5 |
*y = (JSAMPLE)(255.0 - ytmp * 255.0 + 0.5);
|
|
shun-iwasawa |
82a8f5 |
*k = (JSAMPLE)(255.0 - ktmp * 255.0 + 0.5);
|
|
shun-iwasawa |
82a8f5 |
}
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
/* Fully reversible only for C/M/Y/K values generated with rgb_to_cmyk() */
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
INLINE
|
|
shun-iwasawa |
82a8f5 |
LOCAL(void)
|
|
shun-iwasawa |
82a8f5 |
cmyk_to_rgb(JSAMPLE c, JSAMPLE m, JSAMPLE y, JSAMPLE k, JSAMPLE *r, JSAMPLE *g,
|
|
shun-iwasawa |
82a8f5 |
JSAMPLE *b)
|
|
shun-iwasawa |
82a8f5 |
{
|
|
shun-iwasawa |
82a8f5 |
*r = (JSAMPLE)((double)c * (double)k / 255.0 + 0.5);
|
|
shun-iwasawa |
82a8f5 |
*g = (JSAMPLE)((double)m * (double)k / 255.0 + 0.5);
|
|
shun-iwasawa |
82a8f5 |
*b = (JSAMPLE)((double)y * (double)k / 255.0 + 0.5);
|
|
shun-iwasawa |
82a8f5 |
}
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
#endif /* CMYK_H */
|