ibuf16.h

Go to the documentation of this file.
00001 /*
00002  *  ibuf16.h - 16-bit image buffer.
00003  *
00004  *  Copyright (C) 1998-1999  Jeffrey S. Freedman
00005  *  Copyright (C) 2000-2001  The Exult Team
00006  *
00007  *  This program is free software; you can redistribute it and/or modify
00008  *  it under the terms of the GNU General Public License as published by
00009  *  the Free Software Foundation; either version 2 of the License, or
00010  *  (at your option) any later version.
00011  *
00012  *  This program is distributed in the hope that it will be useful,
00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *  GNU General Public License for more details.
00016  *
00017  *  You should have received a copy of the GNU General Public License
00018  *  along with this program; if not, write to the Free Software
00019  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00020  */
00021 
00022 #ifndef INCL_IBUF16
00023 #define INCL_IBUF16 1
00024 
00025 #include "imagebuf.h"
00026 
00027 /*
00028  *  A 16-bit image buffer:
00029  */
00030 class Image_buffer16 : public Image_buffer
00031   {
00032   unsigned short *palette;  // Palette for 8-bit graphics.
00033   void create_default_palette();
00034   unsigned short *get_pixels()  // Cast bits.
00035     { return (unsigned short *) bits; }
00036 public:
00037   Image_buffer16(unsigned int w, unsigned int h, int dpth)
00038     : Image_buffer(w, h, dpth), palette(0)
00039     {
00040     create_default_palette();
00041     bits = new unsigned char[w*h*2];
00042     }
00043   ~Image_buffer16()
00044     {
00045     delete palette;
00046     }
00047           // Create pixel from r,g,b values.
00048   unsigned short rgb(unsigned short r, unsigned short g,
00049               unsigned short b)
00050     { return ((r&0x1f) << 11) + ((g&0x1f) << 6) + (b&0x1f); }
00051           // Set a palette color.
00052   void set_palette_color(unsigned char num,
00053     unsigned short r, unsigned short g, unsigned short b)
00054     {
00055     palette[num] = rgb(r, g, b);
00056     }
00057           // Set palette.
00058   void set_palette(unsigned char *rgbs, int maxval, 
00059             int brightness = 100);
00060           // Rotate palette colors.
00061   void rotate_colors(int first, int num, int upd);
00062   /*
00063    *  16-bit color methods.
00064    */
00065           // Fill with given pixel.
00066   virtual void fill16(unsigned short pix);
00067           // Fill rect. wth pixel.
00068   virtual void fill16(unsigned short pix, int srcw, int srch,
00069             int destx, int desty);
00070           // Fill line with pixel.
00071   virtual void fill_line16(unsigned short pix, int srcw,
00072             int destx, int desty);
00073           // Copy rectangle into here.
00074   virtual void copy16(unsigned short *src_pixels,
00075         int srcw, int srch, int destx, int desty);
00076   /*
00077    *  Depth-independent methods:
00078    */
00079   virtual Image_buffer *create_another(int w, int h)
00080     { return new Image_buffer16(w, h, depth); }
00081           // Copy within itself.
00082   virtual void copy(int srcx, int srcy, int srcw, int srch, 
00083               int destx, int desty);
00084           // Get rect. into another buf.
00085   virtual void get(Image_buffer *dest, int srcx, int srcy);
00086           // Put rect. back.
00087   virtual void put(Image_buffer *src, int destx, int desty);
00088   
00089   virtual void fill_static(int black, int gray, int white);
00090 
00091   /*
00092    *  8-bit color methods:
00093    */
00094           // Fill with given (8-bit) value.
00095   virtual void fill8(unsigned char val)
00096     { Image_buffer16::fill16(palette[val]); }
00097           // Fill rect. wth pixel.
00098   virtual void fill8(unsigned char val, int srcw, int srch,
00099             int destx, int desty)
00100     { Image_buffer16::fill16(
00101         palette[val], srcw, srch, destx, desty); }
00102           // Fill line with pixel.
00103   virtual void fill_line8(unsigned char val, int srcw,
00104             int destx, int desty)
00105     { Image_buffer16::fill_line16(palette[val], srcw,
00106               destx, desty); }
00107           // Copy rectangle into here.
00108   virtual void copy8(unsigned char *src_pixels,
00109         int srcw, int srch, int destx, int desty);
00110           // Copy line to here.
00111   virtual void copy_line8(unsigned char *src_pixels, int srcw,
00112             int destx, int desty);
00113           // Copy with translucency table.
00114   virtual void copy_line_translucent8(
00115     unsigned char *src_pixels, int srcw,
00116     int destx, int desty, int first_translucent,
00117     int last_translucent, Xform_palette *xforms)
00118     { copy_line8(src_pixels, srcw, destx, desty); }
00119           // Apply translucency to a line.
00120   virtual void fill_line_translucent8(unsigned char val,
00121       int srcw, int destx, int desty, Xform_palette& xform)
00122     { fill_line8(val, srcw, destx, desty); }
00123           // Apply translucency to a rectangle
00124   virtual void fill_translucent8(unsigned char val, int srcw, int srch, 
00125         int destx, int desty, Xform_palette& xform)
00126     { fill8(val, srcw, srcw, destx, desty); }
00127           // Copy rect. with transp. color.
00128   virtual void copy_transparent8(unsigned char *src_pixels, int srcw,
00129           int srch, int destx, int desty);
00130   };
00131 
00132 #endif

Generated on Mon Jul 9 14:42:47 2007 for ExultEngine by  doxygen 1.5.1