1 /********************************************************************************
2 *                                                                               *
3 *                        P P M   I c o n   O b j e c t                          *
4 *                                                                               *
5 *********************************************************************************
6 * Copyright (C) 1997,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: FXPPMIcon.cpp,v 1.9 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 "FXObject.h"
36 #include "FXSettings.h"
37 #include "FXRegistry.h"
38 #include "FXApp.h"
39 #include "FXId.h"
40 #include "FXDrawable.h"
41 #include "FXImage.h"
42 #include "FXIcon.h"
43 #include "FXPPMIcon.h"
44 
45 
46 /*
47   Notes:
48   - PPM does not support alpha in the file format.
49 */
50 
51 using namespace FX;
52 
53 /*******************************************************************************/
54 
55 namespace FX {
56 
57 
58 // Suggested file extension
59 const FXchar FXPPMIcon::fileExt[]="ppm";
60 
61 
62 // Object implementation
63 FXIMPLEMENT(FXPPMIcon,FXIcon,NULL,0)
64 
65 
66 // Initialize nicely
FXPPMIcon(FXApp * a,const void * pix,FXColor clr,FXuint opts,FXint w,FXint h)67 FXPPMIcon::FXPPMIcon(FXApp* a,const void *pix,FXColor clr,FXuint opts,FXint w,FXint h):FXIcon(a,NULL,clr,opts,w,h){
68   if(pix){
69     FXMemoryStream ms;
70     ms.open(FXStreamLoad,(FXuchar*)pix);
71     loadPixels(ms);
72     ms.close();
73     }
74   }
75 
76 
77 // Save object to stream
savePixels(FXStream & store) const78 FXbool FXPPMIcon::savePixels(FXStream& store) const {
79   if(fxsavePPM(store,data,width,height)){
80     return TRUE;
81     }
82   return FALSE;
83   }
84 
85 
86 // Load object from stream
loadPixels(FXStream & store)87 FXbool FXPPMIcon::loadPixels(FXStream& store){
88   FXColor *pixels; FXint w,h;
89   if(fxloadPPM(store,pixels,w,h)){
90     setData(pixels,IMAGE_OWNED,w,h);
91     if(options&IMAGE_ALPHAGUESS) transp=guesstransp();
92     return TRUE;
93     }
94   return FALSE;
95   }
96 
97 
98 // Clean up
~FXPPMIcon()99 FXPPMIcon::~FXPPMIcon(){
100   }
101 
102 }
103