| 1 | /* |
| 2 | * |
| 3 | * Dither routine entrypoints |
| 4 | * |
| 5 | * Copyright 1997-2003 Michael Sweet ([email protected]) and |
| 6 | * Robert Krawitz ([email protected]) |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of the GNU General Public License as published by the Free |
| 10 | * Software Foundation; either version 2 of the License, or (at your option) |
| 11 | * any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, but |
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 15 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 16 | * for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 20 | * |
| 21 | * Revision History: |
| 22 | * |
| 23 | * See ChangeLog |
| 24 | */ |
| 25 | |
| 26 | #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:409:9`! |
| 27 | #include <config.h>cxx . . $ `<file>/config.h`/ |
| 28 | #endif |
| 29 | #include <gutenprint/gutenprint.h>cxx . . $ `<file>/include/gutenprint/gutenprint.h`/ |
| 30 | #include "gutenprint-internal.h"cxx . . $ `<file>/src/main/gutenprint-internal.h`/ |
| 31 | #include <gutenprint/gutenprint-intl-internal.h>cxx . . $ `<file>/include/gutenprint/gutenprint-intl-internal.h`/ |
| 32 | #ifdef HAVE_LIMITS_Hcxx . . $ `config.h:94:9`! |
| 33 | #include <limits.h> |
| 34 | #endif |
| 35 | #include <math.h> |
| 36 | #include <string.h> |
| 37 | #include "dither-impl.h"cxx . . $ `<file>/src/main/dither-impl.h`/ |
| 38 | #include "generic-options.h"cxx . . $ `<file>/src/main/generic-options.h`/ |
| 39 | |
| 40 | static const stpi_dither_algorithm_tcxx . . $ stpi_dither_algorithm_t# dither_algoscxx . . $ dither_algos.[] = |
| 41 | { |
| 42 | { "None", N_cxx . . $ `include/gutenprint/gutenprint-intl-internal.h:67:17`! ("Default"), -1 }, |
| 43 | /* TRANSLATORS: "EvenTone" is the proper name, rather than a */ |
| 44 | /* descriptive name, of this algorithm. */ |
| 45 | { "EvenTone", N_cxx . . $ `include/gutenprint/gutenprint-intl-internal.h:67:17`! ("EvenTone"), D_EVENTONEcxx . . $ `src/main/dither-impl.h:53:9`! }, |
| 46 | { "HybridEvenTone", N_cxx . . $ `include/gutenprint/gutenprint-intl-internal.h:67:17`! ("Hybrid EvenTone"), D_HYBRID_EVENTONEcxx . . $ `src/main/dither-impl.h:56:9`! }, |
| 47 | /* Placeholders for future implementation of EvenBetter Screening */ |
| 48 | /* TRANSLATORS: EvenTone, EvenBetter, and UniTone are proper |
| 49 | * names, not descriptive. |
| 50 | */ |
| 51 | { "EBS", N_cxx . . $ `include/gutenprint/gutenprint-intl-internal.h:67:17`! ("EvenBetter"), D_INVALIDcxx . . $ `src/main/dither-impl.h:63:9`! }, |
| 52 | { "HybridEBS", N_cxx . . $ `include/gutenprint/gutenprint-intl-internal.h:67:17`! ("Hybrid EvenBetter"), D_INVALIDcxx . . $ `src/main/dither-impl.h:63:9`! }, |
| 53 | /* |
| 54 | * Unitone dithering seems to have some numerical stability problems |
| 55 | * -- rlk 20050113 |
| 56 | */ |
| 57 | #if UNITONE_WORKS |
| 58 | { "UniTone", N_ ("UniTone"), D_UNITONE }, |
| 59 | { "HybridUniTone", N_ ("Hybrid UniTone"), D_HYBRID_UNITONE }, |
| 60 | #endif |
| 61 | { "Adaptive", N_cxx . . $ `include/gutenprint/gutenprint-intl-internal.h:67:17`! ("Adaptive Hybrid"), D_ADAPTIVE_HYBRIDcxx . . $ `src/main/dither-impl.h:47:9`! }, |
| 62 | { "Ordered", N_cxx . . $ `include/gutenprint/gutenprint-intl-internal.h:67:17`! ("Ordered"), D_ORDEREDcxx . . $ `src/main/dither-impl.h:49:9`! }, |
| 63 | { "OrderedNew", N_cxx . . $ `include/gutenprint/gutenprint-intl-internal.h:67:17`! ("Ordered New"), D_ORDERED_NEWcxx . . $ `src/main/dither-impl.h:60:9`! }, |
| 64 | { "Fast", N_cxx . . $ `include/gutenprint/gutenprint-intl-internal.h:67:17`! ("Fast"), D_FASTcxx . . $ `src/main/dither-impl.h:51:9`! }, |
| 65 | { "VeryFast", N_cxx . . $ `include/gutenprint/gutenprint-intl-internal.h:67:17`! ("Very Fast"), D_VERY_FASTcxx . . $ `src/main/dither-impl.h:52:9`! }, |
| 66 | { "Floyd", N_cxx . . $ `include/gutenprint/gutenprint-intl-internal.h:67:17`! ("Hybrid Floyd-Steinberg"), D_FLOYD_HYBRIDcxx . . $ `src/main/dither-impl.h:45:9`! }, |
| 67 | { "Predithered", N_cxx . . $ `include/gutenprint/gutenprint-intl-internal.h:67:17`! ("Predithered Input"), D_PREDITHEREDcxx . . $ `src/main/dither-impl.h:59:9`! }, |
| 68 | { "Segmented", N_cxx . . $ `include/gutenprint/gutenprint-intl-internal.h:67:17`! ("Drop Size Segmented"), D_ORDERED_SEGMENTEDcxx . . $ `src/main/dither-impl.h:61:9`! }, |
| 69 | { "SegmentedNew", N_cxx . . $ `include/gutenprint/gutenprint-intl-internal.h:67:17`! ("Drop Size Segmented New"),D_ORDERED_SEGMENTED_NEWcxx . . $ `src/main/dither-impl.h:62:9`! } |
| 70 | }; |
| 71 | |
| 72 | static const int num_dither_algoscxx . . $ num_dither_algos. = sizeof(dither_algoscxx . . $ dither_algos.)/sizeof(stpi_dither_algorithm_tcxx . . $ stpi_dither_algorithm_t#); |
| 73 | |
| 74 | |
| 75 | /* |
| 76 | * Bayer's dither matrix using Judice, Jarvis, and Ninke recurrence relation |
| 77 | * http://www.cs.rit.edu/~sxc7922/Project/CRT.htm |
| 78 | */ |
| 79 | |
| 80 | static const unsigned sq2cxx . . $ sq2.[] = |
| 81 | { |
| 82 | 0, 2, |
| 83 | 3, 1 |
| 84 | }; |
| 85 | |
| 86 | static const stp_parameter_tcxx . . $ stp_parameter_t# dither_parameterscxx . . $ dither_parameters.[] = |
| 87 | { |
| 88 | { |
| 89 | "Density", N_cxx . . $ `include/gutenprint/gutenprint-intl-internal.h:67:17`!("Density"), "Color=Yes,Category=Output Level Adjustment", |
| 90 | N_cxx . . $ `include/gutenprint/gutenprint-intl-internal.h:67:17`!("Adjust the density (amount of ink) of the print. " |
| 91 | "Reduce the density if the ink bleeds through the " |
| 92 | "paper or smears; increase the density if black " |
| 93 | "regions are not solid."), |
| 94 | STP_PARAMETER_TYPE_DOUBLEcxx . . $ STP_PARAMETER_TYPE_DOUBLE., STP_PARAMETER_CLASS_OUTPUTcxx . . $ STP_PARAMETER_CLASS_OUTPUT., |
| 95 | STP_PARAMETER_LEVEL_ADVANCEDcxx . . $ STP_PARAMETER_LEVEL_ADVANCED., 0, 1, STP_CHANNEL_NONEcxx . . $ `include/gutenprint/vars.h:154:9`!, 1, 0 |
| 96 | }, |
| 97 | { |
| 98 | "DitherAlgorithm", N_cxx . . $ `include/gutenprint/gutenprint-intl-internal.h:67:17`!("Dither Algorithm"), "Color=Yes,Category=Screening Adjustment", |
| 99 | N_cxx . . $ `include/gutenprint/gutenprint-intl-internal.h:67:17`!("Choose the dither algorithm to be used.\n" |
| 100 | "Adaptive Hybrid usually produces the best all-around quality.\n" |
| 101 | "EvenTone is a new, experimental algorithm that often produces excellent results.\n" |
| 102 | "Ordered is faster and produces almost as good quality on photographs.\n" |
| 103 | "Fast and Very Fast are considerably faster, and work well for text and line art.\n" |
| 104 | "Hybrid Floyd-Steinberg generally produces inferior output."), |
| 105 | STP_PARAMETER_TYPE_STRING_LISTcxx . . $ STP_PARAMETER_TYPE_STRING_LIST., STP_PARAMETER_CLASS_OUTPUTcxx . . $ STP_PARAMETER_CLASS_OUTPUT., |
| 106 | STP_PARAMETER_LEVEL_ADVANCEDcxx . . $ STP_PARAMETER_LEVEL_ADVANCED., 1, 1, STP_CHANNEL_NONEcxx . . $ `include/gutenprint/vars.h:154:9`!, 1, 0 |
| 107 | }, |
| 108 | }; |
| 109 | |
| 110 | static const int dither_parameter_countcxx . . $ dither_parameter_count. = |
| 111 | sizeof(dither_parameterscxx . . $ dither_parameters.) / sizeof(const stp_parameter_tcxx . . $ stp_parameter_t#); |
| 112 | |
| 113 | stp_parameter_list_tcxx . . $ stp_parameter_list_t# |
| 114 | stp_dither_list_parameterscxx . . $ stp_dither_list_parameters(817585d40f809196).(const stp_vars_tcxx . . $ stp_vars_t# *v) |
| 115 | { |
| 116 | stp_parameter_list_tcxx . . $ stp_parameter_list_t# *ret = stp_parameter_list_createcxx . . $ stp_parameter_list_create(50c7df7de5344ebb).(); |
| 117 | int i; |
| 118 | (void)v; |
| 119 | |
| 120 | for (i = 0; i < dither_parameter_countcxx . . $ dither_parameter_count.; i++) |
| 121 | stp_parameter_list_add_paramcxx . . $ stp_parameter_list_add_param(9dab94dbd10bbd1f).(ret, &(dither_parameterscxx . . $ dither_parameters.[i])); |
| 122 | return ret; |
| 123 | } |
| 124 | |
| 125 | void |
| 126 | stp_dither_describe_parametercxx . . $ stp_dither_describe_parameter(dfd5b9531b51a6d2).(const stp_vars_tcxx . . $ stp_vars_t# *v, const char *name, |
| 127 | stp_parameter_tcxx . . $ stp_parameter_t# *description) |
| 128 | { |
| 129 | int i; |
| 130 | (void)v; |
| 131 | |
| 132 | description->p_typecxx . . $ $anonymous_type_c987533f3b833c82_8#p_type. = STP_PARAMETER_TYPE_INVALIDcxx . . $ STP_PARAMETER_TYPE_INVALID.; |
| 133 | if (name == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 134 | return; |
| 135 | description->defltcxx . . $ $anonymous_type_c987533f3b833c82_8#deflt..strcxx . . $ $anonymous_type_c987533f3b833c82_8#$anonymous_type_10#str. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 136 | if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(name, "Density") == 0) |
| 137 | { |
| 138 | stp_fill_parameter_settingscxx . . $ stp_fill_parameter_settings(bb1f9d668495a4b4).(description, &(dither_parameterscxx . . $ dither_parameters.[0])); |
| 139 | description->boundscxx . . $ $anonymous_type_c987533f3b833c82_8#bounds..dblcxx . . $ $anonymous_type_c987533f3b833c82_8#$anonymous_type_9#dbl..uppercxx . . $ $anonymous_type_c987533f3b833c82_5#upper. = 8.0; |
| 140 | description->boundscxx . . $ $anonymous_type_c987533f3b833c82_8#bounds..dblcxx . . $ $anonymous_type_c987533f3b833c82_8#$anonymous_type_9#dbl..lowercxx . . $ $anonymous_type_c987533f3b833c82_5#lower. = 0.1; |
| 141 | description->defltcxx . . $ $anonymous_type_c987533f3b833c82_8#deflt..dblcxx . . $ $anonymous_type_c987533f3b833c82_8#$anonymous_type_10#dbl. = 1.0; |
| 142 | } |
| 143 | else if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(name, "DitherAlgorithm") == 0) |
| 144 | { |
| 145 | stp_fill_parameter_settingscxx . . $ stp_fill_parameter_settings(bb1f9d668495a4b4).(description, &(dither_parameterscxx . . $ dither_parameters.[1])); |
| 146 | description->boundscxx . . $ $anonymous_type_c987533f3b833c82_8#bounds..strcxx . . $ $anonymous_type_c987533f3b833c82_8#$anonymous_type_9#str. = stp_string_list_createcxx . . $ stp_string_list_create(f262b3b5e10fad14).(); |
| 147 | for (i = 0; i < num_dither_algoscxx . . $ num_dither_algos.; i++) |
| 148 | { |
| 149 | const stpi_dither_algorithm_tcxx . . $ stpi_dither_algorithm_t# *dt = &dither_algoscxx . . $ dither_algos.[i]; |
| 150 | if (dt->idcxx . . $ $anonymous_type_2f3242eb862b2f2_0#id. != D_INVALIDcxx . . $ `src/main/dither-impl.h:63:9`!) |
| 151 | stp_string_list_add_stringcxx . . $ stp_string_list_add_string(61ec312b340c2952).(description->boundscxx . . $ $anonymous_type_c987533f3b833c82_8#bounds..strcxx . . $ $anonymous_type_c987533f3b833c82_8#$anonymous_type_9#str., |
| 152 | dt->namecxx . . $ $anonymous_type_2f3242eb862b2f2_0#name., gettextcxx . . $ `include/gutenprint/gutenprint-intl-internal.h:61:11`!(dt->text)); |
| 153 | } |
| 154 | description->defltcxx . . $ $anonymous_type_c987533f3b833c82_8#deflt..strcxx . . $ $anonymous_type_c987533f3b833c82_8#$anonymous_type_10#str. = |
| 155 | stp_string_list_paramcxx . . $ stp_string_list_param(1d71fb1c8ad3926a).(description->boundscxx . . $ $anonymous_type_c987533f3b833c82_8#bounds..strcxx . . $ $anonymous_type_c987533f3b833c82_8#$anonymous_type_9#str., 0)->namecxx . . $ $anonymous_type_cb0224bbe5755622_0#name.; |
| 156 | } |
| 157 | else |
| 158 | return; |
| 159 | } |
| 160 | |
| 161 | #define RETURN_DITHERFUNCcxx . . $ `src/main/dither-main.c:161:9`!(func, v) \ |
| 162 | do \ |
| 163 | { \ |
| 164 | stp_dprintf(STP_DBG_COLORFUNCcxx . . $ `include/gutenprint/util.h:167:9`!, v, "ditherfunc %s\n", #func); \ |
| 165 | return (func); \ |
| 166 | } while (0) |
| 167 | |
| 168 | static stpi_ditherfunc_tcxx . . $ stpi_ditherfunc_t# * |
| 169 | stpi_set_dither_functioncxx . . $ stpi_set_dither_function(5446b7483711b1e2).(stp_vars_tcxx . . $ stp_vars_t# *v) |
| 170 | { |
| 171 | const stpi_quality_tcxx . . $ stpi_quality_t# *quality = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 172 | const char *image_type = stp_get_string_parametercxx . . $ stp_get_string_parameter(3e3ce5d385745545).(v, "ImageType"); |
| 173 | const char *color_correction = stp_get_string_parametercxx . . $ stp_get_string_parameter(3e3ce5d385745545).(v,"ColorCorrection"); |
| 174 | const char *algorithm = stp_get_string_parametercxx . . $ stp_get_string_parameter(3e3ce5d385745545).(v, "DitherAlgorithm"); |
| 175 | stpi_dither_tcxx . . $ stpi_dither_t# *d = (stpi_dither_tcxx . . $ stpi_dither_t# *) stp_get_component_datacxx . . $ stp_get_component_data(2bc0070dfdce2f04).(v, "Dither"); |
| 176 | int i; |
| 177 | d->stpi_dither_typecxx . . $ dither#stpi_dither_type. = -1; |
| 178 | if (stp_check_string_parametercxx . . $ stp_check_string_parameter(cff2817d3dcc2695).(v, "Quality", STP_PARAMETER_ACTIVEcxx . . $ STP_PARAMETER_ACTIVE.)) |
| 179 | quality = stpi_get_quality_by_namecxx . . $ stpi_get_quality_by_name(7488809c3e549f62).(stp_get_string_parametercxx . . $ stp_get_string_parameter(3e3ce5d385745545).(v, "Quality")); |
| 180 | |
| 181 | if (color_correction && strcmpcxx . . $ strcmp(5ae29d726ae57f88).(color_correction, "Predithered") == 0) |
| 182 | d->stpi_dither_typecxx . . $ dither#stpi_dither_type. = D_PREDITHEREDcxx . . $ `src/main/dither-impl.h:59:9`!; |
| 183 | else if (color_correction && strcmpcxx . . $ strcmp(5ae29d726ae57f88).(color_correction, "Raw") != 0 && |
| 184 | algorithm && strcmpcxx . . $ strcmp(5ae29d726ae57f88).(algorithm, "Segmented") == 0) |
| 185 | d->stpi_dither_typecxx . . $ dither#stpi_dither_type. = D_ORDEREDcxx . . $ `src/main/dither-impl.h:49:9`!; |
| 186 | else if (algorithm && strcmpcxx . . $ strcmp(5ae29d726ae57f88).(algorithm, "None") != 0) |
| 187 | { |
| 188 | for (i = 0; i < num_dither_algoscxx . . $ num_dither_algos.; i++) |
| 189 | { |
| 190 | if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88).(algorithm, gettextcxx . . $ `include/gutenprint/gutenprint-intl-internal.h:61:11`!(dither_algos[i].name))) |
| 191 | { |
| 192 | d->stpi_dither_typecxx . . $ dither#stpi_dither_type. = dither_algoscxx . . $ dither_algos.[i].idcxx . . $ $anonymous_type_2f3242eb862b2f2_0#id.; |
| 193 | break; |
| 194 | } |
| 195 | } |
| 196 | if (d->stpi_dither_typecxx . . $ dither#stpi_dither_type. == -1) |
| 197 | { |
| 198 | d->stpi_dither_typecxx . . $ dither#stpi_dither_type. = D_EVENTONEcxx . . $ `src/main/dither-impl.h:53:9`!; |
| 199 | /* EvenTone performs poorly if the aspect ratio is greater than 2 */ |
| 200 | if ((d->stpi_dither_typecxx . . $ dither#stpi_dither_type. & (D_EVENTONEcxx . . $ `src/main/dither-impl.h:53:9`! | D_UNITONEcxx . . $ `src/main/dither-impl.h:54:9`!)) && |
| 201 | (d->x_aspectcxx . . $ dither#x_aspect. > 2 || d->y_aspectcxx . . $ dither#y_aspect. > 2)) |
| 202 | d->stpi_dither_typecxx . . $ dither#stpi_dither_type. = D_ADAPTIVE_HYBRIDcxx . . $ `src/main/dither-impl.h:47:9`!; |
| 203 | } |
| 204 | } |
| 205 | else if (image_type && strcmpcxx . . $ strcmp(5ae29d726ae57f88).(image_type, "Text") == 0) |
| 206 | d->stpi_dither_typecxx . . $ dither#stpi_dither_type. = D_VERY_FASTcxx . . $ `src/main/dither-impl.h:52:9`!; |
| 207 | else if (quality) |
| 208 | { |
| 209 | switch (quality->quality_levelcxx . . $ $anonymous_type_73fe19d713e4464d_0#quality_level.) |
| 210 | { |
| 211 | case 0: |
| 212 | case 1: |
| 213 | d->stpi_dither_typecxx . . $ dither#stpi_dither_type. = D_VERY_FASTcxx . . $ `src/main/dither-impl.h:52:9`!; |
| 214 | break; |
| 215 | case 2: |
| 216 | case 3: |
| 217 | if (image_type && strcmpcxx . . $ strcmp(5ae29d726ae57f88).(image_type, "LineArt") == 0) |
| 218 | d->stpi_dither_typecxx . . $ dither#stpi_dither_type. = D_VERY_FASTcxx . . $ `src/main/dither-impl.h:52:9`!; |
| 219 | else |
| 220 | d->stpi_dither_typecxx . . $ dither#stpi_dither_type. = D_FASTcxx . . $ `src/main/dither-impl.h:51:9`!; |
| 221 | break; |
| 222 | case 4: |
| 223 | if (image_type && |
| 224 | (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(image_type, "LineArt") == 0 || |
| 225 | strcmpcxx . . $ strcmp(5ae29d726ae57f88).(image_type, "TextGraphics") == 0)) |
| 226 | d->stpi_dither_typecxx . . $ dither#stpi_dither_type. = D_ADAPTIVE_HYBRIDcxx . . $ `src/main/dither-impl.h:47:9`!; |
| 227 | else |
| 228 | d->stpi_dither_typecxx . . $ dither#stpi_dither_type. = D_ORDEREDcxx . . $ `src/main/dither-impl.h:49:9`!; |
| 229 | break; |
| 230 | case 5: |
| 231 | if (image_type && |
| 232 | (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(image_type, "LineArt") == 0 || |
| 233 | strcmpcxx . . $ strcmp(5ae29d726ae57f88).(image_type, "TextGraphics") == 0)) |
| 234 | d->stpi_dither_typecxx . . $ dither#stpi_dither_type. = D_HYBRID_EVENTONEcxx . . $ `src/main/dither-impl.h:56:9`!; |
| 235 | else if (image_type && (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(image_type, "Photo") == 0)) |
| 236 | d->stpi_dither_typecxx . . $ dither#stpi_dither_type. = D_EVENTONEcxx . . $ `src/main/dither-impl.h:53:9`!; |
| 237 | else |
| 238 | d->stpi_dither_typecxx . . $ dither#stpi_dither_type. = D_ORDEREDcxx . . $ `src/main/dither-impl.h:49:9`!; |
| 239 | break; |
| 240 | case 6: |
| 241 | case 7: |
| 242 | case 8: |
| 243 | case 9: |
| 244 | case 10: |
| 245 | default: |
| 246 | if (image_type && |
| 247 | (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(image_type, "LineArt") == 0 || |
| 248 | strcmpcxx . . $ strcmp(5ae29d726ae57f88).(image_type, "TextGraphics") == 0)) |
| 249 | d->stpi_dither_typecxx . . $ dither#stpi_dither_type. = D_HYBRID_EVENTONEcxx . . $ `src/main/dither-impl.h:56:9`!; |
| 250 | else |
| 251 | d->stpi_dither_typecxx . . $ dither#stpi_dither_type. = D_EVENTONEcxx . . $ `src/main/dither-impl.h:53:9`!; |
| 252 | break; |
| 253 | } |
| 254 | /* EvenTone performs poorly if the aspect ratio is greater than 2 */ |
| 255 | if ((d->stpi_dither_typecxx . . $ dither#stpi_dither_type. & (D_EVENTONEcxx . . $ `src/main/dither-impl.h:53:9`! | D_UNITONEcxx . . $ `src/main/dither-impl.h:54:9`!)) && |
| 256 | (d->x_aspectcxx . . $ dither#x_aspect. > 2 || d->y_aspectcxx . . $ dither#y_aspect. > 2)) |
| 257 | d->stpi_dither_typecxx . . $ dither#stpi_dither_type. = D_ADAPTIVE_HYBRIDcxx . . $ `src/main/dither-impl.h:47:9`!; |
| 258 | } |
| 259 | if (d->stpi_dither_typecxx . . $ dither#stpi_dither_type. == -1) |
| 260 | d->stpi_dither_typecxx . . $ dither#stpi_dither_type. = D_ADAPTIVE_HYBRIDcxx . . $ `src/main/dither-impl.h:47:9`!; |
| 261 | switch (d->stpi_dither_typecxx . . $ dither#stpi_dither_type.) |
| 262 | { |
| 263 | case D_PREDITHEREDcxx . . $ `src/main/dither-impl.h:59:9`!: |
| 264 | RETURN_DITHERFUNCcxx . . $ `src/main/dither-main.c:161:9`!(stpi_dither_predithered, v); |
| 265 | case D_VERY_FASTcxx . . $ `src/main/dither-impl.h:52:9`!: |
| 266 | RETURN_DITHERFUNCcxx . . $ `src/main/dither-main.c:161:9`!(stpi_dither_very_fast, v); |
| 267 | case D_ORDEREDcxx . . $ `src/main/dither-impl.h:49:9`!: |
| 268 | case D_ORDERED_SEGMENTEDcxx . . $ `src/main/dither-impl.h:61:9`!: |
| 269 | case D_ORDERED_NEWcxx . . $ `src/main/dither-impl.h:60:9`!: |
| 270 | case D_ORDERED_SEGMENTED_NEWcxx . . $ `src/main/dither-impl.h:62:9`!: |
| 271 | case D_FASTcxx . . $ `src/main/dither-impl.h:51:9`!: |
| 272 | RETURN_DITHERFUNCcxx . . $ `src/main/dither-main.c:161:9`!(stpi_dither_ordered, v); |
| 273 | case D_HYBRID_EVENTONEcxx . . $ `src/main/dither-impl.h:56:9`!: |
| 274 | case D_EVENTONEcxx . . $ `src/main/dither-impl.h:53:9`!: |
| 275 | RETURN_DITHERFUNCcxx . . $ `src/main/dither-main.c:161:9`!(stpi_dither_et, v); |
| 276 | case D_HYBRID_UNITONEcxx . . $ `src/main/dither-impl.h:57:9`!: |
| 277 | case D_UNITONEcxx . . $ `src/main/dither-impl.h:54:9`!: |
| 278 | RETURN_DITHERFUNCcxx . . $ `src/main/dither-main.c:161:9`!(stpi_dither_ut, v); |
| 279 | default: |
| 280 | RETURN_DITHERFUNCcxx . . $ `src/main/dither-main.c:161:9`!(stpi_dither_ed, v); |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | void |
| 285 | stp_dither_set_adaptive_limitcxx . . $ stp_dither_set_adaptive_limit(8ce3003bda9b93be).(stp_vars_tcxx . . $ stp_vars_t# *v, double limit) |
| 286 | { |
| 287 | stpi_dither_tcxx . . $ stpi_dither_t# *d = (stpi_dither_tcxx . . $ stpi_dither_t# *) stp_get_component_datacxx . . $ stp_get_component_data(2bc0070dfdce2f04).(v, "Dither"); |
| 288 | d->adaptive_limitcxx . . $ dither#adaptive_limit. = limit; |
| 289 | } |
| 290 | |
| 291 | void |
| 292 | stp_dither_set_ink_spreadcxx . . $ stp_dither_set_ink_spread(c8b26ae77f1a10bd).(stp_vars_tcxx . . $ stp_vars_t# *v, int spread) |
| 293 | { |
| 294 | stpi_dither_tcxx . . $ stpi_dither_t# *d = (stpi_dither_tcxx . . $ stpi_dither_t# *) stp_get_component_datacxx . . $ stp_get_component_data(2bc0070dfdce2f04).(v, "Dither"); |
| 295 | STP_SAFE_FREEcxx . . $ `include/gutenprint/util.h:210:9`!(d->offset0_table); |
| 296 | STP_SAFE_FREEcxx . . $ `include/gutenprint/util.h:210:9`!(d->offset1_table); |
| 297 | if (spread >= 16) |
| 298 | { |
| 299 | d->spreadcxx . . $ dither#spread. = 16; |
| 300 | } |
| 301 | else |
| 302 | { |
| 303 | int max_offset; |
| 304 | int i; |
| 305 | d->spreadcxx . . $ dither#spread. = spread; |
| 306 | max_offset = (1 << (16 - spread)) + 1; |
| 307 | d->offset0_tablecxx . . $ dither#offset0_table. = stp_malloccxx . . $ stp_malloc(bfcfa4d6b7f7ef64).(sizeof(int) * max_offset); |
| 308 | d->offset1_tablecxx . . $ dither#offset1_table. = stp_malloccxx . . $ stp_malloc(bfcfa4d6b7f7ef64).(sizeof(int) * max_offset); |
| 309 | for (i = 0; i < max_offset; i++) |
| 310 | { |
| 311 | d->offset0_tablecxx . . $ dither#offset0_table.[i] = (i + 1) * (i + 1); |
| 312 | d->offset1_tablecxx . . $ dither#offset1_table.[i] = ((i + 1) * i) / 2; |
| 313 | } |
| 314 | } |
| 315 | d->spread_maskcxx . . $ dither#spread_mask. = (1 << d->spreadcxx . . $ dither#spread.) - 1; |
| 316 | } |
| 317 | |
| 318 | void |
| 319 | stp_dither_set_randomizercxx . . $ stp_dither_set_randomizer(4916f40790a27b33).(stp_vars_tcxx . . $ stp_vars_t# *v, int i, double val) |
| 320 | { |
| 321 | stpi_dither_tcxx . . $ stpi_dither_t# *d = (stpi_dither_tcxx . . $ stpi_dither_t# *) stp_get_component_datacxx . . $ stp_get_component_data(2bc0070dfdce2f04).(v, "Dither"); |
| 322 | if (i < 0 || i >= CHANNEL_COUNTcxx . . $ `src/main/dither-impl.h:179:9`!(d)) |
| 323 | return; |
| 324 | CHANNELcxx . . $ `src/main/dither-impl.h:178:9`!(d, i).randomizercxx . . $ dither_channel#randomizer. = val * 65535; |
| 325 | } |
| 326 | |
| 327 | static void |
| 328 | stpi_dither_freecxx . . $ stpi_dither_free(5d22bdacc48458e8).(void *vd) |
| 329 | { |
| 330 | stpi_dither_tcxx . . $ stpi_dither_t# *d = (stpi_dither_tcxx . . $ stpi_dither_t# *) vd; |
| 331 | int j; |
| 332 | if (d->aux_freefunccxx . . $ dither#aux_freefunc.) |
| 333 | (d->aux_freefunccxx . . $ dither#aux_freefunc.)(d); |
| 334 | for (j = 0; j < CHANNEL_COUNTcxx . . $ `src/main/dither-impl.h:179:9`!(d); j++) |
| 335 | stpi_dither_channel_destroycxx . . $ stpi_dither_channel_destroy(ddba87c1765ba781).(&(CHANNELcxx . . $ `src/main/dither-impl.h:178:9`!(d, j))); |
| 336 | STP_SAFE_FREEcxx . . $ `include/gutenprint/util.h:210:9`!(d->offset0_table); |
| 337 | STP_SAFE_FREEcxx . . $ `include/gutenprint/util.h:210:9`!(d->offset1_table); |
| 338 | stp_dither_matrix_destroycxx . . $ stp_dither_matrix_destroy(68c7be79061d109b).(&(d->dither_matrixcxx . . $ dither#dither_matrix.)); |
| 339 | stp_freecxx . . $ stp_free(5d22bdacc48458e8).(d->channelcxx . . $ dither#channel.); |
| 340 | stp_freecxx . . $ stp_free(5d22bdacc48458e8).(d->channel_indexcxx . . $ dither#channel_index.); |
| 341 | stp_freecxx . . $ stp_free(5d22bdacc48458e8).(d->subchannel_countcxx . . $ dither#subchannel_count.); |
| 342 | stp_freecxx . . $ stp_free(5d22bdacc48458e8).(d); |
| 343 | } |
| 344 | |
| 345 | void |
| 346 | stp_dither_initcxx . . $ stp_dither_init(d3ac8ed317e2c6e7).(stp_vars_tcxx . . $ stp_vars_t# *v, stp_image_tcxx . . $ stp_image_t# *image, int out_width, |
| 347 | int xdpi, int ydpi) |
| 348 | { |
| 349 | int in_width = stp_image_widthcxx . . $ stp_image_width(ba31fd85910919f2).(image); |
| 350 | stpi_dither_tcxx . . $ stpi_dither_t# *d = stp_zalloccxx . . $ stp_zalloc(bfcfa4d6b7f7ef64).(sizeof(stpi_dither_tcxx . . $ stpi_dither_t#)); |
| 351 | |
| 352 | stp_allocate_component_datacxx . . $ stp_allocate_component_data(c746010122f90098).(v, "Dither", NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, stpi_dither_freecxx . . $ stpi_dither_free(5d22bdacc48458e8)., d); |
| 353 | |
| 354 | d->finalizedcxx . . $ dither#finalized. = 0; |
| 355 | d->error_rowscxx . . $ dither#error_rows. = ERROR_ROWScxx . . $ `src/main/dither-impl.h:74:9`!; |
| 356 | d->d_cutoffcxx . . $ dither#d_cutoff. = 4096; |
| 357 | |
| 358 | d->offset0_tablecxx . . $ dither#offset0_table. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 359 | d->offset1_tablecxx . . $ dither#offset1_table. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 360 | if (xdpi > ydpi) |
| 361 | { |
| 362 | d->x_aspectcxx . . $ dither#x_aspect. = 1; |
| 363 | d->y_aspectcxx . . $ dither#y_aspect. = xdpi / ydpi; |
| 364 | } |
| 365 | else |
| 366 | { |
| 367 | d->x_aspectcxx . . $ dither#x_aspect. = ydpi / xdpi; |
| 368 | d->y_aspectcxx . . $ dither#y_aspect. = 1; |
| 369 | } |
| 370 | d->ditherfunccxx . . $ dither#ditherfunc. = stpi_set_dither_functioncxx . . $ stpi_set_dither_function(5446b7483711b1e2).(v); |
| 371 | d->adaptive_limitcxx . . $ dither#adaptive_limit. = .75 * 65535; |
| 372 | |
| 373 | /* |
| 374 | * For hybrid EvenTone we want to use the good matrix. For regular |
| 375 | * EvenTone, we don't need to pay the cost. |
| 376 | */ |
| 377 | |
| 378 | if (d->stpi_dither_typecxx . . $ dither#stpi_dither_type. == D_VERY_FASTcxx . . $ `src/main/dither-impl.h:52:9`! || d->stpi_dither_typecxx . . $ dither#stpi_dither_type. ==D_EVENTONEcxx . . $ `src/main/dither-impl.h:53:9`! || |
| 379 | d->stpi_dither_typecxx . . $ dither#stpi_dither_type. == D_FASTcxx . . $ `src/main/dither-impl.h:51:9`! || d->stpi_dither_typecxx . . $ dither#stpi_dither_type. == D_PREDITHEREDcxx . . $ `src/main/dither-impl.h:59:9`!) |
| 380 | { |
| 381 | if (stp_check_int_parametercxx . . $ stp_check_int_parameter(cff2817d3dcc2695).(v, "DitherVeryFastSteps", |
| 382 | STP_PARAMETER_ACTIVEcxx . . $ STP_PARAMETER_ACTIVE.)) |
| 383 | stp_dither_set_iterated_matrixcxx . . $ stp_dither_set_iterated_matrix(6b6d260d194e2c9). |
| 384 | (v, 2, stp_get_int_parametercxx . . $ stp_get_int_parameter(b1e629819c29df09).(v, "DitherVeryFastSteps"), sq2cxx . . $ sq2., 0, 2,4); |
| 385 | else |
| 386 | stp_dither_set_iterated_matrixcxx . . $ stp_dither_set_iterated_matrix(6b6d260d194e2c9).(v, 2, DITHER_FAST_STEPScxx . . $ `src/main/dither-impl.h:65:9`!, sq2cxx . . $ sq2., 0, 2, 4); |
| 387 | } |
| 388 | else if (stp_check_array_parametercxx . . $ stp_check_array_parameter(cff2817d3dcc2695).(v, "DitherMatrix", |
| 389 | STP_PARAMETER_ACTIVEcxx . . $ STP_PARAMETER_ACTIVE.) && |
| 390 | (stp_dither_matrix_validate_arraycxx . . $ stp_dither_matrix_validate_array(3326b8bc3e0c6ce2). |
| 391 | (stp_get_array_parametercxx . . $ stp_get_array_parameter(ec8bd7f0fc89ff45).(v, "DitherMatrix")))) |
| 392 | { |
| 393 | stp_dither_set_matrix_from_dither_arraycxx . . $ stp_dither_set_matrix_from_dither_array(6587d31ec6306ce9). |
| 394 | (v, stp_get_array_parametercxx . . $ stp_get_array_parameter(ec8bd7f0fc89ff45).(v, "DitherMatrix"), 0); |
| 395 | } |
| 396 | else |
| 397 | { |
| 398 | stp_array_tcxx . . $ stp_array_t# *array = |
| 399 | stp_find_standard_dither_arraycxx . . $ stp_find_standard_dither_array(3312a96e2cd8fef).(d->y_aspectcxx . . $ dither#y_aspect., d->x_aspectcxx . . $ dither#x_aspect.); |
| 400 | int transposed = d->y_aspectcxx . . $ dither#y_aspect. < d->x_aspectcxx . . $ dither#x_aspect. ? 1 : 0; |
| 401 | STPI_ASSERTcxx . . $ `src/main/gutenprint-internal.h:58:9`!(array, v); |
| 402 | stp_dither_set_matrix_from_dither_arraycxx . . $ stp_dither_set_matrix_from_dither_array(6587d31ec6306ce9).(v, array, transposed); |
| 403 | stp_array_destroycxx . . $ stp_array_destroy(71c46815489e5a45).(array); |
| 404 | } |
| 405 | |
| 406 | d->src_widthcxx . . $ dither#src_width. = in_width; |
| 407 | d->dst_widthcxx . . $ dither#dst_width. = out_width; |
| 408 | |
| 409 | stp_dither_set_ink_spreadcxx . . $ stp_dither_set_ink_spread(c8b26ae77f1a10bd).(v, 13); |
| 410 | d->channel_countcxx . . $ dither#channel_count. = 0; |
| 411 | } |
| 412 | |
| 413 | void |
| 414 | stpi_dither_reverse_row_endscxx . . $ stpi_dither_reverse_row_ends(eba3149742ad601b).(stpi_dither_tcxx . . $ stpi_dither_t# *d) |
| 415 | { |
| 416 | int i; |
| 417 | for (i = 0; i < CHANNEL_COUNTcxx . . $ `src/main/dither-impl.h:179:9`!(d); i++) |
| 418 | { |
| 419 | int tmp = CHANNELcxx . . $ `src/main/dither-impl.h:178:9`!(d, i).row_endscxx . . $ dither_channel#row_ends.[0]; |
| 420 | CHANNELcxx . . $ `src/main/dither-impl.h:178:9`!(d, i).row_endscxx . . $ dither_channel#row_ends.[0] = |
| 421 | CHANNELcxx . . $ `src/main/dither-impl.h:178:9`!(d, i).row_endscxx . . $ dither_channel#row_ends.[1]; |
| 422 | CHANNELcxx . . $ `src/main/dither-impl.h:178:9`!(d, i).row_endscxx . . $ dither_channel#row_ends.[1] = tmp; |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | int |
| 427 | stp_dither_get_first_positioncxx . . $ stp_dither_get_first_position(c803ced41733a369).(stp_vars_tcxx . . $ stp_vars_t# *v, int color, int subchannel) |
| 428 | { |
| 429 | stpi_dither_tcxx . . $ stpi_dither_t# *d = (stpi_dither_tcxx . . $ stpi_dither_t# *) stp_get_component_datacxx . . $ stp_get_component_data(2bc0070dfdce2f04).(v, "Dither"); |
| 430 | int channel = stpi_dither_translate_channelcxx . . $ stpi_dither_translate_channel(5ddaaec62fc0a803).(v, color, subchannel); |
| 431 | if (channel < 0) |
| 432 | return -1; |
| 433 | return CHANNELcxx . . $ `src/main/dither-impl.h:178:9`!(d, channel).row_endscxx . . $ dither_channel#row_ends.[0]; |
| 434 | } |
| 435 | |
| 436 | int |
| 437 | stp_dither_get_last_positioncxx . . $ stp_dither_get_last_position(c803ced41733a369).(stp_vars_tcxx . . $ stp_vars_t# *v, int color, int subchannel) |
| 438 | { |
| 439 | stpi_dither_tcxx . . $ stpi_dither_t# *d = (stpi_dither_tcxx . . $ stpi_dither_t# *) stp_get_component_datacxx . . $ stp_get_component_data(2bc0070dfdce2f04).(v, "Dither"); |
| 440 | int channel = stpi_dither_translate_channelcxx . . $ stpi_dither_translate_channel(5ddaaec62fc0a803).(v, color, subchannel); |
| 441 | if (channel < 0) |
| 442 | return -1; |
| 443 | return CHANNELcxx . . $ `src/main/dither-impl.h:178:9`!(d, channel).row_endscxx . . $ dither_channel#row_ends.[1]; |
| 444 | } |
| 445 | |
| 446 | int * |
| 447 | stpi_dither_get_errlinecxx . . $ stpi_dither_get_errline(9dcb8238a6bf38ad).(stpi_dither_tcxx . . $ stpi_dither_t# *d, int row, int color) |
| 448 | { |
| 449 | stpi_dither_channel_tcxx . . $ stpi_dither_channel_t# *dc; |
| 450 | if (row < 0 || color < 0 || color >= CHANNEL_COUNTcxx . . $ `src/main/dither-impl.h:179:9`!(d)) |
| 451 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 452 | dc = &(CHANNELcxx . . $ `src/main/dither-impl.h:178:9`!(d, color)); |
| 453 | if (!dc->errscxx . . $ dither_channel#errs.) |
| 454 | dc->errscxx . . $ dither_channel#errs. = stp_zalloccxx . . $ stp_zalloc(bfcfa4d6b7f7ef64).(d->error_rowscxx . . $ dither#error_rows. * sizeof(int *)); |
| 455 | if (!dc->errscxx . . $ dither_channel#errs.[row % dc->error_rowscxx . . $ dither_channel#error_rows.]) |
| 456 | { |
| 457 | int size = 2 * MAX_SPREADcxx . . $ `src/main/dither-impl.h:76:9`! + (16 * ((d->dst_widthcxx . . $ dither#dst_width. + 7) / 8)); |
| 458 | dc->errscxx . . $ dither_channel#errs.[row % dc->error_rowscxx . . $ dither_channel#error_rows.] = stp_zalloccxx . . $ stp_zalloc(bfcfa4d6b7f7ef64).(size * sizeof(int)); |
| 459 | } |
| 460 | return dc->errscxx . . $ dither_channel#errs.[row % dc->error_rowscxx . . $ dither_channel#error_rows.] + MAX_SPREADcxx . . $ `src/main/dither-impl.h:76:9`!; |
| 461 | } |
| 462 | |
| 463 | void |
| 464 | stp_dither_internalcxx . . $ stp_dither_internal(525e4b1c00087d37).(stp_vars_tcxx . . $ stp_vars_t# *v, int row, const unsigned short *input, |
| 465 | int duplicate_line, int zero_mask, |
| 466 | const unsigned char *mask) |
| 467 | { |
| 468 | int i; |
| 469 | stpi_dither_tcxx . . $ stpi_dither_t# *d = (stpi_dither_tcxx . . $ stpi_dither_t# *) stp_get_component_datacxx . . $ stp_get_component_data(2bc0070dfdce2f04).(v, "Dither"); |
| 470 | stpi_dither_finalizecxx . . $ stpi_dither_finalize(1a97b8462f9f913c).(v); |
| 471 | stp_dither_matrix_set_rowcxx . . $ stp_dither_matrix_set_row(befc66d6fe93ad5c).(&(d->dither_matrixcxx . . $ dither#dither_matrix.), row); |
| 472 | for (i = 0; i < CHANNEL_COUNTcxx . . $ `src/main/dither-impl.h:179:9`!(d); i++) |
| 473 | { |
| 474 | CHANNELcxx . . $ `src/main/dither-impl.h:178:9`!(d, i).ptrcxx . . $ dither_channel#ptr. = CHANNELcxx . . $ `src/main/dither-impl.h:178:9`!(d, i).ptrcxx . . $ dither_channel#ptr.; |
| 475 | if (CHANNELcxx . . $ `src/main/dither-impl.h:178:9`!(d, i).ptrcxx . . $ dither_channel#ptr.) |
| 476 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(CHANNELcxx . . $ `src/main/dither-impl.h:178:9`!(d, i).ptrcxx . . $ dither_channel#ptr., 0, |
| 477 | (d->dst_widthcxx . . $ dither#dst_width. + 7) / 8 * CHANNELcxx . . $ `src/main/dither-impl.h:178:9`!(d, i).signif_bitscxx . . $ dither_channel#signif_bits.); |
| 478 | CHANNELcxx . . $ `src/main/dither-impl.h:178:9`!(d, i).row_endscxx . . $ dither_channel#row_ends.[0] = -1; |
| 479 | CHANNELcxx . . $ `src/main/dither-impl.h:178:9`!(d, i).row_endscxx . . $ dither_channel#row_ends.[1] = -1; |
| 480 | |
| 481 | stp_dither_matrix_set_rowcxx . . $ stp_dither_matrix_set_row(befc66d6fe93ad5c).(&(CHANNELcxx . . $ `src/main/dither-impl.h:178:9`!(d, i).dithermatcxx . . $ dither_channel#dithermat.), row); |
| 482 | stp_dither_matrix_set_rowcxx . . $ stp_dither_matrix_set_row(befc66d6fe93ad5c).(&(CHANNELcxx . . $ `src/main/dither-impl.h:178:9`!(d, i).pickcxx . . $ dither_channel#pick.), row); |
| 483 | } |
| 484 | d->ptr_offsetcxx . . $ dither#ptr_offset. = 0; |
| 485 | (d->ditherfunccxx . . $ dither#ditherfunc.)(v, row, input, duplicate_line, zero_mask, mask); |
| 486 | } |
| 487 | |
| 488 | void |
| 489 | stp_dithercxx . . $ stp_dither(c27f96f0d387255a).(stp_vars_tcxx . . $ stp_vars_t# *v, int row, int duplicate_line, int zero_mask, |
| 490 | const unsigned char *mask) |
| 491 | { |
| 492 | const unsigned short *input = stp_channel_get_outputcxx . . $ stp_channel_get_output(58f317534f8c8659).(v); |
| 493 | stp_dither_internalcxx . . $ stp_dither_internal(525e4b1c00087d37).(v, row, input, duplicate_line, zero_mask, mask); |
| 494 | } |