1 /**
2  ** Iwin8.h - 8-bit image window.
3  **
4  ** Written: 8/13/98 - JSF
5  **/
6 
7 /*
8 Copyright (C) 1998 Jeffrey S. Freedman
9 
10 This library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Library General Public
12 License as published by the Free Software Foundation; either
13 version 2 of the License, or (at your option) any later version.
14 
15 This library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 Library General Public License for more details.
19 
20 You should have received a copy of the GNU Library General Public
21 License along with this library; if not, write to the
22 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA  02111-1307, USA.
24 */
25 
26 #ifndef INCL_IWIN8
27 #define INCL_IWIN8  1
28 
29 #include "imagewin.h"
30 #include "ibuf8.h"
31 #include <memory>
32 
33 template <class T> class GammaTable;
34 
35 
36 /*
37  *  Here's an 8-bit color-depth window (faster than the generic).
38  */
39 class Image_window8 : public Image_window {
40 	unsigned char colors[768];  // Palette.
41 	Image_buffer8 *ib8;     // Cast to 8-bit buffer.
42 
43 	static GammaTable<unsigned char>    GammaRed;
44 	static GammaTable<unsigned char>    GammaGreen;
45 	static GammaTable<unsigned char>    GammaBlue;
46 public:
47 	Image_window8(unsigned int w, unsigned int h, unsigned int gw, unsigned int gh, int scl = 1,
48 	              bool fs = false, int sclr = point, Image_window::FillMode fillmode = CentreAspectCorrect, unsigned int fillsclr = point);
49 
get_ib8()50 	Image_buffer8 *get_ib8() const {
51 		return ib8;
52 	}
53 	// Set palette.
54 	void set_palette(const unsigned char *rgbs, int maxval,
55 	                 int brightness = 100) override;
56 	// Get palette.
get_palette()57 	virtual const unsigned char *get_palette() const {
58 		return colors;
59 	}
60 	// Rotate palette colors.
61 	void rotate_colors(int first, int num, int upd) override;
62 	/*
63 	 *  8-bit color methods:
64 	 */
65 	// Fill with given (8-bit) value.
fill8(unsigned char val)66 	void fill8(unsigned char val) {
67 		ib8->Image_buffer8::fill8(val);
68 	}
69 	// Fill rect. wth pixel.
fill8(unsigned char val,int srcw,int srch,int destx,int desty)70 	void fill8(unsigned char val, int srcw, int srch,
71 	           int destx, int desty) {
72 		ib8->Image_buffer8::fill8(val, srcw, srch, destx, desty);
73 	}
74 	// Fill line with pixel.
fill_line8(unsigned char val,int srcw,int destx,int desty)75 	void fill_line8(unsigned char val, int srcw,
76 	                int destx, int desty) {
77 		ib8->Image_buffer8::fill_line8(val, srcw, destx, desty);
78 	}
79 	// Copy rectangle into here.
copy8(const unsigned char * src_pixels,int srcw,int srch,int destx,int desty)80 	void copy8(const unsigned char *src_pixels,
81 	           int srcw, int srch, int destx, int desty) {
82 		ib8->Image_buffer8::copy8(src_pixels, srcw, srch,
83 		                          destx, desty);
84 	}
85 	// Copy line to here.
copy_line8(const unsigned char * src_pixels,int srcw,int destx,int desty)86 	void copy_line8(const unsigned char *src_pixels, int srcw,
87 	                int destx, int desty) {
88 		ib8->Image_buffer8::copy_line8(src_pixels, srcw,
89 		                               destx, desty);
90 	}
91 	// Copy with translucency table.
copy_line_translucent8(const unsigned char * src_pixels,int srcw,int destx,int desty,int first_translucent,int last_translucent,const Xform_palette * xforms)92 	void copy_line_translucent8(
93 	    const unsigned char *src_pixels, int srcw,
94 	    int destx, int desty, int first_translucent,
95 	    int last_translucent, const Xform_palette *xforms) {
96 		ib8->Image_buffer8::copy_line_translucent8(src_pixels, srcw,
97 		        destx, desty,
98 		        first_translucent, last_translucent, xforms);
99 	}
100 	// Apply translucency to a line.
fill_line_translucent8(unsigned char val,int srcw,int destx,int desty,const Xform_palette & xform)101 	void fill_line_translucent8(unsigned char val,
102 	                            int srcw, int destx, int desty, const Xform_palette &xform) {
103 		ib8->Image_buffer8::fill_line_translucent8(val,
104 		        srcw, destx, desty, xform);
105 	}
106 	// Copy rect. with transp. color.
copy_transparent8(const unsigned char * src_pixels,int srcw,int srch,int destx,int desty)107 	void copy_transparent8(const unsigned char *src_pixels, int srcw,
108 	                       int srch, int destx, int desty) {
109 		ib8->Image_buffer8::copy_transparent8(src_pixels, srcw, srch,
110 		                                      destx, desty);
111 	}
112 	// Get/put a single pixel.
get_pixel8(int x,int y)113 	unsigned char get_pixel8(int x, int y) {
114 		return ib8->Image_buffer8::get_pixel8(x, y);
115 	}
put_pixel8(unsigned char pix,int x,int y)116 	void put_pixel8(unsigned char pix, int x, int y) {
117 		ib8->Image_buffer8::put_pixel8(pix, x, y);
118 	}
119 
120 	static void get_gamma(double &r, double &g, double &b);
121 	static void set_gamma(double r, double g, double b);
122 
123 	std::unique_ptr<unsigned char[]> mini_screenshot();
124 };
125 
126 #endif
127