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 X Window Pixmap images. }
30 {$I ImagingOptions.inc}
32 interface
34 uses
38 type
39 { Class for loading X Window Pixmap images known as XPM.
40 It is ASCII-text-based format, basicaly a fragment of C code
41 declaring static array. Loaded image is in ifA8R8G8B8 data format.
42 Loading as well as saving is supported now. }
44 protected
52 public
56 implementation
58 const
63 const
67 const
70 type
72 public
91 { Simple color-string hash table for faster than linear searches
92 during XPM saving. }
94 private
101 public
110 { TSimpleBucketList }
113 begin
118 var
120 begin
127 var
129 begin
135 begin
136 // Skip empty buckets
138 begin
152 var
155 begin
162 begin
165 Break;
170 var
172 begin
175 begin
178 begin
181 else
187 begin
197 var
199 begin
203 {
204 TXPMFileFormat implementation
205 }
208 begin
219 var
225 begin
231 begin
235 begin
243 begin
248 var
250 begin
252 try
259 except
265 var
267 begin
270 Result := pcClear
272 Result := pcBlack
274 Result := pcBlue
276 Result := pcGreen
278 Result := pcAqua
280 Result := pcRed
282 Result := pcFuchsia
284 Result := pcYellow
286 Result := pcWhite
288 Result := pcLtGray
290 Result := pcNavy
292 Result := pcGreen
294 Result := pcTeal
296 Result := pcMaroon
298 Result := pcPurple
300 Result := pcOlive
302 Result := pcMaroon
304 Result := pcOlive
306 Result := pcNavy
308 Result := pcPurple
310 Result := pcTeal
312 Result := pcSilver
314 Result := pcLime
316 Result := pcFuchsia
318 Result := pcAqua
319 else
324 var
329 begin
331 begin
333 // Parse pixel code and color
339 // Convert color from hex number or named constant
341 begin
344 end
345 else
347 // Store code and color in table for later lookup
355 var
359 begin
362 begin
365 begin
366 // Read code and look up color in the palette
370 else
377 begin
381 begin
382 // Look up table for XPM palette entries
386 // Read whole file and assign it to string list
391 // Remove quotes and other stuff
393 begin
397 else
400 // Parse header and create new image
402 Exit;
404 // Read palette entries and assign colors to pixels
405 ParsePalette;
406 ParsePixels;
418 const
420 ColorChars = ' .XoO+@#$%&*=-;:>,<1234567890qwertyuipasdfghjklzxcvbnmMNBVCZASDFGHJKLPIUYTREWQ!~^/()_`''][{}|';
421 var
434 var
436 begin
439 begin
447 var
450 begin
453 begin
457 begin
465 begin
473 try
474 // Put all unique colors of image to table
476 // Compute the character per pixel
480 begin
484 // Assign char id to each color
485 MakeStrIdsForColors;
487 // Start writing XPM file
495 // Write 'colors' part of XPM file
497 begin
501 else
507 // Write pixels - for aech pixel of image find its char id
508 // and append it to line
511 begin
514 begin
526 // Finally save strings to stream and write stream's data to output
527 // (we could directly write lines from list to output, but stream method
528 // takes care of D2009+ Unicode strings).
533 finally
544 begin
549 var
552 begin
555 begin
562 initialization
566 {
567 File Notes:
569 -- TODOS ----------------------------------------------------
570 - nothing now
572 -- 0.26.3 Changes/Bug Fixes -----------------------------------
573 - Added XPM saving.
575 -- 0.25.0 Changes/Bug Fixes -----------------------------------
576 - Added XPM loading.
577 - Unit created.
578 }