1 {
2 $Id: ImagingPcx.pas 100 2007-06-28 21:09:52Z galfar $
3 Vampyre Imaging Library
4 by Marek Mauder
5 http://imaginglib.sourceforge.net
7 The contents of this file are used with permission, subject to the Mozilla
8 Public License Version 1.1 (the "License"); you may not use this file except
9 in compliance with the License. You may obtain a copy of the License at
10 http://www.mozilla.org/MPL/MPL-1.1.html
12 Software distributed under the License is distributed on an "AS IS" basis,
13 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
14 the specific language governing rights and limitations under the License.
16 Alternatively, the contents of this file may be used under the terms of the
17 GNU Lesser General Public License (the "LGPL License"), in which case the
18 provisions of the LGPL License are applicable instead of those above.
19 If you wish to allow use of your version of this file only under the terms
20 of the LGPL License and not to allow others to use your version of this file
21 under the MPL, indicate your decision by deleting the provisions above and
22 replace them with the notice and other provisions required by the LGPL
23 License. If you do not delete the provisions above, a recipient may use
24 your version of this file under either the MPL or the LGPL License.
26 For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html
27 }
29 { This unit contains image format loader for ZSoft Paintbrush images known as PCX.}
32 {$I ImagingOptions.inc}
34 interface
36 uses
39 type
40 { Class for loading ZSoft Paintbrush images known as PCX. It is old
41 format which can store 1bit, 2bit, 4bit, 8bit, and 24bit (and 32bit but is
42 probably non-standard) images. Only loading is supported (you can still come
43 accross some PCX files) but saving is not (I don't wont this venerable format
44 to spread).}
46 protected
49 public
54 implementation
56 const
60 type
78 { TPCXFileFormat }
81 begin
93 const
97 var
110 var
113 begin
116 begin
119 begin
120 // RLE data
126 //Inc(Source);
129 end
130 else
131 begin
132 // Uncompressed data
140 begin
144 begin
145 // Read PCX header and store input position (start of image data)
149 // Determine image's data format and find its Imaging equivalent
150 // (using some custom TImageFormat constants)
167 // No compatible Imaging format found, exit
169 Exit;
171 // Get width, height, and output data format (unsupported formats
172 // like ifMono are converted later to ifIndex8)
176 Format := FileDataFormat
177 else
183 begin
184 // other formats use palette embedded to file header
186 begin
194 // Now we determine various data sizes
199 try
201 begin
202 // Image data is compressed -> read and decompress
204 end
205 else
206 begin
207 // Just read uncompressed data
212 begin
213 // RGB and ARGB images are stored in layout different from
214 // Imaging's (and most other file formats'). First there is
215 // Width red values then there is Width green values and so on
219 begin
222 begin
228 begin
237 end
238 else
239 begin
242 begin
247 begin
256 end
258 begin
259 // Just copy 8bit lines
262 end
264 begin
265 // Convert 1bit images to ifIndex8
267 end
269 begin
270 // Convert 2bit images to ifIndex8. Note that 2bit PCX images
271 // usually use (from specs, I've never seen one myself) CGA palette
272 // which is not array of RGB tripplets. So 2bit PCXs are loaded but
273 // their colors would be wrong
275 end
277 begin
278 // 4bit images can be stored similar to RGB images (in four one bit planes)
279 // or like array of nibbles (which is more common)
281 begin
285 begin
292 begin
305 end
307 begin
308 // Convert 4bit images to ifIndex8
310 end
314 begin
315 // 8bit palette is appended at the end of the file
316 // with $0C identifier
317 //Seek(Handle, -769, smFromEnd);
320 begin
323 begin
329 end
330 else
334 finally
342 var
345 begin
348 begin
362 initialization
365 {
366 File Notes:
368 -- TODOS ----------------------------------------------------
369 - nothing now
371 -- 0.21 Changes/Bug Fixes -----------------------------------
372 - Made loader stream-safe - stream position is exactly at the end of the
373 image after loading and file size doesn't need to be know during the process.
374 - Initial TPCXFileFormat class implemented.
376 }