[messages] [Developers] Re: Roadmap for VASSAL 4

uckelman uckelman at nomic.net
Tue May 3 14:00:29 MST 2011


Michael, here's a diff to apply to load_jpeg.cpp which will modify it
(in an ugly way) to load JPEGs to to RGBA instead of RGB format. If you
recompile with this, does your "blue" problem go away?


Code:
diff --git a/cpp-test/load_jpeg.cpp b/cpp-test/load_jpeg.cpp
index 8f86fb3..49df46b 100644
--- a/cpp-test/load_jpeg.cpp
+++ b/cpp-test/load_jpeg.cpp
@@ -6,6 +6,8 @@
 
 #include <jpeglib.h>
 
+#include <boost/scoped_array.hpp>
+
 #include "image.h"
 
 Image load_jpeg(std::string filename) {
@@ -44,13 +46,21 @@ Image load_jpeg(std::string filename) {
   const unsigned int w = cinfo.image_width;
   const unsigned int h = cinfo.image_height;
   const unsigned int bpp = cinfo.num_components;
-  boost::shared_array<GLubyte> data(new GLubyte[w*h*bpp]);
+  boost::shared_array<GLubyte> data(new GLubyte[w*h*4]);
+  boost::scoped_array<GLubyte> scan(new GLubyte[w*bpp]);
 
   // Extract each scanline of the image
   JSAMPROW j;
   for (unsigned int i = 0; i < h; ++i) {
-    j = data.get() + ((h-(i+1))*w*bpp);
+    j = scan.get();
     jpeg_read_scanlines(&cinfo, &j, 1);
+
+    GLubyte *dst = data.get() + ((h-(i+1))*w*4);
+    GLubyte *src = scan.get();
+    for (unsigned int x = 0; x < w*bpp; ++x, ++dst) {
+      *dst = *(src + x);
+      if (x % 3 == 2) ++dst; // skip alpha component in dst
+    }
   }
 
   // Finish decompression and release memory
@@ -58,5 +68,5 @@ Image load_jpeg(std::string filename) {
   jpeg_destroy_decompress(&cinfo);
 
   fclose(fp);
-  return Image(w, h, bpp, bpp == 1 ? GL_LUMINANCE : GL_RGB, data);
+  return Image(w, h, 4, GL_RGBA, data);
 }



_______________________________________________
Read this topic online here:
http://www.vassalengine.org/forum/viewtopic.php?p=22859#p22859


More information about the messages mailing list