1 {
2 Vampyre Imaging Library
3 by Marek Mauder
4 http://imaginglib.sourceforge.net
6 The contents of this file are used with permission, subject to the Mozilla
7 Public License Version 1.1 (the "License"); you may not use this file except
8 in compliance with the License. You may obtain a copy of the License at
9 http://www.mozilla.org/MPL/MPL-1.1.html
11 Software distributed under the License is distributed on an "AS IS" basis,
12 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
13 the specific language governing rights and limitations under the License.
15 Alternatively, the contents of this file may be used under the terms of the
16 GNU Lesser General Public License (the "LGPL License"), in which case the
17 provisions of the LGPL License are applicable instead of those above.
18 If you wish to allow use of your version of this file only under the terms
19 of the LGPL License and not to allow others to use your version of this file
20 under the MPL, indicate your decision by deleting the provisions above and
21 replace them with the notice and other provisions required by the LGPL
22 License. If you do not delete the provisions above, a recipient may use
23 your version of this file under either the MPL or the LGPL License.
25 For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html
26 }
28 { This unit contains image format loader for ZSoft Paintbrush images known as PCX.}
31 {$I ImagingOptions.inc}
33 interface
35 uses
38 type
39 { Class for loading ZSoft Paintbrush images known as PCX. It is old
40 format which can store 1bit, 2bit, 4bit, 8bit, and 24bit (and 32bit but is
41 probably non-standard) images. Only loading is supported (you can still come
42 accross some PCX files) but saving is not (I don't wont this venerable format
43 to spread).}
45 protected
49 public
53 implementation
55 const
59 type
77 { TPCXFileFormat }
80 begin
90 const
94 var
107 var
110 begin
113 begin
116 begin
117 // RLE data
123 //Inc(Source);
126 end
127 else
128 begin
129 // Uncompressed data
137 begin
141 begin
142 // Read PCX header and store input position (start of image data)
146 // Determine image's data format and find its Imaging equivalent
147 // (using some custom TImageFormat constants)
164 // No compatible Imaging format found, exit
166 Exit;
168 // Get width, height, and output data format (unsupported formats
169 // like ifMono are converted later to ifIndex8)
173 Format := FileDataFormat
174 else
180 begin
181 // other formats use palette embedded to file header
183 begin
191 // Now we determine various data sizes
196 try
198 begin
199 // Image data is compressed -> read and decompress
201 end
202 else
203 begin
204 // Just read uncompressed data
209 begin
210 // RGB and ARGB images are stored in layout different from
211 // Imaging's (and most other file formats'). First there is
212 // Width red values then there is Width green values and so on
216 begin
219 begin
225 begin
234 end
235 else
236 begin
239 begin
244 begin
253 end
255 begin
256 // Just copy 8bit lines
259 end
261 begin
262 // Convert 1bit images to ifIndex8
264 end
266 begin
267 // Convert 2bit images to ifIndex8. Note that 2bit PCX images
268 // usually use (from specs, I've never seen one myself) CGA palette
269 // which is not array of RGB tripplets. So 2bit PCXs are loaded but
270 // their colors would be wrong
272 end
274 begin
275 // 4bit images can be stored similar to RGB images (in four one bit planes)
276 // or like array of nibbles (which is more common)
278 begin
282 begin
289 begin
302 end
304 begin
305 // Convert 4bit images to ifIndex8
307 end
311 begin
312 // 8bit palette is appended at the end of the file
313 // with $0C identifier
314 //Seek(Handle, -769, smFromEnd);
317 begin
320 begin
326 end
327 else
331 finally
339 var
342 begin
345 begin
359 initialization
362 {
363 File Notes:
365 -- TODOS ----------------------------------------------------
366 - nothing now
368 -- 0.21 Changes/Bug Fixes -----------------------------------
369 - Made loader stream-safe - stream position is exactly at the end of the
370 image after loading and file size doesn't need to be know during the process.
371 - Initial TPCXFileFormat class implemented.
373 }