| 1 | /* |
| 2 | * Buffer an Image |
| 3 | * |
| 4 | * Copyright 2007 Sascha Sommer <[email protected]> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU General Public License as published by the Free |
| 8 | * Software Foundation; either version 2 of the License, or (at your option) |
| 9 | * any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 13 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | * for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:409:9`! |
| 21 | #include <config.h>cxx . . $ `<file>/config.h`/ |
| 22 | #endif |
| 23 | #include <gutenprint/gutenprint.h>cxx . . $ `<file>/include/gutenprint/gutenprint.h`/ |
| 24 | #include "gutenprint-internal.h"cxx . . $ `<file>/src/main/gutenprint-internal.h`/ |
| 25 | |
| 26 | struct buffered_image_privcxx . . $ buffered_image_priv# |
| 27 | { |
| 28 | stp_image_tcxx . . $ stp_image_t#* imagecxx . . $ buffered_image_priv#image.; |
| 29 | unsigned char** bufcxx . . $ buffered_image_priv#buf.; |
| 30 | unsigned int flagscxx . . $ buffered_image_priv#flags.; |
| 31 | }; |
| 32 | |
| 33 | static void |
| 34 | buffered_image_initcxx . . $ buffered_image_init(7010b42a94b47a79).(stp_image_tcxx . . $ stp_image_t#* image) |
| 35 | { |
| 36 | struct buffered_image_privcxx . . $ buffered_image_priv# *priv = image->repcxx . . $ stp_image#rep.; |
| 37 | if(priv->imagecxx . . $ buffered_image_priv#image.->initcxx . . $ stp_image#init.) |
| 38 | priv->imagecxx . . $ buffered_image_priv#image.->initcxx . . $ stp_image#init.(priv->imagecxx . . $ buffered_image_priv#image.); |
| 39 | } |
| 40 | |
| 41 | |
| 42 | static int |
| 43 | buffered_image_widthcxx . . $ buffered_image_width(ba31fd85910919f2).(stp_image_tcxx . . $ stp_image_t# * image) |
| 44 | { |
| 45 | struct buffered_image_privcxx . . $ buffered_image_priv# *priv = image->repcxx . . $ stp_image#rep.; |
| 46 | return priv->imagecxx . . $ buffered_image_priv#image.->widthcxx . . $ stp_image#width.(priv->imagecxx . . $ buffered_image_priv#image.); |
| 47 | } |
| 48 | |
| 49 | static int |
| 50 | buffered_image_heightcxx . . $ buffered_image_height(ba31fd85910919f2).(stp_image_tcxx . . $ stp_image_t# * image) |
| 51 | { |
| 52 | struct buffered_image_privcxx . . $ buffered_image_priv# *priv = image->repcxx . . $ stp_image#rep.; |
| 53 | return priv->imagecxx . . $ buffered_image_priv#image.->heightcxx . . $ stp_image#height.(priv->imagecxx . . $ buffered_image_priv#image.); |
| 54 | } |
| 55 | |
| 56 | static const char * |
| 57 | buffered_image_get_appnamecxx . . $ buffered_image_get_appname(97b8a1c82bcbc822).(stp_image_tcxx . . $ stp_image_t# *image) |
| 58 | { |
| 59 | struct buffered_image_privcxx . . $ buffered_image_priv# *priv = image->repcxx . . $ stp_image#rep.; |
| 60 | return priv->imagecxx . . $ buffered_image_priv#image.->get_appnamecxx . . $ stp_image#get_appname.(priv->imagecxx . . $ buffered_image_priv#image.); |
| 61 | } |
| 62 | |
| 63 | static stp_image_status_tcxx . . $ stp_image_status_t# |
| 64 | buffered_image_get_rowcxx . . $ buffered_image_get_row(c6bbe34ec0bddcf0).(stp_image_tcxx . . $ stp_image_t#* image,unsigned char *data, size_t byte_limit, int row) |
| 65 | { |
| 66 | struct buffered_image_privcxx . . $ buffered_image_priv# *priv = image->repcxx . . $ stp_image#rep.; |
| 67 | int width = buffered_image_widthcxx . . $ buffered_image_width(ba31fd85910919f2).(image); |
| 68 | int height = buffered_image_heightcxx . . $ buffered_image_height(ba31fd85910919f2).(image); |
| 69 | /* FIXME this will break with padding bytes */ |
| 70 | int bytes_per_pixel = byte_limit / width; |
| 71 | int inc = bytes_per_pixel; |
| 72 | unsigned char* src; |
| 73 | int i; |
| 74 | /* fill buffer */ |
| 75 | if(!priv->bufcxx . . $ buffered_image_priv#buf.){ |
| 76 | priv->bufcxx . . $ buffered_image_priv#buf. = stp_zalloccxx . . $ stp_zalloc(bfcfa4d6b7f7ef64).((sizeof(unsigned short*) + 1) * height); |
| 77 | if(!priv->bufcxx . . $ buffered_image_priv#buf.){ |
| 78 | return STP_IMAGE_STATUS_ABORTcxx . . $ STP_IMAGE_STATUS_ABORT.; |
| 79 | } |
| 80 | for(i=0;i<height;i++){ |
| 81 | priv->bufcxx . . $ buffered_image_priv#buf.[i] = stp_malloccxx . . $ stp_malloc(bfcfa4d6b7f7ef64).(byte_limit); |
| 82 | if(STP_IMAGE_STATUS_OKcxx . . $ STP_IMAGE_STATUS_OK. != priv->imagecxx . . $ buffered_image_priv#image.->get_rowcxx . . $ stp_image#get_row.(priv->imagecxx . . $ buffered_image_priv#image.,priv->bufcxx . . $ buffered_image_priv#buf.[i],byte_limit,i)) |
| 83 | return STP_IMAGE_STATUS_ABORTcxx . . $ STP_IMAGE_STATUS_ABORT.; |
| 84 | } |
| 85 | } |
| 86 | if(priv->flagscxx . . $ buffered_image_priv#flags. & BUFFER_FLAG_FLIP_Ycxx . . $ `src/main/gutenprint-internal.h:55:9`!) |
| 87 | row = height - row - 1; |
| 88 | |
| 89 | src = priv->bufcxx . . $ buffered_image_priv#buf.[row]; |
| 90 | |
| 91 | if(priv->flagscxx . . $ buffered_image_priv#flags. & BUFFER_FLAG_FLIP_Xcxx . . $ `src/main/gutenprint-internal.h:54:9`!){ |
| 92 | src += byte_limit - bytes_per_pixel; |
| 93 | inc = -bytes_per_pixel; |
| 94 | } |
| 95 | |
| 96 | /* copy data */ |
| 97 | for( i = 0 ; i < width ; i++){ |
| 98 | memcpycxx . . $ memcpy(cc817cb175f282d).(data,src,bytes_per_pixel); |
| 99 | src += inc; |
| 100 | data += bytes_per_pixel; |
| 101 | } |
| 102 | return STP_IMAGE_STATUS_OKcxx . . $ STP_IMAGE_STATUS_OK.; |
| 103 | } |
| 104 | |
| 105 | static void |
| 106 | buffered_image_concludecxx . . $ buffered_image_conclude(7010b42a94b47a79).(stp_image_tcxx . . $ stp_image_t# * image) |
| 107 | { |
| 108 | struct buffered_image_privcxx . . $ buffered_image_priv# *priv = image->repcxx . . $ stp_image#rep.; |
| 109 | if(priv->bufcxx . . $ buffered_image_priv#buf.){ |
| 110 | int i = 0; |
| 111 | while(priv->bufcxx . . $ buffered_image_priv#buf.[i]){ |
| 112 | stp_freecxx . . $ stp_free(5d22bdacc48458e8).(priv->bufcxx . . $ buffered_image_priv#buf.[i]); |
| 113 | ++i; |
| 114 | } |
| 115 | stp_freecxx . . $ stp_free(5d22bdacc48458e8).(priv->bufcxx . . $ buffered_image_priv#buf.); |
| 116 | priv->bufcxx . . $ buffered_image_priv#buf. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 117 | } |
| 118 | if(priv->imagecxx . . $ buffered_image_priv#image.->concludecxx . . $ stp_image#conclude.) |
| 119 | priv->imagecxx . . $ buffered_image_priv#image.->concludecxx . . $ stp_image#conclude.(priv->imagecxx . . $ buffered_image_priv#image.); |
| 120 | |
| 121 | stp_freecxx . . $ stp_free(5d22bdacc48458e8).(priv); |
| 122 | stp_freecxx . . $ stp_free(5d22bdacc48458e8).(image); |
| 123 | } |
| 124 | |
| 125 | stp_image_tcxx . . $ stp_image_t#* |
| 126 | stpi_buffer_imagecxx . . $ stpi_buffer_image(a9d3270e35af0259).(stp_image_tcxx . . $ stp_image_t#* image, unsigned int flags) |
| 127 | { |
| 128 | struct buffered_image_privcxx . . $ buffered_image_priv# *priv; |
| 129 | stp_image_tcxx . . $ stp_image_t#* buffered_image = stp_zalloccxx . . $ stp_zalloc(bfcfa4d6b7f7ef64).(sizeof(stp_image_tcxx . . $ stp_image_t#)); |
| 130 | if(!buffered_image){ |
| 131 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 132 | } |
| 133 | priv = buffered_image->repcxx . . $ stp_image#rep. = stp_zalloccxx . . $ stp_zalloc(bfcfa4d6b7f7ef64).(sizeof(struct buffered_image_privcxx . . $ buffered_image_priv#)); |
| 134 | if(!priv){ |
| 135 | stp_freecxx . . $ stp_free(5d22bdacc48458e8).(buffered_image); |
| 136 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 137 | } |
| 138 | |
| 139 | if(image->initcxx . . $ stp_image#init.) |
| 140 | buffered_image->initcxx . . $ stp_image#init. = buffered_image_initcxx . . $ buffered_image_init(7010b42a94b47a79).; |
| 141 | buffered_image->widthcxx . . $ stp_image#width. = buffered_image_widthcxx . . $ buffered_image_width(ba31fd85910919f2).; |
| 142 | buffered_image->heightcxx . . $ stp_image#height. = buffered_image_heightcxx . . $ buffered_image_height(ba31fd85910919f2).; |
| 143 | buffered_image->get_rowcxx . . $ stp_image#get_row. = buffered_image_get_rowcxx . . $ buffered_image_get_row(c6bbe34ec0bddcf0).; |
| 144 | buffered_image->concludecxx . . $ stp_image#conclude. = buffered_image_concludecxx . . $ buffered_image_conclude(7010b42a94b47a79).; |
| 145 | priv->imagecxx . . $ buffered_image_priv#image. = image; |
| 146 | priv->flagscxx . . $ buffered_image_priv#flags. = flags; |
| 147 | if(image->get_appnamecxx . . $ stp_image#get_appname.) |
| 148 | buffered_image->get_appnamecxx . . $ stp_image#get_appname. = buffered_image_get_appnamecxx . . $ buffered_image_get_appname(97b8a1c82bcbc822).; |
| 149 | |
| 150 | |
| 151 | return buffered_image; |
| 152 | } |