[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] CVS: Games/Pingus/src/editor thumb_cache.cxx,1.4,1.5
From: |
grumbel |
Subject: |
[Pingus-CVS] CVS: Games/Pingus/src/editor thumb_cache.cxx,1.4,1.5 |
Date: |
23 Jun 2002 11:08:32 -0000 |
Update of /usr/local/cvsroot/Games/Pingus/src/editor
In directory dark:/tmp/cvs-serv9287/editor
Modified Files:
thumb_cache.cxx
Log Message:
- placed all those libxml fwd declarations in its own file
- some thumbnail cache tweaking
Index: thumb_cache.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/editor/thumb_cache.cxx,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- thumb_cache.cxx 22 Jun 2002 14:29:18 -0000 1.4
+++ thumb_cache.cxx 23 Jun 2002 11:08:30 -0000 1.5
@@ -27,8 +27,25 @@
#include "../blitter.hxx"
#include "../system.hxx"
#include "../pingus_resource.hxx"
+#include "../math.hxx"
#include "thumb_cache.hxx"
+using namespace Pingus;
+
+const unsigned int thumbcache_version = 2;
+
+/*
+ ~/.pingus/cache/
+
+ Format:
+ uint32: Version
+ uint32: width
+ uint32: height
+ uint32: mtime of parent image
+ data: ...
+
+ */
+
CL_Surface
ThumbCache::load (const std::string & res_ident, const std::string & datafile)
{
@@ -49,30 +66,29 @@
{
CL_InputSource_File in(filename);
- CL_Canvas* canvas = new CL_Canvas (50, 50);
- canvas->lock ();
- void* buffer = canvas->get_data ();
- size_t buffer_size = 50 * 50 * 4;
-
unsigned int version = in.read_uint32 ();
-
- if (version != 1)
+ if (version != thumbcache_version)
{
std::cout << "Thumbnail: version mismatch" << std::endl;
- delete canvas;
return CL_Surface ();
}
+ unsigned int width = in.read_uint32 ();
+ unsigned int height = in.read_uint32 ();
+
unsigned int timestamp = in.read_uint32 ();
-
// The thumbnail needs an update
if (timestamp != PingusResource::get_mtime (res_ident, datafile))
{
std::cout << "Thumbnail: file needs update" << std::endl;
- delete canvas;
return CL_Surface ();
}
+ CL_Canvas* canvas = new CL_Canvas (width, height);
+ canvas->lock ();
+ void* buffer = canvas->get_data ();
+ size_t buffer_size = width * height * 4;
+
size_t read_size = in.read (buffer, buffer_size);
if (read_size != buffer_size)
@@ -99,7 +115,7 @@
void
ThumbCache::cache (const CL_Surface& sur, const std::string & res_ident, const
std::string & datafile)
{
- if (sur.get_provider ()->get_pitch () * sur.get_provider ()->get_width () <
50 * 50 * 4)
+ if (sur.get_provider ()->get_height () * sur.get_provider ()->get_width () <
50 * 50)
{
std::cout << "ThumbCache: image too small for cache: " << res_ident <<
std::endl;
return;
@@ -123,13 +139,19 @@
{
CL_OutputSource_File out(filename);
- CL_Canvas* canvas = Blitter::scale_surface_to_canvas (sur, 50, 50);
+ unsigned int width = Math::min((unsigned int)50, sur.get_width ());
+ unsigned int height = Math::min((unsigned int)50, sur.get_height ());
+
+ CL_Canvas* canvas = Blitter::scale_surface_to_canvas (sur, width,
height);
canvas->lock ();
void* buffer = canvas->get_data();
int buffer_size = canvas->get_height () * canvas->get_pitch ();
// Versionnumber of the thumbnail format
- out.write_uint32 (1);
+ out.write_uint32 (thumbcache_version);
+
+ out.write_uint32 (width);
+ out.write_uint32 (height);
// Modification time of the parent file
out.write_uint32 (timestamp);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] CVS: Games/Pingus/src/editor thumb_cache.cxx,1.4,1.5,
grumbel <=
- Prev by Date:
[Pingus-CVS] CVS: Games/Pingus/src/backgrounds solidcolor_background.hxx,1.1,1.2 starfield_background.hxx,1.1,1.2 surface_background_data.hxx,1.1,1.2 thunderstorm_background_data.hxx,1.1,1.2
- Next by Date:
[Pingus-CVS] CVS: Games/Pingus/src/worldobjs info_box.hxx,1.1,1.2 switch_door.hxx,1.1,1.2 teleporter.hxx,1.1,1.2
- Previous by thread:
[Pingus-CVS] CVS: Games/Pingus/src/backgrounds solidcolor_background.hxx,1.1,1.2 starfield_background.hxx,1.1,1.2 surface_background_data.hxx,1.1,1.2 thunderstorm_background_data.hxx,1.1,1.2
- Next by thread:
[Pingus-CVS] CVS: Games/Pingus/src/worldobjs info_box.hxx,1.1,1.2 switch_door.hxx,1.1,1.2 teleporter.hxx,1.1,1.2
- Index(es):