wpg.c revision 6a1c5a9375dfad129bc7d6ae8f3eadea60cebe46
13ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
23ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
43ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
53ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                            W   W  PPPP    GGGG                              %
63ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                            W   W  P   P  G                                  %
73ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                            W W W  PPPP   G GGG                              %
83ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                            WW WW  P      G   G                              %
93ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                            W   W  P       GGG                               %
103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                       Read WordPerfect Image Format                         %
133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                              Software Design                                %
153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                              Jaroslav Fojtik                                %
163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                 June 2000                                   %
173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
197e41fe84a841d7b9d7b36b245b65e9dcb3314943cristy%  Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization      %
203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  dedicated to making software imaging solutions freely available.           %
213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  You may not use this file except in compliance with the License.  You may  %
233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  obtain a copy of the License at                                            %
243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    http://www.imagemagick.org/script/license.php                            %
263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  Unless required by applicable law or agreed to in writing, software        %
283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  distributed under the License is distributed on an "AS IS" BASIS,          %
293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   %
303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  See the License for the specific language governing permissions and        %
313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  limitations under the License.                                             %
323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Include declarations.
403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "magick/studio.h"
423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "magick/blob.h"
433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "magick/blob-private.h"
443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "magick/color-private.h"
45e7e40559f0408c5f987aec5c1a51c30b0456509fcristy#include "magick/colormap.h"
46316d51773c093e74e15de805e8bf620d6b56bc8bcristy#include "magick/colormap-private.h"
473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "magick/constitute.h"
483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "magick/exception.h"
493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "magick/exception-private.h"
503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "magick/cache.h"
513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "magick/image.h"
523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "magick/image-private.h"
533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "magick/list.h"
543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "magick/magic.h"
553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "magick/magick.h"
563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "magick/memory_.h"
573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "magick/resource_.h"
583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "magick/quantum-private.h"
593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "magick/shear.h"
603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "magick/static.h"
613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "magick/string_.h"
623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "magick/module.h"
633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "magick/transform.h"
643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "magick/utility.h"
653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
663ed852eea50f9d4cd633efb8c2b054b8e33c253cristytypedef struct
673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy   {
683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy   unsigned char Red;
693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy   unsigned char Blue;
703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy   unsigned char Green;
713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy   } RGB_Record;
723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* Default palette for WPG level 1 */
743ed852eea50f9d4cd633efb8c2b054b8e33c253cristyconst RGB_Record WPG1_Palette[256]={
753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{  0,  0,  0},    {  0,  0,168},
763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{  0,168,  0},    {  0,168,168},
773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{168,  0,  0},    {168,  0,168},
783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{168, 84,  0},    {168,168,168},
793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 84, 84, 84},    { 84, 84,252},
803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 84,252, 84},    { 84,252,252},
813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{252, 84, 84},    {252, 84,252},
823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{252,252, 84},    {252,252,252},  /*16*/
833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{  0,  0,  0},    { 20, 20, 20},
843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 32, 32, 32},    { 44, 44, 44},
853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 56, 56, 56},    { 68, 68, 68},
863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 80, 80, 80},    { 96, 96, 96},
873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{112,112,112},    {128,128,128},
883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{144,144,144},    {160,160,160},
893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{180,180,180},    {200,200,200},
903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{224,224,224},    {252,252,252},  /*32*/
913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{  0,  0,252},    { 64,  0,252},
923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{124,  0,252},    {188,  0,252},
933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{252,  0,252},    {252,  0,188},
943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{252,  0,124},    {252,  0, 64},
953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{252,  0,  0},    {252, 64,  0},
963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{252,124,  0},    {252,188,  0},
973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{252,252,  0},    {188,252,  0},
983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{124,252,  0},    { 64,252,  0},  /*48*/
993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{  0,252,  0},    {  0,252, 64},
1003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{  0,252,124},    {  0,252,188},
1013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{  0,252,252},    {  0,188,252},
1023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{  0,124,252},    {  0, 64,252},
1033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{124,124,252},    {156,124,252},
1043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{188,124,252},    {220,124,252},
1053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{252,124,252},    {252,124,220},
1063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{252,124,188},    {252,124,156},  /*64*/
1073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{252,124,124},    {252,156,124},
1083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{252,188,124},    {252,220,124},
1093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{252,252,124},    {220,252,124},
1103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{188,252,124},    {156,252,124},
1113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{124,252,124},    {124,252,156},
1123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{124,252,188},    {124,252,220},
1133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{124,252,252},    {124,220,252},
1143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{124,188,252},    {124,156,252},  /*80*/
1153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{180,180,252},    {196,180,252},
1163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{216,180,252},    {232,180,252},
1173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{252,180,252},    {252,180,232},
1183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{252,180,216},    {252,180,196},
1193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{252,180,180},    {252,196,180},
1203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{252,216,180},    {252,232,180},
1213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{252,252,180},    {232,252,180},
1223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{216,252,180},    {196,252,180},  /*96*/
1233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{180,220,180},    {180,252,196},
1243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{180,252,216},    {180,252,232},
1253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{180,252,252},    {180,232,252},
1263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{180,216,252},    {180,196,252},
1273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{0,0,112},    {28,0,112},
1283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{56,0,112},    {84,0,112},
1293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{112,0,112},    {112,0,84},
1303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{112,0,56},    {112,0,28},  /*112*/
1313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{112,0,0},    {112,28,0},
1323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{112,56,0},    {112,84,0},
1333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{112,112,0},    {84,112,0},
1343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{56,112,0},    {28,112,0},
1353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{0,112,0},    {0,112,28},
1363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{0,112,56},    {0,112,84},
1373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{0,112,112},    {0,84,112},
1383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{0,56,112},    {0,28,112},   /*128*/
1393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{56,56,112},    {68,56,112},
1403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{84,56,112},    {96,56,112},
1413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{112,56,112},    {112,56,96},
1423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{112,56,84},    {112,56,68},
1433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{112,56,56},    {112,68,56},
1443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{112,84,56},    {112,96,56},
1453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{112,112,56},    {96,112,56},
1463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{84,112,56},    {68,112,56},  /*144*/
1473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{56,112,56},    {56,112,69},
1483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{56,112,84},    {56,112,96},
1493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{56,112,112},    {56,96,112},
1503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{56,84,112},    {56,68,112},
1513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{80,80,112},    {88,80,112},
1523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{96,80,112},    {104,80,112},
1533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{112,80,112},    {112,80,104},
1543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{112,80,96},    {112,80,88},  /*160*/
1553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{112,80,80},    {112,88,80},
1563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{112,96,80},    {112,104,80},
1573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{112,112,80},    {104,112,80},
1583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{96,112,80},    {88,112,80},
1593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{80,112,80},    {80,112,88},
1603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{80,112,96},    {80,112,104},
1613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{80,112,112},    {80,114,112},
1623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{80,96,112},    {80,88,112},  /*176*/
1633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{0,0,64},    {16,0,64},
1643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{32,0,64},    {48,0,64},
1653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{64,0,64},    {64,0,48},
1663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{64,0,32},    {64,0,16},
1673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{64,0,0},    {64,16,0},
1683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{64,32,0},    {64,48,0},
1693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{64,64,0},    {48,64,0},
1703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{32,64,0},    {16,64,0},  /*192*/
1713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{0,64,0},    {0,64,16},
1723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{0,64,32},    {0,64,48},
1733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{0,64,64},    {0,48,64},
1743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{0,32,64},    {0,16,64},
1753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{32,32,64},    {40,32,64},
1763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{48,32,64},    {56,32,64},
1773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{64,32,64},    {64,32,56},
1783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{64,32,48},    {64,32,40},  /*208*/
1793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{64,32,32},    {64,40,32},
1803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{64,48,32},    {64,56,32},
1813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{64,64,32},    {56,64,32},
1823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{48,64,32},    {40,64,32},
1833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{32,64,32},    {32,64,40},
1843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{32,64,48},    {32,64,56},
1853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{32,64,64},    {32,56,64},
1863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{32,48,64},    {32,40,64},  /*224*/
1873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{44,44,64},    {48,44,64},
1883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{52,44,64},    {60,44,64},
1893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{64,44,64},    {64,44,60},
1903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{64,44,52},    {64,44,48},
1913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{64,44,44},    {64,48,44},
1923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{64,52,44},    {64,60,44},
1933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{64,64,44},    {60,64,44},
1943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{52,64,44},    {48,64,44},  /*240*/
1953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{44,64,44},    {44,64,48},
1963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{44,64,52},    {44,64,60},
1973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{44,64,64},    {44,60,64},
1983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{44,55,64},    {44,48,64},
1993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{0,0,0},    {0,0,0},
2003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{0,0,0},    {0,0,0},
2013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{0,0,0},    {0,0,0},
2023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{0,0,0},    {0,0,0}    /*256*/
2033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy};
2043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
2063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
2083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
2093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
2103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   I s W P G                                                                 %
2113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
2123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
2133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
2143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
2163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  IsWPG() returns True if the image format type, identified by the magick
2173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  string, is WPG.
2183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
2193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the IsWPG method is:
2203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
2213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      unsigned int IsWPG(const unsigned char *magick,const size_t length)
2223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
2233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
2243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
2253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o status:  Method IsWPG returns True if the image format type is WPG.
2263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
2273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o magick: compare image format pattern against these bytes.
2283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
2293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o length: Specifies the length of the magick string.
2303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
2313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
2323ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic unsigned int IsWPG(const unsigned char *magick,const size_t length)
2333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
2343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (length < 4)
2353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(MagickFalse);
2363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (memcmp(magick,"\377WPC",4) == 0)
2373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(MagickTrue);
2383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(MagickFalse);
2393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
2403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
242bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristystatic void Rd_WP_DWORD(Image *image,size_t *d)
2433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
2443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned char
2453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    b;
2463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  b=ReadBlobByte(image);
2483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  *d=b;
2493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (b < 0xFFU)
2503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return;
2513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  b=ReadBlobByte(image);
252bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  *d=(size_t) b;
2533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  b=ReadBlobByte(image);
254bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  *d+=(size_t) b*256l;
2553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (*d < 0x8000)
2563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return;
2573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  *d=(*d & 0x7FFF) << 16;
2583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  b=ReadBlobByte(image);
259bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  *d+=(size_t) b;
2603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  b=ReadBlobByte(image);
261bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  *d+=(size_t) b*256l;
2623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return;
2633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
2643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
265bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristystatic void InsertRow(unsigned char *p,ssize_t y,Image *image, int bpp)
2663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
2673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  ExceptionInfo
2683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *exception;
2693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
2713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    bit;
2723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
273bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  ssize_t
2743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    x;
2753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register PixelPacket
2773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *q;
2783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  IndexPacket
2803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    index;
2813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register IndexPacket
2833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *indexes;
2843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  exception=(&image->exception);
2863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  switch (bpp)
2873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
2883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case 1:  /* Convert bitmap scanline. */
2893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
2903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
2913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (q == (PixelPacket *) NULL)
2923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
2933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        indexes=GetAuthenticIndexQueue(image);
294bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy        for (x=0; x < ((ssize_t) image->columns-7); x+=8)
2953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
2963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for (bit=0; bit < 8; bit++)
2973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
2983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                index=((*p) & (0x80 >> bit) ? 0x01 : 0x00);
2994e82e51d7ebce7b4ef0f808d906124dd6f812248cristy                SetIndexPixelComponent(indexes+x+bit,index);
3006a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy                SetRedPixelComponent(q,image->colormap[(int) index].red);
3016a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy                SetGreenPixelComponent(q,image->colormap[(int) index].green);
3026a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy                SetBluePixelComponent(q,image->colormap[(int) index].blue);
3036a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy                q++;
3043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
3053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            p++;
3063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
3073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if ((image->columns % 8) != 0)
3083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
309bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy            for (bit=0; bit < (ssize_t) (image->columns % 8); bit++)
3103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
3113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                index=((*p) & (0x80 >> bit) ? 0x01 : 0x00);
3124e82e51d7ebce7b4ef0f808d906124dd6f812248cristy                SetIndexPixelComponent(indexes+x+bit,index);
3136a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy                SetRedPixelComponent(q,image->colormap[(int) index].red);
3146a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy                SetGreenPixelComponent(q,image->colormap[(int) index].green);
3156a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy                SetBluePixelComponent(q,image->colormap[(int) index].blue);
3166a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy                q++;
3173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
3183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            p++;
3193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
3203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (!SyncAuthenticPixels(image,exception))
3213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
3223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        break;
3233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
3243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case 2:  /* Convert PseudoColor scanline. */
3253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
3263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
3273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (q == (PixelPacket *) NULL)
3283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
3293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        indexes=GetAuthenticIndexQueue(image);
330bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy        for (x=0; x < ((ssize_t) image->columns-1); x+=2)
3313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
3323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            index=ConstrainColormapIndex(image,(*p >> 6) & 0x3);
3336a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy            SetIndexPixelComponent(indexes+x,index);
3346a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy            SetRedPixelComponent(q,image->colormap[(ssize_t) index].red);
3356a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy            SetGreenPixelComponent(q,image->colormap[(ssize_t) index].green);
3366a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy            SetBluePixelComponent(q,image->colormap[(ssize_t) index].blue);
3376a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy            q++;
3383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            index=ConstrainColormapIndex(image,(*p >> 4) & 0x3);
3396a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy            SetIndexPixelComponent(indexes+x,index);
3406a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy            SetRedPixelComponent(q,image->colormap[(ssize_t) index].red);
3416a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy            SetGreenPixelComponent(q,image->colormap[(ssize_t) index].green);
3426a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy            SetBluePixelComponent(q,image->colormap[(ssize_t) index].blue);
3436a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy            q++;
3443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            index=ConstrainColormapIndex(image,(*p >> 2) & 0x3);
3456a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy            SetIndexPixelComponent(indexes+x,index);
3466a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy            SetRedPixelComponent(q,image->colormap[(ssize_t) index].red);
3476a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy            SetGreenPixelComponent(q,image->colormap[(ssize_t) index].green);
3486a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy            SetBluePixelComponent(q,image->colormap[(ssize_t) index].blue);
3496a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy            q++;
3503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            index=ConstrainColormapIndex(image,(*p) & 0x3);
3516a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy            SetIndexPixelComponent(indexes+x+1,index);
3526a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy            SetRedPixelComponent(q,image->colormap[(ssize_t) index].red);
3536a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy            SetGreenPixelComponent(q,image->colormap[(ssize_t) index].green);
3546a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy            SetBluePixelComponent(q,image->colormap[(ssize_t) index].blue);
3553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            p++;
3566a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy            q++;
3573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
3583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy       if ((image->columns % 4) != 0)
3593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
3603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            index=ConstrainColormapIndex(image,(*p >> 6) & 0x3);
3616a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy            SetIndexPixelComponent(indexes+x,index);
3626a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy            SetRedPixelComponent(q,image->colormap[(ssize_t) index].red);
3636a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy            SetGreenPixelComponent(q,image->colormap[(ssize_t) index].green);
3646a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy            SetBluePixelComponent(q,image->colormap[(ssize_t) index].blue);
3656a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy            q++;
3663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            if ((image->columns % 4) >= 1)
3673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
3683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
3693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                index=ConstrainColormapIndex(image,(*p >> 4) & 0x3);
3706a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy                SetIndexPixelComponent(indexes+x,index);
3716a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy                SetRedPixelComponent(q,image->colormap[(ssize_t) index].red);
3726a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy                SetGreenPixelComponent(q,image->colormap[(ssize_t)
3736a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy                  index].green);
3746a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy                SetBluePixelComponent(q,image->colormap[(ssize_t) index].blue);
3756a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy                q++;
3763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                if ((image->columns % 4) >= 2)
3773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
3783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  {
3793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    index=ConstrainColormapIndex(image,(*p >> 2) & 0x3);
3806a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy                    SetIndexPixelComponent(indexes+x,index);
3816a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy                    SetRedPixelComponent(q,image->colormap[(ssize_t)
3826a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy                      index].red);
3836a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy                    SetGreenPixelComponent(q,image->colormap[(ssize_t)
3846a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy                      index].green);
3856a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy                    SetBluePixelComponent(q,image->colormap[(ssize_t)
3866a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy                      index].blue);
3876a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy                    q++;
3883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  }
3893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
3903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            p++;
3913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
3923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (SyncAuthenticPixels(image,exception) == MagickFalse)
3933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
3943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        break;
3953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
3963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
3973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case 4:  /* Convert PseudoColor scanline. */
3983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
3993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
4003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (q == (PixelPacket *) NULL)
4013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
4023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        indexes=GetAuthenticIndexQueue(image);
403bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy        for (x=0; x < ((ssize_t) image->columns-1); x+=2)
4043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
4053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            index=ConstrainColormapIndex(image,(*p >> 4) & 0x0f);
4066a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy            SetIndexPixelComponent(indexes+x,index);
4076a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy            SetRedPixelComponent(q,image->colormap[(ssize_t) index].red);
4086a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy            SetGreenPixelComponent(q,image->colormap[(ssize_t) index].green);
4096a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy            SetBluePixelComponent(q,image->colormap[(ssize_t) index].blue);
4106a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy            q++;
4113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            index=ConstrainColormapIndex(image,(*p) & 0x0f);
4126a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy            SetIndexPixelComponent(indexes+x+1,index);
4136a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy            SetRedPixelComponent(q,image->colormap[(ssize_t) index].red);
4146a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy            SetGreenPixelComponent(q,image->colormap[(ssize_t) index].green);
4156a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy            SetBluePixelComponent(q,image->colormap[(ssize_t) index].blue);
4163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            p++;
4176a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy            q++;
4183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
4193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if ((image->columns % 2) != 0)
4203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
4213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            index=ConstrainColormapIndex(image,(*p >> 4) & 0x0f);
4226a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy            SetIndexPixelComponent(indexes+x,index);
4236a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy            SetRedPixelComponent(q,image->colormap[(ssize_t) index].red);
4246a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy            SetGreenPixelComponent(q,image->colormap[(ssize_t) index].green);
4256a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy            SetBluePixelComponent(q,image->colormap[(ssize_t) index].blue);
4263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            p++;
4276a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy            q++;
4283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
4293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (SyncAuthenticPixels(image,exception) == MagickFalse)
4303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
4313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        break;
4323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
4333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case 8: /* Convert PseudoColor scanline. */
4343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
4353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
4363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (q == (PixelPacket *) NULL) break;
4373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        indexes=GetAuthenticIndexQueue(image);
4383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
439bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy        for (x=0; x < (ssize_t) image->columns; x++)
4403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
4413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            index=ConstrainColormapIndex(image,*p);
4426a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy            SetIndexPixelComponent(indexes+x,index);
4436a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy            SetRedPixelComponent(q,image->colormap[(ssize_t) index].red);
4446a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy            SetGreenPixelComponent(q,image->colormap[(ssize_t) index].green);
4456a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy            SetBluePixelComponent(q,image->colormap[(ssize_t) index].blue);
4463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            p++;
4476a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy            q++;
4483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
4493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (SyncAuthenticPixels(image,exception) == MagickFalse)
4503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
4513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
4523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
4533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
4543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case 24:     /*  Convert DirectColor scanline.  */
4553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
4563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (q == (PixelPacket *) NULL)
4573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        break;
458bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy      for (x=0; x < (ssize_t) image->columns; x++)
4593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
4605fde9aa7d6fc3d8aee731855a35463fca177c217cristy          SetRedPixelComponent(q,ScaleCharToQuantum(*p++));
4615fde9aa7d6fc3d8aee731855a35463fca177c217cristy          SetGreenPixelComponent(q,ScaleCharToQuantum(*p++));
4625fde9aa7d6fc3d8aee731855a35463fca177c217cristy          SetBluePixelComponent(q,ScaleCharToQuantum(*p++));
4633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          q++;
4643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
4653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (!SyncAuthenticPixels(image,exception))
4663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        break;
4673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
4683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
4693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
4703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
4713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
4723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* Helper for WPG1 raster reader. */
4733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define InsertByte(b) \
4743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ \
4753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  BImgBuff[x]=b; \
4763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  x++; \
477bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  if((ssize_t) x>=ldblk) \
4783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  { \
479bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy    InsertRow(BImgBuff,(ssize_t) y,image,bpp); \
4803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    x=0; \
4813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    y++; \
4823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    } \
4833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
4843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* WPG1 raster reader. */
4853ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic int UnpackWPGRaster(Image *image,int bpp)
4863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
4873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
4883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    x,
4893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    y,
4903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    i;
4913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
4923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned char
4933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    bbuf,
4943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *BImgBuff,
4953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    RunCount;
4963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
497bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  ssize_t
4983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    ldblk;
4993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
5003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  x=0;
5013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  y=0;
5023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
503bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  ldblk=(ssize_t) ((bpp*image->columns+7)/8);
5043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  BImgBuff=(unsigned char *) AcquireQuantumMemory((size_t) ldblk,
5053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    sizeof(*BImgBuff));
5063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if(BImgBuff==NULL) return(-2);
5073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
508bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  while(y<(ssize_t) image->rows)
5093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
5103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      bbuf=ReadBlobByte(image);
5113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
5123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      RunCount=bbuf & 0x7F;
5133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if(bbuf & 0x80)
5143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
5153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if(RunCount)  /* repeat next byte runcount * */
5163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
5173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              bbuf=ReadBlobByte(image);
5183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              for(i=0;i<(int) RunCount;i++) InsertByte(bbuf);
5193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
5203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          else {  /* read next byte as RunCount; repeat 0xFF runcount* */
5213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            RunCount=ReadBlobByte(image);
5223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for(i=0;i<(int) RunCount;i++) InsertByte(0xFF);
5233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
5243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
5253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      else {
5263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if(RunCount)   /* next runcount byte are readed directly */
5273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
5283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for(i=0;i < (int) RunCount;i++)
5293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
5303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                bbuf=ReadBlobByte(image);
5313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                InsertByte(bbuf);
5323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
5333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
5343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        else {  /* repeat previous line runcount* */
5353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          RunCount=ReadBlobByte(image);
5363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if(x) {    /* attempt to duplicate row from x position: */
5373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            /* I do not know what to do here */
5383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            BImgBuff=(unsigned char *) RelinquishMagickMemory(BImgBuff);
5393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            return(-3);
5403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
5413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for(i=0;i < (int) RunCount;i++)
5423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
5433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              x=0;
5443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              y++;    /* Here I need to duplicate previous row RUNCOUNT* */
5453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              if(y<2) continue;
546bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy              if(y>(ssize_t) image->rows)
5473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
5483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  BImgBuff=(unsigned char *) RelinquishMagickMemory(BImgBuff);
5493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  return(-4);
5503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
5513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              InsertRow(BImgBuff,y-1,image,bpp);
5523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
5533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
5543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
5553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
5563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  BImgBuff=(unsigned char *) RelinquishMagickMemory(BImgBuff);
5573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(0);
5583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
5593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
5603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
5613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* Helper for WPG2 reader. */
5623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define InsertByte6(b) \
5633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ \
5643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if(XorMe)\
5653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    BImgBuff[x] = (unsigned char)~b;\
5663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else\
5673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    BImgBuff[x] = b;\
5683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  x++; \
569bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  if((ssize_t) x >= ldblk) \
5703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  { \
571bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy    InsertRow(BImgBuff,(ssize_t) y,image,bpp); \
5723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    x=0; \
5733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    y++; \
5743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy   } \
5753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
5763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* WPG2 raster reader. */
5773ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic int UnpackWPG2Raster(Image *image,int bpp)
5783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
5796a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy  size_t
5806a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy    x,
5816a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy    y;
5826a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy
5836a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy  ssize_t
5846a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy    ldblk;
5856a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy
5866a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy  int XorMe = 0;
5876a1c5a9375dfad129bc7d6ae8f3eadea60cebe46cristy
5883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned int
5893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    SampleSize=1;
5903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
5913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned char
5923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    bbuf,
5933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *BImgBuff,
5943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    RunCount,
5953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    SampleBuffer[8];
5963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
5973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned int
5983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    i;
5993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
6003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  x=0;
6013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  y=0;
602bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  ldblk=(ssize_t) ((bpp*image->columns+7)/8);
6033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  BImgBuff=(unsigned char *) AcquireQuantumMemory((size_t) ldblk,
6043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    sizeof(*BImgBuff));
6053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if(BImgBuff==NULL)
6063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(-2);
6073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
6083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  while( y< image->rows)
6093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
6103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      bbuf=ReadBlobByte(image);
6113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
6123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      switch(bbuf)
6133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
6143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 0x7D:
6153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          SampleSize=ReadBlobByte(image);  /* DSZ */
6163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if(SampleSize>8)
6173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            return(-2);
6183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if(SampleSize<1)
6193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            return(-2);
6203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
6213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 0x7E:
6223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (void) fprintf(stderr,"\nUnsupported WPG token XOR, please report!");
6233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    XorMe=!XorMe;
6243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
6253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 0x7F:
6263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          RunCount=ReadBlobByte(image);   /* BLK */
6273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for(i=0; i < SampleSize*(RunCount+1); i++)
6283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
6293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              InsertByte6(0);
6303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
6313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
6323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 0xFD:
6333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    RunCount=ReadBlobByte(image);   /* EXT */
6343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    for(i=0; i<= RunCount;i++)
6353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for(bbuf=0; bbuf < SampleSize; bbuf++)
6363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              InsertByte6(SampleBuffer[bbuf]);
6373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
6383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 0xFE:
6393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          RunCount=ReadBlobByte(image);  /* RST */
6403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if(x!=0)
6413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
6423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (void) fprintf(stderr,
643e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy                             "\nUnsupported WPG2 unaligned token RST x=%.20g, please report!\n"
644e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy                             ,(double) x);
6453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              return(-3);
6463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
6473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
6483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            /* duplicate the previous row RunCount x */
6493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for(i=0;i<=RunCount;i++)
6503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
651bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy                InsertRow(BImgBuff,(ssize_t) (image->rows >= y ? y : image->rows-1),
6523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                          image,bpp);
6533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                y++;
6543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
6553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
6563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
6573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 0xFF:
6583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          RunCount=ReadBlobByte(image);   /* WHT */
6593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for(i=0; i < SampleSize*(RunCount+1); i++)
6603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
6613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              InsertByte6(0xFF);
6623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
6633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
6643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        default:
6653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          RunCount=bbuf & 0x7F;
6663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
6673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if(bbuf & 0x80)     /* REP */
6683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
6693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              for(i=0; i < SampleSize; i++)
6703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                SampleBuffer[i]=ReadBlobByte(image);
6713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              for(i=0;i<=RunCount;i++)
6723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                for(bbuf=0;bbuf<SampleSize;bbuf++)
6733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  InsertByte6(SampleBuffer[bbuf]);
6743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
6753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          else {      /* NRP */
6763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for(i=0; i< SampleSize*(RunCount+1);i++)
6773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
6783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                bbuf=ReadBlobByte(image);
6793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                InsertByte6(bbuf);
6803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
6813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
6823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
6833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
6843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  BImgBuff=(unsigned char *) RelinquishMagickMemory(BImgBuff);
6853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(0);
6863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
6873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
6883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
6893ed852eea50f9d4cd633efb8c2b054b8e33c253cristytypedef float tCTM[3][3];
6903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
6913ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic unsigned LoadWPG2Flags(Image *image,char Precision,float *Angle,tCTM *CTM)
6923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
6933ed852eea50f9d4cd633efb8c2b054b8e33c253cristyconst unsigned char TPR=1,TRN=2,SKW=4,SCL=8,ROT=0x10,OID=0x20,LCK=0x80;
694bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristyssize_t x;
6953ed852eea50f9d4cd633efb8c2b054b8e33c253cristyunsigned DenX;
6963ed852eea50f9d4cd633efb8c2b054b8e33c253cristyunsigned Flags;
6973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
6983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) memset(*CTM,0,sizeof(*CTM));     /*CTM.erase();CTM.resize(3,3);*/
6993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (*CTM)[0][0]=1;
7003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (*CTM)[1][1]=1;
7013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (*CTM)[2][2]=1;
7023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Flags=ReadBlobLSBShort(image);
7043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if(Flags & LCK) x=ReadBlobLSBLong(image);  /*Edit lock*/
7053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if(Flags & OID)
7063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
7073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if(Precision==0)
7083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {x=ReadBlobLSBShort(image);}  /*ObjectID*/
7093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
7103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {x=ReadBlobLSBLong(image);}  /*ObjectID (Double precision)*/
7113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
7123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if(Flags & ROT)
7133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
7143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  x=ReadBlobLSBLong(image);  /*Rot Angle*/
7153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if(Angle) *Angle=x/65536.0;
7163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
7173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if(Flags & (ROT|SCL))
7183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
7193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  x=ReadBlobLSBLong(image);  /*Sx*cos()*/
7203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (*CTM)[0][0] = (float)x/0x10000;
7213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  x=ReadBlobLSBLong(image);  /*Sy*cos()*/
7223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (*CTM)[1][1] = (float)x/0x10000;
7233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
7243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if(Flags & (ROT|SKW))
7253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
7263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  x=ReadBlobLSBLong(image);       /*Kx*sin()*/
7273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (*CTM)[1][0] = (float)x/0x10000;
7283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  x=ReadBlobLSBLong(image);       /*Ky*sin()*/
7293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (*CTM)[0][1] = (float)x/0x10000;
7303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
7313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if(Flags & TRN)
7323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
7333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  x=ReadBlobLSBLong(image); DenX=ReadBlobLSBShort(image);  /*Tx*/
7343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if(x>=0) (*CTM)[0][2] = (float)x+(float)DenX/0x10000;
7353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            else (*CTM)[0][2] = (float)x-(float)DenX/0x10000;
7363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  x=ReadBlobLSBLong(image); DenX=ReadBlobLSBShort(image);  /*Ty*/
7373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (*CTM)[1][2]=(float)x + ((x>=0)?1:-1)*(float)DenX/0x10000;
7383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if(x>=0) (*CTM)[1][2] = (float)x+(float)DenX/0x10000;
7393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            else (*CTM)[1][2] = (float)x-(float)DenX/0x10000;
7403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
7413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if(Flags & TPR)
7423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
7433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  x=ReadBlobLSBShort(image); DenX=ReadBlobLSBShort(image);  /*Px*/
7443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (*CTM)[2][0] = x + (float)DenX/0x10000;;
7453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  x=ReadBlobLSBShort(image);  DenX=ReadBlobLSBShort(image); /*Py*/
7463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (*CTM)[2][1] = x + (float)DenX/0x10000;
7473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
7483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(Flags);
7493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
7503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7523ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic Image *ExtractPostscript(Image *image,const ImageInfo *image_info,
753bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  MagickOffsetType PS_Offset,ssize_t PS_Size,ExceptionInfo *exception)
7543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
7553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  char
7563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    postscript_file[MaxTextExtent];
7573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const MagicInfo
7593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *magic_info;
7603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  FILE
7623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *ps_file;
7633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  ImageInfo
7653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *clone_info;
7663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Image
7683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *image2;
7693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned char
7713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    magick[2*MaxTextExtent];
7723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((clone_info=CloneImageInfo(image_info)) == NULL)
7753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(image);
7763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  clone_info->blob=(void *) NULL;
7773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  clone_info->length=0;
7783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /* Obtain temporary file */
7803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  AcquireUniqueFilename(postscript_file);
7813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  ps_file=OpenMagickStream(postscript_file,"wb");
7823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (ps_file == (FILE *) NULL)
7833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    goto FINISH;
7843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /* Copy postscript to temporary file */
7863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) SeekBlob(image,PS_Offset,SEEK_SET);
7873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) ReadBlob(image, 2*MaxTextExtent, magick);
7883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) SeekBlob(image,PS_Offset,SEEK_SET);
7903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  while(PS_Size-- > 0)
7913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
7923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) fputc(ReadBlobByte(image),ps_file);
7933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
7943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) fclose(ps_file);
7953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    /* Detect file format - Check magic.mgk configuration file. */
7973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  magic_info=GetMagicInfo(magick,2*MaxTextExtent,exception);
7983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if(magic_info == (const MagicInfo *) NULL) goto FINISH_UNL;
7993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*     printf("Detected:%s  \n",magic_info->name); */
8003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if(exception->severity != UndefinedException) goto FINISH_UNL;
8013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if(magic_info->name == (char *) NULL) goto FINISH_UNL;
8023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
8033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) CopyMagickMemory(clone_info->magick,magic_info->name,MaxTextExtent);
8043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
8053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    /* Read nested image */
80653a8bc9b0c80f3027e032dcd8e77d8987c53bd6fcristy  /*FormatString(clone_info->filename,"%s:%s",magic_info->name,postscript_file);*/
80753a8bc9b0c80f3027e032dcd8e77d8987c53bd6fcristy  FormatMagickString(clone_info->filename,MaxTextExtent,"%s",postscript_file);
8083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  image2=ReadImage(clone_info,exception);
8093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
8103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (!image2)
8113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    goto FINISH_UNL;
8123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
8133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
8143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Replace current image with new image while copying base image
8153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    attributes.
8163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
8173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) CopyMagickMemory(image2->filename,image->filename,MaxTextExtent);
8183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) CopyMagickMemory(image2->magick_filename,image->magick_filename,MaxTextExtent);
8193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) CopyMagickMemory(image2->magick,image->magick,MaxTextExtent);
8203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  image2->depth=image->depth;
8213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  DestroyBlob(image2);
8223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  image2->blob=ReferenceBlob(image->blob);
8233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
8243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((image->rows == 0) || (image->columns == 0))
8253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    DeleteImageFromList(&image);
8263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
8273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  AppendImageToList(&image,image2);
8283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
8293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy FINISH_UNL:
8303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) RelinquishUniqueFileResource(postscript_file);
8313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy FINISH:
8323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  DestroyImageInfo(clone_info);
8333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(image);
8343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
8353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
8363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
8373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
8393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
8403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
8413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   R e a d W P G I m a g e                                                   %
8423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
8433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
8443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
8453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  Method ReadWPGImage reads an WPG X image file and returns it.  It
8483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  allocates the memory necessary for the new Image structure and returns a
8493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  pointer to the new image.
8503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the ReadWPGImage method is:
8523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    Image *ReadWPGImage(const ImageInfo *image_info,ExceptionInfo *exception)
8543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
8563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o image:  Method ReadWPGImage returns a pointer to the image after
8583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      reading. A null image is returned if there is a memory shortage or if
8593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      the image cannot be read.
8603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o image_info: Specifies a pointer to a ImageInfo structure.
8623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o exception: return any errors or warnings in this structure.
8643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
8663ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic Image *ReadWPGImage(const ImageInfo *image_info,
8673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  ExceptionInfo *exception)
8683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
8693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  typedef struct
8703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
871bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy    size_t FileId;
8723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    MagickOffsetType DataOffset;
8733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    unsigned int ProductType;
8743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    unsigned int FileType;
8753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    unsigned char MajorVersion;
8763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    unsigned char MinorVersion;
8773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    unsigned int EncryptKey;
8783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    unsigned int Reserved;
8793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  } WPGHeader;
8803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
8813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  typedef struct
8823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
8833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    unsigned char RecType;
884bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy    size_t RecordLength;
8853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  } WPGRecord;
8863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
8873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  typedef struct
8883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
8893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    unsigned char Class;
8903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    unsigned char RecType;
891bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy    size_t Extension;
892bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy    size_t RecordLength;
8933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  } WPG2Record;
8943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
8953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  typedef struct
8963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
8973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    unsigned  HorizontalUnits;
8983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    unsigned  VerticalUnits;
8993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    unsigned char PosSizePrecision;
9003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  } WPG2Start;
9013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
9023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  typedef struct
9033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
9043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    unsigned int Width;
9053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    unsigned int Heigth;
9063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    unsigned int Depth;
9073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    unsigned int HorzRes;
9083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    unsigned int VertRes;
9093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  } WPGBitmapType1;
9103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
9113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  typedef struct
9123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
9133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    unsigned int Width;
9143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    unsigned int Heigth;
9153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    unsigned char Depth;
9163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    unsigned char Compression;
9173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  } WPG2BitmapType1;
9183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
9193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  typedef struct
9203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
9213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    unsigned int RotAngle;
9223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    unsigned int LowLeftX;
9233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    unsigned int LowLeftY;
9243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    unsigned int UpRightX;
9253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    unsigned int UpRightY;
9263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    unsigned int Width;
9273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    unsigned int Heigth;
9283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    unsigned int Depth;
9293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    unsigned int HorzRes;
9303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    unsigned int VertRes;
9313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  } WPGBitmapType2;
9323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
9333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  typedef struct
9343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
9353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    unsigned int StartIndex;
9363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    unsigned int NumOfEntries;
9373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  } WPGColorMapRec;
9383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
9393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  typedef struct {
940bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy    size_t PS_unknown1;
9413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    unsigned int PS_unknown2;
9423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    unsigned int PS_unknown3;
9433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  } WPGPSl1Record;
9443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
9453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Image
9463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *image,
9473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *rotated_image;
9483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
9493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned int
9503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status;
9513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
9523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  WPGHeader
9533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Header;
9543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
9553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  WPGRecord
9563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Rec;
9573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
9583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  WPG2Record
9593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Rec2;
9603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
9613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  WPG2Start StartWPG;
9623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
9633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  WPGBitmapType1
9643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    BitmapHeader1;
9653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
9663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  WPG2BitmapType1
9673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Bitmap2Header1;
9683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
9693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  WPGBitmapType2
9703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    BitmapHeader2;
9713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
9723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  WPGColorMapRec
9733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    WPG_Palette;
9743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
9753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
9763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    i,
9773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    bpp,
9783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    WPG2Flags;
9793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
980bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  ssize_t
9813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    ldblk;
9823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
983eaedf06777741da32408da72c1e512975c600c48cristy  size_t
984eaedf06777741da32408da72c1e512975c600c48cristy    one;
985eaedf06777741da32408da72c1e512975c600c48cristy
9863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned char
9873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *BImgBuff;
9883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
9893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  tCTM CTM;         /*current transform matrix*/
9903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
9913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
9923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Open image file.
9933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
9943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(image_info != (const ImageInfo *) NULL);
9953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(image_info->signature == MagickSignature);
9963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(exception != (ExceptionInfo *) NULL);
9973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(exception->signature == MagickSignature);
998eaedf06777741da32408da72c1e512975c600c48cristy  one=1;
9993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  image=AcquireImage(image_info);
10003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  image->depth=8;
10013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
10023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (status == MagickFalse)
10033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
10043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      image=DestroyImageList(image);
10053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return((Image *) NULL);
10063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
10073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
10083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Read WPG image.
10093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
10103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Header.FileId=ReadBlobLSBLong(image);
10113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Header.DataOffset=(MagickOffsetType) ReadBlobLSBLong(image);
10123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Header.ProductType=ReadBlobLSBShort(image);
10133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Header.FileType=ReadBlobLSBShort(image);
10143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Header.MajorVersion=ReadBlobByte(image);
10153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Header.MinorVersion=ReadBlobByte(image);
10163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Header.EncryptKey=ReadBlobLSBShort(image);
10173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Header.Reserved=ReadBlobLSBShort(image);
10183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (Header.FileId!=0x435057FF || (Header.ProductType>>8)!=0x16)
10203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    ThrowReaderException(CorruptImageError,"ImproperImageHeader");
10213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (Header.EncryptKey!=0)
10223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    ThrowReaderException(CoderError,"EncryptedWPGImageFileNotSupported");
10233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  image->columns = 1;
10253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  image->rows = 1;
10263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  image->colors = 0;
10273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  bpp=0;
10283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  BitmapHeader2.RotAngle=0;
10293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  switch(Header.FileType)
10313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
10323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case 1:     /* WPG level 1 */
10333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      while(!EOFBlob(image)) /* object parser loop */
10343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
10353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (void) SeekBlob(image,Header.DataOffset,SEEK_SET);
10363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if(EOFBlob(image))
10373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            break;
10383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          Rec.RecType=(i=ReadBlobByte(image));
10403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if(i==EOF)
10413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            break;
10423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          Rd_WP_DWORD(image,&Rec.RecordLength);
10433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if(EOFBlob(image))
10443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            break;
10453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          Header.DataOffset=TellBlob(image)+Rec.RecordLength;
10473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          switch(Rec.RecType)
10493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
10503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            case 0x0B: /* bitmap type 1 */
10513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              BitmapHeader1.Width=ReadBlobLSBShort(image);
10523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              BitmapHeader1.Heigth=ReadBlobLSBShort(image);
10533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              BitmapHeader1.Depth=ReadBlobLSBShort(image);
10543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              BitmapHeader1.HorzRes=ReadBlobLSBShort(image);
10553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              BitmapHeader1.VertRes=ReadBlobLSBShort(image);
10563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              if(BitmapHeader1.HorzRes && BitmapHeader1.VertRes)
10583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
10593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  image->units=PixelsPerCentimeterResolution;
10603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  image->x_resolution=BitmapHeader1.HorzRes/470.0;
10613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  image->y_resolution=BitmapHeader1.VertRes/470.0;
10623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
10633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              image->columns=BitmapHeader1.Width;
10643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              image->rows=BitmapHeader1.Heigth;
10653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              bpp=BitmapHeader1.Depth;
10663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              goto UnpackRaster;
10683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            case 0x0E:  /*Color palette */
10703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              WPG_Palette.StartIndex=ReadBlobLSBShort(image);
10713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              WPG_Palette.NumOfEntries=ReadBlobLSBShort(image);
10723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              image->colors=WPG_Palette.NumOfEntries;
10743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              if (!AcquireImageColormap(image,image->colors))
10753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                goto NoMemory;
10763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              for (i=WPG_Palette.StartIndex;
10773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                   i < (int)WPG_Palette.NumOfEntries; i++)
10783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
10793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  image->colormap[i].red=ScaleCharToQuantum((unsigned char)
10803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    ReadBlobByte(image));
10813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  image->colormap[i].green=ScaleCharToQuantum((unsigned char)
10823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    ReadBlobByte(image));
10833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  image->colormap[i].blue=ScaleCharToQuantum((unsigned char)
10843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    ReadBlobByte(image));
10853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
10863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
10873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            case 0x11:  /* Start PS l1 */
10893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              if(Rec.RecordLength > 8)
10903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                image=ExtractPostscript(image,image_info,
10913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  TellBlob(image)+8,   /* skip PS header in the wpg */
1092bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy                  (ssize_t) Rec.RecordLength-8,exception);
10933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
10943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            case 0x14:  /* bitmap type 2 */
10963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              BitmapHeader2.RotAngle=ReadBlobLSBShort(image);
10973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              BitmapHeader2.LowLeftX=ReadBlobLSBShort(image);
10983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              BitmapHeader2.LowLeftY=ReadBlobLSBShort(image);
10993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              BitmapHeader2.UpRightX=ReadBlobLSBShort(image);
11003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              BitmapHeader2.UpRightY=ReadBlobLSBShort(image);
11013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              BitmapHeader2.Width=ReadBlobLSBShort(image);
11023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              BitmapHeader2.Heigth=ReadBlobLSBShort(image);
11033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              BitmapHeader2.Depth=ReadBlobLSBShort(image);
11043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              BitmapHeader2.HorzRes=ReadBlobLSBShort(image);
11053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              BitmapHeader2.VertRes=ReadBlobLSBShort(image);
11063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
11073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              image->units=PixelsPerCentimeterResolution;
11083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              image->page.width=(unsigned int)
11093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                ((BitmapHeader2.LowLeftX-BitmapHeader2.UpRightX)/470.0);
11103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              image->page.height=(unsigned int)
11113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                ((BitmapHeader2.LowLeftX-BitmapHeader2.UpRightY)/470.0);
11123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              image->page.x=(int) (BitmapHeader2.LowLeftX/470.0);
11133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              image->page.y=(int) (BitmapHeader2.LowLeftX/470.0);
11143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              if(BitmapHeader2.HorzRes && BitmapHeader2.VertRes)
11153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
11163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  image->x_resolution=BitmapHeader2.HorzRes/470.0;
11173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  image->y_resolution=BitmapHeader2.VertRes/470.0;
11183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
11193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              image->columns=BitmapHeader2.Width;
11203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              image->rows=BitmapHeader2.Heigth;
11213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              bpp=BitmapHeader2.Depth;
11223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
11233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            UnpackRaster:
11243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              if ((image->colors == 0) && (bpp != 24))
11253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
1126eaedf06777741da32408da72c1e512975c600c48cristy                  image->colors=one << bpp;
11273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  if (!AcquireImageColormap(image,image->colors))
11283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    {
11293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    NoMemory:
11303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      ThrowReaderException(ResourceLimitError,
11313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                        "MemoryAllocationFailed");
11323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    }
11333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  /* printf("Load default colormap \n"); */
11343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  for (i=0; (i < (int) image->colors) && (i < 256); i++)
11353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    {
11363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      image->colormap[i].red=ScaleCharToQuantum(WPG1_Palette[i].Red);
11373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      image->colormap[i].green=ScaleCharToQuantum(WPG1_Palette[i].Green);
11383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      image->colormap[i].blue=ScaleCharToQuantum(WPG1_Palette[i].Blue);
11393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    }
11403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
11413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              else
11423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
11433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  if (bpp < 24)
1144eaedf06777741da32408da72c1e512975c600c48cristy                    if ( (image->colors < (one << bpp)) && (bpp != 24) )
11453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      image->colormap=(PixelPacket *) ResizeQuantumMemory(
1146eaedf06777741da32408da72c1e512975c600c48cristy                        image->colormap,(size_t) (one << bpp),
11473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                        sizeof(*image->colormap));
11483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
11493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
11503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              if (bpp == 1)
11513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
11523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  if(image->colormap[0].red==0 &&
11533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                     image->colormap[0].green==0 &&
11543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                     image->colormap[0].blue==0 &&
11553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                     image->colormap[1].red==0 &&
11563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                     image->colormap[1].green==0 &&
11573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                     image->colormap[1].blue==0)
11583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    {  /* fix crippled monochrome palette */
11593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      image->colormap[1].red =
11603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                        image->colormap[1].green =
11613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                        image->colormap[1].blue = QuantumRange;
11623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    }
11633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
11643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
11653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              if(UnpackWPGRaster(image,bpp) < 0)
11663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                /* The raster cannot be unpacked */
11673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
11683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                DecompressionFailed:
11693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  ThrowReaderException(CoderError,"UnableToDecompressImage");
11703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    }
11713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
11723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              if(Rec.RecType==0x14 && BitmapHeader2.RotAngle!=0 && !image_info->ping)
11733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
11743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  /* flop command */
11753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  if(BitmapHeader2.RotAngle & 0x8000)
11763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    {
11773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      rotated_image = FlopImage(image, exception);
11783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      rotated_image->blob = image->blob;
11793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      DuplicateBlob(rotated_image,image);
11803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      (void) RemoveLastImageFromList(&image);
11813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      AppendImageToList(&image,rotated_image);
11823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    }
11833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  /* flip command */
11843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  if(BitmapHeader2.RotAngle & 0x2000)
11853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    {
11863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      rotated_image = FlipImage(image, exception);
11873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      rotated_image->blob = image->blob;
11883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      DuplicateBlob(rotated_image,image);
11893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      (void) RemoveLastImageFromList(&image);
11903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      AppendImageToList(&image,rotated_image);
11913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    }
11923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
11933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /* rotate command */
11943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  if(BitmapHeader2.RotAngle & 0x0FFF)
11953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    {
11963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      rotated_image = RotateImage(image, (BitmapHeader2.RotAngle & 0x0FFF), exception);
11973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      rotated_image->blob = image->blob;
11983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      DuplicateBlob(rotated_image,image);
11993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      (void) RemoveLastImageFromList(&image);
12003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      AppendImageToList(&image,rotated_image);
12013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    }
12023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
12033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
12043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              /* Allocate next image structure. */
12053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              AcquireNextImage(image_info,image);
12063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              image->depth=8;
12073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              if (image->next == (Image *) NULL)
12083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                goto Finish;
12093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              image=SyncNextImageInList(image);
12103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              image->columns=image->rows=0;
12113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              image->colors=0;
12123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
12133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
12143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            case 0x1B:  /* Postscript l2 */
12153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              if(Rec.RecordLength>0x3C)
12163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                image=ExtractPostscript(image,image_info,
12173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  TellBlob(image)+0x3C,   /* skip PS l2 header in the wpg */
1218bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy                  (ssize_t) Rec.RecordLength-0x3C,exception);
12193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
12203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
12213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
12223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
12233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
12243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case 2:  /* WPG level 2 */
12253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) memset(CTM,0,sizeof(CTM));
12263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      StartWPG.PosSizePrecision = 0;
12273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      while(!EOFBlob(image)) /* object parser loop */
12283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
12293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (void) SeekBlob(image,Header.DataOffset,SEEK_SET);
12303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if(EOFBlob(image))
12313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            break;
12323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
12333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          Rec2.Class=(i=ReadBlobByte(image));
12343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if(i==EOF)
12353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            break;
12363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          Rec2.RecType=(i=ReadBlobByte(image));
12373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if(i==EOF)
12383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            break;
12393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          Rd_WP_DWORD(image,&Rec2.Extension);
12403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          Rd_WP_DWORD(image,&Rec2.RecordLength);
12413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if(EOFBlob(image))
12423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            break;
12433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
12443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          Header.DataOffset=TellBlob(image)+Rec2.RecordLength;
12453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
12463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          switch(Rec2.RecType)
12473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
12483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      case 1:
12493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              StartWPG.HorizontalUnits=ReadBlobLSBShort(image);
12503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              StartWPG.VerticalUnits=ReadBlobLSBShort(image);
12513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              StartWPG.PosSizePrecision=ReadBlobByte(image);
12523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
12533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            case 0x0C:    /* Color palette */
12543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              WPG_Palette.StartIndex=ReadBlobLSBShort(image);
12553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              WPG_Palette.NumOfEntries=ReadBlobLSBShort(image);
12563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
12573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              image->colors=WPG_Palette.NumOfEntries;
12583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              if (AcquireImageColormap(image,image->colors) == MagickFalse)
12593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                ThrowReaderException(ResourceLimitError,
12603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  "MemoryAllocationFailed");
12613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              for (i=WPG_Palette.StartIndex;
12623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                   i < (int)WPG_Palette.NumOfEntries; i++)
12633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
12643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  image->colormap[i].red=ScaleCharToQuantum((char)
12653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    ReadBlobByte(image));
12663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  image->colormap[i].green=ScaleCharToQuantum((char)
12673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    ReadBlobByte(image));
12683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  image->colormap[i].blue=ScaleCharToQuantum((char)
12693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    ReadBlobByte(image));
12703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  (void) ReadBlobByte(image);   /*Opacity??*/
12713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
12723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
12733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            case 0x0E:
12743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              Bitmap2Header1.Width=ReadBlobLSBShort(image);
12753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              Bitmap2Header1.Heigth=ReadBlobLSBShort(image);
12763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              Bitmap2Header1.Depth=ReadBlobByte(image);
12773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              Bitmap2Header1.Compression=ReadBlobByte(image);
12783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
12793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              if(Bitmap2Header1.Compression > 1)
12803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                continue; /*Unknown compression method */
12813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              switch(Bitmap2Header1.Depth)
12823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
12833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 1:
12843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  bpp=1;
12853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
12863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 2:
12873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  bpp=2;
12883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
12893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 3:
12903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  bpp=4;
12913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
12923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 4:
12933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  bpp=8;
12943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
12953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 8:
12963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  bpp=24;
12973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
12983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                default:
12993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  continue;  /*Ignore raster with unknown depth*/
13003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
13013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              image->columns=Bitmap2Header1.Width;
13023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              image->rows=Bitmap2Header1.Heigth;
13033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
13043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              if ((image->colors == 0) && (bpp != 24))
13053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
13060b29b25525c4612c77b1b3c8abcc40685d0aa33fcristy                  size_t
13070b29b25525c4612c77b1b3c8abcc40685d0aa33fcristy                    one;
13080b29b25525c4612c77b1b3c8abcc40685d0aa33fcristy
13090b29b25525c4612c77b1b3c8abcc40685d0aa33fcristy                  one=1;
13100b29b25525c4612c77b1b3c8abcc40685d0aa33fcristy                  image->colors=one << bpp;
13113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  if (!AcquireImageColormap(image,image->colors))
13123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    goto NoMemory;
13133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
13143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              else
13153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
13163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  if(bpp < 24)
1317eaedf06777741da32408da72c1e512975c600c48cristy                    if( image->colors<(one << bpp) && bpp!=24 )
13183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      image->colormap=(PixelPacket *) ResizeQuantumMemory(
1319eaedf06777741da32408da72c1e512975c600c48cristy                       image->colormap,(size_t) (one << bpp),
13203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                       sizeof(*image->colormap));
13213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
13223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
13233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
13243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              switch(Bitmap2Header1.Compression)
13253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
13263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 0:    /*Uncompressed raster*/
13273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  {
1328bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy                    ldblk=(ssize_t) ((bpp*image->columns+7)/8);
13293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    BImgBuff=(unsigned char *) AcquireQuantumMemory((size_t)
13303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      ldblk,sizeof(*BImgBuff));
13313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    if (BImgBuff == (unsigned char *) NULL)
13323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      goto NoMemory;
13333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1334bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy                    for(i=0; i< (ssize_t) image->rows; i++)
13353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      {
13363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                        (void) ReadBlob(image,ldblk,BImgBuff);
13373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                        InsertRow(BImgBuff,i,image,bpp);
13383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      }
13393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
13403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    if(BImgBuff)
13413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      BImgBuff=(unsigned char *) RelinquishMagickMemory(BImgBuff);;
13423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    break;
13433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  }
13443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 1:    /*RLE for WPG2 */
13453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  {
13463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    if( UnpackWPG2Raster(image,bpp) < 0)
13473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      goto DecompressionFailed;
13483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    break;
13493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  }
13503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
13513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
13523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              if(CTM[0][0]<0 && !image_info->ping)
13533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {    /*?? RotAngle=360-RotAngle;*/
13543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      rotated_image = FlopImage(image, exception);
13553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      rotated_image->blob = image->blob;
13563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      DuplicateBlob(rotated_image,image);
13573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) RemoveLastImageFromList(&image);
13583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      AppendImageToList(&image,rotated_image);
13593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  /* Try to change CTM according to Flip - I am not sure, must be checked.
13603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                     Tx(0,0)=-1;      Tx(1,0)=0;   Tx(2,0)=0;
13613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                     Tx(0,1)= 0;      Tx(1,1)=1;   Tx(2,1)=0;
13623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                     Tx(0,2)=(WPG._2Rect.X_ur+WPG._2Rect.X_ll);
13633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                     Tx(1,2)=0;   Tx(2,2)=1; */
13643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
13653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              if(CTM[1][1]<0 && !image_info->ping)
13663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {    /*?? RotAngle=360-RotAngle;*/
13673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      rotated_image = FlipImage(image, exception);
13683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      rotated_image->blob = image->blob;
13693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      DuplicateBlob(rotated_image,image);
13703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) RemoveLastImageFromList(&image);
13713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      AppendImageToList(&image,rotated_image);
13723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  /* Try to change CTM according to Flip - I am not sure, must be checked.
13733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                     float_matrix Tx(3,3);
13743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                     Tx(0,0)= 1;   Tx(1,0)= 0;   Tx(2,0)=0;
13753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                     Tx(0,1)= 0;   Tx(1,1)=-1;   Tx(2,1)=0;
13763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                     Tx(0,2)= 0;   Tx(1,2)=(WPG._2Rect.Y_ur+WPG._2Rect.Y_ll);
13773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                     Tx(2,2)=1; */
13783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
13793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
13803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
13813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              /* Allocate next image structure. */
13823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              AcquireNextImage(image_info,image);
13833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              image->depth=8;
13843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              if (image->next == (Image *) NULL)
13853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                goto Finish;
13863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              image=SyncNextImageInList(image);
13873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              image->columns=image->rows=1;
13883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              image->colors=0;
13893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
13903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
13913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            case 0x12:  /* Postscript WPG2*/
13923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        i=ReadBlobLSBShort(image);
13933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              if(Rec2.RecordLength > (unsigned int) i)
13943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                image=ExtractPostscript(image,image_info,
13953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  TellBlob(image)+i,    /*skip PS header in the wpg2*/
1396bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy                  (ssize_t) (Rec2.RecordLength-i-2),exception);
13973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
13983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
13993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      case 0x1B:          /*bitmap rectangle*/
14003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              WPG2Flags = LoadWPG2Flags(image,StartWPG.PosSizePrecision,NULL,&CTM);
1401da16f16767eb31921af855f17bda465fffc4e000cristy              (void) WPG2Flags;
14023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
14033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
14043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
14053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
14063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
14073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
14083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    default:
14093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
14103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy         ThrowReaderException(CoderError,"DataEncodingSchemeIsNotSupported");
14113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
14123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy   }
14133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
14143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Finish:
14153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) CloseBlob(image);
14163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
14173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
14183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Image
14193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      *p;
14203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1421bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy    ssize_t
14223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      scene=0;
14233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
14243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    /*
14253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      Rewind list, removing any empty images while rewinding.
14263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    */
14273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    p=image;
14283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    image=NULL;
14293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    while (p != (Image *) NULL)
14303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
14313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Image *tmp=p;
14323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if ((p->rows == 0) || (p->columns == 0)) {
14333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          p=p->previous;
14343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          DeleteImageFromList(&tmp);
14353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        } else {
14363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          image=p;
14373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          p=p->previous;
14383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
14393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
14403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    /*
14413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      Fix scene numbers.
14423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    */
14433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    for (p=image; p != (Image *) NULL; p=p->next)
1444bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy      p->scene=(size_t) scene++;
14453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
14463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (image == (Image *) NULL)
14473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    ThrowReaderException(CorruptImageError,
14483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "ImageFileDoesNotContainAnyImageData");
14493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(image);
14503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
14513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
14523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
14533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
14553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
14563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
14573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   R e g i s t e r W P G I m a g e                                           %
14583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
14593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
14603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
14613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
14633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  Method RegisterWPGImage adds attributes for the WPG image format to
14643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  the list of supported formats.  The attributes include the image format
14653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  tag, a method to read and/or write the format, whether the format
14663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  supports the saving of more than one frame to the same file or blob,
14673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  whether the format supports native in-memory I/O, and a brief
14683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  description of the format.
14693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
14703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the RegisterWPGImage method is:
14713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
1472bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy%      size_t RegisterWPGImage(void)
14733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
14743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
1475bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristyModuleExport size_t RegisterWPGImage(void)
14763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
14773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  MagickInfo
14783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *entry;
14793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
14803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  entry=SetMagickInfo("WPG");
14813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  entry->decoder=(DecodeImageHandler *) ReadWPGImage;
14823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  entry->magick=(IsImageFormatHandler *) IsWPG;
14833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  entry->description=AcquireString("Word Perfect Graphics");
14843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  entry->module=ConstantString("WPG");
14853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  entry->seekable_stream=MagickTrue;
14863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) RegisterMagickInfo(entry);
14873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(MagickImageCoderSignature);
14883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
14893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
14903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
14913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
14933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
14943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
14953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   U n r e g i s t e r W P G I m a g e                                       %
14963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
14973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
14983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
14993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
15013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  Method UnregisterWPGImage removes format registrations made by the
15023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  WPG module from the list of supported formats.
15033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
15043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the UnregisterWPGImage method is:
15053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
15063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      UnregisterWPGImage(void)
15073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
15083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
15093ed852eea50f9d4cd633efb8c2b054b8e33c253cristyModuleExport void UnregisterWPGImage(void)
15103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
15113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) UnregisterMagickInfo("WPG");
15123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
1513