]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/tools/compilers/roqvq/NSBitmapImageRep.cpp
hello world
[icculus/iodoom3.git] / neo / tools / compilers / roqvq / NSBitmapImageRep.cpp
1 /*
2 ===========================================================================
3
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company. 
6
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).  
8
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code.  If not, see <http://www.gnu.org/licenses/>.
21
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code.  If not, please request a copy in writing from id Software at the address below.
23
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25
26 ===========================================================================
27 */
28 #include "../../../idlib/precompiled.h"
29 #pragma hdrstop
30
31 #include "roq.h"
32
33 void R_LoadImage( const char *name, byte **pic, int *width, int *height, ID_TIME_T *timestamp, bool makePowerOf2 );
34
35 NSBitmapImageRep::NSBitmapImageRep( void ) {
36         bmap = NULL;
37         width = 0;
38         height = 0;
39         timestamp = 0;
40 }
41
42 NSBitmapImageRep::NSBitmapImageRep( const char *filename ) {
43
44         R_LoadImage( filename, &bmap, &width, &height, &timestamp, false );
45         if (!width || !height) {
46                 common->FatalError( "roqvq: unable to load image %s\n", filename );
47         }
48 }
49
50 NSBitmapImageRep::NSBitmapImageRep( int wide, int high ) {
51         bmap = (byte *)Mem_ClearedAlloc( wide * high * 4 );
52         width = wide;
53         height = high;
54 }
55
56 void R_StaticFree( void *data );
57
58 NSBitmapImageRep::~NSBitmapImageRep() {
59         R_StaticFree( bmap );
60         bmap = NULL;
61 }
62
63 int NSBitmapImageRep::samplesPerPixel( void ) {
64         return 4;
65 }
66
67 int NSBitmapImageRep::pixelsWide( void ) {
68         return width;
69 }
70
71 int NSBitmapImageRep::pixelsHigh( void ) {
72         return height;
73 }
74
75 byte * NSBitmapImageRep::bitmapData( void ) {
76         return bmap;
77 }
78
79 bool NSBitmapImageRep::hasAlpha( void ) {
80         return false;
81 }
82
83 bool NSBitmapImageRep::isPlanar( void ) {
84         return false;
85 }
86
87 NSBitmapImageRep &NSBitmapImageRep::operator=( const NSBitmapImageRep &a ) {
88
89         // check for assignment to self
90         if ( this == &a ) {
91                 return *this;
92         }
93
94         if (bmap) {
95                 Mem_Free(bmap);
96         }
97         bmap    = (byte *)Mem_Alloc( a.width * a.height * 4 );
98         memcpy( bmap, a.bmap, a.width * a.height * 4 );
99         width = a.width;
100         height = a.height;
101         timestamp = a.timestamp;
102
103         return *this;
104 }
105