summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorleo2001-03-26 18:03:32 +0000
committerleo2001-03-26 18:03:32 +0000
commit8d291f870c589a35930c068326daffceebc63daa (patch)
tree2aa85c440c4f3e68efe9c938e6a09d9c74dbe708 /common
parentf1b22e07982337233ee4c1ad4cfbee0334ad93df (diff)
Fixed the file dialog preview.
git-svn-id: http://svn.leocad.org/trunk@264 c7d43263-9d01-0410-8a33-9dba5d9f93d6
Diffstat (limited to 'common')
-rw-r--r--common/image.cpp22
-rw-r--r--common/image.h3
-rw-r--r--common/texture.cpp2
3 files changed, 20 insertions, 7 deletions
diff --git a/common/image.cpp b/common/image.cpp
index 7f2e5c8..1accf6f 100644
--- a/common/image.cpp
+++ b/common/image.cpp
@@ -41,6 +41,20 @@ void Image::FreeData ()
m_pData = NULL;
}
+void Image::Allocate (int width, int height, bool alpha)
+{
+ FreeData ();
+
+ m_nWidth = width;
+ m_nHeight = height;
+ m_bAlpha = alpha;
+
+ if (m_bAlpha)
+ m_pData = (unsigned char*)malloc (width * height * 4);
+ else
+ m_pData = (unsigned char*)malloc (width * height * 3);
+}
+
void Image::ResizePow2 ()
{
int i, shifted_x, shifted_y;
@@ -124,12 +138,11 @@ bool Image::FileLoad (File& file)
file.Seek (-8, SEEK_CUR);
// Check for the BMP header
- if ((buf[0] == 'B') && (buf[1] == 'M'))
+ if ((buf[0] == 'B') && (buf[1] == 'M'))
{
if (!LoadBMP (file))
return false;
- ResizePow2 ();
return true;
}
@@ -139,7 +152,6 @@ bool Image::FileLoad (File& file)
if (!LoadJPG (file))
return false;
- ResizePow2 ();
return true;
}
#endif
@@ -153,20 +165,18 @@ bool Image::FileLoad (File& file)
if (!LoadPNG (file))
return false;
- ResizePow2 ();
return true;
}
#endif
// Check for the GIF header
if ((buf[0] == 'G') && (buf[1] == 'I') && (buf[2] == 'F') &&
- (buf[3] == '8') && ((buf[4] != '7') || (buf[4] == '9')) &&
+ (buf[3] == '8') && ((buf[4] == '7') || (buf[4] == '9')) &&
(buf[5] == 'a'))
{
if (!LoadGIF (file))
return false;
- ResizePow2 ();
return true;
}
diff --git a/common/image.h b/common/image.h
index ae7fb9e..8bff6c5 100644
--- a/common/image.h
+++ b/common/image.h
@@ -19,6 +19,7 @@ public:
void Resize (int width, int height);
void ResizePow2 ();
void FromOpenGL (int width, int height);
+ void Allocate (int width, int height, bool alpha);
int Width () const
{ return m_nWidth; }
@@ -50,4 +51,4 @@ protected:
void SaveVideo(char* filename, Image *images, int count, float fps);
-#endif // _IMAGE_H_ \ No newline at end of file
+#endif // _IMAGE_H_
diff --git a/common/texture.cpp b/common/texture.cpp
index a4d34f2..0f31195 100644
--- a/common/texture.cpp
+++ b/common/texture.cpp
@@ -155,6 +155,8 @@ bool Texture::LoadFromFile (char* strFilename, bool bFilter)
if (image.FileLoad (strFilename))
{
+ image.ResizePow2 ();
+
m_nWidth = image.Width ();
m_nHeight = image.Height ();