imagelib.h
Go to the documentation of this file.00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #if !defined(INCLUDED_IMAGELIB_H)
00027 #define INCLUDED_IMAGELIB_H
00028
00029 #include "iimage.h"
00030 #include "iarchive.h"
00031 #include "idatastream.h"
00032 #include <stdlib.h>
00033
00034 struct RGBAPixel
00035 {
00036 unsigned char red, green, blue, alpha;
00037 };
00038
00039 class RGBAImage: public Image
00040 {
00041 RGBAImage (const RGBAImage& other);
00042 RGBAImage& operator= (const RGBAImage& other);
00043 public:
00044 RGBAPixel* pixels;
00045 unsigned int width, height;
00046
00047 RGBAImage (unsigned int _width, unsigned int _height) :
00048 pixels(new RGBAPixel[_width * _height]), width(_width), height(_height)
00049 {
00050 }
00051 ~RGBAImage ()
00052 {
00053 delete pixels;
00054 }
00055
00056 byte* getRGBAPixels () const
00057 {
00058 return reinterpret_cast<byte*> (pixels);
00059 }
00060 unsigned int getWidth () const
00061 {
00062 return width;
00063 }
00064 unsigned int getHeight () const
00065 {
00066 return height;
00067 }
00068 };
00069
00074 class ScopedArchiveBuffer
00075 {
00076 private:
00077 inline InputStream::byte_type* ArchiveFile_loadBuffer (ArchiveFile& file, std::size_t& length)
00078 {
00079 InputStream::byte_type* buffer = (InputStream::byte_type*) malloc(file.size() + 1);
00080 length = file.getInputStream().read(buffer, file.size());
00081 buffer[file.size()] = 0;
00082 return buffer;
00083 }
00084
00085 inline void ArchiveFile_freeBuffer (InputStream::byte_type* buffer)
00086 {
00087 free(buffer);
00088 }
00089 public:
00090 std::size_t length;
00091 InputStream::byte_type* buffer;
00092
00093 ScopedArchiveBuffer (ArchiveFile& file)
00094 {
00095 buffer = ArchiveFile_loadBuffer(file, length);
00096 }
00097 ~ScopedArchiveBuffer ()
00098 {
00099 ArchiveFile_freeBuffer(buffer);
00100 }
00101 };
00102
00103 #endif