2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Read ZX-Spectrum SCREEN$ Format %
20 % Copyright 1999-2018 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % https://www.imagemagick.org/script/license.php %
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. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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"
62 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66 % R e a d S C R I m a g e %
70 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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
76 % The format of the ReadSCRImage method is:
78 % Image *ReadSCRImage(const ImageInfo *image_info,ExceptionInfo *exception)
80 % A description of each parameter follows:
82 % o image_info: the image info.
84 % o exception: return any errors or warnings in this structure.
87 static Image *ReadSCRImage(const ImageInfo *image_info,ExceptionInfo *exception)
109 unsigned char colour_palette[] = {
143 assert(image_info != (const ImageInfo *) NULL);
144 assert(image_info->signature == MagickCoreSignature);
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 == MagickCoreSignature);
150 image=AcquireImage(image_info,exception);
151 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
152 if (status == MagickFalse)
154 image=DestroyImageList(image);
155 return((Image *) NULL);
157 image->columns = 256;
159 status=SetImageExtent(image,image->columns,image->rows,exception);
160 if (status == MagickFalse)
161 return(DestroyImageList(image));
162 count=ReadBlob(image,6144,(unsigned char *) zxscr);
164 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
165 count=ReadBlob(image,768,(unsigned char *) zxattr);
167 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
168 for(zonenr=0;zonenr<3;zonenr++)
170 for(zoneline=0;zoneline<8;zoneline++)
172 for(octetline=0;octetline<8;octetline++)
174 for(octetnr=(zoneline*32);octetnr<((zoneline*32)+32);octetnr++)
176 octet_val = zxscr[octetnr+(256*octetline)+(zonenr*2048)];
177 attr_nr = zxattr[octetnr+(256*zonenr)];
179 pix = (((8*octetnr)-(256*zoneline)));
180 piy = ((octetline+(8*zoneline)+(zonenr*64)));
213 ink = (attrbin[0]+(2*attrbin[1])+(4*attrbin[2]));
214 paper = (attrbin[3]+(2*attrbin[4])+(4*attrbin[5]));
217 if(bright) { ink=ink+8; paper=paper+8; }
221 q=QueueAuthenticPixels(image,pix,piy,1,1,exception);
222 if (q == (Quantum *) NULL)
227 SetPixelRed(image,ScaleCharToQuantum(
228 colour_palette[3*ink]),q);
229 SetPixelGreen(image,ScaleCharToQuantum(
230 colour_palette[1+(3*ink)]),q);
231 SetPixelBlue(image,ScaleCharToQuantum(
232 colour_palette[2+(3*ink)]),q);
234 SetPixelRed(image,ScaleCharToQuantum(
235 colour_palette[3*paper]),q);
236 SetPixelGreen(image,ScaleCharToQuantum(
237 colour_palette[1+(3*paper)]),q);
238 SetPixelBlue(image,ScaleCharToQuantum(
239 colour_palette[2+(3*paper)]),q);
248 (void) CloseBlob(image);
249 return(GetFirstImageInList(image));
253 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
257 % R e g i s t e r S C R I m a g e %
261 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
263 % RegisterSCRImage() adds attributes for the SCR image format to
264 % the list of supported formats. The attributes include the image format
265 % tag, a method to read and/or write the format, whether the format
266 % supports the saving of more than one frame to the same file or blob,
267 % whether the format supports native in-memory I/O, and a brief
268 % description of the format.
270 % The format of the RegisterSCRImage method is:
272 % size_t RegisterSCRImage(void)
275 ModuleExport size_t RegisterSCRImage(void)
280 entry=AcquireMagickInfo("SCR","SCR","ZX-Spectrum SCREEN$");
281 entry->decoder=(DecodeImageHandler *) ReadSCRImage;
282 entry->flags^=CoderAdjoinFlag;
283 (void) RegisterMagickInfo(entry);
284 return(MagickImageCoderSignature);
288 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
292 % U n r e g i s t e r S C R I m a g e %
296 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
298 % UnregisterSCRImage() removes format registrations made by the
299 % SCR module from the list of supported formats.
301 % The format of the UnregisterSCRImage method is:
303 % UnregisterSCRImage(void)
306 ModuleExport void UnregisterSCRImage(void)
308 (void) UnregisterMagickInfo("SCR");