2
* Copyright (C) 2001 by Holger Rapp
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23
/** Pic::Pic(const Pic& p)
25
* Copy constructor. Slow and simple
30
Pic::Pic(const Pic& p) {
35
/** Pic& Pic::operator=(const Pic& p)
37
* Copy operator. Simple and slow. Don't use often
42
Pic& Pic::operator=(const Pic& p) {
44
sh_clrkey=p.sh_clrkey;
46
bhas_clrkey=p.bhas_clrkey;
50
memcpy(pixels, p.pixels, sizeof(short)*w*h);
55
/** void Pic::set_size(const unsigned short nw, const unsigned short nh)
57
* This functions sets the new size of a pic
59
* Args: nw = new width
63
void Pic::set_size(const unsigned short nw, const unsigned short nh) {
64
if(pixels) free(pixels);
68
// We make sure, that everything pic is aligned to 4bytes, so that clearing can
69
// goes fast with dwords
75
pixels=(unsigned short*) malloc(sizeof(short)*w*h);
83
/** void Pic::clear_all(void)
85
* This function clear all the pixels and sets them to the clrkey, if defined
90
void Pic::clear_all(void) {
93
for(unsigned int i=(w*h-2); i; i-=2) {
98
/** int Pic::load(const char* file)
100
* This function loads a bitmap from a file using the SDL functions
102
* Args: file Path to pic
103
* Returns: RET_OK or ERR_FAILED
105
int Pic::load(const char* file) {
106
if(!file) return ERR_FAILED;
108
SDL_Surface* bmp=NULL;
111
unsigned char* bits, R, G, B;
113
bmp=SDL_LoadBMP(file);
114
if(bmp == NULL) { return ERR_FAILED; }
116
set_size(bmp->w, bmp->h);
120
bits=((Uint8*)bmp->pixels)+y*bmp->pitch+x*bmp->format->BytesPerPixel;
121
R= (Uint8) *((bits)+bmp->format->Rshift/8);
122
G= (Uint8) *((bits)+bmp->format->Gshift/8);
123
B= (Uint8) *((bits)+bmp->format->Bshift/8);
124
set_pixel(x, y, R, G, B);
128
SDL_FreeSurface(bmp);
133
/** void Pic::set_clrkey(unsigned short dclrkey)
135
* sets the clrkey of this pic
137
* Args: dclrkey The clrkey to use
140
void Pic::set_clrkey(unsigned short dclrkey) {
142
clrkey= (dclrkey<<16 | dclrkey);
146
/** void Pic::set_clrkey(unsigned char r, unsigned char g, unsigned char b)
148
* sets the clrkey of this pic
150
* Args: r red value of clrkey
151
* g green value of clrkey
152
* b blue value of clrkey
155
void Pic::set_clrkey(unsigned char r, unsigned char g, unsigned char b) {
156
unsigned short dclrkey=pack_rgb(r,g,b);
158
clrkey= (dclrkey<<16 & clrkey);