00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef FIFE_VIDEO_IMAGE_H
00023 #define FIFE_VIDEO_IMAGE_H
00024
00025
00026 #include <stack>
00027
00028
00029 #include <SDL.h>
00030 #include <png.h>
00031
00032
00033
00034
00035
00036 #include "util/base/fife_stdint.h"
00037 #include "util/resource/resource.h"
00038 #include "util/structures/point.h"
00039 #include "util/structures/rect.h"
00040
00041 namespace FIFE {
00042 class Image;
00043 typedef SharedPtr<Image> ImagePtr;
00044
00047 class Image : public IResource {
00048 public:
00051 Image(IResourceLoader* loader = 0);
00052 Image(const std::string& name, IResourceLoader* loader = 0);
00053
00058 Image(SDL_Surface* surface);
00059 Image(const std::string& name, SDL_Surface* surface);
00060
00066 Image(const uint8_t* data, uint32_t width, uint32_t height);
00067 Image(const std::string& name, const uint8_t* data, uint32_t width, uint32_t height);
00068
00071 virtual ~Image();
00072
00075 virtual void invalidate() = 0;
00076
00083 virtual void render(const Rect& rect, uint8_t alpha = 255, uint8_t const* rgb = 0) = 0;
00084 virtual void renderZ(const Rect& rect, float vertexZ, uint8_t alpha = 255, bool forceNewBatch = false, uint8_t const* rgb = 0) {}
00085
00089 SDL_Surface* detachSurface();
00090
00091 SDL_Surface* getSurface() { assert(m_surface); return m_surface; }
00092 const SDL_Surface* getSurface() const { assert(m_surface); return m_surface; }
00093
00099 virtual void setSurface(SDL_Surface* surface) = 0;
00100
00103 void saveImage(const std::string& filename);
00104
00107 static void saveAsPng(const std::string& filename, const SDL_Surface& surface);
00108 static bool putPixel(SDL_Surface* surface, int32_t x, int32_t y, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255);
00109
00110 uint32_t getWidth() const;
00111 uint32_t getHeight() const;
00112 const Rect& getArea() const;
00113
00114 void setXShift(int32_t xshift) {
00115 m_xshift = xshift;
00116 }
00117 int32_t getXShift() const {
00118 return m_xshift;
00119 }
00120 void setYShift(int32_t yshift) {
00121 m_yshift = yshift;
00122 }
00123 int32_t getYShift() const {
00124 return m_yshift;
00125 }
00126
00127 void getPixelRGBA(int32_t x, int32_t y, uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a);
00128
00129 virtual size_t getSize();
00130 virtual void load();
00131 virtual void free();
00132
00135 virtual void useSharedImage(const ImagePtr& shared, const Rect& region) = 0;
00136
00139 virtual void forceLoadInternal() = 0;
00140
00143 bool isSharedImage() const { return m_shared; }
00144
00147 const Rect& getSubImageRect() const { return m_subimagerect; }
00148
00151 virtual void copySubimage(uint32_t xoffset, uint32_t yoffset, const ImagePtr& img);
00152
00153 protected:
00154
00155 SDL_Surface* m_surface;
00156
00157 int32_t m_xshift;
00158
00159 int32_t m_yshift;
00160
00167 void reset(SDL_Surface* surface);
00168
00169
00170 bool m_shared;
00171
00172 Rect m_subimagerect;
00173
00174 private:
00175 std::string createUniqueImageName();
00176 };
00177 }
00178
00179 #endif