imagelib.h

Go to the documentation of this file.
00001 
00005 /*
00006  Copyright (C) 2001-2006, William Joseph.
00007  All Rights Reserved.
00008 
00009  This file is part of GtkRadiant.
00010 
00011  GtkRadiant is free software; you can redistribute it and/or modify
00012  it under the terms of the GNU General Public License as published by
00013  the Free Software Foundation; either version 2 of the License, or
00014  (at your option) any later version.
00015 
00016  GtkRadiant is distributed in the hope that it will be useful,
00017  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  GNU General Public License for more details.
00020 
00021  You should have received a copy of the GNU General Public License
00022  along with GtkRadiant; if not, write to the Free Software
00023  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
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

Generated by  doxygen 1.6.2