Orb/Doxygen/src/image.cpp
changeset 0 42188c7ea2d9
child 4 468f4c8d3d5b
equal deleted inserted replaced
-1:000000000000 0:42188c7ea2d9
       
     1 /******************************************************************************
       
     2  *
       
     3  * 
       
     4  *
       
     5  *
       
     6  * Copyright (C) 1997-2008 by Dimitri van Heesch.
       
     7  *
       
     8  * Permission to use, copy, modify, and distribute this software and its
       
     9  * documentation under the terms of the GNU General Public License is hereby 
       
    10  * granted. No representations are made about the suitability of this software 
       
    11  * for any purpose. It is provided "as is" without express or implied warranty.
       
    12  * See the GNU General Public License for more details.
       
    13  *
       
    14  * Documents produced by Doxygen are derivative works derived from the
       
    15  * input used in their production; they are not affected by this license.
       
    16  *
       
    17  */
       
    18 
       
    19 #include "qtbc.h"
       
    20 #include "image.h"
       
    21 //#include "gifenc.h"
       
    22 #include <qfile.h>
       
    23 #include "lodepng.h"
       
    24 
       
    25 typedef unsigned char  Byte;
       
    26 
       
    27 struct Color
       
    28 {
       
    29   Byte red;
       
    30   Byte green;
       
    31   Byte blue;
       
    32   Byte alpha;
       
    33 };
       
    34 
       
    35 const int charSetWidth=80;
       
    36 const int charHeight=12;
       
    37 const int numChars=96;
       
    38 
       
    39 unsigned short charPos[numChars]    = 
       
    40   {   
       
    41       0,  5,  8, 13, 20, 27, 38, 47, 
       
    42      50, 54, 58, 65, 72, 76, 83, 87, 
       
    43      91, 98,105,112,119,126,133,140,
       
    44     147,154,161,164,167,174,181,188,
       
    45     195,207,216,224,233,242,250,258,
       
    46     267,276,279,286,294,301,312,321,
       
    47     331,339,349,357,365,372,380,389,
       
    48     400,409,418,427,430,434,437,443,
       
    49     450,453,460,467,474,481,488,492,
       
    50     499,506,509,512,518,521,530,537,
       
    51     544,551,557,562,568,571,578,585,
       
    52     594,600,607,613,617,620,624,631
       
    53   };
       
    54 
       
    55 unsigned char charWidth[numChars] = 
       
    56   {
       
    57      5, 3, 5, 7, 7,11, 9, 3,
       
    58      4, 4, 7, 7, 4, 7, 4, 4,
       
    59 
       
    60      7, 7, 7, 7, 7, 7, 7, 7,
       
    61      7, 7, 3, 3, 7, 7, 7, 7,
       
    62     12, 9, 8, 9, 9, 8, 8, 9,
       
    63      9, 3, 7, 8, 7,11, 9,10,
       
    64      8,10, 8, 8, 7, 8, 9,11,
       
    65      9, 9, 9, 3, 4, 3, 6, 7,
       
    66      3, 7, 7, 7, 7, 7, 4, 7,
       
    67      7, 3, 3, 6, 3, 9, 7, 7,
       
    68      7, 6, 5, 6, 3, 7, 7, 9,
       
    69      6, 7, 6, 4, 3, 4, 7, 5   
       
    70   };
       
    71 
       
    72 unsigned char fontRaw[charSetWidth*charHeight] = {
       
    73   0x02, 0x50, 0x01, 0x06, 0x20, 0x60, 0xc6, 0x04, 0x00, 0x00, 0x00, 0x27,
       
    74   0x04, 0x1c, 0x38, 0x11, 0xf1, 0xc7, 0xc7, 0x0e, 0x00, 0x00, 0x00, 0x03,
       
    75   0x81, 0xf0, 0x10, 0x7c, 0x1e, 0x3e, 0x1f, 0x9f, 0x87, 0x88, 0x24, 0x09,
       
    76   0x09, 0x02, 0x02, 0x41, 0x0f, 0x0f, 0x83, 0xc3, 0xe1, 0xe7, 0xf4, 0x24,
       
    77   0x12, 0x22, 0x41, 0x20, 0x9f, 0xce, 0x30, 0x00, 0x10, 0x04, 0x00, 0x01,
       
    78   0x00, 0x30, 0x08, 0x12, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40,
       
    79   0x00, 0x00, 0x00, 0x00, 0x01, 0xac, 0x00, 0x00, 0x02, 0x51, 0x43, 0x89,
       
    80   0x40, 0x90, 0x49, 0x15, 0x00, 0x00, 0x00, 0x28, 0x9c, 0x22, 0x44, 0x31,
       
    81   0x02, 0x20, 0x48, 0x91, 0x00, 0x00, 0x00, 0x04, 0x46, 0x08, 0x28, 0x42,
       
    82   0x21, 0x21, 0x10, 0x10, 0x08, 0x48, 0x24, 0x09, 0x11, 0x03, 0x06, 0x61,
       
    83   0x10, 0x88, 0x44, 0x22, 0x12, 0x10, 0x84, 0x24, 0x12, 0x22, 0x22, 0x20,
       
    84   0x80, 0x4a, 0x11, 0x00, 0x20, 0x04, 0x00, 0x01, 0x00, 0x40, 0x08, 0x00,
       
    85   0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00,
       
    86   0x02, 0x22, 0x00, 0x00, 0x02, 0x51, 0x45, 0x49, 0x40, 0x90, 0x89, 0x0a,
       
    87   0x00, 0x00, 0x00, 0x48, 0x84, 0x02, 0x04, 0x51, 0x02, 0x00, 0x88, 0x91,
       
    88   0x00, 0x00, 0x00, 0x04, 0x44, 0xd4, 0x28, 0x42, 0x40, 0x20, 0x90, 0x10,
       
    89   0x10, 0x08, 0x24, 0x09, 0x21, 0x03, 0x06, 0x51, 0x20, 0x48, 0x48, 0x12,
       
    90   0x12, 0x00, 0x84, 0x22, 0x22, 0x22, 0x22, 0x11, 0x00, 0x89, 0x12, 0x80,
       
    91   0x31, 0xc5, 0x87, 0x0d, 0x1c, 0xe3, 0x4b, 0x12, 0x49, 0x29, 0x16, 0x1c,
       
    92   0x58, 0x69, 0x4c, 0xe8, 0x91, 0x44, 0x61, 0x44, 0xf2, 0x22, 0x00, 0x00,
       
    93   0x02, 0x07, 0xe5, 0x06, 0x80, 0x60, 0x10, 0x95, 0x08, 0x00, 0x00, 0x48,
       
    94   0x84, 0x04, 0x18, 0x51, 0xe2, 0xc0, 0x87, 0x11, 0x24, 0x18, 0x03, 0x00,
       
    95   0x89, 0x24, 0x44, 0x42, 0x40, 0x20, 0x90, 0x10, 0x10, 0x08, 0x24, 0x09,
       
    96   0x41, 0x02, 0x8a, 0x51, 0x20, 0x48, 0x48, 0x12, 0x11, 0x80, 0x84, 0x22,
       
    97   0x21, 0x24, 0x14, 0x11, 0x01, 0x09, 0x14, 0x40, 0x02, 0x26, 0x48, 0x93,
       
    98   0x22, 0x44, 0xcc, 0x92, 0x51, 0x36, 0x99, 0x22, 0x64, 0x99, 0x92, 0x48,
       
    99   0x91, 0x44, 0x52, 0x44, 0x12, 0x22, 0x00, 0x00, 0x02, 0x01, 0x43, 0x80,
       
   100   0x80, 0xa0, 0x10, 0x84, 0x08, 0x00, 0x00, 0x88, 0x84, 0x08, 0x04, 0x90,
       
   101   0x13, 0x21, 0x08, 0x8f, 0x00, 0x61, 0xf0, 0xc0, 0x8a, 0x24, 0x44, 0x7c,
       
   102   0x40, 0x20, 0x9f, 0x9f, 0x11, 0xcf, 0xe4, 0x09, 0xc1, 0x02, 0x8a, 0x49,
       
   103   0x20, 0x4f, 0x88, 0x13, 0xe0, 0x60, 0x84, 0x22, 0x21, 0x54, 0x08, 0x0a,
       
   104   0x02, 0x08, 0x90, 0x00, 0x00, 0x24, 0x48, 0x11, 0x22, 0x44, 0x48, 0x92,
       
   105   0x61, 0x24, 0x91, 0x22, 0x44, 0x89, 0x10, 0x48, 0x91, 0x24, 0x8c, 0x44,
       
   106   0x22, 0x22, 0x64, 0x00, 0x02, 0x07, 0xe1, 0x41, 0x31, 0x14, 0x10, 0x80,
       
   107   0x3e, 0x07, 0xc0, 0x88, 0x84, 0x10, 0x05, 0x10, 0x12, 0x21, 0x08, 0x81,
       
   108   0x01, 0x80, 0x00, 0x31, 0x0a, 0x24, 0x7c, 0x42, 0x40, 0x20, 0x90, 0x10,
       
   109   0x10, 0x48, 0x24, 0x09, 0x21, 0x02, 0x52, 0x45, 0x20, 0x48, 0x08, 0x92,
       
   110   0x20, 0x10, 0x84, 0x21, 0x41, 0x54, 0x14, 0x04, 0x04, 0x08, 0x90, 0x00,
       
   111   0x01, 0xe4, 0x48, 0x11, 0x3e, 0x44, 0x48, 0x92, 0x61, 0x24, 0x91, 0x22,
       
   112   0x44, 0x89, 0x0c, 0x48, 0x8a, 0x24, 0x8c, 0x48, 0x44, 0x21, 0x98, 0x00,
       
   113   0x02, 0x02, 0x85, 0x41, 0x49, 0x08, 0x10, 0x80, 0x08, 0x00, 0x00, 0x88,
       
   114   0x84, 0x20, 0x45, 0xf9, 0x12, 0x21, 0x08, 0x81, 0x00, 0x61, 0xf0, 0xc1,
       
   115   0x0a, 0x68, 0x82, 0x42, 0x40, 0x20, 0x90, 0x10, 0x10, 0x48, 0x24, 0x89,
       
   116   0x11, 0x02, 0x52, 0x45, 0x20, 0x48, 0x08, 0x52, 0x12, 0x10, 0x84, 0x21,
       
   117   0x40, 0x88, 0x22, 0x04, 0x08, 0x08, 0x90, 0x00, 0x02, 0x24, 0x48, 0x11,
       
   118   0x20, 0x44, 0x48, 0x92, 0x51, 0x24, 0x91, 0x22, 0x44, 0x89, 0x02, 0x48,
       
   119   0x8a, 0x2a, 0x92, 0x28, 0x42, 0x22, 0x00, 0x00, 0x00, 0x02, 0x85, 0x41,
       
   120   0x49, 0x18, 0x10, 0x80, 0x08, 0x00, 0x01, 0x08, 0x84, 0x20, 0x44, 0x11,
       
   121   0x12, 0x22, 0x08, 0x91, 0x00, 0x18, 0x03, 0x00, 0x09, 0xb0, 0x82, 0x42,
       
   122   0x21, 0x21, 0x10, 0x10, 0x08, 0xc8, 0x24, 0x89, 0x09, 0x02, 0x22, 0x43,
       
   123   0x10, 0x88, 0x04, 0x22, 0x12, 0x10, 0x84, 0x20, 0x80, 0x88, 0x22, 0x04,
       
   124   0x10, 0x08, 0x50, 0x00, 0x02, 0x26, 0x48, 0x93, 0x22, 0x44, 0xc8, 0x92,
       
   125   0x49, 0x24, 0x91, 0x22, 0x64, 0x99, 0x12, 0x49, 0x84, 0x11, 0x21, 0x28,
       
   126   0x82, 0x22, 0x00, 0x00, 0x02, 0x02, 0x83, 0x82, 0x30, 0xe4, 0x10, 0x80,
       
   127   0x00, 0x20, 0x05, 0x07, 0x04, 0x3e, 0x38, 0x10, 0xe1, 0xc2, 0x07, 0x0e,
       
   128   0x24, 0x00, 0x00, 0x01, 0x04, 0x00, 0x82, 0x7c, 0x1e, 0x3e, 0x1f, 0x90,
       
   129   0x07, 0x48, 0x24, 0x71, 0x05, 0xf2, 0x22, 0x41, 0x0f, 0x08, 0x03, 0xd2,
       
   130   0x11, 0xe0, 0x83, 0xc0, 0x80, 0x88, 0x41, 0x04, 0x1f, 0xc8, 0x50, 0x00,
       
   131   0x01, 0xd5, 0x87, 0x0d, 0x1c, 0x43, 0x48, 0x92, 0x45, 0x24, 0x91, 0x1c,
       
   132   0x58, 0x69, 0x0c, 0x66, 0x84, 0x11, 0x21, 0x10, 0xf2, 0x22, 0x00, 0x00,
       
   133   0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x20, 0x00, 0x00,
       
   134   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
       
   135   0x03, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
       
   136   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
       
   137   0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
       
   138   0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x00, 0x00, 0x40, 0x08, 0x00, 0x00,
       
   139   0x00, 0x00, 0x00, 0x10, 0x02, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
       
   140   0x00, 0x00, 0x09, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
       
   141   0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
       
   142   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
       
   143   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
       
   144   0x00, 0x08, 0x10, 0x1f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x04, 0x40, 0x02,
       
   145   0x00, 0x00, 0x00, 0x00, 0x40, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20,
       
   146   0x02, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00,
       
   147   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
       
   148   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
       
   149   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
       
   150   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x30, 0x00,
       
   151   0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x04, 0x00, 0x00, 0x00, 0x00,
       
   152   0x40, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x01, 0xac, 0x00, 0x00
       
   153 };
       
   154 
       
   155 static Color palette[] =
       
   156 {
       
   157   { 0xff, 0xff, 0xff, 0x00 },
       
   158   { 0x00, 0x00, 0x00, 0xff },
       
   159   { 0xff, 0xff, 0xc0, 0xff },
       
   160   { 0x9f, 0x9f, 0x60, 0xff },
       
   161   { 0x90, 0x00, 0x00, 0xff },
       
   162   { 0x00, 0x90, 0x00, 0xff },
       
   163   { 0x00, 0x00, 0x90, 0xff },
       
   164   { 0xc0, 0xc0, 0xc0, 0xff }
       
   165 };
       
   166 
       
   167 #if 0
       
   168 static Color palette2[] =
       
   169 {
       
   170   { 0xff, 0xff, 0xff },
       
   171   { 0xe0, 0xe0, 0xe0 },
       
   172   { 0xd0, 0xd0, 0xd0 },
       
   173   { 0xc0, 0xc0, 0xc0 },
       
   174   { 0xb0, 0xb0, 0xb0 },
       
   175   { 0xa0, 0xa0, 0xa0 },
       
   176   { 0x90, 0x90, 0x90 },
       
   177   { 0x80, 0x80, 0x80 },
       
   178   { 0x70, 0x70, 0x70 },
       
   179   { 0x60, 0x60, 0x60 },
       
   180   { 0x50, 0x50, 0x50 },
       
   181   { 0x40, 0x40, 0x40 },
       
   182   { 0x30, 0x30, 0x30 },
       
   183   { 0x20, 0x20, 0x20 },
       
   184   { 0x10, 0x10, 0x10 },
       
   185   { 0x00, 0x00, 0x00 }
       
   186 };
       
   187 #endif
       
   188 
       
   189 // for alpha we use x^(1/1.3)
       
   190 static Color palette2[] =
       
   191 {
       
   192   { 0x00, 0x00, 0x00, 0x00 },
       
   193   { 0x00, 0x00, 0x00, 0x2e },
       
   194   { 0x00, 0x00, 0x00, 0x48 },
       
   195   { 0x00, 0x00, 0x00, 0x5d },
       
   196   { 0x00, 0x00, 0x00, 0x6f },
       
   197   { 0x00, 0x00, 0x00, 0x80 },
       
   198   { 0x00, 0x00, 0x00, 0x8f },
       
   199   { 0x00, 0x00, 0x00, 0x9e },
       
   200   { 0x00, 0x00, 0x00, 0xac },
       
   201   { 0x00, 0x00, 0x00, 0xb9 },
       
   202   { 0x00, 0x00, 0x00, 0xc5 },
       
   203   { 0x00, 0x00, 0x00, 0xd2 },
       
   204   { 0x00, 0x00, 0x00, 0xdd },
       
   205   { 0x00, 0x00, 0x00, 0xe9 },
       
   206   { 0x00, 0x00, 0x00, 0xf4 },
       
   207   { 0x00, 0x00, 0x00, 0xff }
       
   208 };
       
   209 
       
   210 Image::Image(int w,int h)
       
   211 {
       
   212   data = new uchar[w*h];
       
   213   memset(data,0,w*h);
       
   214   width = w;
       
   215   height = h;
       
   216 }
       
   217 
       
   218 Image::~Image()
       
   219 {
       
   220   delete[] data;
       
   221 }
       
   222 
       
   223 void Image::setPixel(int x,int y,uchar val)
       
   224 {
       
   225   if (x>=0 && x<width && y>=0 && y<height)
       
   226     data[y*width+x] = val;
       
   227 }
       
   228 
       
   229 uchar Image::getPixel(int x,int y) const
       
   230 {
       
   231   if (x>=0 && x<width && y>=0 && y<height)
       
   232     return data[y*width+x];
       
   233   else
       
   234     return 0;
       
   235 }
       
   236 
       
   237 void Image::writeChar(int x,int y,char c,uchar fg) 
       
   238 {
       
   239   if (c>=' ')
       
   240   {
       
   241     int xf,yf,ci=c-' ';
       
   242     int rowOffset=0;
       
   243     int cw = charWidth[ci];
       
   244     int cp = charPos[ci];
       
   245     for (yf=0;yf<charHeight;yf++)
       
   246     {
       
   247       unsigned short bitPattern=0;
       
   248       int bitsLeft=cw;
       
   249       int byteOffset = rowOffset+(cp>>3);
       
   250       int bitOffset  = cp&7;
       
   251       // get the bit pattern for row yf of the character from the font data
       
   252       while (bitsLeft>0)
       
   253       {
       
   254         int bits=8-bitOffset;
       
   255         if (bits>bitsLeft) bits=bitsLeft; 
       
   256         bitPattern<<=bits; 
       
   257         bitPattern|=((fontRaw[byteOffset]<<bitOffset)&0xff)>>(8-bits);
       
   258         bitsLeft-=bits;
       
   259         bitOffset=0;
       
   260         byteOffset++;
       
   261       }
       
   262       int mask=1<<(cw-1);
       
   263       // draw character row yf
       
   264       for (xf=0;xf<cw;xf++)
       
   265       {
       
   266         setPixel(x+xf,y+yf,(bitPattern&mask) ? fg : getPixel(x+xf,y+yf));
       
   267         mask>>=1;
       
   268       }
       
   269       rowOffset+=charSetWidth;
       
   270     }
       
   271   } 
       
   272 }
       
   273 
       
   274 void Image::writeString(int x,int y,const char *s,uchar fg) 
       
   275 {
       
   276   if (s)
       
   277   {
       
   278     char c;
       
   279     while ((c=*s++))
       
   280     {
       
   281       writeChar(x,y,c,fg);
       
   282       x+=charWidth[c-' '];
       
   283     }
       
   284   }
       
   285 }
       
   286 
       
   287 uint Image::stringLength(const char *s) 
       
   288 {
       
   289   int w=0;
       
   290   if (s)
       
   291   {
       
   292     char c;
       
   293     while ((c=*s++)) w+=charWidth[c-' '];
       
   294   }
       
   295   return w;
       
   296 }
       
   297 
       
   298 void Image::drawHorzLine(int y,int xs,int xe,uchar colIndex,uint mask)
       
   299 {
       
   300   int x,i=0,j=0;
       
   301   for (x=xs;x<=xe;x++,j++) 
       
   302   {
       
   303     if (j&1) i++;
       
   304     if (mask&(1<<(i&0x1f))) setPixel(x,y,colIndex);
       
   305   }
       
   306 } 
       
   307 
       
   308 void Image::drawHorzArrow(int y,int xs,int xe,uchar colIndex,uint mask)
       
   309 {
       
   310   drawHorzLine(y,xs,xe,colIndex,mask);
       
   311   int i;
       
   312   for (i=0;i<6;i++)
       
   313   {
       
   314     int h=i>>1;
       
   315     drawVertLine(xe-i,y-h,y+h,colIndex,0xffffffff);
       
   316   }
       
   317 } 
       
   318 
       
   319 void Image::drawVertLine(int x,int ys,int ye,uchar colIndex,uint mask)
       
   320 {
       
   321   int y,i=0;
       
   322   for (y=ys;y<=ye;y++,i++) 
       
   323   {
       
   324     if (mask&(1<<(i&0x1f))) setPixel(x,y,colIndex);
       
   325   }
       
   326 }
       
   327 
       
   328 void Image::drawVertArrow(int x,int ys,int ye,uchar colIndex,uint mask)
       
   329 {
       
   330   drawVertLine(x,ys,ye,colIndex,mask);
       
   331   int i;
       
   332   for (i=0;i<6;i++)
       
   333   {
       
   334     int h=i>>1;
       
   335     drawHorzLine(ys+i,x-h,x+h,colIndex,0xffffffff);
       
   336   }
       
   337 }
       
   338 
       
   339 void Image::drawRect(int x,int y,int w,int h,uchar colIndex,uint mask)
       
   340 {
       
   341   drawHorzLine(y,x,x+w-1,colIndex,mask);
       
   342   drawHorzLine(y+h-1,x,x+w-1,colIndex,mask);
       
   343   drawVertLine(x,y,y+h-1,colIndex,mask);
       
   344   drawVertLine(x+w-1,y,y+h-1,colIndex,mask);
       
   345 }
       
   346 
       
   347 void Image::fillRect(int x,int y,int lwidth,int lheight,uchar colIndex,uint mask)
       
   348 {
       
   349   int xp,yp,xi,yi;
       
   350   for (yp=y,yi=0;yp<y+lheight;yp++,yi++)
       
   351     for (xp=x,xi=0;xp<x+lwidth;xp++,xi++)
       
   352       if (mask&(1<<((xi+yi)&0x1f))) 
       
   353         setPixel(xp,yp,colIndex);
       
   354 }
       
   355 
       
   356 bool Image::save(const char *fileName,int mode)
       
   357 {
       
   358 #if 0
       
   359   GifEncoder gifenc(data,
       
   360                     mode==0 ? palette : palette2,
       
   361                     width,height,
       
   362                     mode==0 ? 3 : 4,
       
   363                     0);
       
   364   QFile file(fileName);
       
   365   if (file.open(IO_WriteOnly))
       
   366   {
       
   367     gifenc.writeGIF(file);
       
   368     return TRUE;
       
   369   }
       
   370   else
       
   371   {
       
   372     return FALSE;
       
   373   }
       
   374 #endif
       
   375   uchar* buffer;
       
   376   size_t bufferSize;
       
   377   LodePNG_Encoder encoder;
       
   378   LodePNG_Encoder_init(&encoder);
       
   379   int numCols = mode==0 ? 8 : 16;
       
   380   Color *pPal = mode==0 ? palette : palette2;
       
   381   int i;
       
   382   for (i=0;i<numCols;i++,pPal++)
       
   383   {
       
   384     LodePNG_InfoColor_addPalette(&encoder.infoPng.color,
       
   385                                  pPal->red,pPal->green,pPal->blue,pPal->alpha);
       
   386   }
       
   387   encoder.infoPng.color.colorType = 3; 
       
   388   encoder.infoRaw.color.colorType = 3;
       
   389   LodePNG_encode(&encoder, &buffer, &bufferSize, data, width, height);
       
   390   LodePNG_saveFile(buffer, bufferSize, fileName);
       
   391   free(buffer);
       
   392   LodePNG_Encoder_cleanup(&encoder);
       
   393   return TRUE;
       
   394 }
       
   395