imagewin.h

Go to the documentation of this file.
00001 
00007 /*
00008 Copyright (C) 1998 Jeffrey S. Freedman
00009 
00010 This library is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU Library General Public
00012 License as published by the Free Software Foundation; either
00013 version 2 of the License, or (at your option) any later version.
00014 
00015 This library is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 Library General Public License for more details.
00019 
00020 You should have received a copy of the GNU Library General Public
00021 License along with this library; if not, write to the
00022 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00023 Boston, MA  02111-1307, USA.
00024 */
00025 
00026 #ifndef INCL_IMAGEWIN
00027 #define INCL_IMAGEWIN 1
00028 
00029 //#include "SDL_video.h"
00030 #include "imagebuf.h"
00031 #include "exult_types.h"
00032 #include <string>
00033 
00034 struct SDL_Surface;
00035 struct SDL_RWops;
00036 
00037 #ifdef HAVE_OPENGL
00038 #define IF_OPENGL(a,b) if (scaler == OpenGL) a; else b
00039 #else
00040 #define IF_OPENGL(a,b) b
00041 #endif
00042 
00043 /*
00044  *  Here's the top-level class to use for image buffers.  Image_window
00045  *  should be derived from it.
00046  */
00047 
00048 class Image_window
00049   {
00050 public:
00051   // Firstly just some public scaler stuff
00052 
00053   // The scaler types. ScalerNames needs to match this
00054 #ifdef HAVE_OPENGL
00055   enum ScalerType {
00056     point = 0,
00057     interlaced = 1,
00058     bilinear = 2,
00059     BilinearPlus = 3,
00060     SaI = 4,
00061     SuperEagle = 5,
00062     Super2xSaI = 6,
00063     Scale2x = 7,
00064     OpenGL = 8,
00065 
00066     NoScaler = -1,
00067     NumScalers = 9
00068   };
00069 #else
00070   enum ScalerType {
00071     point = 0,
00072     interlaced = 1,
00073     bilinear = 2,
00074     BilinearPlus = 3,
00075     SaI = 4,
00076     SuperEagle = 5,
00077     Super2xSaI = 6,
00078     Scale2x = 7,
00079     OpenGL = 8,
00080 
00081     NoScaler = -1,
00082     NumScalers = 8 // no OpenGL. (But leave it in the enum.)
00083 };
00084 #endif
00085 
00086 
00087   static const char *ScalerNames[];
00088   static ScalerType get_scaler_for_name(const std::string &name);
00089   inline static const char *get_name_for_scaler(int num) { return ScalerNames[num]; }
00090 
00091 protected:
00092   Image_buffer *ibuf;   // Where the data is actually stored.
00093   int scale;      // Only 1 or 2 for now.
00094   int scaler;     // What scaler do we want to use
00095   bool uses_palette;    // Does this window have a palette
00096   bool fullscreen;    // Rendering fullscreen.
00097   SDL_Surface *surface;   // Represents window in memory. (has palette)
00098   SDL_Surface *scaled_surface;  // 2X surface if scaling, else 0. (only used when scaling)
00099   SDL_Surface *unscaled_surface;  // Unscaled surface (used for screenshots only)
00100           // Method to blit scaled:
00101   void (Image_window::*show_scaled)(int x, int y, int w, int h);
00102   /*
00103    *  Scaled blits:
00104    */
00105   void show_scaled8to16_2xSaI(int x, int y, int w, int h);
00106   void show_scaled8to555_2xSaI(int x, int y, int w, int h);
00107   void show_scaled8to565_2xSaI(int x, int y, int w, int h);
00108   void show_scaled8to32_2xSaI(int x, int y, int w, int h);  
00109   void show_scaled8to16_Super2xSaI(int x, int y, int w, int h);
00110   void show_scaled8to555_Super2xSaI(int x, int y, int w, int h);
00111   void show_scaled8to565_Super2xSaI(int x, int y, int w, int h);
00112   void show_scaled8to32_Super2xSaI(int x, int y, int w, int h); 
00113 
00114   void show_scaled8to16_bilinear(int x, int y, int w, int h);
00115   void show_scaled8to555_bilinear(int x, int y, int w, int h);
00116   void show_scaled8to565_bilinear(int x, int y, int w, int h);
00117   void show_scaled8to32_bilinear(int x, int y, int w, int h); 
00118   void show_scaled8to16_SuperEagle(int x, int y, int w, int h);
00119   void show_scaled8to555_SuperEagle(int x, int y, int w, int h);
00120   void show_scaled8to565_SuperEagle(int x, int y, int w, int h);
00121   void show_scaled8to32_SuperEagle(int x, int y, int w, int h); 
00122   void show_scaled_point(int x, int y, int w, int h);
00123   void show_scaled_interlace(int x, int y, int w, int h);
00124   void show_scale2x_noblur(int x, int y, int w, int h);
00125   void show_scaled8to16_BilinearPlus(int x, int y, int w, int h);
00126   void show_scaled8to555_BilinearPlus(int x, int y, int w, int h);
00127   void show_scaled8to565_BilinearPlus(int x, int y, int w, int h);
00128   void show_scaled8to32_BilinearPlus(int x, int y, int w, int h); 
00129   void show_scaledOpenGL(int x, int y, int w, int h);
00130   /*
00131    *  Image info.
00132    */
00133           // Create new SDL surface.
00134   void create_surface(unsigned int w, unsigned int h);
00135   void free_surface();    // Free it.
00136   bool try_scaler(int w, int h, uint32 flags);
00137 public:
00138           // Create with given buffer.
00139   Image_window(Image_buffer *ib, int scl = 1, bool fs = false, int sclr = point)
00140     : ibuf(ib), scale(scl), scaler(sclr), uses_palette(true), 
00141       fullscreen(fs), surface(0), 
00142       scaled_surface(0), show_scaled(0)
00143     { create_surface(ibuf->width, ibuf->height); }
00144   virtual ~Image_window();
00145   int get_scale()     // Returns 1 or 2.
00146     { return scale; }
00147   int get_scaler()    // Returns 1 or 2.
00148     { return scaler; }
00149   bool is_palettized()    // Does the window have a palette?
00150     { return uses_palette; }
00151 
00152           // Is rect. visible within clip?
00153   int is_visible(int x, int y, int w, int h)
00154     { return ibuf->is_visible(x, y, w, h); }
00155           // Set title.
00156   void set_title(const char *title);
00157 
00158   Image_buffer *get_ibuf()
00159     { return ibuf; }
00160   int get_width()
00161     { return ibuf->width; }
00162   int get_height()
00163     { return ibuf->height; }
00164   int ready()     // Ready to draw?
00165     { return (ibuf->bits != 0); }
00166   bool is_fullscreen() { return fullscreen; }
00167           // Create a compatible image buffer.
00168   Image_buffer *create_buffer(int w, int h);
00169           // Resize event occurred.
00170   void resized(unsigned int neww, unsigned int nehh, int newsc, int newscaler = point);
00171   void show();      // Repaint entire window.
00172           // Repaint rectangle.
00173   void show(int x, int y, int w, int h);
00174 
00175   void toggle_fullscreen();
00176           // Set palette.
00177   virtual void set_palette(unsigned char *rgbs, int maxval, 
00178             int brightness = 100)
00179     {  }
00180           // Rotate palette colors.
00181   virtual void rotate_colors(int first, int num, int upd)
00182     {  }
00183   /*
00184    *  16-bit color methods.
00185    */
00186           // Fill with given pixel.
00187   void fill16(unsigned short pix)
00188     { ibuf->fill16(pix); }
00189           // Fill rect. wth pixel.
00190   void fill16(unsigned short pix, int srcw, int srch,
00191             int destx, int desty)
00192     { ibuf->fill16(pix, srcw, srch, destx, desty); }
00193           // Copy rectangle into here.
00194   void copy16(unsigned short *src_pixels,
00195         int srcw, int srch, int destx, int desty)
00196     { ibuf->copy16(src_pixels, srcw, srch, destx, desty); }
00197           // Copy rect. with transp. color.
00198   void copy_transparent16(unsigned char *src_pixels, int srcw,
00199           int srch, int destx, int desty)
00200     { ibuf->copy_transparent16(src_pixels, srcw, srch,
00201               destx, desty); }
00202   /*
00203    *  8-bit color methods:
00204    */
00205           // Fill with given (8-bit) value.
00206   void fill8(unsigned char val)
00207     { ibuf->fill8(val); }
00208           // Fill rect. wth pixel.
00209   void fill8(unsigned char val, int srcw, int srch,
00210             int destx, int desty)
00211     { IF_OPENGL(opengl_fill8(val, srcw, srch, destx, desty),
00212       ibuf->fill8(val, srcw, srch, destx, desty)); }
00213           // Fill line with pixel.
00214   void fill_line8(unsigned char val, int srcw,
00215             int destx, int desty)
00216     { ibuf->fill_line8(val, srcw, destx, desty); }
00217           // Copy rectangle into here.
00218   void copy8(unsigned char *src_pixels,
00219         int srcw, int srch, int destx, int desty)
00220     { ibuf->copy8(src_pixels, srcw, srch, destx, desty); }
00221           // Copy line to here.
00222   void copy_line8(unsigned char *src_pixels, int srcw,
00223             int destx, int desty)
00224     { ibuf->copy_line8(src_pixels, srcw, destx, desty); }
00225           // Copy with translucency table.
00226   void copy_line_translucent8(
00227     unsigned char *src_pixels, int srcw,
00228     int destx, int desty, int first_translucent,
00229     int last_translucent, Xform_palette *xforms)
00230     { ibuf->copy_line_translucent8(src_pixels, srcw, destx, desty,
00231         first_translucent, last_translucent, xforms); }
00232           // Apply translucency to a line.
00233   void fill_line_translucent8(unsigned char val,
00234       int srcw, int destx, int desty, Xform_palette& xform)
00235     { ibuf->fill_line_translucent8(val, srcw, destx, desty,
00236                 xform); }
00237           // Apply translucency to a rectangle
00238   virtual void fill_translucent8(unsigned char val, int srcw, int srch, 
00239         int destx, int desty, Xform_palette& xform)
00240     { IF_OPENGL(opengl_fill_translucent8(val, srcw, srch,
00241       destx, desty, xform), ibuf->fill_translucent8(val, 
00242           srcw, srch, destx, desty, xform)); }
00243           // Copy rect. with transp. color.
00244   void copy_transparent8(unsigned char *src_pixels, int srcw,
00245           int srch, int destx, int desty)
00246     { ibuf->copy_transparent8(src_pixels, srcw, srch,
00247               destx, desty); }
00248   /*
00249    *  OpenGL:
00250    */
00251 #ifdef HAVE_OPENGL
00252           // Fill rect. wth pixel.
00253   void opengl_fill8(unsigned char val, int srcw, int srch,
00254             int destx, int desty);
00255   virtual void opengl_fill_translucent8(unsigned char val, 
00256       int srcw, int srch, int destx, int desty, Xform_palette& xform);
00257 #endif
00258   /*
00259    *  Depth-independent methods:
00260    */
00261   void clear_clip()   // Reset clip to whole window.
00262     { ibuf->clear_clip(); }
00263           // Set clip.
00264   void set_clip(int x, int y, int w, int h)
00265     { ibuf->set_clip(x, y, w, h); }
00266           // Copy within itself.
00267   void copy(int srcx, int srcy, int srcw, int srch, 
00268             int destx, int desty)
00269     { ibuf->copy(srcx, srcy, srcw, srch, destx, desty); }
00270           // Get rect. into another buf.
00271   void get(Image_buffer *dest, int srcx, int srcy)
00272     { ibuf->get(dest, srcx, srcy); }
00273           // Put rect. back.
00274   void put(Image_buffer *src, int destx, int desty)
00275     { ibuf->put(src, destx, desty); }
00276 
00277   bool screenshot(SDL_RWops *dst);
00278   };
00279 
00280 
00281 #endif  /* INCL_IMAGEWIN  */

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