Image.cpp

00001 
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024 
00026 // Headers
00028 #include <SFML/Graphics/Image.h>
00029 #include <SFML/Graphics/Image.hpp>
00030 #include <SFML/Internal.h>
00031 
00032 
00033 struct sfImage
00034 {
00035     sf::Image This;
00036 };
00037 
00038 
00042 sfImage* sfImage_Create()
00043 {
00044     return new sfImage;
00045 }
00046 
00047 
00051 sfImage* sfImage_CreateFromColor(unsigned int Width, unsigned int Height, sfColor Color)
00052 {
00053     sfImage* Image = new sfImage;
00054 
00055     Image->This.Create(Width, Height, sf::Color(Color.r, Color.g, Color.b, Color.a));
00056 
00057     return Image;
00058 }
00059 
00060 
00064 sfImage* sfImage_CreateFromPixels(unsigned int Width, unsigned int Height, const sfUint8* Data)
00065 {
00066     sfImage* Image = new sfImage;
00067 
00068     Image->This.LoadFromPixels(Width, Height, Data);
00069 
00070     return Image;
00071 }
00072 
00073 
00077 sfImage* sfImage_CreateFromFile(const char* Filename)
00078 {
00079     sfImage* Image = new sfImage;
00080 
00081     if (!Image->This.LoadFromFile(Filename))
00082     {
00083         delete Image;
00084         Image = NULL;
00085     }
00086 
00087     return Image;
00088 }
00089 
00090 
00094 sfImage* sfImage_CreateFromMemory(const char* Data, size_t SizeInBytes)
00095 {
00096     sfImage* Image = new sfImage;
00097 
00098     if (!Image->This.LoadFromMemory(Data, SizeInBytes))
00099     {
00100         delete Image;
00101         Image = NULL;
00102     }
00103 
00104     return Image;
00105 }
00106 
00107 
00111 void sfImage_Destroy(sfImage* Image)
00112 {
00113     delete Image;
00114 }
00115 
00116 
00120 sfBool sfImage_SaveToFile(sfImage* Image, const char* Filename)
00121 {
00122     CSFML_CALL_RETURN(Image, SaveToFile(Filename), sfFalse);
00123 }
00124 
00125 
00129 void sfImage_CreateMaskFromColor(sfImage* Image, sfColor ColorKey, sfUint8 Alpha)
00130 {
00131     sf::Color SFMLColor(ColorKey.r, ColorKey.g, ColorKey.b, ColorKey.a);
00132     CSFML_CALL(Image, CreateMaskFromColor(SFMLColor, Alpha));
00133 }
00134 
00135 
00140 void sfImage_Resize(sfImage* Image, unsigned int Width, unsigned int Height, sfColor Color)
00141 {
00142     sf::Color SFMLColor(Color.r, Color.g, Color.b, Color.a);
00143     CSFML_CALL(Image, Resize(Width, Height, SFMLColor));
00144 }
00145 
00146 
00151 void sfImage_SetPixel(sfImage* Image, unsigned int X, unsigned int Y, sfColor Color)
00152 {
00153     sf::Color SFMLColor(Color.r, Color.g, Color.b, Color.a);
00154     CSFML_CALL(Image, SetPixel(X, Y, SFMLColor));
00155 }
00156 
00157 
00161 sfColor sfImage_GetPixel(sfImage* Image, unsigned int X, unsigned int Y)
00162 {
00163     sfColor Color = {0, 0, 0, 0};
00164     CSFML_CHECK_RETURN(Image, Color);
00165 
00166     sf::Color SFMLColor = Image->This.GetPixel(X, Y);
00167 
00168     return sfColor_FromRGBA(SFMLColor.r, SFMLColor.g, SFMLColor.b, SFMLColor.a);
00169 }
00170 
00171 
00177 const sfUint8* sfImage_GetPixelsPtr(sfImage* Image)
00178 {
00179     CSFML_CALL_RETURN(Image, GetPixelsPtr(), NULL);
00180 }
00181 
00182 
00186 void sfImage_Bind(sfImage* Image)
00187 {
00188     CSFML_CALL(Image, Bind());
00189 }
00190 
00191 
00195 void sfImage_SetSmooth(sfImage* Image, sfBool Smooth)
00196 {
00197     CSFML_CALL(Image, SetSmooth(Smooth == sfTrue));
00198 }
00199 
00200 
00205 void sfImage_SetRepeat(sfImage* Image, sfBool Repeat)
00206 {
00207     CSFML_CALL(Image, SetRepeat(Repeat == sfTrue));
00208 }
00209 
00210 
00214 unsigned int sfImage_GetWidth(sfImage* Image)
00215 {
00216     CSFML_CALL_RETURN(Image, GetWidth(), 0);
00217 }
00218 
00219 
00223 unsigned int sfImage_GetHeight(sfImage* Image)
00224 {
00225     CSFML_CALL_RETURN(Image, GetHeight(), 0);
00226 }