1 /********************************************************************************
2 *                                                                               *
3 *                     T A R G A   I c o n   O b j e c t                         *
4 *                                                                               *
5 *********************************************************************************
6 * Copyright (C) 2001,2005 by Janusz Ganczarski.   All Rights Reserved.          *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or                 *
9 * modify it under the terms of the GNU Lesser General Public                    *
10 * License as published by the Free Software Foundation; either                  *
11 * version 2.1 of the License, or (at your option) any later version.            *
12 *                                                                               *
13 * This library is distributed in the hope that it will be useful,               *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU             *
16 * Lesser General Public License for more details.                               *
17 *                                                                               *
18 * You should have received a copy of the GNU Lesser General Public              *
19 * License along with this library; if not, write to the Free Software           *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.    *
21 *********************************************************************************
22 * $Id: FXTGAIcon.cpp,v 1.20 2005/01/16 16:06:07 fox Exp $                       *
23 ********************************************************************************/
24 #include "xincs.h"
25 #include "fxver.h"
26 #include "fxdefs.h"
27 #include "FXHash.h"
28 #include "FXThread.h"
29 #include "FXStream.h"
30 #include "FXMemoryStream.h"
31 #include "FXString.h"
32 #include "FXSize.h"
33 #include "FXPoint.h"
34 #include "FXRectangle.h"
35 #include "FXRegistry.h"
36 #include "FXApp.h"
37 #include "FXTGAIcon.h"
38 
39 
40 /*
41   Notes:
42   - Targa does not support alpha in the file format.
43   - You can also let the system guess a transparancy color based on the corners.
44   - If that doesn't work, you can force a specific transparency color.
45   - This is just an idea at this point:
46 
47       // Compute name of image support class
48       FXString name="FX"+ext.upper()+"Image";
49 
50       // Find the meta class
51       const FXMetaClass *meta=FXMetaClass::getMetaClassFromName(name.text());
52 
53       // Make instance of this class
54       if(meta) img=(FXImage*)meta->makeInstance();
55 
56     The above is a simplistic view; we will need to set the image's visual,
57     options, and other stuff before this can work.
58     Also, when linking statically, we have to convince the linker to include
59     the referred image code...
60 
61 */
62 
63 using namespace FX;
64 
65 /*******************************************************************************/
66 
67 namespace FX {
68 
69 
70 // Suggested file extension
71 const FXchar FXTGAIcon::fileExt[]="tga";
72 
73 
74 // Object implementation
75 FXIMPLEMENT(FXTGAIcon,FXIcon,NULL,0)
76 
77 
78 // Initialize nicely
FXTGAIcon(FXApp * a,const void * pix,FXColor clr,FXuint opts,FXint w,FXint h)79 FXTGAIcon::FXTGAIcon(FXApp* a,const void *pix,FXColor clr,FXuint opts,FXint w,FXint h):FXIcon(a,NULL,clr,opts,w,h){
80   if(pix){
81     FXMemoryStream ms;
82     ms.open(FXStreamLoad,(FXuchar*)pix);
83     loadPixels(ms);
84     ms.close();
85     }
86   }
87 
88 
89 // Save pixels to stream
savePixels(FXStream & store) const90 FXbool FXTGAIcon::savePixels(FXStream& store) const {
91   if(fxsaveTGA(store,data,width,height)){
92     return TRUE;
93     }
94   return FALSE;
95   }
96 
97 
98 // Load pixels from stream
loadPixels(FXStream & store)99 FXbool FXTGAIcon::loadPixels(FXStream& store){
100   FXColor *pixels; FXint w,h;
101   if(fxloadTGA(store,pixels,w,h)){
102     setData(pixels,IMAGE_OWNED,w,h);
103     if(options&IMAGE_ALPHAGUESS) transp=guesstransp();
104     return TRUE;
105     }
106   return FALSE;
107   }
108 
109 
110 // Clean up
~FXTGAIcon()111 FXTGAIcon::~FXTGAIcon(){
112   }
113 
114 }
115