AppEasy Core SDK  1.5.0
Cross platform mobile and desktop app and game development SDK - The easy way to make apps
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines
CzImage.h
Go to the documentation of this file.
00001 // 
00002 //
00003 // AppEasy SDK - Cross Platform Multi-purpose Game and App Engine
00004 //
00005 // Developed by Matthew Hopwood of Pocketeers Limited - www.pocketeers.co.uk
00006 //
00007 // For updates, tutorials and more details check out www.appeasymobile.com
00008 //
00009 // This code is provided free of charge and without any warranty whatsoever. You must ensure that this whole notice is present in all files and derivatives, so the reader knows its origin.
00010 // If you use this SDK in your product then please ensure that you credit AppEasy's usage appropriately. Please see www.appeasymobile.com for licensing details and support
00011 //
00012 //
00013 
00014 #if !defined(_CCZ_IMAGE_H_)
00015 #define _CCZ_IMAGE_H_
00016 
00017 #include "CzUtil.h"
00018 #include "CzXoml.h"
00019 #include "CzFile.h"
00020 
00021 class CzXomlResourceManager;
00022 
00023 struct CzTextureinfo
00024 {
00025     int                 Width, Height;
00026     int                 Format;
00027     bool                Filter;
00028 
00029     CzTextureinfo();
00030 };
00031 
00032 
00033 //
00034 //
00035 //
00036 //
00037 // CzImage - Represents a bitmapped image
00038 //
00039 // Note that images can be either loaded on demand (loaded on first call to getTexture() or pre loaded by calling Load()
00040 //
00041 //
00042 //
00043 //
00044 class CzImage : public IzXomlResource
00045 {
00046 public:
00047     enum eState
00048     {
00049         State_Invalid, 
00050         State_Loading, 
00051         State_Loaded, 
00052         State_Uploaded, 
00053     };
00054 
00055     enum eFormat
00056     {
00057         Format_Invalid, 
00058         Format_RGB332, 
00059         Format_RGB565, 
00060         Format_RGB888, 
00061         Format_RGBA4444, 
00062         Format_RGBA6666, 
00063         Format_RGBA5551, 
00064         Format_RGBA8888, 
00065     };
00066 
00067     // Properties
00068 protected:
00069     CzTexture               Texture;            // Texture
00070     CzTextureinfo           TextureInfo;        // Details of texture
00071     eState                  State;              // State of image
00072     bool                    Filter;             // Value to set filtering to
00073     bool                    FilterSet;          // True if the filter was set
00074     eFormat                 ToFormat;           // Format to convert texture to
00075     bool                    ToFormatSet;        // If set then format conversion will take place
00076 public:
00077     eState                  getState() const                    { return State; }
00078     CzTexture               getTexture();
00079     int                     getWidth() const;
00080     int                     getHeight() const;
00081     CzImage*                getCopy();
00082     void                    setFilter(bool enable);
00083     bool                    isFilter() const;
00084     bool                    isFilterSet() const                 { return FilterSet; }
00085     void                    setToFormat(eFormat format)         { ToFormat = format; ToFormatSet = true; }
00086     eFormat                 getFormat() const;
00087     // Properties End
00088 protected:
00089     CzFile*                 File;               // File object (if image is file based)
00090     bool                    DecompressJPEG(char* jpeg_data, int jpeg_data_size);
00091 
00092 public:
00093     CzImage() : IzXomlResource(), File(NULL), State(State_Invalid), ToFormat(Format_RGBA5551), ToFormatSet(false), Filter(true), FilterSet(false), Texture(NULL) { setClassType("image"); }
00094     virtual ~CzImage();
00095 
00096 /*  void            Init(const char* ResourceName, CIwResGroup* resource_group)     // Init an image from an image located within a resource group (image is not loaded)
00097     {
00098         setName(ResourceName);
00099         ResourceGroup = resource_group;
00100     }*/
00101 
00102     bool            Init(void* memory_file, int memory_file_size);  // Init an image from a memory based file (image is loaded)
00103     void            Init(const char* filename);                     // Init an image from a file (image is not loaded)
00104     bool            Init(void* pixels, int width, int height, int pitch, eFormat format, bool modifiable);  // Init an image from raw data
00105     void            Release();
00106 
00107     bool            Load(bool blocking = true);                             // Load the image
00108     bool            Reload(const char* filename, bool blocking = true);     // Reload the image
00109 
00110     // Utility
00111     void            ChangePixels(void* data, CzImage::eFormat format);
00112     CzTexture       ConvertToFormat(CzImage& source, CzImage::eFormat format);
00113     void            SavePng(const char* filename);
00114     void            SaveJpg(const char* filename, int quality = 100);
00115 
00116     // Implementation of IzXomlClass interface
00117     int             LoadFromXoml(IzXomlResource* parebt, bool load_children, CzXmlNode* node);
00118 
00119     // Internal
00120     void            FinishLoad();                                   // Called back when aysnc loading is completed
00121 };
00122 
00123 //
00124 //  CzImageCreator - Creates an instance of an image object
00125 //
00126 class CzImageCreator : public IzXomlClassCreator
00127 {
00128 public:
00129     CzImageCreator()
00130     {
00131         setClassName("image");
00132     }
00133     IzXomlResource* CreateInstance(IzXomlResource* parent)  { return new CzImage(); }
00134 };
00135 
00136 //
00137 //
00138 //
00139 //
00140 //  Helper macros
00141 //
00142 //
00143 //
00144 //
00145 
00146 #define CZ_NEW_IMAGE(image, name, location, filter)         \
00147     CzImage* image = new CzImage();                         \
00148     image->setName(name);                                   \
00149     image->Init(location);                                  \
00150     image->setFilter(filter);                               \
00151     image->Load();
00152 
00153 
00154 
00155 #endif  // _CCZ_IMAGE_H_