blob: f7dfcae90c3498fcb0a7440f039ef75006d84876 [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% %
cristy16af1cb2009-12-11 21:38:29 +000020% Copyright 1999-2010 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);
159 count=ReadBlob(image,768,(unsigned char *) zxattr);
160 for(zonenr=0;zonenr<3;zonenr++)
161 {
162 for(zoneline=0;zoneline<8;zoneline++)
163 {
164 for(octetline=0;octetline<8;octetline++)
165 {
166 for(octetnr=(zoneline*32);octetnr<((zoneline*32)+32);octetnr++)
167 {
168 octet_val = zxscr[octetnr+(256*octetline)+(zonenr*2048)];
169 attr_nr = zxattr[octetnr+(256*zonenr)];
170
171 pix = (((8*octetnr)-(256*zoneline)));
172 piy = ((octetline+(8*zoneline)+(zonenr*64)));
173
174 pbin = binar;
175 abin = attrbin;
176
177 one_nr=1;
178
179 for(z=0;z<8;z++)
180 {
181 if(octet_val&one_nr)
182 {
183 *pbin = 1;
184 } else {
185 *pbin = 0;
186 }
187 one_nr=one_nr*2;
188 pbin++;
189 }
190
191 one_nr = 1;
192
193 for(z=0;z<8;z++)
194 {
195 if(attr_nr&one_nr)
196 {
197 *abin = 1;
198 } else {
199 *abin = 0;
200 }
201 one_nr=one_nr*2;
202 abin++;
203 }
204
205 ink = (attrbin[0]+(2*attrbin[1])+(4*attrbin[2]));
206 paper = (attrbin[3]+(2*attrbin[4])+(4*attrbin[5]));
207 bright = attrbin[6];
208
209 if(bright) { ink=ink+8; paper=paper+8; }
210
211 for(z=7;z>-1;z--)
212 {
213 q=QueueAuthenticPixels(image,pix,piy,1,1,exception);
214
215 if(binar[z])
216 {
cristy472afc72010-05-16 19:29:35 +0000217 q->red=ScaleCharToQuantum(colour_palette[3*ink]);
218 q->green=ScaleCharToQuantum(colour_palette[1+(3*ink)]);
219 q->blue=ScaleCharToQuantum(colour_palette[2+(3*ink)]);
cristy3ed852e2009-09-05 21:47:34 +0000220 } else {
cristy472afc72010-05-16 19:29:35 +0000221 q->red=ScaleCharToQuantum(colour_palette[3*paper]);
222 q->green=ScaleCharToQuantum(colour_palette[1+(3*paper)]);
223 q->blue=ScaleCharToQuantum(colour_palette[2+(3*paper)]);
cristy3ed852e2009-09-05 21:47:34 +0000224 }
225
226 pix++;
227 }
228 }
229 }
230 }
231 }
232 (void) CloseBlob(image);
233 return(GetFirstImageInList(image));
234}
235
236/*
237%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
238% %
239% %
240% %
241% R e g i s t e r S C R I m a g e %
242% %
243% %
244% %
245%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
246%
247% RegisterSCRImage() adds attributes for the SCR image format to
248% the list of supported formats. The attributes include the image format
249% tag, a method to read and/or write the format, whether the format
250% supports the saving of more than one frame to the same file or blob,
251% whether the format supports native in-memory I/O, and a brief
252% description of the format.
253%
254% The format of the RegisterSCRImage method is:
255%
cristybb503372010-05-27 20:51:26 +0000256% size_t RegisterSCRImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000257%
258*/
cristybb503372010-05-27 20:51:26 +0000259ModuleExport size_t RegisterSCRImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000260{
261 MagickInfo
262 *entry;
263
264 entry=SetMagickInfo("SCR");
265 entry->decoder=(DecodeImageHandler *) ReadSCRImage;
266 entry->adjoin=MagickFalse;
267 entry->description=ConstantString("ZX-Spectrum SCREEN$");
268 entry->module=ConstantString("SCR");
269 (void) RegisterMagickInfo(entry);
270 return(MagickImageCoderSignature);
271}
272
273/*
274%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
275% %
276% %
277% %
278% U n r e g i s t e r S C R I m a g e %
279% %
280% %
281% %
282%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
283%
284% UnregisterSCRImage() removes format registrations made by the
285% SCR module from the list of supported formats.
286%
287% The format of the UnregisterSCRImage method is:
288%
289% UnregisterSCRImage(void)
290%
291*/
292ModuleExport void UnregisterSCRImage(void)
293{
294 (void) UnregisterMagickInfo("SCR");
295}