]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - libs/imagelib.h
Remove <gtk/gtk.h> from gtkutil/entry.h
[xonotic/netradiant.git] / libs / imagelib.h
1 /*
2    Copyright (C) 2001-2006, William Joseph.
3    All Rights Reserved.
4
5    This file is part of GtkRadiant.
6
7    GtkRadiant is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11
12    GtkRadiant is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with GtkRadiant; if not, write to the Free Software
19    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20  */
21
22 #if !defined( INCLUDED_IMAGELIB_H )
23 #define INCLUDED_IMAGELIB_H
24
25 #include "iimage.h"
26 #include "iarchive.h"
27 #include "idatastream.h"
28 #include <stdlib.h>
29
30 struct RGBAPixel
31 {
32         unsigned char red, green, blue, alpha;
33 };
34
35 class RGBAImage : public Image
36 {
37 RGBAImage( const RGBAImage& other );
38 RGBAImage& operator=( const RGBAImage& other );
39 public:
40 RGBAPixel* pixels;
41 unsigned int width, height;
42
43 RGBAImage( unsigned int _width, unsigned int _height )
44         : pixels( new RGBAPixel[_width * _height] ), width( _width ), height( _height ){
45 }
46 ~RGBAImage(){
47         delete[] pixels;
48 }
49
50 void release(){
51         delete this;
52 }
53 byte* getRGBAPixels() const {
54         return reinterpret_cast<byte*>( pixels );
55 }
56 unsigned int getWidth() const {
57         return width;
58 }
59 unsigned int getHeight() const {
60         return height;
61 }
62 };
63
64 class RGBAImageFlags : public RGBAImage
65 {
66 public:
67 int m_surfaceFlags;
68 int m_contentFlags;
69 int m_value;
70 RGBAImageFlags( unsigned short _width, unsigned short _height, int surfaceFlags, int contentFlags, int value ) :
71         RGBAImage( _width, _height ), m_surfaceFlags( surfaceFlags ), m_contentFlags( contentFlags ), m_value( value ){
72 }
73
74 int getSurfaceFlags() const {
75         return m_surfaceFlags;
76 }
77 int getContentFlags() const {
78         return m_contentFlags;
79 }
80 int getValue() const {
81         return m_value;
82 }
83 };
84
85
86 inline InputStream::byte_type* ArchiveFile_loadBuffer( ArchiveFile& file, std::size_t& length ){
87         InputStream::byte_type* buffer = (InputStream::byte_type*)malloc( file.size() + 1 );
88         length = file.getInputStream().read( buffer, file.size() );
89         buffer[file.size()] = 0;
90         return buffer;
91 }
92
93 inline void ArchiveFile_freeBuffer( InputStream::byte_type* buffer ){
94         free( buffer );
95 }
96
97 class ScopedArchiveBuffer
98 {
99 public:
100 std::size_t length;
101 InputStream::byte_type* buffer;
102
103 ScopedArchiveBuffer( ArchiveFile& file ){
104         buffer = ArchiveFile_loadBuffer( file, length );
105 }
106 ~ScopedArchiveBuffer(){
107         ArchiveFile_freeBuffer( buffer );
108 }
109 };
110
111 class PointerInputStream : public InputStream
112 {
113 const byte* m_read;
114 public:
115 PointerInputStream( const byte* pointer )
116         : m_read( pointer ){
117 }
118 std::size_t read( byte* buffer, std::size_t length ){
119         const byte* end = m_read + length;
120         while ( m_read != end )
121         {
122                 *buffer++ = *m_read++;
123         }
124         return length;
125 }
126 void seek( std::size_t offset ){
127         m_read += offset;
128 }
129 const byte* get(){
130         return m_read;
131 }
132 };
133
134 #endif