[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] CVS: Games/Pingus/src blitter.cxx,1.17,1.18 indexed_canvas.
From: |
grumbel |
Subject: |
[Pingus-CVS] CVS: Games/Pingus/src blitter.cxx,1.17,1.18 indexed_canvas.cxx,1.1,1.2 indexed_canvas.hxx,1.1,1.2 |
Date: |
16 Oct 2002 10:27:33 -0000 |
Update of /usr/local/cvsroot/Games/Pingus/src
In directory dark:/tmp/cvs-serv3318
Modified Files:
blitter.cxx indexed_canvas.cxx indexed_canvas.hxx
Log Message:
fixed some bugs in indexed_canvas and started with writing better rot/flip
blitters
Index: blitter.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/blitter.cxx,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- blitter.cxx 16 Oct 2002 09:14:45 -0000 1.17
+++ blitter.cxx 16 Oct 2002 10:27:30 -0000 1.18
@@ -27,6 +27,7 @@
#include "math.hxx"
#include "blitter.hxx"
#include "debug.hxx"
+#include "indexed_canvas.hxx"
/* Headers needed for i18n / gettext */
#include <clocale>
@@ -614,22 +615,54 @@
Blitter::rotate_90 (const CL_Surface& sur)
{
CL_SurfaceProvider* prov = sur.get_provider ();
- CL_Canvas* canvas = new CL_Canvas (sur.get_height (), sur.get_width ());
- prov->lock ();
- canvas->lock ();
+ if (prov->is_indexed())
+ {
+ std::cout << "Using indexed blitter" << std::endl;
+ int pwidth = prov->get_width();
+ int pheight = prov->get_height();
- float r, b, g, a;
- for (unsigned int y = 0; y < sur.get_height (); ++y)
- for (unsigned int x = 0; x < sur.get_width (); ++x)
- {
- prov->get_pixel (x, y, &r, &g, &b, &a);
- canvas->draw_pixel (sur.get_height () - 1 - y, x , r, g, b, a);
- }
+ IndexedCanvas* canvas = new IndexedCanvas(pheight, pwidth);
+ if (prov->uses_src_colorkey())
+ canvas->set_src_colorkey(prov->get_src_colorkey());
+
+ prov->lock ();
+ canvas->lock ();
- canvas->unlock ();
- prov->unlock ();
- return CL_Surface(canvas, true);
+ canvas->set_palette(prov->get_palette());
+
+ unsigned char* source_buf = static_cast<unsigned
char*>(prov->get_data());
+ unsigned char* target_buf = static_cast<unsigned
char*>(canvas->get_data());
+
+ for (int y = 0; y < pheight; ++y)
+ for (int x = 0; x < pwidth; ++x)
+ {
+ target_buf[x * pheight + (pheight - y - 1)] = source_buf[y *
pwidth + x];
+ }
+
+ canvas->unlock ();
+ prov->unlock ();
+ return CL_Surface(canvas, true);
+ }
+ else
+ {
+ CL_Canvas* canvas = new CL_Canvas (sur.get_height (), sur.get_width ());
+
+ prov->lock ();
+ canvas->lock ();
+
+ float r, b, g, a;
+ for (unsigned int y = 0; y < sur.get_height (); ++y)
+ for (unsigned int x = 0; x < sur.get_width (); ++x)
+ {
+ prov->get_pixel (x, y, &r, &g, &b, &a);
+ canvas->draw_pixel (sur.get_height () - 1 - y, x , r, g, b, a);
+ }
+
+ canvas->unlock ();
+ prov->unlock ();
+ return CL_Surface(canvas, true);
+ }
}
Index: indexed_canvas.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/indexed_canvas.cxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- indexed_canvas.cxx 12 Oct 2002 00:24:26 -0000 1.1
+++ indexed_canvas.cxx 16 Oct 2002 10:27:31 -0000 1.2
@@ -19,21 +19,24 @@
#include "indexed_canvas.hxx"
-IndexedCanvas::IndexedCanvas(int width, int height)
+IndexedCanvas::IndexedCanvas(int w, int h)
+ : width(w),
+ height(h),
+ transcol(-1)
{
data = new unsigned char [width * height];
- new IndexedCanvas(10, 10);
}
IndexedCanvas::~IndexedCanvas()
{
- delete data;
+ delete[] data;
}
void
IndexedCanvas::set_palette(CL_Palette* p)
{
- palette = *p;
+ assert(p);
+ memcpy(palette.palette, p->palette, p->num_colors*3);
}
CL_Palette*
Index: indexed_canvas.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/indexed_canvas.hxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- indexed_canvas.hxx 12 Oct 2002 00:24:26 -0000 1.1
+++ indexed_canvas.hxx 16 Oct 2002 10:27:31 -0000 1.2
@@ -25,11 +25,12 @@
/** This class is analog to CL_Canvas, but instead of being true
color, it is indexed */
-class IndexedCanvas : public CL_SurfaceProvider_Generic
+class IndexedCanvas : public CL_SurfaceProvider
{
private:
unsigned int width;
unsigned int height;
+ int transcol;
unsigned char* data;
CL_Palette palette;
public:
@@ -41,21 +42,26 @@
unsigned int get_pitch() const { return width; }
unsigned int get_height() const { return height; }
- unsigned int get_num_frames() const { return 1; }
+ unsigned int get_num_frames() const { return 1; }
void* get_data() const { return data; }
void set_palette(CL_Palette*);
CL_Palette* get_palette() const;
- void perform_lock() {}
- void perform_unlock() {}
+ void lock() {}
+ void unlock() {}
- bool uses_src_colorkey() const { return false; }
- unsigned int get_src_colorkey() const { return 0; }
+ unsigned int get_bytes_per_pixel () const { return 1; }
+ unsigned int get_depth() const { return 8; }
+
+ bool uses_src_colorkey() const { return transcol != -1; }
+ unsigned int get_src_colorkey() const { return transcol; }
+ void set_src_colorkey(int t) { transcol = t; }
unsigned int get_red_mask() const { return 0; }
unsigned int get_green_mask() const { return 0; }
unsigned int get_blue_mask() const { return 0; }
unsigned int get_alpha_mask() const { return 0; }
+
private:
IndexedCanvas (const IndexedCanvas&);
IndexedCanvas& operator= (const IndexedCanvas&);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] CVS: Games/Pingus/src blitter.cxx,1.17,1.18 indexed_canvas.cxx,1.1,1.2 indexed_canvas.hxx,1.1,1.2,
grumbel <=
- Prev by Date:
[Pingus-CVS] CVS: Games/Pingus/src/worldmap path_graph.cxx,1.14,1.15 path_graph.hxx,1.6,1.7 pathfinder.hxx,1.10,1.11
- Next by Date:
[Pingus-CVS] CVS: Games/Pingus/src action_button.cxx,1.18,1.19 display_graphic_context.cxx,1.7,1.8 pingus_counter.cxx,1.10,1.11 smallmap.cxx,1.25,1.26 spot_map.cxx,1.20,1.21
- Previous by thread:
[Pingus-CVS] CVS: Games/Pingus/src/worldmap path_graph.cxx,1.14,1.15 path_graph.hxx,1.6,1.7 pathfinder.hxx,1.10,1.11
- Next by thread:
[Pingus-CVS] CVS: Games/Pingus/src action_button.cxx,1.18,1.19 display_graphic_context.cxx,1.7,1.8 pingus_counter.cxx,1.10,1.11 smallmap.cxx,1.25,1.26 spot_map.cxx,1.20,1.21
- Index(es):