1 /********************************************************************************
2 *                                                                               *
3 *                        P P M   I c o n   O b j e c t                          *
4 *                                                                               *
5 *********************************************************************************
6 * Copyright (C) 1997,2006 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 3297 2015-12-14 20:30:04Z arthurcnorman $                       *
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 // Suggested mime type
63 const FXchar FXPPMIcon::mimeType[]="image/x-portable-pixmap";
64 
65 
66 // Object implementation
67 FXIMPLEMENT(FXPPMIcon,FXIcon,NULL,0)
68 
69 
70 // Initialize nicely
FXPPMIcon(FXApp * a,const void * pix,FXColor clr,FXuint opts,FXint w,FXint h)71 FXPPMIcon::FXPPMIcon(FXApp* a,const void *pix,FXColor clr,FXuint opts,FXint w,FXint h):FXIcon(a,NULL,clr,opts,w,h){
72   if(pix){
73     FXMemoryStream ms;
74     ms.open(FXStreamLoad,(FXuchar*)pix);
75     loadPixels(ms);
76     ms.close();
77     }
78   }
79 
80 
81 // Save object to stream
savePixels(FXStream & store) const82 bool FXPPMIcon::savePixels(FXStream& store) const {
83   if(fxsavePPM(store,data,width,height)){
84     return true;
85     }
86   return false;
87   }
88 
89 
90 // Load object from stream
loadPixels(FXStream & store)91 bool FXPPMIcon::loadPixels(FXStream& store){
92   FXColor *pixels; FXint w,h;
93   if(fxloadPPM(store,pixels,w,h)){
94     setData(pixels,IMAGE_OWNED,w,h);
95     if(options&IMAGE_ALPHAGUESS) transp=guesstransp();
96     return true;
97     }
98   return false;
99   }
100 
101 
102 // Clean up
~FXPPMIcon()103 FXPPMIcon::~FXPPMIcon(){
104   }
105 
106 }
107