cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % SSSSS CCCC RRRR % |
| 7 | % SS C R R % |
| 8 | % SSS C RRRR % |
| 9 | % SS C R R % |
| 10 | % SSSSS CCCC R R % |
| 11 | % % |
| 12 | % % |
| 13 | % Read ZX-Spectrum SCREEN$ Format % |
| 14 | % % |
| 15 | % Software Design % |
| 16 | % Catalin Mihaila % |
| 17 | % October 2003 % |
| 18 | % % |
| 19 | % % |
cristy | 7e41fe8 | 2010-12-04 23:12:08 +0000 | [diff] [blame] | 20 | % Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 21 | % dedicated to making software imaging solutions freely available. % |
| 22 | % % |
| 23 | % You may not use this file except in compliance with the License. You may % |
| 24 | % obtain a copy of the License at % |
| 25 | % % |
| 26 | % http://www.imagemagick.org/script/license.php % |
| 27 | % % |
| 28 | % Unless required by applicable law or agreed to in writing, software % |
| 29 | % distributed under the License is distributed on an "AS IS" BASIS, % |
| 30 | % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % |
| 31 | % See the License for the specific language governing permissions and % |
| 32 | % limitations under the License. % |
| 33 | % % |
| 34 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 35 | % |
| 36 | % |
| 37 | */ |
| 38 | |
| 39 | /* |
| 40 | Include declarations. |
| 41 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame^] | 42 | #include "MagickCore/studio.h" |
| 43 | #include "MagickCore/blob.h" |
| 44 | #include "MagickCore/blob-private.h" |
| 45 | #include "MagickCore/cache.h" |
| 46 | #include "MagickCore/exception.h" |
| 47 | #include "MagickCore/exception-private.h" |
| 48 | #include "MagickCore/image.h" |
| 49 | #include "MagickCore/image-private.h" |
| 50 | #include "MagickCore/list.h" |
| 51 | #include "MagickCore/magick.h" |
| 52 | #include "MagickCore/memory_.h" |
| 53 | #include "MagickCore/monitor.h" |
| 54 | #include "MagickCore/monitor-private.h" |
| 55 | #include "MagickCore/pixel-accessor.h" |
| 56 | #include "MagickCore/quantum-private.h" |
| 57 | #include "MagickCore/static.h" |
| 58 | #include "MagickCore/string_.h" |
| 59 | #include "MagickCore/module.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 60 | |
| 61 | /* |
| 62 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 63 | % % |
| 64 | % % |
| 65 | % % |
| 66 | % R e a d S C R I m a g e % |
| 67 | % % |
| 68 | % % |
| 69 | % % |
| 70 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 71 | % |
| 72 | % ReadSCRImage() reads a Scitex image file and returns it. It allocates |
| 73 | % the memory necessary for the new Image structure and returns a pointer to |
| 74 | % the new image. |
| 75 | % |
| 76 | % The format of the ReadSCRImage method is: |
| 77 | % |
| 78 | % Image *ReadSCRImage(const ImageInfo *image_info,ExceptionInfo *exception) |
| 79 | % |
| 80 | % A description of each parameter follows: |
| 81 | % |
| 82 | % o image_info: the image info. |
| 83 | % |
| 84 | % o exception: return any errors or warnings in this structure. |
| 85 | % |
| 86 | */ |
| 87 | static Image *ReadSCRImage(const ImageInfo *image_info,ExceptionInfo *exception) |
| 88 | { |
| 89 | char zxscr[6144]; |
| 90 | char zxattr[768]; |
| 91 | int octetnr; |
| 92 | int octetline; |
| 93 | int zoneline; |
| 94 | int zonenr; |
| 95 | int octet_val; |
| 96 | int attr_nr; |
| 97 | int pix; |
| 98 | int piy; |
| 99 | int binar[8]; |
| 100 | int attrbin[8]; |
| 101 | int *pbin; |
| 102 | int *abin; |
| 103 | int z; |
| 104 | int one_nr; |
| 105 | int ink; |
| 106 | int paper; |
| 107 | int bright; |
| 108 | |
| 109 | unsigned char colour_palette[] = { |
cristy | 472afc7 | 2010-05-16 19:29:35 +0000 | [diff] [blame] | 110 | 0, 0, 0, |
| 111 | 0, 0,192, |
| 112 | 192, 0, 0, |
| 113 | 192, 0,192, |
| 114 | 0,192, 0, |
| 115 | 0,192,192, |
| 116 | 192,192, 0, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 117 | 192,192,192, |
cristy | 472afc7 | 2010-05-16 19:29:35 +0000 | [diff] [blame] | 118 | 0, 0, 0, |
| 119 | 0, 0,255, |
| 120 | 255, 0, 0, |
| 121 | 255, 0,255, |
| 122 | 0,255, 0, |
| 123 | 0,255,255, |
| 124 | 255,255, 0, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 125 | 255,255,255 |
| 126 | }; |
| 127 | |
| 128 | Image |
| 129 | *image; |
| 130 | |
| 131 | MagickBooleanType |
| 132 | status; |
| 133 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame^] | 134 | register Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 135 | *q; |
| 136 | |
| 137 | ssize_t |
| 138 | count; |
| 139 | |
| 140 | /* |
| 141 | Open image file. |
| 142 | */ |
| 143 | assert(image_info != (const ImageInfo *) NULL); |
| 144 | assert(image_info->signature == MagickSignature); |
| 145 | if (image_info->debug != MagickFalse) |
| 146 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 147 | image_info->filename); |
| 148 | assert(exception != (ExceptionInfo *) NULL); |
| 149 | assert(exception->signature == MagickSignature); |
| 150 | image=AcquireImage(image_info); |
| 151 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
| 152 | if (status == MagickFalse) |
| 153 | { |
| 154 | image=DestroyImageList(image); |
| 155 | return((Image *) NULL); |
| 156 | } |
| 157 | image->columns = 256; |
| 158 | image->rows = 192; |
| 159 | count=ReadBlob(image,6144,(unsigned char *) zxscr); |
cristy | da16f16 | 2011-02-19 23:52:17 +0000 | [diff] [blame] | 160 | (void) count; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 161 | count=ReadBlob(image,768,(unsigned char *) zxattr); |
| 162 | for(zonenr=0;zonenr<3;zonenr++) |
| 163 | { |
| 164 | for(zoneline=0;zoneline<8;zoneline++) |
| 165 | { |
| 166 | for(octetline=0;octetline<8;octetline++) |
| 167 | { |
| 168 | for(octetnr=(zoneline*32);octetnr<((zoneline*32)+32);octetnr++) |
| 169 | { |
| 170 | octet_val = zxscr[octetnr+(256*octetline)+(zonenr*2048)]; |
| 171 | attr_nr = zxattr[octetnr+(256*zonenr)]; |
| 172 | |
| 173 | pix = (((8*octetnr)-(256*zoneline))); |
| 174 | piy = ((octetline+(8*zoneline)+(zonenr*64))); |
| 175 | |
| 176 | pbin = binar; |
| 177 | abin = attrbin; |
| 178 | |
| 179 | one_nr=1; |
| 180 | |
| 181 | for(z=0;z<8;z++) |
| 182 | { |
| 183 | if(octet_val&one_nr) |
| 184 | { |
| 185 | *pbin = 1; |
| 186 | } else { |
| 187 | *pbin = 0; |
| 188 | } |
| 189 | one_nr=one_nr*2; |
| 190 | pbin++; |
| 191 | } |
| 192 | |
| 193 | one_nr = 1; |
| 194 | |
| 195 | for(z=0;z<8;z++) |
| 196 | { |
| 197 | if(attr_nr&one_nr) |
| 198 | { |
| 199 | *abin = 1; |
| 200 | } else { |
| 201 | *abin = 0; |
| 202 | } |
| 203 | one_nr=one_nr*2; |
| 204 | abin++; |
| 205 | } |
| 206 | |
| 207 | ink = (attrbin[0]+(2*attrbin[1])+(4*attrbin[2])); |
| 208 | paper = (attrbin[3]+(2*attrbin[4])+(4*attrbin[5])); |
| 209 | bright = attrbin[6]; |
| 210 | |
| 211 | if(bright) { ink=ink+8; paper=paper+8; } |
| 212 | |
| 213 | for(z=7;z>-1;z--) |
| 214 | { |
| 215 | q=QueueAuthenticPixels(image,pix,piy,1,1,exception); |
| 216 | |
| 217 | if(binar[z]) |
| 218 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame^] | 219 | SetPixelRed(image,ScaleCharToQuantum( |
| 220 | colour_palette[3*ink]),q); |
| 221 | SetPixelGreen(image,ScaleCharToQuantum( |
| 222 | colour_palette[1+(3*ink)]),q); |
| 223 | SetPixelBlue(image,ScaleCharToQuantum( |
| 224 | colour_palette[2+(3*ink)]),q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 225 | } else { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame^] | 226 | SetPixelRed(image,ScaleCharToQuantum( |
| 227 | colour_palette[3*paper]),q); |
| 228 | SetPixelGreen(image,ScaleCharToQuantum( |
| 229 | colour_palette[1+(3*paper)]),q); |
| 230 | SetPixelBlue(image,ScaleCharToQuantum( |
| 231 | colour_palette[2+(3*paper)]),q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | pix++; |
| 235 | } |
| 236 | } |
| 237 | } |
| 238 | } |
| 239 | } |
| 240 | (void) CloseBlob(image); |
| 241 | return(GetFirstImageInList(image)); |
| 242 | } |
| 243 | |
| 244 | /* |
| 245 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 246 | % % |
| 247 | % % |
| 248 | % % |
| 249 | % R e g i s t e r S C R I m a g e % |
| 250 | % % |
| 251 | % % |
| 252 | % % |
| 253 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 254 | % |
| 255 | % RegisterSCRImage() adds attributes for the SCR image format to |
| 256 | % the list of supported formats. The attributes include the image format |
| 257 | % tag, a method to read and/or write the format, whether the format |
| 258 | % supports the saving of more than one frame to the same file or blob, |
| 259 | % whether the format supports native in-memory I/O, and a brief |
| 260 | % description of the format. |
| 261 | % |
| 262 | % The format of the RegisterSCRImage method is: |
| 263 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 264 | % size_t RegisterSCRImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 265 | % |
| 266 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 267 | ModuleExport size_t RegisterSCRImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 268 | { |
| 269 | MagickInfo |
| 270 | *entry; |
| 271 | |
| 272 | entry=SetMagickInfo("SCR"); |
| 273 | entry->decoder=(DecodeImageHandler *) ReadSCRImage; |
| 274 | entry->adjoin=MagickFalse; |
| 275 | entry->description=ConstantString("ZX-Spectrum SCREEN$"); |
| 276 | entry->module=ConstantString("SCR"); |
| 277 | (void) RegisterMagickInfo(entry); |
| 278 | return(MagickImageCoderSignature); |
| 279 | } |
| 280 | |
| 281 | /* |
| 282 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 283 | % % |
| 284 | % % |
| 285 | % % |
| 286 | % U n r e g i s t e r S C R I m a g e % |
| 287 | % % |
| 288 | % % |
| 289 | % % |
| 290 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 291 | % |
| 292 | % UnregisterSCRImage() removes format registrations made by the |
| 293 | % SCR module from the list of supported formats. |
| 294 | % |
| 295 | % The format of the UnregisterSCRImage method is: |
| 296 | % |
| 297 | % UnregisterSCRImage(void) |
| 298 | % |
| 299 | */ |
| 300 | ModuleExport void UnregisterSCRImage(void) |
| 301 | { |
| 302 | (void) UnregisterMagickInfo("SCR"); |
| 303 | } |