1 /********************************************************************************
2 * *
3 * P N G I m a g e O b j e c t *
4 * *
5 *********************************************************************************
6 * Copyright (C) 1999,2005 by Jeroen van der Zijp. 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: FXPNGIcon.cpp,v 1.32 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 "FXPNGIcon.h"
38
39
40 /*
41 Notes:
42 - FXPNGIcon has an alpha channel
43 */
44
45 using namespace FX;
46
47 /*******************************************************************************/
48
49 namespace FX {
50
51
52 // Suggested file extension
53 const FXchar FXPNGIcon::fileExt[]="png";
54
55
56 // Object implementation
57 FXIMPLEMENT(FXPNGIcon,FXIcon,NULL,0)
58
59
60 #ifdef HAVE_PNG_H
61 const FXbool FXPNGIcon::supported=TRUE;
62 #else
63 const FXbool FXPNGIcon::supported=FALSE;
64 #endif
65
66
67 // Initialize
FXPNGIcon(FXApp * a,const void * pix,FXColor clr,FXuint opts,FXint w,FXint h)68 FXPNGIcon::FXPNGIcon(FXApp* a,const void *pix,FXColor clr,FXuint opts,FXint w,FXint h):FXIcon(a,NULL,clr,opts,w,h){
69 if(pix){
70 FXMemoryStream ms;
71 ms.open(FXStreamLoad,(FXuchar*)pix);
72 loadPixels(ms);
73 ms.close();
74 }
75 }
76
77
78 // Save pixels only
savePixels(FXStream & store) const79 FXbool FXPNGIcon::savePixels(FXStream& store) const {
80 if(fxsavePNG(store,data,width,height)){
81 return TRUE;
82 }
83 return FALSE;
84 }
85
86
87 // Load pixels only
loadPixels(FXStream & store)88 FXbool FXPNGIcon::loadPixels(FXStream& store){
89 FXColor *pixels; FXint w,h;
90 if(fxloadPNG(store,pixels,w,h)){
91 setData(pixels,IMAGE_OWNED,w,h);
92 if(options&IMAGE_ALPHAGUESS) transp=guesstransp();
93 return TRUE;
94 }
95 return FALSE;
96 }
97
98
99 // Clean up
~FXPNGIcon()100 FXPNGIcon::~FXPNGIcon(){
101 }
102
103 }
104