jpeg: revert to using RBGA textures
authortheuni <theuni-nospam-@xbmc.org>
Wed, 21 Sep 2011 02:23:03 +0000 (22:23 -0400)
committertheuni <theuni-nospam-@xbmc.org>
Wed, 21 Sep 2011 05:45:20 +0000 (01:45 -0400)
There are still a few issues with the thumbnailer when using a texture
with only 3 components. So until we get everything in order we'll just
use the textures like we did with cximage.

xbmc/guilib/JpegIO.cpp
xbmc/guilib/JpegIO.h
xbmc/guilib/Texture.cpp

index 044b05f..0559b94 100644 (file)
@@ -26,6 +26,7 @@
 #include "settings/Settings.h"
 #include "filesystem/File.h"
 #include "utils/log.h"
+#include "XBTF.h"
 #include "JpegIO.h"
 
 /*Override libjpeg's error function to avoid an exit() call.*/
@@ -239,17 +240,42 @@ bool CJpegIO::GetExif()
   return false;
 }
 
-bool CJpegIO::Decode(const unsigned char *pixels)
+bool CJpegIO::Decode(const unsigned char *pixels, unsigned int format)
 {
-  //requires a pre-allocated buffer of size pitch*3
   unsigned char *dst = (unsigned char *) pixels;
   try
   {
     jpeg_start_decompress( &m_cinfo );
-    while( m_cinfo.output_scanline < m_height )
+
+    if (format == XB_FMT_RGB8)
+    {
+      while( m_cinfo.output_scanline < m_height )
+      {
+       jpeg_read_scanlines( &m_cinfo, &dst, 1 );
+       dst+=m_pitch;
+      }
+    }
+    else if (format == XB_FMT_A8R8G8B8)
     {
-      jpeg_read_scanlines( &m_cinfo, &dst, 1 );
-      dst+=m_pitch;
+      unsigned char* row = new unsigned char[m_width * 3];
+      while( m_cinfo.output_scanline < m_height)
+      {
+        jpeg_read_scanlines( &m_cinfo, &row, 1 );
+        unsigned char *dst2 = dst;
+        for (unsigned int x = 0; x < m_width; x++, dst2 += 4)
+        {
+          dst2[0] = row[(x*3)+2];
+          dst2[1] = row[(x*3)+1];
+          dst2[2] = row[(x*3)+0];
+          dst2[3] = 0xff;
+        }
+        dst += m_width * 4;
+      }
+    }
+    else
+    {
+      CLog::Log(LOGWARNING, "JpegIO: Incorrect output format specified");
+      return false;
     }
     jpeg_finish_decompress( &m_cinfo );
   }
index faca0a0..8d45322 100644 (file)
@@ -37,7 +37,7 @@ public:
   CJpegIO();
   ~CJpegIO();
   bool           Open(const CStdString& m_texturePath,  unsigned int m_minx=0, unsigned int m_miny=0);
-  bool           Decode(const unsigned char *pixels);
+  bool           Decode(const unsigned char *pixels, unsigned int format);
   void           Close();
 
   unsigned int   FileSize()    { return m_imgsize; }
index 7ab1d70..3800c6c 100644 (file)
@@ -307,8 +307,8 @@ bool CBaseTexture::LoadFromFile(const CStdString& texturePath, unsigned int maxW
     {
       if (jpegfile.Width() > 0 && jpegfile.Height() > 0)
       {
-        Allocate(jpegfile.Width(), jpegfile.Height(), XB_FMT_RGB8);
-        if (jpegfile.Decode(m_pixels))
+        Allocate(jpegfile.Width(), jpegfile.Height(), XB_FMT_A8R8G8B8);
+        if (jpegfile.Decode(m_pixels, XB_FMT_A8R8G8B8))
         {
           if (autoRotate && jpegfile.Orientation())
             m_orientation = jpegfile.Orientation() - 1;