[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] rev 2321 - trunk/src
From: |
Ingo Ruhnke |
Subject: |
[Pingus-CVS] rev 2321 - trunk/src |
Date: |
Sun, 09 May 2004 18:20:24 +0200 |
Author: grumbel
Date: 2004-05-09 18:20:24 +0200 (Sun, 09 May 2004)
New Revision: 2321
Modified:
trunk/src/blitter.cxx
trunk/src/blitter.hxx
trunk/src/blitter_impl.hxx
trunk/src/pingus_resource.cxx
trunk/src/pingus_resource.hxx
Log:
- fixed rotating
Modified: trunk/src/blitter.cxx
===================================================================
--- trunk/src/blitter.cxx 2004-05-09 14:42:59 UTC (rev 2320)
+++ trunk/src/blitter.cxx 2004-05-09 16:20:24 UTC (rev 2321)
@@ -70,6 +70,8 @@
Blitter::put_surface_8bit(CL_PixelBuffer target, CL_PixelBuffer source,
int x_pos, int y_pos)
{
+ //std::cout << "8bit blit" << std::endl;
+
assert(target.get_format().get_depth() == 32);
target.lock();
@@ -110,6 +112,10 @@
*tptr++ = palette.colors[*sptr].get_green();
*tptr++ = palette.colors[*sptr].get_red();
}
+ else
+ {
+ tptr += 4;
+ }
sptr += 1;
}
}
@@ -141,6 +147,8 @@
Blitter::put_surface_32bit(CL_PixelBuffer target, CL_PixelBuffer source,
const int x_pos, const int y_pos)
{
+ //std::cout << "32bit blit" << std::endl;
+
target.lock();
source.lock();
@@ -601,25 +609,23 @@
*/
/** Flip a surface horizontal */
-CL_Surface
-Blitter::flip_horizontal (const CL_Surface& sur)
+CL_PixelBuffer
+Blitter::flip_horizontal (CL_PixelBuffer prov)
{
- return BlitterImpl::modify(sur, BlitterImpl::transform_flip());
+ return BlitterImpl::modify(prov, BlitterImpl::transform_flip());
}
/** Flip a surface vertical */
-CL_Surface
-Blitter::flip_vertical (const CL_Surface& sur)
+CL_PixelBuffer
+Blitter::flip_vertical (CL_PixelBuffer sur)
{
return BlitterImpl::modify(sur, BlitterImpl::transform_rot180_flip());
}
/** Rotate a surface 90 degrees */
-CL_Surface
-Blitter::rotate_90 (const CL_Surface& sur)
+CL_PixelBuffer
+Blitter::rotate_90 (CL_PixelBuffer prov)
{
- CL_PixelBuffer prov = sur.get_pixeldata();
-
if (prov.get_format().get_type() == pixelformat_index)
{
//std::cout << "Using indexed blitter" << std::endl;
@@ -646,61 +652,59 @@
canvas.unlock();
prov.unlock();
- return CL_Surface(new CL_PixelBuffer(canvas), true);
+ return canvas;
}
else
{
- CL_PixelBuffer canvas(sur.get_height (), sur.get_width (),
sur.get_height()*4, CL_PixelFormat::rgba8888);
+ CL_PixelBuffer canvas(prov.get_height (), prov.get_width (),
prov.get_height()*4, CL_PixelFormat::rgba8888);
prov.lock ();
canvas.lock ();
CL_Color color;
- for (int y = 0; y < sur.get_height (); ++y)
- for (int x = 0; x < sur.get_width (); ++x)
+ for (int y = 0; y < prov.get_height (); ++y)
+ for (int x = 0; x < prov.get_width (); ++x)
{
color = prov.get_pixel (x, y);
- canvas.draw_pixel (sur.get_height () - 1 - y, x , color);
+ canvas.draw_pixel (prov.get_height () - 1 - y, x , color);
}
canvas.unlock ();
prov.unlock ();
- return CL_Surface(new CL_PixelBuffer(canvas), true);
+
+ return canvas;
}
}
-CL_Surface
-Blitter::rotate_180 (const CL_Surface& sur)
+CL_PixelBuffer
+Blitter::rotate_180 (CL_PixelBuffer sur)
{
return BlitterImpl::modify(sur, BlitterImpl::transform_rot180());
}
-CL_Surface
-Blitter::rotate_270 (const CL_Surface& sur)
+CL_PixelBuffer
+Blitter::rotate_270 (CL_PixelBuffer sur)
{
return BlitterImpl::modify(sur, BlitterImpl::transform_rot270());
}
-CL_Surface
-Blitter::rotate_90_flip (const CL_Surface& sur)
+CL_PixelBuffer
+Blitter::rotate_90_flip (CL_PixelBuffer sur)
{
return BlitterImpl::modify(sur, BlitterImpl::transform_rot90_flip());
- //return Blitter::flip_horizontal(Blitter::rotate_90(sur));
}
-CL_Surface
-Blitter::rotate_180_flip (const CL_Surface& sur)
+CL_PixelBuffer
+Blitter::rotate_180_flip (CL_PixelBuffer sur)
{
return BlitterImpl::modify(sur, BlitterImpl::transform_rot180_flip());
- //return Blitter::flip_horizontal(Blitter::rotate_180(sur));
}
-CL_Surface
-Blitter::rotate_270_flip (const CL_Surface& sur)
+CL_PixelBuffer
+Blitter::rotate_270_flip (CL_PixelBuffer sur)
{
return BlitterImpl::modify(sur, BlitterImpl::transform_rot270_flip());
- //return Blitter::flip_horizontal(Blitter::rotate_270(sur));
}
} // namespace Pingus
Modified: trunk/src/blitter.hxx
===================================================================
--- trunk/src/blitter.hxx 2004-05-09 14:42:59 UTC (rev 2320)
+++ trunk/src/blitter.hxx 2004-05-09 16:20:24 UTC (rev 2321)
@@ -85,23 +85,23 @@
static CL_Surface scale_surface (const CL_Surface& sur, int width, int
height);
/** Flip a surface horizontal */
- static CL_Surface flip_horizontal (const CL_Surface& sur);
+ static CL_PixelBuffer flip_horizontal (CL_PixelBuffer sur);
/** Flip a surface vertical */
- static CL_Surface flip_vertical (const CL_Surface& sur);
+ static CL_PixelBuffer flip_vertical (CL_PixelBuffer sur);
/** Rotate a surface 90 degrees */
- static CL_Surface rotate_90 (const CL_Surface& sur);
+ static CL_PixelBuffer rotate_90 (CL_PixelBuffer sur);
- static CL_Surface rotate_180 (const CL_Surface& sur);
+ static CL_PixelBuffer rotate_180 (CL_PixelBuffer sur);
- static CL_Surface rotate_270 (const CL_Surface& sur);
+ static CL_PixelBuffer rotate_270 (CL_PixelBuffer sur);
- static CL_Surface rotate_90_flip (const CL_Surface& sur);
+ static CL_PixelBuffer rotate_90_flip (CL_PixelBuffer sur);
- static CL_Surface rotate_180_flip (const CL_Surface& sur);
+ static CL_PixelBuffer rotate_180_flip (CL_PixelBuffer sur);
- static CL_Surface rotate_270_flip (const CL_Surface& sur);
+ static CL_PixelBuffer rotate_270_flip (CL_PixelBuffer sur);
/** Creates a new canvas with the given width and height and
stretches the source surface onto it, the caller is responsible
Modified: trunk/src/blitter_impl.hxx
===================================================================
--- trunk/src/blitter_impl.hxx 2004-05-09 14:42:59 UTC (rev 2320)
+++ trunk/src/blitter_impl.hxx 2004-05-09 16:20:24 UTC (rev 2321)
@@ -180,25 +180,22 @@
template<class TransF>
inline
-CL_Surface modify(const CL_Surface& sur, const TransF&)
+CL_PixelBuffer modify(CL_PixelBuffer prov, const TransF&)
{
- CL_PixelBuffer prov = sur.get_pixeldata();
-
if (prov.get_format().get_type() == pixelformat_index)
{
-#if CLANLIB_0_6
- // FIXME: Needs indexed pixelbuffer
- CL_PixelBuffer canvas(TransF::get_width (pwidth, pheight),
- TransF::get_height(pwidth, pheight));
+ CL_PixelFormat format(8, 0, 0, 0, 0,
+ prov.get_format().has_colorkey(),
prov.get_format().get_colorkey(),
+ pixelformat_index);
+
+ CL_PixelBuffer canvas(TransF::get_width (prov.get_width(),
prov.get_height()),
+ TransF::get_height(prov.get_width(),
prov.get_height()),
+ TransF::get_width (prov.get_width(),
prov.get_height()),
+ format, prov.get_palette());
- if (prov.get_format().has_colorkey())
- canvas.get_format().set_colorkey(prov.get_format().get_colorkey());
-
prov.lock ();
canvas.lock ();
- 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());
@@ -213,13 +210,12 @@
canvas.unlock ();
prov.unlock ();
- return CL_Surface(new CL_PixelBuffer(&canvas), true);
-#endif
- return CL_Surface();
+
+ return canvas;
}
else
{
- CL_PixelBuffer canvas(sur.get_height(), sur.get_width(),
sur.get_width()*4, CL_PixelFormat::rgba8888);
+ CL_PixelBuffer canvas(prov.get_height(), prov.get_width(),
prov.get_width()*4, CL_PixelFormat::rgba8888);
prov.lock();
canvas.lock();
@@ -227,8 +223,8 @@
int pwidth = prov.get_width();
int pheight = prov.get_height();
- for (int y = 0; y < sur.get_height (); ++y)
- for (int x = 0; x < sur.get_width (); ++x)
+ for (int y = 0; y < prov.get_height (); ++y)
+ for (int x = 0; x < prov.get_width (); ++x)
{
CL_Color color = prov.get_pixel(x, y);
canvas.draw_pixel(TransF::get_x(pwidth, pheight, x, y),
@@ -238,7 +234,8 @@
canvas.unlock ();
prov.unlock ();
- return CL_Surface(new CL_PixelBuffer(canvas), true);
+
+ return canvas;
}
}
Modified: trunk/src/pingus_resource.cxx
===================================================================
--- trunk/src/pingus_resource.cxx 2004-05-09 14:42:59 UTC (rev 2320)
+++ trunk/src/pingus_resource.cxx 2004-05-09 16:20:24 UTC (rev 2321)
@@ -129,26 +129,26 @@
}
CL_PixelBuffer
-PingusResource::load_pixelbuffer(const ResDescriptor& desc)
+PingusResource::load_pixelbuffer(const ResDescriptor& desc_)
{
- return load_pixelbuffer(desc.res_name, desc.datafile);
-}
+ CL_SpriteDescription desc = load_sprite_desc(desc_.res_name, desc_.datafile);
-CL_PixelBuffer
-PingusResource::load_pixelbuffer(const std::string& res_name,
- const std::string& datafile)
-{
- CL_SpriteDescription desc = load_sprite_desc(res_name, datafile);
-
if (desc.get_frames().size() == 0)
{
- std::cout << "Error: load_pixelbuffer: " << res_name << " " << datafile
<< std::endl;
+ std::cout << "Error: load_pixelbuffer: " << desc_.res_name << " " <<
desc_.datafile << std::endl;
assert(0);
}
- return *desc.get_frames().begin()->first;
+ return apply_modifier_to_pixelbuffer(*desc.get_frames().begin()->first,
desc_);
}
+CL_PixelBuffer
+PingusResource::load_pixelbuffer(const std::string& res_name,
+ const std::string& datafile)
+{
+ return load_pixelbuffer(ResDescriptor(res_name, datafile));
+}
+
CL_Surface
PingusResource::load_surface(const ResDescriptor& res_desc)
{
@@ -205,39 +205,75 @@
}
}
+CL_PixelBuffer
+PingusResource::apply_modifier_to_pixelbuffer(CL_PixelBuffer prov, const
ResDescriptor& res_desc)
+{
+ switch (res_desc.modifier)
+ {
+ case ResourceModifierNS::ROT0:
+ return prov;
+
+ case ResourceModifierNS::ROT90:
+ return Blitter::rotate_90(prov);
+
+ case ResourceModifierNS::ROT180:
+ return Blitter::rotate_180(prov);
+
+ case ResourceModifierNS::ROT270:
+ return Blitter::rotate_270(prov);
+
+ case ResourceModifierNS::ROT0FLIP:
+ return Blitter::flip_horizontal(prov);
+
+ case ResourceModifierNS::ROT90FLIP:
+ return Blitter::rotate_90_flip(prov);
+
+ case ResourceModifierNS::ROT180FLIP:
+ return Blitter::rotate_180_flip(prov);
+
+ case ResourceModifierNS::ROT270FLIP:
+ return Blitter::rotate_270_flip(prov);
+
+ default:
+ perr << "PingusResource: Unhandled modifier: " << res_desc.modifier <<
std::endl;
+ return prov;
+ }
+}
+
CL_Surface
PingusResource::apply_modifier (const CL_Surface& surf, const ResDescriptor&
res_desc)
{
+ CL_PixelBuffer prov = surf.get_pixeldata();
+
switch (res_desc.modifier)
{
- // FIXME: muahhhaa... I write slower code than you....
case ResourceModifierNS::ROT0:
- return surf;
+ return CL_Surface(new CL_PixelBuffer(prov), true);
case ResourceModifierNS::ROT90:
- return Blitter::rotate_90(surf);
+ return CL_Surface(new CL_PixelBuffer(Blitter::rotate_90(prov)), true);
case ResourceModifierNS::ROT180:
- return Blitter::rotate_180(surf);
-
+ return CL_Surface(new CL_PixelBuffer(Blitter::rotate_180(prov)), true);
+
case ResourceModifierNS::ROT270:
- return Blitter::rotate_270(surf);
+ return CL_Surface(new CL_PixelBuffer(Blitter::rotate_270(prov)), true);
case ResourceModifierNS::ROT0FLIP:
- return Blitter::flip_horizontal(surf);
+ return CL_Surface(new CL_PixelBuffer(Blitter::flip_horizontal(prov)),
true);
case ResourceModifierNS::ROT90FLIP:
- return Blitter::rotate_90_flip(surf);
+ return CL_Surface(new CL_PixelBuffer(Blitter::rotate_90_flip(prov)),
true);
case ResourceModifierNS::ROT180FLIP:
- return Blitter::rotate_180_flip(surf);
+ return CL_Surface(new CL_PixelBuffer(Blitter::rotate_180_flip(prov)),
true);
case ResourceModifierNS::ROT270FLIP:
- return Blitter::rotate_270_flip(surf);
+ return CL_Surface(new CL_PixelBuffer(Blitter::rotate_270_flip(prov)),
true);
default:
perr << "PingusResource: Unhandled modifier: " << res_desc.modifier <<
std::endl;
- return surf;
+ return CL_Surface(new CL_PixelBuffer(prov), true);
}
}
Modified: trunk/src/pingus_resource.hxx
===================================================================
--- trunk/src/pingus_resource.hxx 2004-05-09 14:42:59 UTC (rev 2320)
+++ trunk/src/pingus_resource.hxx 2004-05-09 16:20:24 UTC (rev 2321)
@@ -36,11 +36,12 @@
private:
static std::map<std::string, CL_ResourceManager> resource_map;
static std::map<ResDescriptor, CL_Surface> surface_map;
- static std::map<ResDescriptor, CL_Font> font_map;
+ static std::map<ResDescriptor, CL_Font> font_map;
static CL_Surface load_from_source (const ResDescriptor& res_desc);
static CL_Surface load_from_cache (const ResDescriptor& res_desc);
static CL_Surface apply_modifier (const CL_Surface&, const ResDescriptor&
res_desc);
+ static CL_PixelBuffer apply_modifier_to_pixelbuffer(CL_PixelBuffer, const
ResDescriptor& res_desc);
public:
static void init();
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] rev 2321 - trunk/src,
Ingo Ruhnke <=