ROLAND  0.70
Amstrad Emulator based on Caprice Source rewritten in C++.
image.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) by Fred Klaus *
3  * development@fkweb.de *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
20 #ifndef SDLTK_IMAGE_H
21 #define SDLTK_IMAGE_H
22 
23 #include "exception.h"
24 #include "pixel.h"
25 #include "rect.h"
26 #include "SDL.h"
27 #include "SDL_image.h"
28 #include "glfuncs.h"
29 #include <string>
30 
31 namespace sdltk
32 {
33 
34  class Color;
35  class Point;
36  class Size;
37 
39  class Image
40  {
41 
42  public:
44  Image(bool autoconvert = true);
45  Image(const String & fname, bool autoconvert = true);
46  ~Image();
47 
49  void clear();
51  void load(const String & fname, bool autoconvert, uchar alpha=255);
52  void load(const String & fname, uchar alpha=255);
54  void convert();
56  bool hasAlpha() const {return mHasAlpha;}
58  bool hasColorKey() const {return mHasColorKey;}
60  Uint16 width () const {return mSize.width();}
62  Uint16 height() const {return mSize.height();}
64  const Size & size() const {return mSize;}
65 
68  void setAutoConvert(bool autoconvert) {mAutoConvert=autoconvert;}
69 
70  void setAlpha(uchar alpha=255) {SDL_SetAlpha(mSurface, SDL_SRCALPHA, alpha);}
71  void setColorKey(Color color) {mColorKey = color;}
72 
73  Color pixel(const Point & pos) {return Pixel::get(mSurface, pos.x(), pos.y());}
74  SDL_Surface * surface() {return mSurface;}
75  void * pixels() {return mSurface->pixels;}
76 
77  GLuint texNum() const {return mTexNum;}
78  bool hasTexture() const {return (mTexNum ? true : false);}
79 
80  GLuint textureWidth() const {return mTextureWidth;}
81  GLuint textureHeight() const {return mTextureHeight;}
82 
83  protected:
85  void checkAlpha();
87  void checkColorKey();
88 
89  void genTexture();
90  void calcTexSize();
91  void clearTexture();
92  void clearSurface();
93 
94  private:
95  SDL_Surface * mSurface;
96 
98 
99  bool mHasAlpha;
102 
104 
106 
109  GLuint mTexNum;
110  };
111 
112 } // sdltk
113 
114 #endif // SDLTK_IMAGE_H
GLuint textureHeight() const
Definition: image.h:81
Color pixel(const Point &pos)
Definition: image.h:73
void checkColorKey()
checks the surface for ColorKey
Definition: image.cpp:126
bool mAutoConvert
Definition: image.h:103
void * pixels()
Definition: image.h:75
Image to display either on an OpenGL- or plain SDL-Surface.
Definition: image.h:39
bool hasColorKey() const
has colorkey? RGB(255, 0, 255)
Definition: image.h:58
~Image()
Definition: image.cpp:48
Color mColorKey
Definition: image.h:97
bool hasTexture() const
Definition: image.h:78
void setColorKey(Color color)
Definition: image.h:71
SDL_Surface * mSurface
Definition: image.h:95
Image(bool autoconvert=true)
Constructor. Does some init.
Definition: image.cpp:26
void clearTexture()
Definition: image.cpp:75
unsigned char uchar
Definition: types.h:127
void calcTexSize()
Definition: image.cpp:91
GLuint mTextureWidth
Definition: image.h:107
bool hasAlpha() const
has alphachannel?
Definition: image.h:56
GLuint mTexNum
Definition: image.h:109
void clear()
Clears the Image and frees all resources.
Definition: image.cpp:53
GLuint textureWidth() const
Definition: image.h:80
void convert()
converts an Image to Screenformat
Definition: image.cpp:162
const Size & size() const
Definition: image.h:64
GLuint mTextureHeight
Definition: image.h:108
void load(const String &fname, bool autoconvert, uchar alpha=255)
loads an Image into a SDL_Surface
Definition: image.cpp:147
GLuint texNum() const
Definition: image.h:77
Uint16 width() const
Definition: image.h:60
void genTexture()
Definition: image.cpp:207
bool mHasColorKey
Definition: image.h:100
void setAutoConvert(bool autoconvert)
Definition: image.h:68
bool mHasAlpha
Definition: image.h:99
Uint16 height() const
Definition: image.h:62
Defines a 2D point (x, y)
Definition: point.h:28
Size mSize
Definition: image.h:105
defines a planar size (width, height)
Definition: size.h:30
Uint16 height() const
Definition: size.h:59
RGBA Color Type.
Definition: color.h:30
Uint16 width() const
Definition: size.h:57
Sint16 y
Definition: point.h:35
void setAlpha(uchar alpha=255)
Definition: image.h:70
SDL_Surface * surface()
Definition: image.h:74
std::string String
Definition: types.h:29
the SDL based Stuff
Definition: audio.cpp:22
void clearSurface()
Definition: image.cpp:65
bool mIsConverted
Definition: image.h:101
void checkAlpha()
checks the surface for Alpha
Definition: image.cpp:106