blob: 7c956d16f08939df4c1d487a20111fff42fc1a74 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
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% %
cristy7e41fe82010-12-04 23:12:08 +000020% Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% 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*/
42#include "magick/studio.h"
43#include "magick/blob.h"
44#include "magick/blob-private.h"
45#include "magick/cache.h"
46#include "magick/exception.h"
47#include "magick/exception-private.h"
48#include "magick/image.h"
49#include "magick/image-private.h"
50#include "magick/list.h"
51#include "magick/magick.h"
52#include "magick/memory_.h"
53#include "magick/monitor.h"
54#include "magick/monitor-private.h"
55#include "magick/quantum-private.h"
56#include "magick/static.h"
57#include "magick/string_.h"
58#include "magick/module.h"
59
60/*
61%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62% %
63% %
64% %
65% R e a d S C R I m a g e %
66% %
67% %
68% %
69%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
70%
71% ReadSCRImage() reads a Scitex image file and returns it. It allocates
72% the memory necessary for the new Image structure and returns a pointer to
73% the new image.
74%
75% The format of the ReadSCRImage method is:
76%
77% Image *ReadSCRImage(const ImageInfo *image_info,ExceptionInfo *exception)
78%
79% A description of each parameter follows:
80%
81% o image_info: the image info.
82%
83% o exception: return any errors or warnings in this structure.
84%
85*/
86static Image *ReadSCRImage(const ImageInfo *image_info,ExceptionInfo *exception)
87{
88 char zxscr[6144];
89 char zxattr[768];
90 int octetnr;
91 int octetline;
92 int zoneline;
93 int zonenr;
94 int octet_val;
95 int attr_nr;
96 int pix;
97 int piy;
98 int binar[8];
99 int attrbin[8];
100 int *pbin;
101 int *abin;
102 int z;
103 int one_nr;
104 int ink;
105 int paper;
106 int bright;
107
108 unsigned char colour_palette[] = {
cristy472afc72010-05-16 19:29:35 +0000109 0, 0, 0,
110 0, 0,192,
111 192, 0, 0,
112 192, 0,192,
113 0,192, 0,
114 0,192,192,
115 192,192, 0,
cristy3ed852e2009-09-05 21:47:34 +0000116 192,192,192,
cristy472afc72010-05-16 19:29:35 +0000117 0, 0, 0,
118 0, 0,255,
119 255, 0, 0,
120 255, 0,255,
121 0,255, 0,
122 0,255,255,
123 255,255, 0,
cristy3ed852e2009-09-05 21:47:34 +0000124 255,255,255
125 };
126
127 Image
128 *image;
129
130 MagickBooleanType
131 status;
132
133 register PixelPacket
134 *q;
135
136 ssize_t
137 count;
138
139 /*
140 Open image file.
141 */
142 assert(image_info != (const ImageInfo *) NULL);
143 assert(image_info->signature == MagickSignature);
144 if (image_info->debug != MagickFalse)
145 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
146 image_info->filename);
147 assert(exception != (ExceptionInfo *) NULL);
148 assert(exception->signature == MagickSignature);
149 image=AcquireImage(image_info);
150 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
151 if (status == MagickFalse)
152 {
153 image=DestroyImageList(image);
154 return((Image *) NULL);
155 }
156 image->columns = 256;
157 image->rows = 192;
158 count=ReadBlob(image,6144,(unsigned char *) zxscr);
cristyda16f162011-02-19 23:52:17 +0000159 (void) count;
cristy3ed852e2009-09-05 21:47:34 +0000160 count=ReadBlob(image,768,(unsigned char *) zxattr);
161 for(zonenr=0;zonenr<3;zonenr++)
162 {
163 for(zoneline=0;zoneline<8;zoneline++)
164 {
165 for(octetline=0;octetline<8;octetline++)
166 {
167 for(octetnr=(zoneline*32);octetnr<((zoneline*32)+32);octetnr++)
168 {
169 octet_val = zxscr[octetnr+(256*octetline)+(zonenr*2048)];
170 attr_nr = zxattr[octetnr+(256*zonenr)];
171
172 pix = (((8*octetnr)-(256*zoneline)));
173 piy = ((octetline+(8*zoneline)+(zonenr*64)));
174
175 pbin = binar;
176 abin = attrbin;
177
178 one_nr=1;
179
180 for(z=0;z<8;z++)
181 {
182 if(octet_val&one_nr)
183 {
184 *pbin = 1;
185 } else {
186 *pbin = 0;
187 }
188 one_nr=one_nr*2;
189 pbin++;
190 }
191
192 one_nr = 1;
193
194 for(z=0;z<8;z++)
195 {
196 if(attr_nr&one_nr)
197 {
198 *abin = 1;
199 } else {
200 *abin = 0;
201 }
202 one_nr=one_nr*2;
203 abin++;
204 }
205
206 ink = (attrbin[0]+(2*attrbin[1])+(4*attrbin[2]));
207 paper = (attrbin[3]+(2*attrbin[4])+(4*attrbin[5]));
208 bright = attrbin[6];
209
210 if(bright) { ink=ink+8; paper=paper+8; }
211
212 for(z=7;z>-1;z--)
213 {
214 q=QueueAuthenticPixels(image,pix,piy,1,1,exception);
215
216 if(binar[z])
217 {
cristy472afc72010-05-16 19:29:35 +0000218 q->red=ScaleCharToQuantum(colour_palette[3*ink]);
219 q->green=ScaleCharToQuantum(colour_palette[1+(3*ink)]);
220 q->blue=ScaleCharToQuantum(colour_palette[2+(3*ink)]);
cristy3ed852e2009-09-05 21:47:34 +0000221 } else {
cristy472afc72010-05-16 19:29:35 +0000222 q->red=ScaleCharToQuantum(colour_palette[3*paper]);
223 q->green=ScaleCharToQuantum(colour_palette[1+(3*paper)]);
224 q->blue=ScaleCharToQuantum(colour_palette[2+(3*paper)]);
cristy3ed852e2009-09-05 21:47:34 +0000225 }
226
227 pix++;
228 }
229 }
230 }
231 }
232 }
233 (void) CloseBlob(image);
234 return(GetFirstImageInList(image));
235}
236
237/*
238%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
239% %
240% %
241% %
242% R e g i s t e r S C R I m a g e %
243% %
244% %
245% %
246%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
247%
248% RegisterSCRImage() adds attributes for the SCR image format to
249% the list of supported formats. The attributes include the image format
250% tag, a method to read and/or write the format, whether the format
251% supports the saving of more than one frame to the same file or blob,
252% whether the format supports native in-memory I/O, and a brief
253% description of the format.
254%
255% The format of the RegisterSCRImage method is:
256%
cristybb503372010-05-27 20:51:26 +0000257% size_t RegisterSCRImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000258%
259*/
cristybb503372010-05-27 20:51:26 +0000260ModuleExport size_t RegisterSCRImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000261{
262 MagickInfo
263 *entry;
264
265 entry=SetMagickInfo("SCR");
266 entry->decoder=(DecodeImageHandler *) ReadSCRImage;
267 entry->adjoin=MagickFalse;
268 entry->description=ConstantString("ZX-Spectrum SCREEN$");
269 entry->module=ConstantString("SCR");
270 (void) RegisterMagickInfo(entry);
271 return(MagickImageCoderSignature);
272}
273
274/*
275%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
276% %
277% %
278% %
279% U n r e g i s t e r S C R I m a g e %
280% %
281% %
282% %
283%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
284%
285% UnregisterSCRImage() removes format registrations made by the
286% SCR module from the list of supported formats.
287%
288% The format of the UnregisterSCRImage method is:
289%
290% UnregisterSCRImage(void)
291%
292*/
293ModuleExport void UnregisterSCRImage(void)
294{
295 (void) UnregisterMagickInfo("SCR");
296}