Path: blob/master/thirdparty/libjpeg-turbo/src/cmyk.h
9904 views
/*1* cmyk.h2*3* Copyright (C) 2017-2018, 2022, 2024, D. R. Commander.4* For conditions of distribution and use, see the accompanying README.ijg5* file.6*7* This file contains convenience functions for performing quick & dirty8* CMYK<->RGB conversion. This algorithm is suitable for testing purposes9* only. Properly converting between CMYK and RGB requires a color management10* system.11*/1213#ifndef CMYK_H14#define CMYK_H1516#include <jinclude.h>17#define JPEG_INTERNALS18#include <jpeglib.h>19#include "jsamplecomp.h"202122/* Fully reversible */2324INLINE25LOCAL(void)26rgb_to_cmyk(int maxval, _JSAMPLE r, _JSAMPLE g, _JSAMPLE b,27_JSAMPLE *c, _JSAMPLE *m, _JSAMPLE *y, _JSAMPLE *k)28{29double ctmp = 1.0 - ((double)r / (double)maxval);30double mtmp = 1.0 - ((double)g / (double)maxval);31double ytmp = 1.0 - ((double)b / (double)maxval);32double ktmp = MIN(MIN(ctmp, mtmp), ytmp);3334if (ktmp == 1.0) ctmp = mtmp = ytmp = 0.0;35else {36ctmp = (ctmp - ktmp) / (1.0 - ktmp);37mtmp = (mtmp - ktmp) / (1.0 - ktmp);38ytmp = (ytmp - ktmp) / (1.0 - ktmp);39}40*c = (_JSAMPLE)((double)maxval - ctmp * (double)maxval + 0.5);41*m = (_JSAMPLE)((double)maxval - mtmp * (double)maxval + 0.5);42*y = (_JSAMPLE)((double)maxval - ytmp * (double)maxval + 0.5);43*k = (_JSAMPLE)((double)maxval - ktmp * (double)maxval + 0.5);44}454647/* Fully reversible only for C/M/Y/K values generated with rgb_to_cmyk() */4849INLINE50LOCAL(void)51cmyk_to_rgb(int maxval, _JSAMPLE c, _JSAMPLE m, _JSAMPLE y, _JSAMPLE k,52_JSAMPLE *r, _JSAMPLE *g, _JSAMPLE *b)53{54*r = (_JSAMPLE)((double)c * (double)k / (double)maxval + 0.5);55*g = (_JSAMPLE)((double)m * (double)k / (double)maxval + 0.5);56*b = (_JSAMPLE)((double)y * (double)k / (double)maxval + 0.5);57}585960#endif /* CMYK_H */616263