diff options
Diffstat (limited to 'support/dktools/dk4cs.c')
-rw-r--r-- | support/dktools/dk4cs.c | 2386 |
1 files changed, 0 insertions, 2386 deletions
diff --git a/support/dktools/dk4cs.c b/support/dktools/dk4cs.c deleted file mode 100644 index 1dccad682f..0000000000 --- a/support/dktools/dk4cs.c +++ /dev/null @@ -1,2386 +0,0 @@ -/* -Copyright (C) 2017-2020, Dirk Krause -SPDX-License-Identifier: BSD-3-Clause -*/ - -/* - WARNING: This file was generated by the dkct program (see - http://dktools.sourceforge.net/ for details). - Changes you make here will be lost if dkct is run again! - You should modify the original source and run dkct on it. - Original source: dk4cs.ctr -*/ - -/** @file dk4cs.c The dk4cs module. -*/ - - -#line 702 "dk4cs.ctr" - -#ifndef DK4CONF_H_INCLUDED -#include "dk4conf.h" -#endif - -#ifndef DK4BIFTY_H_INCLUDED -#include "dk4bifty.h" -#endif - -#ifndef DK4CS_H_INCLUDED -#include "dk4cs.h" -#endif - -#ifndef DK4MEM_H_INCLUDED -#include "dk4mem.h" -#endif - -#ifndef DK4MATH_H_INCLUDED -#include "dk4math.h" -#endif - - -#ifndef DK4STRD_H_INCLUDED -#include "dk4strd.h" -#endif - -#ifndef BIF_H_INCLUDED -#include "bif.h" -#endif - -#if DK4_HAVE_ASSERT_H -#ifndef ASSERT_H_INCLUDED -#include <assert.h> -#define ASSERT_H_INCLUDED 1 -#endif -#endif - - - - -#line 741 "dk4cs.ctr" - - - -/** Names for the conversion methods from RGB to CMYK. -*/ -static const dkChar * const dk4cs_rgb_to_cmyk_names[] = { -/* 0 */ -dkT("n$on-standard"), - -/* 1 */ -dkT("s$tandard"), - -NULL - - -#line 757 "dk4cs.ctr" -}; - - -/** Names for the conversion methods from RGB to GRAY. -*/ -static const dkChar * const dk4cs_rgb_to_gray_names[] = { -/* 0 */ -dkT("l$uminance"), - -/* 1 */ -dkT("in$accurate"), - -/* 2 */ -dkT("fast"), - -/* 3 */ -dkT("fastest"), - -/* 4 */ -dkT("it$u-bt709"), - -/* 5 */ -dkT("a$verage"), - -/* 6 */ -dkT("d$esaturation"), - -/* 7 */ -dkT("mi$n-decomposition"), - -/* 8 */ -dkT("me$dium-decomposition"), - -/* 9 */ -dkT("ma$x-decomposition"), - -/* 10 */ -dkT("r$ed"), - -/* 11 */ -dkT("g$reen"), - -/* 12 */ -dkT("b$lue"), - -NULL - - -#line 817 "dk4cs.ctr" -}; - - - -/** Names of alpha channel handling mechanisms. -*/ -static const dkChar * const dk4cs_alpha_names[] = { -/* 0 */ -dkT("m$ix"), - -/* 1 */ -dkT("i$gnore"), - -NULL - - -#line 828 "dk4cs.ctr" -}; - - - -int -dk4cs_context_init( - dk4_cs_conv_ctx_t *pctx, - dk4_er_t *erp -) -{ - int back = 0; - - -#line 840 "dk4cs.ctr" -#if DK4_USE_ASSERT - assert(NULL != pctx); -#endif - if (NULL != pctx) { - /* - Initialize all components - */ - pctx->rgb_to_cmyk = DK4_CS_CONV_RGB_TO_CMYK_NOT_PS_PDF; - pctx->rgb_to_gray = DK4_CS_CONV_RGB_TO_GRAY_ITU_BT601; - pctx->alpha = DK4_CS_CONV_ALPHA_MIX; - /* - Indicate success - */ - back = 1; - } - else { - -#line 856 "dk4cs.ctr" - dk4error_set_simple_error_code(erp,DK4_E_INVALID_ARGUMENTS); - } - -#line 858 "dk4cs.ctr" - return back; -} - - - -dk4_cs_conv_ctx_t * -dk4cs_context_open( - dk4_er_t *erp -) -{ - dk4_cs_conv_ctx_t *back; - - -#line 870 "dk4cs.ctr" - back = dk4mem_new(dk4_cs_conv_ctx_t,1,erp); - if (NULL != back) { - (void)dk4cs_context_init(back, NULL); - } - -#line 874 "dk4cs.ctr" - return back; -} - - - -int -dk4cs_context_set_rgb_to_cmyk( - dk4_cs_conv_ctx_t *pctx, - dk4_cs_conv_rgb_to_cmyk_t rgb_to_cmyk, - dk4_er_t *erp -) -{ - int back = 0; - - -#line 888 "dk4cs.ctr" -#if DK4_USE_ASSERT - assert(NULL != pctx); -#endif - if (NULL != pctx) { - pctx->rgb_to_cmyk = rgb_to_cmyk; - back = 1; - } - else { - -#line 896 "dk4cs.ctr" - dk4error_set_simple_error_code(erp,DK4_E_INVALID_ARGUMENTS); - } - -#line 898 "dk4cs.ctr" - return back; -} - - - -int -dk4cs_context_set_rgb_to_gray( - dk4_cs_conv_ctx_t *pctx, - dk4_cs_conv_rgb_to_gray_t rgb_to_gray, - dk4_er_t *erp -) -{ - int back = 0; - - -#line 912 "dk4cs.ctr" -#if DK4_USE_ASSERT - assert(NULL != pctx); -#endif - if (NULL != pctx) { - pctx->rgb_to_gray = rgb_to_gray; - back = 1; - } - else { - -#line 920 "dk4cs.ctr" - dk4error_set_simple_error_code(erp,DK4_E_INVALID_ARGUMENTS); - } - -#line 922 "dk4cs.ctr" - return back; -} - - - -int -dk4cs_context_set_alpha( - dk4_cs_conv_ctx_t *pctx, - dk4_cs_conv_alpha_t alpha, - dk4_er_t *erp -) -{ - int back = 0; - - -#line 936 "dk4cs.ctr" -#if DK4_USE_ASSERT - assert(NULL != pctx); -#endif - if (NULL != pctx) { - pctx->alpha = alpha; - back = 1; - } - else { - dk4error_set_simple_error_code(erp,DK4_E_INVALID_ARGUMENTS); - } - -#line 946 "dk4cs.ctr" - return back; -} - - - -int -dk4cs_context_text_rgb_to_cmyk( - dk4_cs_conv_ctx_t *pctx, - dkChar const *txt, - dk4_er_t *erp -) -{ - int back = 0; - int ind = 0; /* String index in array */ -#if DK4_USE_ASSERT - assert(NULL != pctx); - assert(NULL != txt); -#endif - if ((NULL == pctx) || (NULL == txt)) { - dk4error_set_simple_error_code(erp,DK4_E_INVALID_ARGUMENTS); - goto finished; - } - ind = dk4str_abbr_index(dk4cs_rgb_to_cmyk_names, dkT('$'), txt, 0); - if (0 > ind) { - dk4error_set_simple_error_code(erp,DK4_E_SYNTAX); - goto finished; - } - pctx->rgb_to_cmyk = (dk4_cs_conv_rgb_to_cmyk_t)ind; - back = 1; - - finished: - return back; -} - - - -int -dk4cs_context_text_rgb_to_gray( - dk4_cs_conv_ctx_t *pctx, - dkChar const *txt, - dk4_er_t *erp -) -{ - int back = 0; - int ind = 0; /* String index in array */ -#if DK4_USE_ASSERT - assert(NULL != pctx); - assert(NULL != txt); -#endif - if ((NULL == pctx) || (NULL == txt)) { - dk4error_set_simple_error_code(erp,DK4_E_INVALID_ARGUMENTS); - goto finished; - } - ind = dk4str_abbr_index(dk4cs_rgb_to_gray_names, dkT('$'), txt, 0); - if (0 > ind) { - dk4error_set_simple_error_code(erp,DK4_E_SYNTAX); - goto finished; - } - pctx->rgb_to_gray = (dk4_cs_conv_rgb_to_gray_t)ind; - back = 1; - - finished: - return back; -} - - - -int -dk4cs_context_text_alpha( - dk4_cs_conv_ctx_t *pctx, - dkChar const *txt, - dk4_er_t *erp -) -{ - int back = 0; - int ind = 0; /* String index in array */ -#if DK4_USE_ASSERT - assert(NULL != pctx); - assert(NULL != txt); -#endif - if ((NULL == pctx) || (NULL == txt)) { - dk4error_set_simple_error_code(erp,DK4_E_INVALID_ARGUMENTS); - goto finished; - } - ind = dk4str_abbr_index(dk4cs_alpha_names, dkT('$'), txt, 0); - if (0 > ind) { - dk4error_set_simple_error_code(erp,DK4_E_SYNTAX); - goto finished; - } - pctx->alpha = (dk4_cs_conv_alpha_t)ind; - back = 1; - - finished: - return back; -} - - - -void -dk4cs_context_close( - dk4_cs_conv_ctx_t *pctx -) -{ - - -#line 1050 "dk4cs.ctr" -#if DK4_USE_ASSERT - assert(NULL != pctx); -#endif - if (NULL != pctx) { - dk4mem_free(pctx); - } - -#line 1056 "dk4cs.ctr" -} - - - -dk4_px_t -dk4cs_mix_alpha(dk4_px_t value, dk4_px_t alpha, dk4_px_t bg, dk4_px_t max) -{ - - -#line 1064 "dk4cs.ctr" - return ( - (dk4_px_t)( - ( - ((unsigned long)value * (unsigned long)alpha) - + ( - (unsigned long)bg - * ((unsigned long)max - (unsigned long)alpha) - ) - ) / ((unsigned long)max) - ) - ); -} - - - -double -dk4cs_color_mix_alpha( - double v, - double a, - double b -) -{ - - -#line 1087 "dk4cs.ctr" - return ((v * a) + ((1.0 - a) * b)); -} - - - -dk4_px_t -dk4cs_mix_rgb_to_gray( - unsigned long r, - unsigned long g, - unsigned long b, - dk4_cs_conv_ctx_t const *pctx -) -{ - unsigned long min; /* Minimum of r g b */ - unsigned long max; /* Maximum of r g b */ - unsigned long back = 0UL; - dk4_cs_conv_rgb_to_gray_t alg = DK4_CS_CONV_RGB_TO_GRAY_ITU_BT601; - - -#line 1105 "dk4cs.ctr" - if (NULL != pctx) { alg = pctx->rgb_to_gray; } - switch (alg) { - case DK4_CS_CONV_RGB_TO_GRAY_CHANNEL_BLUE : { - back = b; - } break; - case DK4_CS_CONV_RGB_TO_GRAY_CHANNEL_GREEN : { - back = g; - } break; - case DK4_CS_CONV_RGB_TO_GRAY_CHANNEL_RED : { - back = r; - } break; - case DK4_CS_CONV_RGB_TO_GRAY_MAX_DECOMPOSITION : { - back = r; - if (g > back) back = g; - if (b > back) back = b; - } break; - case DK4_CS_CONV_RGB_TO_GRAY_MEDIUM_DECOMPOSITION : { - if (r > g) { - if (g > b) { - back = g; - } - else { - if (r > b) { - back = b; - } - else { - back = r; - } - } - } - else { - if (g < b) { - back = g; - } - else { - if (r < b) { - back = b; - } - else { - back = r; - } - } - } - } break; - case DK4_CS_CONV_RGB_TO_GRAY_MIN_DECOMPOSITION : { - back = r; - if (g < back) back = g; - if (b < back) back = b; - } break; - case DK4_CS_CONV_RGB_TO_GRAY_DESATURATION : { - min = max = r; - if (g < min) min = g; - if (g > max) max = g; - if (b < min) min = b; - if (b > max) max = b; - back = (max + min) / 2UL; - } break; - case DK4_CS_CONV_RGB_TO_GRAY_ITU_BT709 : { - back = (2126UL * r + 7152UL * g + 722UL * b) / 10000UL; - } break; - case DK4_CS_CONV_RGB_TO_GRAY_AVERAGE : { - back = (r + g + b) / 3UL; - } break; - case DK4_CS_CONV_RGB_TO_GRAY_VERY_FAST : { - back = ((r << 1) + ((g << 2) + g) + b) >> 3; - } break; - case DK4_CS_CONV_RGB_TO_GRAY_FAST : { - back = (77UL * r + 151UL * g + 28UL * b) >> 8; - } break; - case DK4_CS_CONV_RGB_TO_GRAY_LUMA : { - back = (30UL * r + 59UL * g + 11UL * b) / 100UL; - } break; - default : { - back = (299UL * r + 587UL * g + 114UL * b) / 1000UL; - } break; - } - -#line 1181 "dk4cs.ctr" - return ((dk4_px_t)back); -} - - - -/** Convert pixel data RGB to CMYK - @param dptr Destination array address. - @param sptr Source array address. - @param max Maximum value for R, G, B, C, M, Y, and K. - @param pctx Conversion context, may be NULL. -*/ - -static -void -dk4cs_mix_rgb_to_cmyk( - dk4_px_t *dptr, - dk4_px_t const *sptr, - dk4_px_t max, - dk4_cs_conv_ctx_t const *pctx -) -{ - dk4_px_t maxrgb; /* Maximum of r g b */ - dk4_px_t c; /* Cyan */ - dk4_px_t m; /* Magenta */ - dk4_px_t y; /* Yellow */ - dk4_px_t k; /* Black */ - dk4_cs_conv_rgb_to_cmyk_t rgb_to_cmyk = DK4_CS_CONV_RGB_TO_CMYK_NOT_PS_PDF; - - -#line 1209 "dk4cs.ctr" -#if DK4_USE_ASSERT - assert(NULL != dptr); - assert(NULL != sptr); -#endif - - -#line 1214 "dk4cs.ctr" - - -#line 1215 "dk4cs.ctr" - - -#line 1216 "dk4cs.ctr" - if (NULL != pctx) { rgb_to_cmyk = pctx->rgb_to_cmyk; } - maxrgb = sptr[0]; - if (sptr[1] > maxrgb) { maxrgb = sptr[1]; } - if (sptr[2] > maxrgb) { maxrgb = sptr[2]; } - k = max - maxrgb; - switch (rgb_to_cmyk) { - case DK4_CS_CONV_RGB_TO_CMYK_PS_PDF : { - c = maxrgb - sptr[0]; - m = maxrgb - sptr[1]; - y = maxrgb - sptr[2]; - } break; - default : { - if ((dk4_px_t)0U == maxrgb) { - c = m = y = (dk4_px_t)0U; - } - else { - c = (dk4_px_t)( - ( - ((unsigned long)max) - * (((unsigned long)maxrgb) - ((unsigned long)(sptr[0]))) - ) / ((unsigned long)maxrgb) - ); - m = (dk4_px_t)( - ( - ((unsigned long)max) - * (((unsigned long)maxrgb) - ((unsigned long)(sptr[1]))) - ) / ((unsigned long)maxrgb) - ); - y = (dk4_px_t)( - ( - ((unsigned long)max) - * (((unsigned long)maxrgb) - ((unsigned long)(sptr[2]))) - ) / ((unsigned long)maxrgb) - ); - } - } break; - } - dptr[0] = c; dptr[1] = m; dptr[2] = y; dptr[3] = k; - - -#line 1255 "dk4cs.ctr" - - -#line 1256 "dk4cs.ctr" - - -#line 1257 "dk4cs.ctr" - - -#line 1258 "dk4cs.ctr" - - -#line 1259 "dk4cs.ctr" -} - - - -/** Convert pixel data CMYK to RGB. - @param dptr Destination array address. - @param sptr Source array address. - @param max Maximum value for R, G, B, C, M, Y, and K. - @param pctx Conversion context, may be NULL. -*/ - -static -void -dk4cs_mix_cmyk_to_rgb( - dk4_px_t *dptr, - dk4_px_t const *sptr, - dk4_px_t max, - dk4_cs_conv_ctx_t const *pctx -) -{ - dk4_cs_conv_rgb_to_cmyk_t alg = DK4_CS_CONV_RGB_TO_CMYK_NOT_PS_PDF; - dk4_px_t r; /* Red */ - dk4_px_t g; /* Green */ - dk4_px_t b; /* Blue */ - dk4_px_t tr; /* Additional red component */ - dk4_px_t tg; /* Additional green component */ - dk4_px_t tb; /* Additional blue component */ - - -#line 1287 "dk4cs.ctr" -#if DK4_USE_ASSERT - assert(NULL != dptr); - assert(NULL != sptr); -#endif - - -#line 1292 "dk4cs.ctr" - - -#line 1293 "dk4cs.ctr" - - -#line 1294 "dk4cs.ctr" - - -#line 1295 "dk4cs.ctr" - if (NULL != pctx) { alg = pctx->rgb_to_cmyk; } - r = g = b = max - sptr[3]; - switch (alg) { - case DK4_CS_CONV_RGB_TO_CMYK_PS_PDF : { - /* Do nothing */ - } break; - default : { - tr = (dk4_px_t)( - (((unsigned long)(sptr[0])) * ((unsigned long)(sptr[3]))) - / ((unsigned long)max) - ); - tg = (dk4_px_t)( - (((unsigned long)(sptr[1])) * ((unsigned long)(sptr[3]))) - / ((unsigned long)max) - ); - tb = (dk4_px_t)( - (((unsigned long)(sptr[2])) * ((unsigned long)(sptr[3]))) - / ((unsigned long)max) - ); - if ((max - tr) >= r) { - r += tr; - } - else { - r = max; - } - if ((max - tg) >= g) { - g += tg; - } - else { - g = max; - } - if ((max - tb) >= b) { - b += tb; - } - else { - b = max; - } - } break; - } - if (r >= sptr[0]) { - r -= sptr[0]; - } - else { - r = 0; - } - if (g >= sptr[1]) { - g -= sptr[1]; - } - else { - g = 0; - } - if (b >= sptr[2]) { - g -= sptr[2]; - } - else { - g = 0; - } - dptr[0] = r; - -#line 1353 "dk4cs.ctr" - dptr[1] = g; - -#line 1354 "dk4cs.ctr" - dptr[2] = b; - -#line 1355 "dk4cs.ctr" - - -#line 1356 "dk4cs.ctr" -} - - - -size_t -dk4cs_color_space_size(int cs) -{ - size_t back = 0; - - -#line 1365 "dk4cs.ctr" - switch (cs) { - case DK4_CS_GRAY : { - back = 1; - } break; - case DK4_CS_GRAY_ALPHA : { - back = 2; - } break; - case DK4_CS_RGB : { - back = 3; - } break; - case DK4_CS_RGB_ALPHA : case DK4_CS_CMYK : { - back = 4; - } break; - } - -#line 1379 "dk4cs.ctr" - return back; -} - - - -void -dk4cs_nc_px_convert( - dk4_px_t *dptr, - int dcs, - dk4_px_t const *sptr, - int scs, - dk4_px_t const *bptr, - dk4_px_t max, - dk4_cs_conv_ctx_t const *pctx -) -{ - dk4_px_t myrgb[4]; /* Temporary pixel value */ - size_t i; /* Traverse components when mixing */ - dk4_cs_conv_alpha_t alpha; /* Alpha handling choice */ - - -#line 1399 "dk4cs.ctr" -#if DK4_USE_ASSERT - assert(NULL != dptr); - assert(NULL != sptr); -#endif - switch (scs) { - case DK4_CS_GRAY : { - - -#line 1406 "dk4cs.ctr" - switch (dcs) { - case DK4_CS_GRAY : { - - -#line 1409 "dk4cs.ctr" - dptr[0] = sptr[0]; - - -#line 1411 "dk4cs.ctr" - } break; - case DK4_CS_GRAY_ALPHA : { - - -#line 1414 "dk4cs.ctr" - dptr[0] = sptr[0]; - dptr[1] = max; - - -#line 1417 "dk4cs.ctr" - - -#line 1418 "dk4cs.ctr" - } break; - case DK4_CS_RGB : { - - -#line 1421 "dk4cs.ctr" - dptr[0] = dptr[1] = dptr[2] = sptr[0]; - - -#line 1423 "dk4cs.ctr" - - -#line 1424 "dk4cs.ctr" - - -#line 1425 "dk4cs.ctr" - } break; - case DK4_CS_RGB_ALPHA : { - - -#line 1428 "dk4cs.ctr" - dptr[0] = dptr[1] = dptr[2] = sptr[0]; - dptr[3] = max; - - -#line 1431 "dk4cs.ctr" - - -#line 1432 "dk4cs.ctr" - - -#line 1433 "dk4cs.ctr" - - -#line 1434 "dk4cs.ctr" - } break; - case DK4_CS_CMYK : { - - -#line 1437 "dk4cs.ctr" - dptr[3] = max - sptr[0]; - dptr[0] = dptr[1] = dptr[2] = 0; - - -#line 1440 "dk4cs.ctr" - - -#line 1441 "dk4cs.ctr" - - -#line 1442 "dk4cs.ctr" - - -#line 1443 "dk4cs.ctr" - } break; - default : { - } break; - } - } break; - case DK4_CS_GRAY_ALPHA : { - - -#line 1450 "dk4cs.ctr" - - -#line 1451 "dk4cs.ctr" - alpha = DK4_CS_CONV_ALPHA_MIX; - if (NULL != pctx) { alpha = pctx->alpha; } - switch (dcs) { - case DK4_CS_GRAY : { - - -#line 1456 "dk4cs.ctr" - switch (alpha) { - case DK4_CS_CONV_ALPHA_FOREGROUND : { - dptr[0] = sptr[0]; - } break; - default : { - dptr[0] = dk4cs_mix_alpha( - sptr[0], sptr[1], bptr[0], max - ); - } break; - } - - -#line 1467 "dk4cs.ctr" - } break; - case DK4_CS_GRAY_ALPHA : { - - -#line 1470 "dk4cs.ctr" - dptr[0] = sptr[0]; - dptr[1] = sptr[1]; - - -#line 1473 "dk4cs.ctr" - - -#line 1474 "dk4cs.ctr" - } break; - case DK4_CS_RGB : { - - -#line 1477 "dk4cs.ctr" - switch (alpha) { - case DK4_CS_CONV_ALPHA_FOREGROUND : { - dptr[0] = dptr[1] = dptr[2] = sptr[0]; - } break; - default : { - dptr[0] = dptr[1] = dptr[2] = dk4cs_mix_alpha( - sptr[0], sptr[1], bptr[0], max - ); - } break; - } - - -#line 1488 "dk4cs.ctr" - - -#line 1489 "dk4cs.ctr" - - -#line 1490 "dk4cs.ctr" - } break; - case DK4_CS_RGB_ALPHA : { - - -#line 1493 "dk4cs.ctr" - dptr[3] = sptr[1]; - dptr[0] = dptr[1] = dptr[2] = sptr[0]; - - -#line 1496 "dk4cs.ctr" - - -#line 1497 "dk4cs.ctr" - - -#line 1498 "dk4cs.ctr" - - -#line 1499 "dk4cs.ctr" - } break; - case DK4_CS_CMYK : { - - -#line 1502 "dk4cs.ctr" - switch (alpha) { - case DK4_CS_CONV_ALPHA_FOREGROUND : { - dptr[3] = max - sptr[0]; - } break; - default : { - dptr[3] = max - dk4cs_mix_alpha( - sptr[0], sptr[1], bptr[0], max - ); - } break; - } - dptr[0] = dptr[1] = dptr[2] = 0; - - -#line 1514 "dk4cs.ctr" - - -#line 1515 "dk4cs.ctr" - - -#line 1516 "dk4cs.ctr" - - -#line 1517 "dk4cs.ctr" - } break; - default : { - } break; - } - } break; - case DK4_CS_RGB : { - - -#line 1524 "dk4cs.ctr" - - -#line 1525 "dk4cs.ctr" - - -#line 1526 "dk4cs.ctr" - switch (dcs) { - case DK4_CS_GRAY : { - - -#line 1529 "dk4cs.ctr" - dptr[0] = dk4cs_mix_rgb_to_gray( - sptr[0], sptr[1], sptr[2], pctx - ); - - -#line 1533 "dk4cs.ctr" - } break; - case DK4_CS_GRAY_ALPHA : { - - -#line 1536 "dk4cs.ctr" - dptr[0] = dk4cs_mix_rgb_to_gray( - sptr[0], sptr[1], sptr[2], pctx - ); - dptr[1] = max; - - -#line 1541 "dk4cs.ctr" - - -#line 1542 "dk4cs.ctr" - } break; - case DK4_CS_RGB : { - - -#line 1545 "dk4cs.ctr" - dptr[0] = sptr[0]; - dptr[1] = sptr[1]; - dptr[2] = sptr[2]; - - -#line 1549 "dk4cs.ctr" - - -#line 1550 "dk4cs.ctr" - - -#line 1551 "dk4cs.ctr" - } break; - case DK4_CS_RGB_ALPHA : { - - -#line 1554 "dk4cs.ctr" - dptr[0] = sptr[0]; - dptr[1] = sptr[1]; - dptr[2] = sptr[2]; - dptr[3] = max; - - -#line 1559 "dk4cs.ctr" - - -#line 1560 "dk4cs.ctr" - - -#line 1561 "dk4cs.ctr" - - -#line 1562 "dk4cs.ctr" - } break; - case DK4_CS_CMYK : { - - -#line 1565 "dk4cs.ctr" - dk4cs_mix_rgb_to_cmyk(dptr, sptr, max, pctx); - - -#line 1567 "dk4cs.ctr" - - -#line 1568 "dk4cs.ctr" - - -#line 1569 "dk4cs.ctr" - - -#line 1570 "dk4cs.ctr" - } break; - default : { - } break; - } - } break; - case DK4_CS_RGB_ALPHA : { - - -#line 1577 "dk4cs.ctr" - - -#line 1578 "dk4cs.ctr" - - -#line 1579 "dk4cs.ctr" - - -#line 1580 "dk4cs.ctr" - alpha = DK4_CS_CONV_ALPHA_MIX; - if (NULL != pctx) { alpha = pctx->alpha; } - switch (dcs) { - case DK4_CS_GRAY : { - - -#line 1585 "dk4cs.ctr" - switch (alpha) { - case DK4_CS_CONV_ALPHA_FOREGROUND : { - dptr[0] = dk4cs_mix_rgb_to_gray( - sptr[0], sptr[1], sptr[2], pctx - ); - } break; - default : { - for (i = 0; i < 3; i++) { - myrgb[i] = dk4cs_mix_alpha( - sptr[i], sptr[3], bptr[i], max - ); - } - dptr[0] = dk4cs_mix_rgb_to_gray( - myrgb[0], myrgb[1], myrgb[2], pctx - ); - } break; - } - - -#line 1603 "dk4cs.ctr" - } break; - case DK4_CS_GRAY_ALPHA : { - - -#line 1606 "dk4cs.ctr" - dptr[0] = dk4cs_mix_rgb_to_gray( - sptr[0], sptr[1], sptr[2], pctx - ); - dptr[1] = sptr[3]; - - -#line 1611 "dk4cs.ctr" - - -#line 1612 "dk4cs.ctr" - } break; - case DK4_CS_RGB : { - - -#line 1615 "dk4cs.ctr" - for (i = 0; i < 3; i++) { - switch (alpha) { - case DK4_CS_CONV_ALPHA_FOREGROUND : { - dptr[i] = sptr[i]; - } break; - default : { - dptr[i] = dk4cs_mix_alpha( - sptr[i], sptr[3], bptr[i], max - ); - } break; - } - } - - -#line 1628 "dk4cs.ctr" - - -#line 1629 "dk4cs.ctr" - - -#line 1630 "dk4cs.ctr" - } break; - case DK4_CS_RGB_ALPHA : { - - -#line 1633 "dk4cs.ctr" - for (i = 0; i < 4; i++) { - dptr[i] = sptr[i]; - } - - -#line 1637 "dk4cs.ctr" - - -#line 1638 "dk4cs.ctr" - - -#line 1639 "dk4cs.ctr" - - -#line 1640 "dk4cs.ctr" - } break; - case DK4_CS_CMYK : { - - -#line 1643 "dk4cs.ctr" - switch (alpha) { - case DK4_CS_CONV_ALPHA_FOREGROUND : { - dk4cs_mix_rgb_to_cmyk(dptr, sptr, max, pctx); - } break; - default : { - for (i = 0; i < 3; i++) { - myrgb[i] = dk4cs_mix_alpha( - sptr[i], sptr[3], bptr[i], max - ); - } - dk4cs_mix_rgb_to_cmyk(dptr, myrgb, max, pctx); - } break; - } - - -#line 1657 "dk4cs.ctr" - - -#line 1658 "dk4cs.ctr" - - -#line 1659 "dk4cs.ctr" - - -#line 1660 "dk4cs.ctr" - } break; - default : { - } break; - } - } break; - case DK4_CS_CMYK : { - - -#line 1667 "dk4cs.ctr" - - -#line 1668 "dk4cs.ctr" - - -#line 1669 "dk4cs.ctr" - - -#line 1670 "dk4cs.ctr" - switch (dcs) { - case DK4_CS_GRAY : { - - -#line 1673 "dk4cs.ctr" - dk4cs_mix_cmyk_to_rgb(myrgb, sptr, max, pctx); - dptr[0] = dk4cs_mix_rgb_to_gray( - myrgb[0], myrgb[1], myrgb[2], pctx - ); - - -#line 1678 "dk4cs.ctr" - } break; - case DK4_CS_GRAY_ALPHA : { - - -#line 1681 "dk4cs.ctr" - dk4cs_mix_cmyk_to_rgb(myrgb, sptr, max, pctx); - dptr[0] = dk4cs_mix_rgb_to_gray( - myrgb[0], myrgb[1], myrgb[2], pctx - ); - dptr[1] = max; - - -#line 1687 "dk4cs.ctr" - - -#line 1688 "dk4cs.ctr" - } break; - case DK4_CS_RGB : { - - -#line 1691 "dk4cs.ctr" - dk4cs_mix_cmyk_to_rgb(dptr, sptr, max, pctx); - - -#line 1693 "dk4cs.ctr" - - -#line 1694 "dk4cs.ctr" - - -#line 1695 "dk4cs.ctr" - } break; - case DK4_CS_RGB_ALPHA : { - - -#line 1698 "dk4cs.ctr" - dk4cs_mix_cmyk_to_rgb(dptr, sptr, max, pctx); - dptr[3] = max; - - -#line 1701 "dk4cs.ctr" - - -#line 1702 "dk4cs.ctr" - - -#line 1703 "dk4cs.ctr" - - -#line 1704 "dk4cs.ctr" - } break; - case DK4_CS_CMYK : { - - -#line 1707 "dk4cs.ctr" - for (i = 0; i < 4; i++) { - dptr[i] = sptr[i]; - } - - -#line 1711 "dk4cs.ctr" - - -#line 1712 "dk4cs.ctr" - - -#line 1713 "dk4cs.ctr" - - -#line 1714 "dk4cs.ctr" - } break; - default : { - } break; - } - } break; - default : { - } break; - } - - -#line 1723 "dk4cs.ctr" -} - - - -void -dk4cs_px_convert( - dk4_px_t *dptr, - int dcs, - size_t dsz, - dk4_px_t const *sptr, - int scs, - size_t ssz, - dk4_px_t const *bptr, - size_t bsz, - dk4_px_t max, - dk4_cs_conv_ctx_t const *pctx, - dk4_er_t *erp -) -{ - size_t i; - - -#line 1744 "dk4cs.ctr" -#if DK4_USE_ASSERT - assert(NULL != dptr); - assert(0 < dsz); - assert(NULL != sptr); - assert(0 < ssz); -#endif - /* - Check arguments - */ - if (NULL == dptr) { - -#line 1754 "dk4cs.ctr" - dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS); - goto finished; - } - if ((DK4_CS_MIN > dcs) || (DK4_CS_MAX < dcs)) { - -#line 1758 "dk4cs.ctr" - dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS); - goto finished; - } - if (dsz < dk4cs_color_space_size(dcs)) { - -#line 1762 "dk4cs.ctr" - dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS); - goto finished; - } - if (NULL == sptr) { - -#line 1766 "dk4cs.ctr" - dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS); - goto finished; - } - if ((DK4_CS_MIN > scs) || (DK4_CS_MAX < scs)) { - -#line 1770 "dk4cs.ctr" - dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS); - goto finished; - } - if (ssz < dk4cs_color_space_size(scs)) { - -#line 1774 "dk4cs.ctr" - dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS); - goto finished; - } - if ((dk4_px_t)0U == max) { - -#line 1778 "dk4cs.ctr" - dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS); - goto finished; - } - for (i = 0; i < ssz; i++) { - if (max < sptr[i]) { - -#line 1783 "dk4cs.ctr" - dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS); - goto finished; - } - } - switch (scs) { - case DK4_CS_GRAY_ALPHA : - case DK4_CS_RGB_ALPHA : { - if (NULL == bptr) { - -#line 1791 "dk4cs.ctr" - dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS); - goto finished; - } - if (bsz < (dk4cs_color_space_size(scs) - 1)) { - -#line 1795 "dk4cs.ctr" - dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS); - goto finished; - } - for (i = 0; i < bsz; i++) { - if (max < bptr[i]) { - -#line 1800 "dk4cs.ctr" - dk4error_set_simple_error_code(erp,DK4_E_INVALID_ARGUMENTS); - goto finished; - } - } - } break; - } - /* Do conversion - */ - dk4cs_nc_px_convert(dptr, dcs, sptr, scs, bptr, max, pctx); - finished: - - -#line 1811 "dk4cs.ctr" - return; -} - - - -double -dk4cs_color_mix_rgb_to_gray( - double r, - double g, - double b, - dk4_cs_conv_ctx_t const *pctx -) -{ - double min; /* Minimum of r g b */ - double max; /* Maximum of r g b */ - double back = 0.0; - dk4_cs_conv_rgb_to_gray_t alg = DK4_CS_CONV_RGB_TO_GRAY_ITU_BT601; - - -#line 1829 "dk4cs.ctr" - if (NULL != pctx) { alg = pctx->rgb_to_gray; } - switch (alg) { - case DK4_CS_CONV_RGB_TO_GRAY_CHANNEL_BLUE : { - back = b; - } break; - case DK4_CS_CONV_RGB_TO_GRAY_CHANNEL_GREEN : { - back = g; - } break; - case DK4_CS_CONV_RGB_TO_GRAY_CHANNEL_RED : { - back = r; - } break; - case DK4_CS_CONV_RGB_TO_GRAY_MAX_DECOMPOSITION : { - back = r; - if (g > back) back = g; - if (b > back) back = b; - } break; - case DK4_CS_CONV_RGB_TO_GRAY_MEDIUM_DECOMPOSITION : { - if (r > g) { - if (g > b) { - back = g; - } - else { - if (r > b) { - back = b; - } - else { - back = r; - } - } - } - else { - if (g < b) { - back = g; - } - else { - if (r < b) { - back = b; - } - else { - back = r; - } - } - } - } break; - case DK4_CS_CONV_RGB_TO_GRAY_MIN_DECOMPOSITION : { - back = r; - if (g < back) back = g; - if (b < back) back = b; - } break; - case DK4_CS_CONV_RGB_TO_GRAY_DESATURATION : { - min = max = r; - if (g < min) min = g; - if (g > max) max = g; - if (b < min) min = b; - if (b > max) max = b; - back = (max + min) / 2.0; - } break; - case DK4_CS_CONV_RGB_TO_GRAY_ITU_BT709 : { - back = 0.2126*r + 0.7152*g + 0.0722*b; - } break; - case DK4_CS_CONV_RGB_TO_GRAY_AVERAGE : { - back = (r + g + b) / 3.0; - } break; - case DK4_CS_CONV_RGB_TO_GRAY_LUMA : { - back = 0.3*r + 0.59*g + 0.11*b; - } break; - default : { - back = 0.299*r + 0.587*g + 0.114*b; - } break; - } - -#line 1899 "dk4cs.ctr" - return back; -} - - - -/** Convert normalized color RGB to CMYK - @param dptr Address of result array (CMYK). - @param sptr Source values (RGB). - @param pctx Conversion context, may be NULL. -*/ - -static -void -dk4cs_color_mix_rgb_to_cmyk( - double *dptr, - const double *sptr, - dk4_cs_conv_ctx_t const *pctx -) -{ - double c; /* Cyan */ - double m; /* Magenta */ - double y; /* Yellow */ - double k; /* Black */ - double maxrgb; /* Maximum of r g b */ - int me; /* Flag: Math error */ - dk4_cs_conv_rgb_to_cmyk_t alg = DK4_CS_CONV_RGB_TO_CMYK_NOT_PS_PDF; - - -#line 1926 "dk4cs.ctr" -#if DK4_USE_ASSERT - assert(NULL != dptr); - assert(NULL != sptr); -#endif - - -#line 1931 "dk4cs.ctr" - - -#line 1932 "dk4cs.ctr" - - -#line 1933 "dk4cs.ctr" - if (NULL != pctx) { alg = pctx->rgb_to_cmyk; } - maxrgb = sptr[0]; - if (sptr[1] > maxrgb) { maxrgb = sptr[1]; } - if (sptr[2] > maxrgb) { maxrgb = sptr[2]; } - c = maxrgb - sptr[0]; - m = maxrgb - sptr[1]; - y = maxrgb - sptr[2]; - k = 1.0 - maxrgb; - switch (alg) { - case DK4_CS_CONV_RGB_TO_CMYK_PS_PDF : { - /* Nothing to do */ - } break; - default : { - me = 0; - c = c / maxrgb; m = m / maxrgb ; y = y / maxrgb; - if (!(dk4ma_is_finite(c))) { me = 1; } - if (!(dk4ma_is_finite(m))) { me = 1; } - if (!(dk4ma_is_finite(y))) { me = 1; } - if ((0.0 > c) || (1.0 < c)) { me = 1; } - if ((0.0 > m) || (1.0 < m)) { me = 1; } - if ((0.0 > y) || (1.0 < y)) { me = 1; } - if (0 != me) { - c = m = y = 0.0; k = 1.0; - } - } break; - } - dptr[0] = c; dptr[1] = m; dptr[2] = y; dptr[3] = k; - - -#line 1961 "dk4cs.ctr" - - -#line 1962 "dk4cs.ctr" - - -#line 1963 "dk4cs.ctr" - - -#line 1964 "dk4cs.ctr" - - -#line 1965 "dk4cs.ctr" -} - - - -/** Convert normalized color CMYK to RGB. - @param dptr Address of result array. - @param sptr Address of source array. - @param pctx Conversion context, may be NULL. -*/ - -static -void -dk4cs_color_mix_cmyk_to_rgb( - double *dptr, - double const *sptr, - dk4_cs_conv_ctx_t const *pctx -) -{ - double r; /* Red */ - double g; /* Green */ - double b; /* Blue */ - dk4_cs_conv_rgb_to_cmyk_t alg = DK4_CS_CONV_RGB_TO_CMYK_NOT_PS_PDF; - - -#line 1988 "dk4cs.ctr" -#if DK4_USE_ASSERT - assert(NULL != dptr); - assert(NULL != sptr); -#endif - - -#line 1993 "dk4cs.ctr" - - -#line 1994 "dk4cs.ctr" - - -#line 1995 "dk4cs.ctr" - - -#line 1996 "dk4cs.ctr" - if (NULL != pctx) { alg = pctx->rgb_to_cmyk; } - r = g = b = 1.0 - sptr[3]; - r -= sptr[0]; - g -= sptr[1]; - b -= sptr[2]; - switch (alg) { - case DK4_CS_CONV_RGB_TO_CMYK_PS_PDF : { - /* Nothing to do */ - } break; - default : { - r += (sptr[0] * sptr[3]); - g += (sptr[1] * sptr[3]); - b += (sptr[2] * sptr[3]); - } break; - } - if (0.0 > r) { r = 0.0; } if (1.0 < r) { r = 1.0; } - if (0.0 > g) { g = 0.0; } if (1.0 < g) { g = 1.0; } - if (0.0 > b) { b = 0.0; } if (1.0 < b) { b = 1.0; } - dptr[0] = r; dptr[1] = g; dptr[2] = b; - - -#line 2016 "dk4cs.ctr" - - -#line 2017 "dk4cs.ctr" - - -#line 2018 "dk4cs.ctr" - - -#line 2019 "dk4cs.ctr" -} - - - -void -dk4cs_nc_color_convert( - double *dptr, - int dcs, - double const *sptr, - int scs, - double const *bptr, - dk4_cs_conv_ctx_t const *pctx -) -{ - double myrgb[4]; /* Temporary pixel data for mixing */ - size_t i; /* Traverse all pixel components */ - dk4_cs_conv_alpha_t alpha; - - -#line 2037 "dk4cs.ctr" -#if DK4_USE_ASSERT - assert(NULL != dptr); - assert(NULL != sptr); -#endif - switch (scs) { - case DK4_CS_GRAY : { - - -#line 2044 "dk4cs.ctr" - switch (dcs) { - case DK4_CS_GRAY : { - - -#line 2047 "dk4cs.ctr" - dptr[0] = sptr[0]; - - -#line 2049 "dk4cs.ctr" - } break; - case DK4_CS_GRAY_ALPHA : { - - -#line 2052 "dk4cs.ctr" - dptr[0] = sptr[0]; - dptr[1] = 1.0; - - -#line 2055 "dk4cs.ctr" - - -#line 2056 "dk4cs.ctr" - } break; - case DK4_CS_RGB : { - - -#line 2059 "dk4cs.ctr" - dptr[0] = dptr[1] = dptr[2] = sptr[0]; - - -#line 2061 "dk4cs.ctr" - - -#line 2062 "dk4cs.ctr" - - -#line 2063 "dk4cs.ctr" - } break; - case DK4_CS_RGB_ALPHA : { - - -#line 2066 "dk4cs.ctr" - dptr[0] = dptr[1] = dptr[2] = sptr[0]; - dptr[3] = 1.0; - - -#line 2069 "dk4cs.ctr" - - -#line 2070 "dk4cs.ctr" - - -#line 2071 "dk4cs.ctr" - - -#line 2072 "dk4cs.ctr" - } break; - case DK4_CS_CMYK : { - - -#line 2075 "dk4cs.ctr" - dptr[3] = 1.0 - sptr[0]; - dptr[0] = dptr[1] = dptr[2] = 0.0; - - -#line 2078 "dk4cs.ctr" - - -#line 2079 "dk4cs.ctr" - - -#line 2080 "dk4cs.ctr" - - -#line 2081 "dk4cs.ctr" - } break; - default : { - } break; - } - } break; - case DK4_CS_GRAY_ALPHA : { - - -#line 2088 "dk4cs.ctr" - - -#line 2089 "dk4cs.ctr" - alpha = DK4_CS_CONV_ALPHA_MIX; - if (NULL != pctx) { alpha = pctx->alpha; } - switch (dcs) { - case DK4_CS_GRAY : { - - -#line 2094 "dk4cs.ctr" - switch (alpha) { - case DK4_CS_CONV_ALPHA_FOREGROUND : { - dptr[0] = sptr[0]; - } break; - default : { - dptr[0] = dk4cs_color_mix_alpha( - sptr[0], sptr[1], bptr[0] - ); - } break; - } - - -#line 2105 "dk4cs.ctr" - } break; - case DK4_CS_GRAY_ALPHA : { - - -#line 2108 "dk4cs.ctr" - dptr[0] = sptr[0]; - dptr[1] = sptr[1]; - - -#line 2111 "dk4cs.ctr" - - -#line 2112 "dk4cs.ctr" - } break; - case DK4_CS_RGB : { - - -#line 2115 "dk4cs.ctr" - switch (alpha) { - case DK4_CS_CONV_ALPHA_FOREGROUND : { - dptr[0] = dptr[1] = dptr[2] = sptr[0]; - } break; - default : { - dptr[0] = dptr[1] = dptr[2] = - dk4cs_color_mix_alpha(sptr[0], sptr[1], bptr[0]); - } - } - - -#line 2125 "dk4cs.ctr" - - -#line 2126 "dk4cs.ctr" - - -#line 2127 "dk4cs.ctr" - } break; - case DK4_CS_RGB_ALPHA : { - - -#line 2130 "dk4cs.ctr" - dptr[3] = sptr[1]; - dptr[0] = dptr[1] = dptr[2] = sptr[0]; - - -#line 2133 "dk4cs.ctr" - - -#line 2134 "dk4cs.ctr" - - -#line 2135 "dk4cs.ctr" - - -#line 2136 "dk4cs.ctr" - } break; - case DK4_CS_CMYK : { - - -#line 2139 "dk4cs.ctr" - switch (alpha) { - case DK4_CS_CONV_ALPHA_FOREGROUND : { - dptr[3] = 1.0 - sptr[0]; - } break; - default : { - dptr[3] = - 1.0-dk4cs_color_mix_alpha(sptr[0],sptr[1],bptr[0]); - } - } - dptr[0] = dptr[1] = dptr[2] = 0.0; - - -#line 2150 "dk4cs.ctr" - - -#line 2151 "dk4cs.ctr" - - -#line 2152 "dk4cs.ctr" - - -#line 2153 "dk4cs.ctr" - } break; - default : { - } break; - } - } break; - case DK4_CS_RGB : { - - -#line 2160 "dk4cs.ctr" - - -#line 2161 "dk4cs.ctr" - - -#line 2162 "dk4cs.ctr" - switch (dcs) { - case DK4_CS_GRAY : { - - -#line 2165 "dk4cs.ctr" - dptr[0] = dk4cs_color_mix_rgb_to_gray( - sptr[0], sptr[1], sptr[2], pctx - ); - - -#line 2169 "dk4cs.ctr" - } break; - case DK4_CS_GRAY_ALPHA : { - - -#line 2172 "dk4cs.ctr" - dptr[0] = dk4cs_color_mix_rgb_to_gray( - sptr[0], sptr[1], sptr[2], pctx - ); - dptr[1] = 1.0; - - -#line 2177 "dk4cs.ctr" - - -#line 2178 "dk4cs.ctr" - } break; - case DK4_CS_RGB : { - - -#line 2181 "dk4cs.ctr" - for (i = 0; i < 3; i++) { - dptr[i] = sptr[i]; - } - - -#line 2185 "dk4cs.ctr" - - -#line 2186 "dk4cs.ctr" - - -#line 2187 "dk4cs.ctr" - } break; - case DK4_CS_RGB_ALPHA : { - - -#line 2190 "dk4cs.ctr" - for (i = 0; i < 3; i++) { - dptr[i] = sptr[i]; - } - dptr[3] = 1.0; - - -#line 2195 "dk4cs.ctr" - - -#line 2196 "dk4cs.ctr" - - -#line 2197 "dk4cs.ctr" - - -#line 2198 "dk4cs.ctr" - } break; - case DK4_CS_CMYK : { - - -#line 2201 "dk4cs.ctr" - dk4cs_color_mix_rgb_to_cmyk(dptr, sptr, pctx); - - -#line 2203 "dk4cs.ctr" - - -#line 2204 "dk4cs.ctr" - - -#line 2205 "dk4cs.ctr" - - -#line 2206 "dk4cs.ctr" - } break; - default : { - } break; - } - } break; - case DK4_CS_RGB_ALPHA : { - - -#line 2213 "dk4cs.ctr" - - -#line 2214 "dk4cs.ctr" - - -#line 2215 "dk4cs.ctr" - - -#line 2216 "dk4cs.ctr" - alpha = DK4_CS_CONV_ALPHA_MIX; - if (NULL != pctx) { alpha = pctx->alpha; } - switch (dcs) { - case DK4_CS_GRAY : { - - -#line 2221 "dk4cs.ctr" - switch (alpha) { - case DK4_CS_CONV_ALPHA_FOREGROUND : { - dptr[0] = dk4cs_color_mix_rgb_to_gray( - sptr[0], sptr[1], sptr[2], pctx - ); - } break; - default : { - for (i = 0; i < 3; i++) { - myrgb[i] = dk4cs_color_mix_alpha( - sptr[i], sptr[3], bptr[i] - ); - } - dptr[0] = dk4cs_color_mix_rgb_to_gray( - myrgb[0], myrgb[1], myrgb[2], pctx - ); - } - } - - -#line 2239 "dk4cs.ctr" - } break; - case DK4_CS_GRAY_ALPHA : { - - -#line 2242 "dk4cs.ctr" - dptr[0] = dk4cs_color_mix_rgb_to_gray( - sptr[0], sptr[1], sptr[2], pctx - ); - dptr[1] = sptr[3]; - - -#line 2247 "dk4cs.ctr" - - -#line 2248 "dk4cs.ctr" - } break; - case DK4_CS_RGB : { - - -#line 2251 "dk4cs.ctr" - for (i = 0; i < 3; i++) { - switch (alpha) { - case DK4_CS_CONV_ALPHA_FOREGROUND : { - dptr[i] = sptr[i]; - } break; - default : { - dptr[i] = dk4cs_color_mix_alpha( - sptr[i], sptr[3], bptr[i] - ); - } break; - } - } - - -#line 2264 "dk4cs.ctr" - - -#line 2265 "dk4cs.ctr" - - -#line 2266 "dk4cs.ctr" - } break; - case DK4_CS_RGB_ALPHA : { - - -#line 2269 "dk4cs.ctr" - for (i = 0; i < 4; i++) { - dptr[i] = sptr[i]; - } - - -#line 2273 "dk4cs.ctr" - - -#line 2274 "dk4cs.ctr" - - -#line 2275 "dk4cs.ctr" - - -#line 2276 "dk4cs.ctr" - } break; - case DK4_CS_CMYK : { - - -#line 2279 "dk4cs.ctr" - switch (alpha) { - case DK4_CS_CONV_ALPHA_FOREGROUND : { - dk4cs_color_mix_rgb_to_cmyk(dptr, sptr, pctx); - } break; - default : { - for (i = 0; i < 3; i++) { - myrgb[i] = dk4cs_color_mix_alpha( - sptr[i], sptr[3], bptr[i] - ); - } - dk4cs_color_mix_rgb_to_cmyk(dptr, myrgb, pctx); - } break; - } - - -#line 2293 "dk4cs.ctr" - - -#line 2294 "dk4cs.ctr" - - -#line 2295 "dk4cs.ctr" - - -#line 2296 "dk4cs.ctr" - } break; - default : { - } break; - } - } break; - case DK4_CS_CMYK : { - - -#line 2303 "dk4cs.ctr" - - -#line 2304 "dk4cs.ctr" - - -#line 2305 "dk4cs.ctr" - - -#line 2306 "dk4cs.ctr" - switch (dcs) { - case DK4_CS_GRAY : { - - -#line 2309 "dk4cs.ctr" - dk4cs_color_mix_cmyk_to_rgb(myrgb, sptr, pctx); - dptr[0] = dk4cs_color_mix_rgb_to_gray( - myrgb[0], myrgb[1], myrgb[2], pctx - ); - - -#line 2314 "dk4cs.ctr" - } break; - case DK4_CS_GRAY_ALPHA : { - - -#line 2317 "dk4cs.ctr" - dk4cs_color_mix_cmyk_to_rgb(myrgb, sptr, pctx); - dptr[0] = dk4cs_color_mix_rgb_to_gray( - myrgb[0], myrgb[1], myrgb[2], pctx - ); - dptr[1] = 1.0; - - -#line 2323 "dk4cs.ctr" - - -#line 2324 "dk4cs.ctr" - } break; - case DK4_CS_RGB : { - - -#line 2327 "dk4cs.ctr" - dk4cs_color_mix_cmyk_to_rgb(dptr, sptr, pctx); - - -#line 2329 "dk4cs.ctr" - - -#line 2330 "dk4cs.ctr" - - -#line 2331 "dk4cs.ctr" - } break; - case DK4_CS_RGB_ALPHA : { - - -#line 2334 "dk4cs.ctr" - dk4cs_color_mix_cmyk_to_rgb(dptr, sptr, pctx); - dptr[3] = 1.0; - - -#line 2337 "dk4cs.ctr" - - -#line 2338 "dk4cs.ctr" - - -#line 2339 "dk4cs.ctr" - - -#line 2340 "dk4cs.ctr" - } break; - case DK4_CS_CMYK : { - - -#line 2343 "dk4cs.ctr" - for (i = 0; i < 4; i++) { - dptr[i] = sptr[i]; - } - - -#line 2347 "dk4cs.ctr" - - -#line 2348 "dk4cs.ctr" - - -#line 2349 "dk4cs.ctr" - - -#line 2350 "dk4cs.ctr" - } break; - default : { - } break; - } - } break; - default : { - } break; - } - - -#line 2359 "dk4cs.ctr" -} - - - -void -dk4cs_color_convert( - double *dptr, - int dcs, - size_t dsz, - double const *sptr, - int scs, - size_t ssz, - double const *bptr, - size_t bsz, - dk4_cs_conv_ctx_t const *pctx, - dk4_er_t *erp -) -{ - size_t i; - - -#line 2379 "dk4cs.ctr" -#if DK4_USE_ASSERT - assert(NULL != dptr); - assert(0 < dsz); - assert(NULL != sptr); - assert(0 < ssz); -#endif - /* - Check arguments - */ - if (NULL == dptr) { - -#line 2389 "dk4cs.ctr" - dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS); - goto finished; - } - if ((DK4_CS_MIN > dcs) || (DK4_CS_MAX < dcs)) { - -#line 2393 "dk4cs.ctr" - dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS); - goto finished; - } - if (dsz < dk4cs_color_space_size(dcs)) { - -#line 2397 "dk4cs.ctr" - dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS); - goto finished; - } - if (NULL == sptr) { - -#line 2401 "dk4cs.ctr" - dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS); - goto finished; - } - if ((DK4_CS_MIN > scs) || (DK4_CS_MAX < scs)) { - -#line 2405 "dk4cs.ctr" - dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS); - goto finished; - } - if (ssz < dk4cs_color_space_size(scs)) { - -#line 2409 "dk4cs.ctr" - dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS); - goto finished; - } - for (i = 0; i < ssz; i++) { - if ((0.0 > sptr[i]) || (1.0 < sptr[i])) { - -#line 2414 "dk4cs.ctr" - dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS); - goto finished; - } - } - switch (scs) { - case DK4_CS_GRAY_ALPHA : - case DK4_CS_RGB_ALPHA : { - if (NULL == bptr) { - -#line 2422 "dk4cs.ctr" - dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS); - goto finished; - } - if (bsz < (dk4cs_color_space_size(scs) - 1)) { - -#line 2426 "dk4cs.ctr" - dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS); - goto finished; - } - for (i = 0; i < bsz; i++) { - if ((0.0 > bptr[i]) || (1.0 < bptr[i])) { - -#line 2431 "dk4cs.ctr" - dk4error_set_simple_error_code(erp,DK4_E_INVALID_ARGUMENTS); - goto finished; - } - } - } break; - } - /* Do conversion - */ - dk4cs_nc_color_convert(dptr, dcs, sptr, scs, bptr, pctx); - finished: - - -#line 2442 "dk4cs.ctr" - return; -} - - - -int -dk4cs_check(int cs) -{ - int back = 0; - if ((DK4_CS_MIN <= cs) && (DK4_CS_MAX >= cs)) { - back = 1; - } - return back; -} - - - -/* vim: set ai sw=4 ts=4 : */ - |