Browse files

Everything's under the CppImage namespace now

  • Loading branch information...
1 parent d883067 commit 51c8a609ae0e762d28095057a892424d02d748a1 @grahamboree committed Nov 20, 2012
Showing with 7,620 additions and 7,629 deletions.
  1. +282 −276 Source/cppimage/CImageIterator.h
  2. +16 −18 Source/cppimage/CxDefines.h
  3. +179 −230 Source/cppimage/CxImage.h
  4. +410 −410 Source/cppimage/formatSpecific/ximabmp.cpp
  5. +18 −16 Source/cppimage/formatSpecific/ximabmp.h
  6. +1,444 −1,442 Source/cppimage/formatSpecific/ximagif.cpp
  7. +191 −193 Source/cppimage/formatSpecific/ximagif.h
  8. +367 −367 Source/cppimage/formatSpecific/ximaico.cpp
  9. +38 −39 Source/cppimage/formatSpecific/ximaico.h
  10. +484 −483 Source/cppimage/formatSpecific/ximajpg.cpp
  11. +3 −3 Source/cppimage/formatSpecific/ximajpg.h
  12. +407 −406 Source/cppimage/formatSpecific/ximapcx.cpp
  13. +39 −40 Source/cppimage/formatSpecific/ximapcx.h
  14. +474 −472 Source/cppimage/formatSpecific/ximapng.cpp
  15. +61 −61 Source/cppimage/formatSpecific/ximapng.h
  16. +1,105 −1,108 Source/cppimage/formatSpecific/ximapsd.cpp
  17. +65 −65 Source/cppimage/formatSpecific/ximapsd.h
  18. +258 −257 Source/cppimage/formatSpecific/ximaraw.cpp
  19. +104 −78 Source/cppimage/formatSpecific/ximaraw.h
  20. +97 −96 Source/cppimage/formatSpecific/ximaska.cpp
  21. +21 −21 Source/cppimage/formatSpecific/ximaska.h
  22. +267 −265 Source/cppimage/formatSpecific/ximatga.cpp
  23. +35 −36 Source/cppimage/formatSpecific/ximatga.h
  24. +856 −855 Source/cppimage/formatSpecific/ximatif.cpp
  25. +34 −36 Source/cppimage/formatSpecific/ximatif.h
  26. +105 −104 Source/cppimage/formatSpecific/ximawbmp.cpp
  27. +30 −31 Source/cppimage/formatSpecific/ximawbmp.h
  28. +183 −182 Source/cppimage/tif_xfile.cpp
  29. +1 −1 Source/cppimage/ximadsp.cpp
  30. +5 −5 Source/cppimage/ximaexif.cpp
  31. +6 −6 Source/cppimage/ximage.cpp
  32. +5 −5 Source/cppimage/ximainfo.cpp
  33. +6 −6 Source/cppimage/ximapal.cpp
  34. +6 −6 Source/cppimage/ximawnd.cpp
  35. +10 −2 cppimage.xcodeproj/project.pbxproj
  36. +8 −8 cppimage_tests/TestCxDefines.h
View
558 Source/cppimage/CImageIterator.h
@@ -31,357 +31,363 @@
#include "CxImage.h"
#include "CxDefines.h"
-//////////////////////////////////////////////////////////////////////////
-class CImageIterator
+namespace CppImage
{
- friend class CxImage;
-
-protected:
- int32_t Itx;
- int32_t Ity; // Counters
- int32_t Stepx;
- int32_t Stepy;
- uint8_t* IterImage; // Image pointer
- CxImage* mImage;
-
-public:
- // Constructors
- CImageIterator();
- CImageIterator(CxImage* inImage);
-
- // Operators
- operator CxImage* ();
-
- // Iterators
- bool ItOK();
- void Reset();
- void Upset();
-
- void GetRow(uint8_t* buf, int32_t n);
- uint8_t* GetRow();
- uint8_t* GetRow(int32_t n);
- void SetRow(uint8_t* buf, int32_t n);
-
- uint8_t GetByte();
- void SetByte(uint8_t b);
-
- bool NextRow();
- bool PrevRow();
-
- bool NextByte();
- bool PrevByte();
-
- void GetSteps(int32_t* x, int32_t* y);
- void SetSteps(int32_t x, int32_t y = 0);
-
- bool NextStep();
- bool PrevStep();
-
- int32_t GetY();
- void SetY(int32_t y); /* AD - for interlace */
-
- bool GetCol(uint8_t* outCol, uint32_t inColIndex);
- bool SetCol(uint8_t* inCol, uint32_t inColIndex);
-};
-
-//////////////////////////////////////////////////////////////////////////
-inline void CImageIterator::SetByte(uint8_t b)
-{
- IterImage[Itx] = b;
-}
-
-//////////////////////////////////////////////////////////////////////////
-inline uint8_t CImageIterator::GetByte()
-{
- return IterImage[Itx];
-}
-
-//////////////////////////////////////////////////////////////////////////
-inline void CImageIterator::SetSteps(int32_t x, int32_t y)
-{
- Stepx = x;
- Stepy = y;
-}
-
-//////////////////////////////////////////////////////////////////////////
-inline void CImageIterator::GetSteps(int32_t* x, int32_t* y)
-{
- *x = Stepx;
- *y = Stepy;
-}
-
-//////////////////////////////////////////////////////////////////////////
-inline int32_t CImageIterator::GetY()
-{
- return Ity;
+ //////////////////////////////////////////////////////////////////////////
+ class CImageIterator
+ {
+ friend class CxImage;
+
+ protected:
+ int32_t Itx;
+ int32_t Ity; // Counters
+ int32_t Stepx;
+ int32_t Stepy;
+ uint8_t* IterImage; // Image pointer
+ CxImage* mImage;
+
+ public:
+ // Constructors
+ CImageIterator();
+ CImageIterator(CxImage* inImage);
+
+ // Operators
+ operator CxImage* ();
+
+ // Iterators
+ bool ItOK();
+ void Reset();
+ void Upset();
+
+ void GetRow(uint8_t* buf, int32_t n);
+ uint8_t* GetRow();
+ uint8_t* GetRow(int32_t n);
+ void SetRow(uint8_t* buf, int32_t n);
+
+ uint8_t GetByte();
+ void SetByte(uint8_t b);
+
+ bool NextRow();
+ bool PrevRow();
+
+ bool NextByte();
+ bool PrevByte();
+
+ void GetSteps(int32_t* x, int32_t* y);
+ void SetSteps(int32_t x, int32_t y = 0);
+
+ bool NextStep();
+ bool PrevStep();
+
+ int32_t GetY();
+ void SetY(int32_t y); /* AD - for interlace */
+
+ bool GetCol(uint8_t* outCol, uint32_t inColIndex);
+ bool SetCol(uint8_t* inCol, uint32_t inColIndex);
+ };
}
-//////////////////////////////////////////////////////////////////////////
-inline CImageIterator::CImageIterator(void)
+namespace CppImage
{
- mImage = NULL;
- IterImage = 0;
- Itx = 0;
- Ity = 0;
- Stepx = 0;
- Stepy = 0;
-}
+ //////////////////////////////////////////////////////////////////////////
+ inline void CImageIterator::SetByte(uint8_t b)
+ {
+ IterImage[Itx] = b;
+ }
-/////////////////////////////////////////////////////////////////////
-inline CImageIterator::CImageIterator(CxImage* inImage)
-: mImage(inImage)
-{
- if (mImage != NULL)
- IterImage = mImage->GetBits();
- Itx = 0;
- Ity = 0;
- Stepx = 0;
- Stepy = 0;
-}
+ //////////////////////////////////////////////////////////////////////////
+ inline uint8_t CImageIterator::GetByte()
+ {
+ return IterImage[Itx];
+ }
-/////////////////////////////////////////////////////////////////////
-inline CImageIterator::operator CxImage* ()
-{
- return mImage;
-}
+ //////////////////////////////////////////////////////////////////////////
+ inline void CImageIterator::SetSteps(int32_t x, int32_t y)
+ {
+ Stepx = x;
+ Stepy = y;
+ }
-/////////////////////////////////////////////////////////////////////
-inline bool CImageIterator::ItOK()
-{
- return (mImage != NULL) && mImage->IsInside(Itx, Ity);
- /*
- if (mImage)
+ //////////////////////////////////////////////////////////////////////////
+ inline void CImageIterator::GetSteps(int32_t* x, int32_t* y)
{
- return mImage->IsInside(Itx, Ity);
+ *x = Stepx;
+ *y = Stepy;
}
- else
+
+ //////////////////////////////////////////////////////////////////////////
+ inline int32_t CImageIterator::GetY()
{
- return false;
- }*/
-}
+ return Ity;
+ }
-/////////////////////////////////////////////////////////////////////
-inline void CImageIterator::Reset()
-{
- if (mImage != NULL)
- IterImage = mImage->GetBits();
- else
+ //////////////////////////////////////////////////////////////////////////
+ inline CImageIterator::CImageIterator(void)
+ {
+ mImage = NULL;
IterImage = 0;
- Itx = 0;
- Ity = 0;
-}
-/////////////////////////////////////////////////////////////////////
-inline void CImageIterator::Upset()
-{
- Itx = 0;
- Ity = mImage->GetHeight() - 1;
- IterImage = mImage->GetBits() + mImage->GetEffWidth() * (mImage->GetHeight() - 1);
-}
+ Itx = 0;
+ Ity = 0;
+ Stepx = 0;
+ Stepy = 0;
+ }
-/////////////////////////////////////////////////////////////////////
-inline bool CImageIterator::NextRow()
-{
- if (++Ity >= (int32_t)mImage->GetHeight())
- return 0;
- IterImage += mImage->GetEffWidth();
- return 1;
-}
+ /////////////////////////////////////////////////////////////////////
+ inline CImageIterator::CImageIterator(CxImage* inImage)
+ : mImage(inImage)
+ {
+ if (mImage != NULL)
+ IterImage = mImage->GetBits();
+ Itx = 0;
+ Ity = 0;
+ Stepx = 0;
+ Stepy = 0;
+ }
-/////////////////////////////////////////////////////////////////////
-inline bool CImageIterator::PrevRow()
-{
- if (--Ity < 0)
- return false;
- IterImage -= mImage->GetEffWidth();
- return true;
-}
+ /////////////////////////////////////////////////////////////////////
+ inline CImageIterator::operator CxImage* ()
+ {
+ return mImage;
+ }
-//////////////////////////////////////////////////////////////////////////
-/* AD - for interlace */
-inline void CImageIterator::SetY(int32_t y)
-{
- if ((y < 0) || (y > (int32_t)mImage->GetHeight()))
- return;
- Ity = y;
- IterImage = mImage->GetBits() + mImage->GetEffWidth()*y;
-}
+ /////////////////////////////////////////////////////////////////////
+ inline bool CImageIterator::ItOK()
+ {
+ return (mImage != NULL) && mImage->IsInside(Itx, Ity);
+ /*
+ if (mImage)
+ {
+ return mImage->IsInside(Itx, Ity);
+ }
+ else
+ {
+ return false;
+ }*/
+ }
-/////////////////////////////////////////////////////////////////////
-inline void CImageIterator::SetRow(uint8_t *buf, int32_t n)
-{
- if (n<0)
+ /////////////////////////////////////////////////////////////////////
+ inline void CImageIterator::Reset()
{
- n = (int32_t)mImage->GetEffWidth();
+ if (mImage != NULL)
+ IterImage = mImage->GetBits();
+ else
+ IterImage = 0;
+ Itx = 0;
+ Ity = 0;
}
- else
+ /////////////////////////////////////////////////////////////////////
+ inline void CImageIterator::Upset()
{
- n = min(n, (int32_t)mImage->GetEffWidth());
+ Itx = 0;
+ Ity = mImage->GetHeight() - 1;
+ IterImage = mImage->GetBits() + mImage->GetEffWidth() * (mImage->GetHeight() - 1);
}
- if ((IterImage!=NULL)&&(buf!=NULL)&&(n>0))
+ /////////////////////////////////////////////////////////////////////
+ inline bool CImageIterator::NextRow()
{
- memcpy(IterImage,buf,n);
+ if (++Ity >= (int32_t)mImage->GetHeight())
+ return 0;
+ IterImage += mImage->GetEffWidth();
+ return 1;
}
-}
-/////////////////////////////////////////////////////////////////////
-inline void CImageIterator::GetRow(uint8_t *buf, int32_t n)
-{
- if ((IterImage!=NULL)&&(buf!=NULL)&&(n>0))
+ /////////////////////////////////////////////////////////////////////
+ inline bool CImageIterator::PrevRow()
{
- memcpy(buf,IterImage,min(n,(int32_t)mImage->GetEffWidth()));
+ if (--Ity < 0)
+ return false;
+ IterImage -= mImage->GetEffWidth();
+ return true;
}
-}
-/////////////////////////////////////////////////////////////////////
-inline uint8_t* CImageIterator::GetRow()
-{
- return IterImage;
-}
-
-/////////////////////////////////////////////////////////////////////
-inline uint8_t* CImageIterator::GetRow(int32_t n)
-{
- SetY(n);
- return IterImage;
-}
-
-/////////////////////////////////////////////////////////////////////
-inline bool CImageIterator::NextByte()
-{
- if (++Itx < (int32_t)mImage->GetEffWidth())
+ //////////////////////////////////////////////////////////////////////////
+ /* AD - for interlace */
+ inline void CImageIterator::SetY(int32_t y)
{
- return 1;
+ if ((y < 0) || (y > (int32_t)mImage->GetHeight()))
+ return;
+ Ity = y;
+ IterImage = mImage->GetBits() + mImage->GetEffWidth()*y;
}
- else
+
+ /////////////////////////////////////////////////////////////////////
+ inline void CImageIterator::SetRow(uint8_t *buf, int32_t n)
{
- if (++Ity < (int32_t)mImage->GetHeight())
+ if (n<0)
{
- IterImage += mImage->GetEffWidth();
- Itx = 0;
- return 1;
+ n = (int32_t)mImage->GetEffWidth();
}
else
{
- return 0;
+ n = min(n, (int32_t)mImage->GetEffWidth());
+ }
+
+ if ((IterImage!=NULL)&&(buf!=NULL)&&(n>0))
+ {
+ memcpy(IterImage,buf,n);
}
}
-}
-/////////////////////////////////////////////////////////////////////
-inline bool CImageIterator::PrevByte()
-{
- if (--Itx >= 0)
+ /////////////////////////////////////////////////////////////////////
+ inline void CImageIterator::GetRow(uint8_t *buf, int32_t n)
{
- return 1;
+ if ((IterImage!=NULL)&&(buf!=NULL)&&(n>0))
+ {
+ memcpy(buf,IterImage,min(n,(int32_t)mImage->GetEffWidth()));
+ }
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ inline uint8_t* CImageIterator::GetRow()
+ {
+ return IterImage;
}
- else
+
+ /////////////////////////////////////////////////////////////////////
+ inline uint8_t* CImageIterator::GetRow(int32_t n)
+ {
+ SetY(n);
+ return IterImage;
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ inline bool CImageIterator::NextByte()
{
- if (--Ity >= 0)
+ if (++Itx < (int32_t)mImage->GetEffWidth())
{
- IterImage -= mImage->GetEffWidth();
- Itx = 0;
return 1;
}
else
{
- return 0;
+ if (++Ity < (int32_t)mImage->GetHeight())
+ {
+ IterImage += mImage->GetEffWidth();
+ Itx = 0;
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
}
}
-}
-/////////////////////////////////////////////////////////////////////
-inline bool CImageIterator::NextStep()
-{
- Itx += Stepx;
- if (Itx < (int32_t)mImage->GetEffWidth())
+ /////////////////////////////////////////////////////////////////////
+ inline bool CImageIterator::PrevByte()
{
- return 1;
- }
- else
- {
- Ity += Stepy;
- if (Ity < (int32_t)mImage->GetHeight())
+ if (--Itx >= 0)
{
- IterImage += mImage->GetEffWidth();
- Itx = 0;
return 1;
}
else
{
- return 0;
+ if (--Ity >= 0)
+ {
+ IterImage -= mImage->GetEffWidth();
+ Itx = 0;
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
}
}
-}
-/////////////////////////////////////////////////////////////////////
-inline bool CImageIterator::PrevStep()
-{
- Itx -= Stepx;
- if (Itx >= 0)
+ /////////////////////////////////////////////////////////////////////
+ inline bool CImageIterator::NextStep()
{
- return 1;
- }
- else
- {
- Ity -= Stepy;
- if (Ity >= 0 && Ity < (int32_t)mImage->GetHeight())
+ Itx += Stepx;
+ if (Itx < (int32_t)mImage->GetEffWidth())
{
- IterImage -= mImage->GetEffWidth();
- Itx = 0;
return 1;
}
else
{
- return 0;
+ Ity += Stepy;
+ if (Ity < (int32_t)mImage->GetHeight())
+ {
+ IterImage += mImage->GetEffWidth();
+ Itx = 0;
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
}
}
-}
-/////////////////////////////////////////////////////////////////////
-inline bool CImageIterator::GetCol(uint8_t* outCol, uint32_t inColIndex)
-{
- if ((outCol == NULL) ||
- (mImage->GetBpp() < 8) ||
- (inColIndex >= mImage->GetWidth()))
+ /////////////////////////////////////////////////////////////////////
+ inline bool CImageIterator::PrevStep()
{
- return 0;
- }
- uint32_t h = mImage->GetHeight();
- //uint32_t line = mImage->GetEffWidth();
- uint8_t bytes = (uint8_t)(mImage->GetBpp() >> 3);
- uint8_t* pSrc;
- for (uint32_t y = 0; y < h; y++)
- {
- pSrc = mImage->GetBits(y) + inColIndex * bytes;
- for (uint8_t w = 0; w < bytes; w++)
+ Itx -= Stepx;
+ if (Itx >= 0)
{
- *outCol++=*pSrc++;
+ return 1;
+ }
+ else
+ {
+ Ity -= Stepy;
+ if (Ity >= 0 && Ity < (int32_t)mImage->GetHeight())
+ {
+ IterImage -= mImage->GetEffWidth();
+ Itx = 0;
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
}
}
- return 1;
-}
-/////////////////////////////////////////////////////////////////////
-inline bool CImageIterator::SetCol(uint8_t* inCol, uint32_t inColIndex)
-{
- if ((inCol == 0) ||
- (mImage->GetBpp() < 8) ||
- (inColIndex >= mImage->GetWidth()))
+ /////////////////////////////////////////////////////////////////////
+ inline bool CImageIterator::GetCol(uint8_t* outCol, uint32_t inColIndex)
{
- return 0;
+ if ((outCol == NULL) ||
+ (mImage->GetBpp() < 8) ||
+ (inColIndex >= mImage->GetWidth()))
+ {
+ return 0;
+ }
+ uint32_t h = mImage->GetHeight();
+ //uint32_t line = mImage->GetEffWidth();
+ uint8_t bytes = (uint8_t)(mImage->GetBpp() >> 3);
+ uint8_t* pSrc;
+ for (uint32_t y = 0; y < h; y++)
+ {
+ pSrc = mImage->GetBits(y) + inColIndex * bytes;
+ for (uint8_t w = 0; w < bytes; w++)
+ {
+ *outCol++=*pSrc++;
+ }
+ }
+ return 1;
}
- uint32_t h = mImage->GetHeight();
- //uint32_t line = mImage->GetEffWidth();
- uint8_t bytes = (uint8_t)(mImage->GetBpp() >> 3);
- uint8_t* pSrc;
- for (uint32_t y = 0; y < h; y++)
+
+ /////////////////////////////////////////////////////////////////////
+ inline bool CImageIterator::SetCol(uint8_t* inCol, uint32_t inColIndex)
{
- pSrc = mImage->GetBits(y) + inColIndex * bytes;
- for (uint8_t w = 0; w < bytes; w++)
+ if ((inCol == 0) ||
+ (mImage->GetBpp() < 8) ||
+ (inColIndex >= mImage->GetWidth()))
{
- *pSrc++=*inCol++;
+ return 0;
}
+ uint32_t h = mImage->GetHeight();
+ //uint32_t line = mImage->GetEffWidth();
+ uint8_t bytes = (uint8_t)(mImage->GetBpp() >> 3);
+ uint8_t* pSrc;
+ for (uint32_t y = 0; y < h; y++)
+ {
+ pSrc = mImage->GetBits(y) + inColIndex * bytes;
+ for (uint8_t w = 0; w < bytes; w++)
+ {
+ *pSrc++=*inCol++;
+ }
+ }
+ return 1;
}
- return 1;
}
View
34 Source/cppimage/CxDefines.h
@@ -178,24 +178,24 @@ namespace CppImage
# define MACRO_GetGValue(rgb) ((uint8_t)(((uint16_t)(rgb)) >> 8))
# define MACRO_GetBValue(rgb) ((uint8_t)((rgb) >> 16))
-# define MACRO_RGB(r,g,b) ((COLORREF)(((uint8_t)(r) | ((uint16_t)((uint8_t)(g)) << 8)) | (((uint32_t)(uint8_t)(b)) << 16)))
+# define MACRO_RGB(r,g,b) ((ColorRef)(((uint8_t)(r) | ((uint16_t)((uint8_t)(g)) << 8)) | (((uint32_t)(uint8_t)(b)) << 16)))
//# define RGB2GRAY(r,g,b) (((b)*114 + (g)*587 + (r)*299)/1000)
# define MACRO_RGB2GRAY(r,g,b) (((b)*117 + (g)*601 + (r)*306) >> 10)
#endif
#if 1
//////////////////////////////////////////////////////////////////////////
- class COLORREF
+ class ColorRef
{
public:
- inline COLORREF(uint8_t r, uint8_t g, uint8_t b)
+ inline ColorRef(uint8_t r, uint8_t g, uint8_t b)
: mValue(static_cast<uint32_t>(r) << 0 |
static_cast<uint32_t>(g) << 8 |
static_cast<uint32_t>(b) << 16)
{}
- inline COLORREF(uint32_t rgb) : mValue(rgb) {}
+ inline ColorRef(uint32_t rgb) : mValue(rgb) {}
inline uint8_t GetRValue() const { return static_cast<uint8_t>(mValue); }
inline uint8_t GetGValue() const { return static_cast<uint8_t>(mValue >> 8); }
@@ -204,33 +204,31 @@ namespace CppImage
/*inline operator uint8_t() { return static_cast<uint8_t>(mValue); }
inline operator uint16_t() { return static_cast<uint16_t>(mValue); }
inline operator uint32_t() { return mValue; }*/
- inline bool operator==(const COLORREF& color) { return color.mValue == mValue; }
+ inline bool operator==(const ColorRef& color) { return color.mValue == mValue; }
inline bool operator==(uint32_t inColor) { return inColor == mValue; }
inline uint32_t operator >>(int inShift) const { return mValue >> inShift; }
inline uint32_t operator <<(int inShift) const { return mValue << inShift; }
private:
uint32_t mValue;
};
-
-
// For compatibility..
- static inline COLORREF RGB(uint8_t r, uint8_t g, uint8_t b) { return COLORREF(r, g, b); }
- static inline uint8_t GetRValue(COLORREF rgb) { return rgb.GetRValue(); }
- static inline uint8_t GetGValue(COLORREF rgb) { return rgb.GetGValue(); }
- static inline uint8_t GetBValue(COLORREF rgb) { return rgb.GetBValue(); }
+ static inline ColorRef RGB(uint8_t r, uint8_t g, uint8_t b) { return ColorRef(r, g, b); }
+ static inline uint8_t GetRValue(ColorRef rgb) { return rgb.GetRValue(); }
+ static inline uint8_t GetGValue(ColorRef rgb) { return rgb.GetGValue(); }
+ static inline uint8_t GetBValue(ColorRef rgb) { return rgb.GetBValue(); }
#else
- typedef uint32_t COLORREF;
+ typedef uint32_t ColorRef;
- static inline uint8_t GetRValue(COLORREF rgb) { return static_cast<uint8_t>(rgb); }
- static inline uint8_t GetGValue(COLORREF rgb) { return static_cast<uint16_t>(rgb) >> 8; }
- static inline uint8_t GetBValue(COLORREF rgb) { return static_cast<uint8_t>(rgb >> 16); }
+ static inline uint8_t GetRValue(ColorRef rgb) { return static_cast<uint8_t>(rgb); }
+ static inline uint8_t GetGValue(ColorRef rgb) { return static_cast<uint16_t>(rgb) >> 8; }
+ static inline uint8_t GetBValue(ColorRef rgb) { return static_cast<uint8_t>(rgb >> 16); }
- static inline COLORREF RGB(uint8_t r, uint8_t g, uint8_t b)
+ static inline ColorRef RGB(uint8_t r, uint8_t g, uint8_t b)
{
- return static_cast<COLORREF>(static_cast<uint32_t>(r) << 0 |
+ return static_cast<ColorRef>(static_cast<uint32_t>(r) << 0 |
static_cast<uint32_t>(g) << 8 |
static_cast<uint32_t>(b) << 16);
}
@@ -271,5 +269,5 @@ namespace CppImage
#endif
}
-using namespace CppImage;
+//using namespace CppImage;
View
409 Source/cppimage/CxImage.h
@@ -1,62 +1,16 @@
/*
- * File: ximage.h
+ * File: CxImage.h
* Purpose: General Purpose Image Class
*/
-/*
- --------------------------------------------------------------------------------
-
- COPYRIGHT NOTICE, DISCLAIMER, and LICENSE:
-
- CxImage version 7.0.1 07/Jan/2011
-
- CxImage : Copyright (C) 2001 - 2010, Davide Pizzolato
-
- Original CImage and CImageIterator implementation are:
- Copyright (C) 1995, Alejandro Aguilar Sierra (asierra(at)servidor(dot)unam(dot)mx)
-
- Covered code is provided under this license on an "as is" basis, without warranty
- of any kind, either expressed or implied, including, without limitation, warranties
- that the covered code is free of defects, merchantable, fit for a particular purpose
- or non-infringing. The entire risk as to the quality and performance of the covered
- code is with you. Should any covered code prove defective in any respect, you (not
- the initial developer or any other contributor) assume the cost of any necessary
- servicing, repair or correction. This disclaimer of warranty constitutes an essential
- part of this license. No use of any covered code is authorized hereunder except under
- this disclaimer.
-
- Permission is hereby granted to use, copy, modify, and distribute this
- source code, or portions hereof, for any purpose, including commercial applications,
- freely and without fee, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
-
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
-
- 3. This notice may not be removed or altered from any source distribution.
-
- --------------------------------------------------------------------------------
-
- Other information about CxImage, and the latest version, can be found at the
- CxImage home page: http://www.xdp.it/cximage/
-
- --------------------------------------------------------------------------------
- */
#pragma once
-/*#if !defined(__CXIMAGE_H)
-#define __CXIMAGE_H*/
#ifdef _LINUX
-#define _XOPEN_SOURCE
+# define _XOPEN_SOURCE
# include <unistd.h>
# include <arpa/inet.h>
#endif
-/////////////////////////////////////////////////////////////////////////////
#include "CxFile.h"
#include "CxIOFile.h"
#include "CxMemfile.h"
@@ -71,66 +25,66 @@ namespace CppImage
enum ENUM_CXIMAGE_FORMATS
{
CXIMAGE_FORMAT_UNKNOWN = 0,
- #if CXIMAGE_SUPPORT_BMP
+#if CXIMAGE_SUPPORT_BMP
CXIMAGE_FORMAT_BMP = 1,
- #endif
- #if CXIMAGE_SUPPORT_GIF
+#endif
+#if CXIMAGE_SUPPORT_GIF
CXIMAGE_FORMAT_GIF = 2,
- #endif
- #if CXIMAGE_SUPPORT_JPG
+#endif
+#if CXIMAGE_SUPPORT_JPG
CXIMAGE_FORMAT_JPG = 3,
- #endif
- #if CXIMAGE_SUPPORT_PNG
+#endif
+#if CXIMAGE_SUPPORT_PNG
CXIMAGE_FORMAT_PNG = 4,
- #endif
- #if CXIMAGE_SUPPORT_ICO
+#endif
+#if CXIMAGE_SUPPORT_ICO
CXIMAGE_FORMAT_ICO = 5,
- #endif
- #if CXIMAGE_SUPPORT_TIF
+#endif
+#if CXIMAGE_SUPPORT_TIF
CXIMAGE_FORMAT_TIF = 6,
- #endif
- #if CXIMAGE_SUPPORT_TGA
+#endif
+#if CXIMAGE_SUPPORT_TGA
CXIMAGE_FORMAT_TGA = 7,
- #endif
- #if CXIMAGE_SUPPORT_PCX
+#endif
+#if CXIMAGE_SUPPORT_PCX
CXIMAGE_FORMAT_PCX = 8,
- #endif
- #if CXIMAGE_SUPPORT_WBMP
+#endif
+#if CXIMAGE_SUPPORT_WBMP
CXIMAGE_FORMAT_WBMP = 9,
- #endif
- #if CXIMAGE_SUPPORT_WMF
+#endif
+#if CXIMAGE_SUPPORT_WMF
CXIMAGE_FORMAT_WMF = 10,
- #endif
- #if CXIMAGE_SUPPORT_JP2
+#endif
+#if CXIMAGE_SUPPORT_JP2
CXIMAGE_FORMAT_JP2 = 11,
- #endif
- #if CXIMAGE_SUPPORT_JPC
+#endif
+#if CXIMAGE_SUPPORT_JPC
CXIMAGE_FORMAT_JPC = 12,
- #endif
- #if CXIMAGE_SUPPORT_PGX
+#endif
+#if CXIMAGE_SUPPORT_PGX
CXIMAGE_FORMAT_PGX = 13,
- #endif
- #if CXIMAGE_SUPPORT_PNM
+#endif
+#if CXIMAGE_SUPPORT_PNM
CXIMAGE_FORMAT_PNM = 14,
- #endif
- #if CXIMAGE_SUPPORT_RAS
+#endif
+#if CXIMAGE_SUPPORT_RAS
CXIMAGE_FORMAT_RAS = 15,
- #endif
- #if CXIMAGE_SUPPORT_JBG
+#endif
+#if CXIMAGE_SUPPORT_JBG
CXIMAGE_FORMAT_JBG = 16,
- #endif
- #if CXIMAGE_SUPPORT_MNG
+#endif
+#if CXIMAGE_SUPPORT_MNG
CXIMAGE_FORMAT_MNG = 17,
- #endif
- #if CXIMAGE_SUPPORT_SKA
+#endif
+#if CXIMAGE_SUPPORT_SKA
CXIMAGE_FORMAT_SKA = 18,
- #endif
- #if CXIMAGE_SUPPORT_RAW
+#endif
+#if CXIMAGE_SUPPORT_RAW
CXIMAGE_FORMAT_RAW = 19,
- #endif
- #if CXIMAGE_SUPPORT_PSD
+#endif
+#if CXIMAGE_SUPPORT_PSD
CXIMAGE_FORMAT_PSD = 20,
- #endif
+#endif
CMAX_IMAGE_FORMATS = CXIMAGE_SUPPORT_BMP + CXIMAGE_SUPPORT_GIF + CXIMAGE_SUPPORT_JPG +
CXIMAGE_SUPPORT_PNG + CXIMAGE_SUPPORT_MNG + CXIMAGE_SUPPORT_ICO +
CXIMAGE_SUPPORT_TIF + CXIMAGE_SUPPORT_TGA + CXIMAGE_SUPPORT_PCX +
@@ -141,11 +95,11 @@ namespace CppImage
};
//////////////////////////////////////////////////////////////////////////
- #if CXIMAGE_SUPPORT_EXIF
+#if CXIMAGE_SUPPORT_EXIF
- # define MAX_COMMENT 255
- # define MAX_SECTIONS 20
- struct tag_ExifInfo
+# define MAX_COMMENT 255
+# define MAX_SECTIONS 20
+ struct ExifInfo
{
char Version [5];
char CameraMake [32];
@@ -179,22 +133,21 @@ namespace CppImage
uint8_t* ThumbnailPointer; /* Pointer at the thumbnail */
unsigned ThumbnailSize; /* Size of thumbnail. */
- bool IsExif;
+ bool IsExif;
};
- typedef tag_ExifInfo EXIFINFO;
- #endif //CXIMAGE_SUPPORT_EXIF
+#endif //CXIMAGE_SUPPORT_EXIF
/////////////////////////////////////////////////////////////////////////////
// CxImage class
class DLL_EXP CxImage
{
private:
//extensible information collector
- struct CXIMAGEINFO
+ struct tagCxImageInfo
{
uint32_t dwEffWidth; ///< uint32_t aligned scan line width
uint8_t* pImage; ///< THE IMAGE BITS
- CxImage* pGhost; ///< if this is a ghost, pGhost points to the body
+ CxImage* pGhost; ///< if this is a ghost, pGhost points to the body
CxImage* pParent; ///< if this is a layer, pParent points to the body
uint32_t dwType; ///< original image format
char szLastError[256]; ///< debugging
@@ -211,7 +164,7 @@ namespace CppImage
int32_t yDPI; ///< vertical resolution
Rect rSelectionBox; ///< bounding rectangle
uint8_t nAlphaMax; ///< max opacity (fade)
- bool bAlphaPaletteEnabled; ///< true if alpha values in the palette are enabled.
+ bool bAlphaPaletteEnabled;///< true if alpha values in the palette are enabled.
bool bEnabled; ///< enables the painting functions
int32_t xOffset;
int32_t yOffset;
@@ -225,65 +178,63 @@ namespace CppImage
bool bGetAllFrames;
bool bLittleEndianHost;
- #if CXIMAGE_SUPPORT_EXIF
- EXIFINFO ExifInfo;
- #endif
+#if CXIMAGE_SUPPORT_EXIF
+ ExifInfo ExifInfo;
+#endif
};
- typedef CXIMAGEINFO tagCxImageInfo;
public: //public structures
struct rgb_color
{
uint8_t r,g,b;
};
- #if CXIMAGE_SUPPORT_WINDOWS
+#if CXIMAGE_SUPPORT_WINDOWS
// <VATI> text placement data
// members must be initialized with the InitTextInfo(&this) function.
- struct CXTEXTINFO
+ struct tagCxTextInfo
{
- #if defined (_WIN32_WCE)
+# if defined (_WIN32_WCE)
TCHAR text[256]; ///< text for windows CE
- #else
+# else
TCHAR text[4096]; ///< text (char -> TCHAR for UNICODE [Cesar M])
- #endif
+# endif
LOGFONT lfont; ///< font and codepage data
- COLORREF fcolor; ///< foreground color
+ ColorRef fcolor; ///< foreground color
int32_t align; ///< DT_CENTER, DT_RIGHT, DT_LEFT aligment for multiline text
uint8_t smooth; ///< text smoothing option. Default is false.
uint8_t opaque; ///< text has background or hasn't. Default is true.
///< data for background (ignored if .opaque==false)
- COLORREF bcolor; ///< background color
+ ColorRef bcolor; ///< background color
float b_opacity; ///< opacity value for background between 0.0-1.0 Default is 0. (opaque)
uint8_t b_outline; ///< outline width for background (zero: no outline)
uint8_t b_round; ///< rounding radius for background rectangle. % of the height, between 0-50. Default is 10.
///< (backgr. always has a frame: width = 3 pixel + 10% of height by default.)
};
- typedef CXTEXTINFO tagCxTextInfo
- #endif
+#endif
public:
- /** \addtogroup Constructors */ //@{
+ /** \addtogroup Constructors */ //@{
CxImage(uint32_t imagetype = 0);
CxImage(uint32_t dwWidth, uint32_t dwHeight, uint32_t wBpp, uint32_t imagetype = 0);
CxImage(const CxImage& src, bool copypixels = true, bool copyselection = true, bool copyalpha = true);
- #if CXIMAGE_SUPPORT_DECODE
+#if CXIMAGE_SUPPORT_DECODE
CxImage(const TCHAR* filename, uint32_t imagetype); // For UNICODE support: char -> TCHAR
CxImage(FILE* stream, uint32_t imagetype);
CxImage(CxFile* stream, uint32_t imagetype);
CxImage(uint8_t* buffer, uint32_t size, uint32_t imagetype);
- #endif
- //@}
+#endif
+ //@}
- /** \addtogroup Destructors */ //@{
+ /** \addtogroup Destructors */ //@{
virtual ~CxImage() { DestroyFrames(); Destroy(); };
- //@}
+ //@}
- /** \addtogroup Operators */ //@{
+ /** \addtogroup Operators */ //@{
CxImage& operator=(const CxImage&);
- //@}
+ //@}
- /** \addtogroup Initialization */ //@{
+ /** \addtogroup Initialization */ //@{
void Clear(uint8_t bval = 0);
void Copy(const CxImage& src, bool copypixels = true, bool copyselection = true, bool copyalpha = true);
void* Create(uint32_t dwWidth, uint32_t dwHeight, uint32_t wBpp, uint32_t imagetype = 0);
@@ -297,9 +248,9 @@ namespace CppImage
uint32_t Dump(uint8_t* dst);
uint32_t DumpSize();
uint32_t UnDump(const uint8_t* src);
- //@}
+ //@}
- /** \addtogroup Attributes */ //@{
+ /** \addtogroup Attributes */ //@{
int32_t GetSize();
uint8_t* GetBits(uint32_t row = 0);
uint8_t GetColorType();
@@ -328,13 +279,13 @@ namespace CppImage
uint8_t GetJpegScale() const;
void SetJpegScale(uint8_t q);
- #if CXIMAGE_SUPPORT_EXIF
- EXIFINFO* GetExifInfo() {return &info.ExifInfo; }
+#if CXIMAGE_SUPPORT_EXIF
+ ExifInfo* GetExifInfo() {return &info.ExifInfo; }
bool GetExifThumbnail(const TCHAR* filename, const TCHAR* outname, int32_t imageType);
- #if CXIMAGE_SUPPORT_TRANSFORMATION
+# if CXIMAGE_SUPPORT_TRANSFORMATION
bool RotateExif(int32_t orientation = 0);
- #endif
- #endif
+# endif
+#endif
int32_t GetXDPI() const;
int32_t GetYDPI() const;
@@ -377,60 +328,60 @@ namespace CppImage
//void* GetUserData() const {return info.pUserData;}
//void SetUserData(void* pUserData) {info.pUserData = pUserData;}
- //@}
-
- /** \addtogroup Palette
- * These functions have no effects on RGB images and in this case the returned value is always 0.
- * @{ */
- bool IsGrayScale();
- bool IsIndexed() const;
- bool IsSamePalette(CxImage& img, bool bCheckAlpha = true);
+ //@}
+
+ /** \addtogroup Palette
+ * These functions have no effects on RGB images and in this case the returned value is always 0.
+ * @{ */
+ bool IsGrayScale();
+ bool IsIndexed() const;
+ bool IsSamePalette(CxImage& img, bool bCheckAlpha = true);
uint32_t GetPaletteSize();
- RGBQuad* GetPalette() const;
- RGBQuad GetPaletteColor(uint8_t idx);
- bool GetPaletteColor(uint8_t i, uint8_t* r, uint8_t* g, uint8_t* b);
- uint8_t GetNearestIndex(RGBQuad c);
- void BlendPalette(COLORREF cr,int32_t perc);
- void SetGrayPalette();
- void SetPalette(uint32_t n, uint8_t* r, uint8_t* g, uint8_t* b);
- void SetPalette(RGBQuad* pPal,uint32_t nColors=256);
- void SetPalette(rgb_color* rgb,uint32_t nColors=256);
- void SetPaletteColor(uint8_t idx, uint8_t r, uint8_t g, uint8_t b, uint8_t alpha=0);
- void SetPaletteColor(uint8_t idx, RGBQuad c);
- void SetPaletteColor(uint8_t idx, COLORREF cr);
- void SwapIndex(uint8_t idx1, uint8_t idx2);
- void SwapRGB2BGR();
- void SetStdPalette();
- //@}
-
- /** \addtogroup Pixel */ //@{
+ RGBQuad* GetPalette() const;
+ RGBQuad GetPaletteColor(uint8_t idx);
+ bool GetPaletteColor(uint8_t i, uint8_t* r, uint8_t* g, uint8_t* b);
+ uint8_t GetNearestIndex(RGBQuad c);
+ void BlendPalette(ColorRef cr,int32_t perc);
+ void SetGrayPalette();
+ void SetPalette(uint32_t n, uint8_t* r, uint8_t* g, uint8_t* b);
+ void SetPalette(RGBQuad* pPal,uint32_t nColors=256);
+ void SetPalette(rgb_color* rgb,uint32_t nColors=256);
+ void SetPaletteColor(uint8_t idx, uint8_t r, uint8_t g, uint8_t b, uint8_t alpha=0);
+ void SetPaletteColor(uint8_t idx, RGBQuad c);
+ void SetPaletteColor(uint8_t idx, ColorRef cr);
+ void SwapIndex(uint8_t idx1, uint8_t idx2);
+ void SwapRGB2BGR();
+ void SetStdPalette();
+ //@}
+
+ /** \addtogroup Pixel */ //@{
bool IsInside(int32_t x, int32_t y);
bool IsTransparent(int32_t x, int32_t y);
bool GetTransparentMask(CxImage* iDst = 0);
RGBQuad GetPixelColor(int32_t x, int32_t y, bool bGetAlpha = true);
uint8_t GetPixelIndex(int32_t x, int32_t y);
uint8_t GetPixelGray(int32_t x, int32_t y);
void SetPixelColor(int32_t x, int32_t y, RGBQuad c, bool bSetAlpha = false);
- void SetPixelColor(int32_t x, int32_t y, COLORREF cr);
+ void SetPixelColor(int32_t x, int32_t y, ColorRef cr);
void SetPixelIndex(int32_t x, int32_t y, uint8_t i);
void DrawLine(int32_t StartX, int32_t EndX, int32_t StartY, int32_t EndY, RGBQuad color, bool bSetAlpha = false);
- void DrawLine(int32_t StartX, int32_t EndX, int32_t StartY, int32_t EndY, COLORREF cr);
+ void DrawLine(int32_t StartX, int32_t EndX, int32_t StartY, int32_t EndY, ColorRef cr);
void BlendPixelColor(int32_t x,int32_t y,RGBQuad c, float blend, bool bSetAlpha = false);
- //@}
+ //@}
protected:
- /** \addtogroup Protected */ //@{
+ /** \addtogroup Protected */ //@{
uint8_t BlindGetPixelIndex(const int32_t x, const int32_t y);
RGBQuad BlindGetPixelColor(const int32_t x, const int32_t y, bool bGetAlpha = true);
void* BlindGetPixelPointer(const int32_t x, const int32_t y);
void BlindSetPixelColor(int32_t x, int32_t y, RGBQuad c, bool bSetAlpha = false);
void BlindSetPixelIndex(int32_t x, int32_t y, uint8_t i);
- //@}
+ //@}
public:
- #if CXIMAGE_SUPPORT_INTERPOLATION
- /** \addtogroup Interpolation */ //@{
+#if CXIMAGE_SUPPORT_INTERPOLATION
+ /** \addtogroup Interpolation */ //@{
//overflow methods:
enum OverflowMethod
{
@@ -469,14 +420,14 @@ namespace CppImage
};
RGBQuad GetPixelColorInterpolated(float x, float y, InterpolationMethod const inMethod = IM_BILINEAR, OverflowMethod const ofMethod = OM_BACKGROUND, RGBQuad* const rplColor = 0);
RGBQuad GetAreaColorInterpolated(float const xc, float const yc, float const w, float const h, InterpolationMethod const inMethod, OverflowMethod const ofMethod = OM_BACKGROUND, RGBQuad* const rplColor = 0);
- //@}
+ //@}
protected:
- /** \addtogroup Protected */ //@{
+ /** \addtogroup Protected */ //@{
void AddAveragingCont(RGBQuad const& color, float const surf, float& rr, float& gg, float& bb, float& aa);
- //@}
+ //@}
- /** \addtogroup Kernels */ //@{
+ /** \addtogroup Kernels */ //@{
public:
static float KernelBSpline(const float x);
static float KernelLinear(const float t);
@@ -499,11 +450,11 @@ namespace CppImage
static float KernelCatrom(const float x);
static float KernelHanning(const float x);
static float KernelPower(const float x, const float a = 2);
- //@}
- #endif //CXIMAGE_SUPPORT_INTERPOLATION
+ //@}
+#endif //CXIMAGE_SUPPORT_INTERPOLATION
- /** \addtogroup Painting */ //@{
- #if CXIMAGE_SUPPORT_WINDOWS
+ /** \addtogroup Painting */ //@{
+#if CXIMAGE_SUPPORT_WINDOWS
int32_t Blt(HDC pDC, int32_t x = 0, int32_t y = 0);
HBITMAP Draw2HBITMAP(HDC hdc, int32_t x, int32_t y, int32_t cx, int32_t cy, Rect* pClipRect, bool bSmooth);
HBITMAP MakeBitmap(HDC hdc = NULL, bool bTransparency = false);
@@ -522,21 +473,21 @@ namespace CppImage
//int32_t DrawString(HDC hdc, int32_t x, int32_t y, const char* text, RGBQuad color, const char* font, int32_t lSize=0, int32_t lWeight=400, uint8_t bItalic=0, uint8_t bUnderline=0, bool bSetAlpha=false);
int32_t DrawString(HDC hdc, int32_t x, int32_t y, const TCHAR* text, RGBQuad color, const TCHAR* font, int32_t lSize = 0, int32_t lWeight = 400, uint8_t bItalic = 0, uint8_t bUnderline = 0, bool bSetAlpha = false);
// <VATI> extensions
- int32_t DrawStringEx(HDC hdc, int32_t x, int32_t y, CXTEXTINFO* pTextType, bool bSetAlpha = false);
- void InitTextInfo(CXTEXTINFO* txt);
+ int32_t DrawStringEx(HDC hdc, int32_t x, int32_t y, tagCxTextInfo* pTextType, bool bSetAlpha = false);
+ void InitTextInfo(tagCxTextInfo* txt);
protected:
bool IsHBITMAPAlphaValid(HBITMAP hbmp);
public:
- #endif //CXIMAGE_SUPPORT_WINDOWS
- //@}
+#endif //CXIMAGE_SUPPORT_WINDOWS
+ //@}
// file operations
- #if CXIMAGE_SUPPORT_DECODE
- /** \addtogroup Decode */ //@{
- #ifdef WIN32
+#if CXIMAGE_SUPPORT_DECODE
+ /** \addtogroup Decode */ //@{
+# ifdef WIN32
//bool Load(LPCWSTR filename, uint32_t imagetype=0);
bool LoadResource(HRSRC hRes, uint32_t imagetype, HMODULE hModule = NULL);
- #endif
+# endif
// For UNICODE support: char -> TCHAR
bool Load(const TCHAR* filename, uint32_t imagetype = 0);
//bool Load(const char * filename, uint32_t imagetype=0);
@@ -546,20 +497,20 @@ namespace CppImage
bool CheckFormat(CxFile* hFile, uint32_t imagetype = 0);
bool CheckFormat(uint8_t* buffer, uint32_t size, uint32_t imagetype = 0);
- //@}
- #endif //CXIMAGE_SUPPORT_DECODE
+ //@}
+#endif //CXIMAGE_SUPPORT_DECODE
- #if CXIMAGE_SUPPORT_ENCODE
+#if CXIMAGE_SUPPORT_ENCODE
protected:
- /** \addtogroup Protected */ //@{
+ /** \addtogroup Protected */ //@{
bool EncodeSafeCheck(CxFile* hFile);
- //@}
+ //@}
public:
- /** \addtogroup Encode */ //@{
- #ifdef WIN32
+ /** \addtogroup Encode */ //@{
+# ifdef WIN32
//bool Save(LPCWSTR filename, uint32_t imagetype=0);
- #endif
+# endif
// For UNICODE support: char -> TCHAR
bool Save(const TCHAR* filename, uint32_t imagetype);
//bool Save(const char * filename, uint32_t imagetype=0);
@@ -571,10 +522,10 @@ namespace CppImage
bool Encode2RGBA(CxFile* hFile, bool bFlipY = false);
bool Encode2RGBA(uint8_t*& buffer, int32_t& size, bool bFlipY = false);
- //@}
- #endif //CXIMAGE_SUPPORT_ENCODE
+ //@}
+#endif //CXIMAGE_SUPPORT_ENCODE
- /** \addtogroup Attributes */ //@{
+ /** \addtogroup Attributes */ //@{
//misc.
bool IsValid() const;
bool IsEnabled() const;
@@ -584,22 +535,22 @@ namespace CppImage
int32_t GetNumFrames() const;
int32_t GetFrame() const;
void SetFrame(int32_t nFrame);
- //@}
+ //@}
- #if CXIMAGE_SUPPORT_BASICTRANSFORMATIONS
- /** \addtogroup BasicTransformations */ //@{
+#if CXIMAGE_SUPPORT_BASICTRANSFORMATIONS
+ /** \addtogroup BasicTransformations */ //@{
bool GrayScale();
bool Flip(bool bFlipSelection = false, bool bFlipAlpha = true);
bool Mirror(bool bMirrorSelection = false, bool bMirrorAlpha = true);
bool Negative();
bool RotateLeft(CxImage* iDst = NULL);
bool RotateRight(CxImage* iDst = NULL);
bool IncreaseBpp(uint32_t nbit);
- //@}
- #endif //CXIMAGE_SUPPORT_BASICTRANSFORMATIONS
+ //@}
+#endif //CXIMAGE_SUPPORT_BASICTRANSFORMATIONS
- #if CXIMAGE_SUPPORT_TRANSFORMATION
- /** \addtogroup Transformations */ //@{
+#if CXIMAGE_SUPPORT_TRANSFORMATION
+ /** \addtogroup Transformations */ //@{
// image operations
bool Rotate(float angle, CxImage* iDst = NULL);
bool Rotate2(float angle, CxImage *iDst = NULL, InterpolationMethod inMethod = IM_BILINEAR, OverflowMethod ofMethod = OM_BACKGROUND, RGBQuad* replColor = 0, bool const optimizeRightAngles = true, bool const bKeepOriginalSize = false);
@@ -618,11 +569,11 @@ namespace CppImage
bool CircleTransform(int32_t type,int32_t rmax = 0, float Koeff = 1.0f);
bool QIShrink(int32_t newx, int32_t newy, CxImage* const iDst = NULL, bool bChangeBpp = false);
- //@}
- #endif //CXIMAGE_SUPPORT_TRANSFORMATION
+ //@}
+#endif //CXIMAGE_SUPPORT_TRANSFORMATION
- #if CXIMAGE_SUPPORT_DSP
- /** \addtogroup DSP */ //@{
+#if CXIMAGE_SUPPORT_DSP
+ /** \addtogroup DSP */ //@{
enum ImageOpType
{
OpAdd,
@@ -682,10 +633,10 @@ namespace CppImage
bool AdaptiveThreshold(int32_t method = 0, int32_t nBoxSize = 64, CxImage* pContrastMask = 0, int32_t nBias = 0, float fGlobalLocalBalance = 0.5f);
bool RedEyeRemove(float strength = 0.8f);
bool Trace(RGBQuad color_target, RGBQuad color_trace);
- //@}
+ //@}
protected:
- /** \addtogroup Protected */ //@{
+ /** \addtogroup Protected */ //@{
bool IsPowerof2(int32_t x);
bool FFT(int32_t dir, int32_t m, double *x, double *y);
bool DFT(int32_t dir, int32_t m, double *x1, double *y1, double *x2, double *y2);
@@ -695,17 +646,17 @@ namespace CppImage
float* gen_lookup_table(float* cmatrix, int32_t cmatrix_length);
void blur_line(float* ctable, float* cmatrix, int32_t cmatrix_length, uint8_t* cur_col, uint8_t* dest_col, int32_t y, int32_t bytes);
void blur_text(uint8_t threshold, uint8_t decay, uint8_t max_depth, CxImage* iSrc, CxImage* iDst, uint8_t bytes);
- //@}
+ //@}
public:
- /** \addtogroup ColorSpace */ //@{
+ /** \addtogroup ColorSpace */ //@{
bool SplitRGB(CxImage* r, CxImage* g, CxImage* b);
bool SplitYUV(CxImage* y, CxImage* u, CxImage* v);
bool SplitHSL(CxImage* h, CxImage* s, CxImage* l);
bool SplitYIQ(CxImage* y, CxImage* i, CxImage* q);
bool SplitXYZ(CxImage* x, CxImage* y, CxImage* z);
bool SplitCMYK(CxImage* c, CxImage* m, CxImage* y, CxImage* k);
- static RGBQuad HSLtoRGB(COLORREF cHSLColor);
+ static RGBQuad HSLtoRGB(ColorRef cHSLColor);
static RGBQuad RGBtoHSL(RGBQuad lRGBColor);
static RGBQuad HSLtoRGB(RGBQuad lHSLColor);
static RGBQuad YUVtoRGB(RGBQuad lYUVColor);
@@ -714,14 +665,14 @@ namespace CppImage
static RGBQuad RGBtoYIQ(RGBQuad lRGBColor);
static RGBQuad XYZtoRGB(RGBQuad lXYZColor);
static RGBQuad RGBtoXYZ(RGBQuad lRGBColor);
- #endif //CXIMAGE_SUPPORT_DSP
- static RGBQuad RGBtoRGBQUAD(COLORREF cr);
- static COLORREF RGBQUADtoRGB(RGBQuad c);
- //@}
+#endif //CXIMAGE_SUPPORT_DSP
+ static RGBQuad RGBtoRGBQUAD(ColorRef cr);
+ static ColorRef RGBQUADtoRGB(RGBQuad c);
+ //@}
- /** \addtogroup Selection */ //@{
+ /** \addtogroup Selection */ //@{
bool SelectionIsValid();
- #if CXIMAGE_SUPPORT_SELECTION
+#if CXIMAGE_SUPPORT_SELECTION
bool SelectionClear(uint8_t level = 0);
bool SelectionCreate();
bool SelectionDelete();
@@ -742,20 +693,20 @@ namespace CppImage
bool SelectionSet(CxImage& from);
void SelectionRebuildBox();
uint8_t* SelectionGetPointer(const int32_t x = 0, const int32_t y = 0);
- //@}
+ //@}
protected:
- /** \addtogroup Protected */ //@{
+ /** \addtogroup Protected */ //@{
bool BlindSelectionIsInside(int32_t x, int32_t y);
uint8_t BlindSelectionGet(const int32_t x, const int32_t y);
void SelectionSet(const int32_t x, const int32_t y, const uint8_t level);
- //@}
+ //@}
public:
- #endif //CXIMAGE_SUPPORT_SELECTION
+#endif //CXIMAGE_SUPPORT_SELECTION
- #if CXIMAGE_SUPPORT_ALPHA
- /** \addtogroup Alpha */ //@{
+#if CXIMAGE_SUPPORT_ALPHA
+ /** \addtogroup Alpha */ //@{
void AlphaClear();
bool AlphaCreate();
void AlphaDelete();
@@ -780,32 +731,32 @@ namespace CppImage
bool AlphaPaletteIsEnabled();
bool AlphaPaletteIsValid();
bool AlphaPaletteSplit(CxImage* dest);
- //@}
+ //@}
protected:
- /** \addtogroup Protected */ //@{
+ /** \addtogroup Protected */ //@{
uint8_t BlindAlphaGet(const int32_t x, const int32_t y);
- //@}
- #endif //CXIMAGE_SUPPORT_ALPHA
+ //@}
+#endif //CXIMAGE_SUPPORT_ALPHA
public:
- #if CXIMAGE_SUPPORT_LAYERS
- /** \addtogroup Layers */ //@{
+#if CXIMAGE_SUPPORT_LAYERS
+ /** \addtogroup Layers */ //@{
bool LayerCreate(int32_t position = -1);
bool LayerDelete(int32_t position = -1);
void LayerDeleteAll();
CxImage* GetLayer(int32_t position);
CxImage* GetParent() const;
int32_t GetNumLayers() const;
- #ifdef WIN32 //@HACK
+# ifdef WIN32 //@HACK
int32_t LayerDrawAll(HDC hdc, int32_t x = 0, int32_t y = 0, int32_t cx = -1, int32_t cy = -1, Rect* pClipRect = 0, bool bSmooth = false);
int32_t LayerDrawAll(HDC hdc, const Rect& rect, Rect* pClipRect = NULL, bool bSmooth = false);
- #endif
- //@}
- #endif //CXIMAGE_SUPPORT_LAYERS
+# endif
+ //@}
+#endif //CXIMAGE_SUPPORT_LAYERS
protected:
- /** \addtogroup Protected */ //@{
+ /** \addtogroup Protected */ //@{
void Startup(uint32_t imagetype = 0);
void CopyInfo(const CxImage& src);
void Ghost(const CxImage* src);
@@ -819,13 +770,11 @@ namespace CppImage
void* pDib; //contains the header, the palette, the pixels
BitmapInfoHeader head; //standard header
- CXIMAGEINFO info; //extended information
+ tagCxImageInfo info; //extended information
uint8_t* pSelection; //selected region
uint8_t* pAlpha; //alpha channel
CxImage** ppLayers; //generic layers
CxImage** ppFrames;
- //@}
+ //@}
};
-
- //#endif
}
View
820 Source/cppimage/formatSpecific/ximabmp.cpp
@@ -13,517 +13,517 @@
////////////////////////////////////////////////////////////////////////////////
#if CXIMAGE_SUPPORT_ENCODE
-////////////////////////////////////////////////////////////////////////////////
-bool CxImageBMP::Encode(CxFile * hFile)
+namespace CppImage
{
- if (EncodeSafeCheck(hFile))
- return false;
+ ////////////////////////////////////////////////////////////////////////////////
+ bool CxImageBMP::Encode(CxFile * hFile)
+ {
+ if (EncodeSafeCheck(hFile))
+ return false;
- BitmapFileHeader hdr;
+ BitmapFileHeader hdr;
- hdr.bfType = 0x4d42; // 'BM' WINDOWS_BITMAP_SIGNATURE
- hdr.bfSize = GetSize() + 14 /*sizeof(BitmapFileHeader)*/;
- hdr.bfReserved1 = 0;
- hdr.bfReserved2 = 0;
- hdr.bfOffBits = 14 /*sizeof(BitmapFileHeader)*/ + head.biSize + GetPaletteSize();
+ hdr.bfType = 0x4d42; // 'BM' WINDOWS_BITMAP_SIGNATURE
+ hdr.bfSize = GetSize() + 14 /*sizeof(BitmapFileHeader)*/;
+ hdr.bfReserved1 = 0;
+ hdr.bfReserved2 = 0;
+ hdr.bfOffBits = 14 /*sizeof(BitmapFileHeader)*/ + head.biSize + GetPaletteSize();
- hdr.bfType = m_ntohs(hdr.bfType);
- hdr.bfSize = m_ntohl(hdr.bfSize);
- hdr.bfOffBits = m_ntohl(hdr.bfOffBits);
+ hdr.bfType = m_ntohs(hdr.bfType);
+ hdr.bfSize = m_ntohl(hdr.bfSize);
+ hdr.bfOffBits = m_ntohl(hdr.bfOffBits);
#if CXIMAGE_SUPPORT_ALPHA
- if (GetNumColors() == 0 && AlphaIsValid())
- {
- BitmapInfoHeader infohdr;
- memcpy(&infohdr, &head, sizeof(BitmapInfoHeader));
- infohdr.biCompression = BI_RGB;
- infohdr.biBitCount = 32;
- uint32_t dwEffWidth = ((((infohdr.biBitCount * infohdr.biWidth) + 31) / 32) * 4);
- infohdr.biSizeImage = dwEffWidth * infohdr.biHeight;
-
- hdr.bfSize = infohdr.biSize + infohdr.biSizeImage + 14 /*sizeof(BitmapFileHeader)*/;
-
- hdr.bfSize = m_ntohl(hdr.bfSize);
- bihtoh(&infohdr);
-
- // Write the file header
- hFile->Write(&hdr, min(14, (int)sizeof(BitmapFileHeader)), 1);
- hFile->Write(&infohdr, sizeof(BitmapInfoHeader), 1);
- //and DIB+ALPHA interlaced
- uint8_t *srcalpha = AlphaGetPointer();
- for (int32_t y = 0; y < infohdr.biHeight; ++y)
+ if (GetNumColors() == 0 && AlphaIsValid())
{
- uint8_t* srcdib = GetBits(y);
- for (int32_t x = 0; x < infohdr.biWidth; ++x)
+ BitmapInfoHeader infohdr;
+ memcpy(&infohdr, &head, sizeof(BitmapInfoHeader));
+ infohdr.biCompression = BI_RGB;
+ infohdr.biBitCount = 32;
+ uint32_t dwEffWidth = ((((infohdr.biBitCount * infohdr.biWidth) + 31) / 32) * 4);
+ infohdr.biSizeImage = dwEffWidth * infohdr.biHeight;
+
+ hdr.bfSize = infohdr.biSize + infohdr.biSizeImage + 14 /*sizeof(BitmapFileHeader)*/;
+
+ hdr.bfSize = m_ntohl(hdr.bfSize);
+ bihtoh(&infohdr);
+
+ // Write the file header
+ hFile->Write(&hdr, min(14, (int)sizeof(BitmapFileHeader)), 1);
+ hFile->Write(&infohdr, sizeof(BitmapInfoHeader), 1);
+ //and DIB+ALPHA interlaced
+ uint8_t *srcalpha = AlphaGetPointer();
+ for (int32_t y = 0; y < infohdr.biHeight; ++y)
{
- hFile->Write(srcdib, 3, 1);
- hFile->Write(srcalpha, 1, 1);
- srcdib += 3;
- ++srcalpha;
+ uint8_t* srcdib = GetBits(y);
+ for (int32_t x = 0; x < infohdr.biWidth; ++x)
+ {
+ hFile->Write(srcdib, 3, 1);
+ hFile->Write(srcalpha, 1, 1);
+ srcdib += 3;
+ ++srcalpha;
+ }
}
}
- }
- else
+ else
#endif //CXIMAGE_SUPPORT_ALPHA
- {
- // Write the file header
- hFile->Write(&hdr, min(14, (int)sizeof(BitmapFileHeader)), 1);
- //copy attributes
- memcpy(pDib, &head, sizeof(BitmapInfoHeader));
- bihtoh(static_cast<BitmapInfoHeader*>(pDib));
- // Write the DIB header and the pixels
- hFile->Write(pDib, GetSize(), 1);
- bihtoh(static_cast<BitmapInfoHeader*>(pDib));
+ {
+ // Write the file header
+ hFile->Write(&hdr, min(14, (int)sizeof(BitmapFileHeader)), 1);
+ //copy attributes
+ memcpy(pDib, &head, sizeof(BitmapInfoHeader));
+ bihtoh(static_cast<BitmapInfoHeader*>(pDib));
+ // Write the DIB header and the pixels
+ hFile->Write(pDib, GetSize(), 1);
+ bihtoh(static_cast<BitmapInfoHeader*>(pDib));
+ }
+ return true;
}
- return true;
-}
-////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////
#endif //CXIMAGE_SUPPORT_ENCODE
-////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////
#if CXIMAGE_SUPPORT_DECODE
-////////////////////////////////////////////////////////////////////////////////
-bool CxImageBMP::Decode(CxFile * hFile)
-{
- if (hFile == NULL)
- return false;
-
- BitmapFileHeader bf;
- uint32_t off = hFile->Tell(); //<CSC>
- cx_try
+ ////////////////////////////////////////////////////////////////////////////////
+ bool CxImageBMP::Decode(CxFile * hFile)
{
- if (hFile->Read(&bf, min(14, (int)sizeof(bf)), 1) == 0)
- cx_throw("Not a BMP");
-
- bf.bfSize = m_ntohl(bf.bfSize);
- bf.bfOffBits = m_ntohl(bf.bfOffBits);
+ if (hFile == NULL)
+ return false;
- if (m_ntohs(bf.bfType) != BFT_BITMAP) //do we have a RC HEADER?
+ BitmapFileHeader bf;
+ uint32_t off = hFile->Tell(); //<CSC>
+ cx_try
{
- bf.bfOffBits = 0L;
- hFile->Seek(off, SEEK_SET);
- }
+ if (hFile->Read(&bf, min(14, (int)sizeof(bf)), 1) == 0)
+ cx_throw("Not a BMP");
- BitmapInfoHeader bmpHeader;
- if (!DibReadBitmapInfo(hFile, &bmpHeader))
- cx_throw("Error reading BMP info");
- uint32_t dwCompression = bmpHeader.biCompression;
- uint32_t dwBitCount = bmpHeader.biBitCount; //preserve for BI_BITFIELDS compression <Thomas Ernst>
- bool bIsOldBmp = (bmpHeader.biSize == sizeof(BitmapCoreHeader));
+ bf.bfSize = m_ntohl(bf.bfSize);
+ bf.bfOffBits = m_ntohl(bf.bfOffBits);
- bool bTopDownDib = bmpHeader.biHeight < 0; //<Flanders> check if it's a top-down bitmap
- if (bTopDownDib)
- bmpHeader.biHeight =- bmpHeader.biHeight;
+ if (m_ntohs(bf.bfType) != BFT_BITMAP) //do we have a RC HEADER?
+ {
+ bf.bfOffBits = 0L;
+ hFile->Seek(off, SEEK_SET);
+ }
- if (info.nEscape == -1)
- {
- // Return output dimensions only
- head.biWidth = bmpHeader.biWidth;
- head.biHeight = bmpHeader.biHeight;
- info.dwType = CXIMAGE_FORMAT_BMP;
- cx_throw("output dimensions returned");
- }
+ BitmapInfoHeader bmpHeader;
+ if (!DibReadBitmapInfo(hFile, &bmpHeader))
+ cx_throw("Error reading BMP info");
+ uint32_t dwCompression = bmpHeader.biCompression;
+ uint32_t dwBitCount = bmpHeader.biBitCount; //preserve for BI_BITFIELDS compression <Thomas Ernst>
+ bool bIsOldBmp = (bmpHeader.biSize == sizeof(BitmapCoreHeader));
- if (!Create(bmpHeader.biWidth, bmpHeader.biHeight, bmpHeader.biBitCount, CXIMAGE_FORMAT_BMP))
- cx_throw("");
+ bool bTopDownDib = bmpHeader.biHeight < 0; //<Flanders> check if it's a top-down bitmap
+ if (bTopDownDib)
+ bmpHeader.biHeight =- bmpHeader.biHeight;
- SetXDPI(static_cast<int32_t>(floor(bmpHeader.biXPelsPerMeter * 254.0 / 10000.0 + 0.5)));
- SetYDPI(static_cast<int32_t>(floor(bmpHeader.biYPelsPerMeter * 254.0 / 10000.0 + 0.5)));
+ if (info.nEscape == -1)
+ {
+ // Return output dimensions only
+ head.biWidth = bmpHeader.biWidth;
+ head.biHeight = bmpHeader.biHeight;
+ info.dwType = CXIMAGE_FORMAT_BMP;
+ cx_throw("output dimensions returned");
+ }
- if (info.nEscape)
- cx_throw("Cancelled"); // <vho> - cancel decoding
+ if (!Create(bmpHeader.biWidth, bmpHeader.biHeight, bmpHeader.biBitCount, CXIMAGE_FORMAT_BMP))
+ cx_throw("");
- RGBQuad* pRgb = GetPalette();
- if (pRgb)
- {
- if (bIsOldBmp)
+ SetXDPI(static_cast<int32_t>(floor(bmpHeader.biXPelsPerMeter * 254.0 / 10000.0 + 0.5)));
+ SetYDPI(static_cast<int32_t>(floor(bmpHeader.biYPelsPerMeter * 254.0 / 10000.0 + 0.5)));
+
+ if (info.nEscape)
+ cx_throw("Cancelled"); // <vho> - cancel decoding
+
+ RGBQuad* pRgb = GetPalette();
+ if (pRgb)
{
- // convert a old color table (3 byte entries) to a new
- // color table (4 byte entries)
- hFile->Read(reinterpret_cast<void*>(pRgb), DibNumColors(&bmpHeader) * sizeof(RGBTriple), 1);
- for (int32_t i = DibNumColors(&head) - 1; i >= 0; i--)
+ if (bIsOldBmp)
{
- pRgb[i].rgbRed = (reinterpret_cast<RGBTriple*>(pRgb))[i].rgbtRed;
- pRgb[i].rgbBlue = (reinterpret_cast<RGBTriple*>(pRgb))[i].rgbtBlue;
- pRgb[i].rgbGreen = (reinterpret_cast<RGBTriple*>(pRgb))[i].rgbtGreen;
- /*
- pRgb[i].rgbRed = ((RGBTriple*)(pRgb))[i].rgbtRed;
- pRgb[i].rgbBlue = ((RGBTriple*)(pRgb))[i].rgbtBlue;
- pRgb[i].rgbGreen = ((RGBTriple*)(pRgb))[i].rgbtGreen;
- */
- pRgb[i].rgbReserved = static_cast<uint8_t>(0);
+ // convert a old color table (3 byte entries) to a new
+ // color table (4 byte entries)
+ hFile->Read(reinterpret_cast<void*>(pRgb), DibNumColors(&bmpHeader) * sizeof(RGBTriple), 1);
+ for (int32_t i = DibNumColors(&head) - 1; i >= 0; i--)
+ {
+ pRgb[i].rgbRed = (reinterpret_cast<RGBTriple*>(pRgb))[i].rgbtRed;
+ pRgb[i].rgbBlue = (reinterpret_cast<RGBTriple*>(pRgb))[i].rgbtBlue;
+ pRgb[i].rgbGreen = (reinterpret_cast<RGBTriple*>(pRgb))[i].rgbtGreen;
+ /*
+ pRgb[i].rgbRed = ((RGBTriple*)(pRgb))[i].rgbtRed;
+ pRgb[i].rgbBlue = ((RGBTriple*)(pRgb))[i].rgbtBlue;
+ pRgb[i].rgbGreen = ((RGBTriple*)(pRgb))[i].rgbtGreen;
+ */
+ pRgb[i].rgbReserved = static_cast<uint8_t>(0);
+ }
}
- }
- else
- {
- hFile->Read(reinterpret_cast<void*>(pRgb), DibNumColors(&bmpHeader) * sizeof(RGBQuad), 1);
- //force rgbReserved=0, to avoid problems with some WinXp bitmaps
- for (uint32_t i = 0; i < head.biClrUsed; i++)
+ else
{
- pRgb[i].rgbReserved = 0;
+ hFile->Read(reinterpret_cast<void*>(pRgb), DibNumColors(&bmpHeader) * sizeof(RGBQuad), 1);
+ //force rgbReserved=0, to avoid problems with some WinXp bitmaps
+ for (uint32_t i = 0; i < head.biClrUsed; i++)
+ {
+ pRgb[i].rgbReserved = 0;
+ }
}
}
- }
- if (info.nEscape)
- cx_throw("Cancelled"); // <vho> - cancel decoding
+ if (info.nEscape)
+ cx_throw("Cancelled"); // <vho> - cancel decoding
- switch (dwBitCount)
- {
- case 32 :
- uint32_t bfmask[3];
- if (dwCompression == BI_BITFIELDS)
- {
- hFile->Read(bfmask, 12, 1);
- }
- else
+ switch (dwBitCount)
{
- bfmask[0]=0x00FF0000;
- bfmask[1]=0x0000FF00;
- bfmask[2]=0x000000FF;
- }
- if (bf.bfOffBits != 0L)
- hFile->Seek(off + bf.bfOffBits, SEEK_SET);
- if (dwCompression == BI_BITFIELDS || dwCompression == BI_RGB)
- {
- int32_t imagesize=4*head.biHeight*head.biWidth;
- uint8_t* buff32 = (uint8_t*)malloc(imagesize);
- if (buff32)
+ case 32 :
+ uint32_t bfmask[3];
+ if (dwCompression == BI_BITFIELDS)
+ {
+ hFile->Read(bfmask, 12, 1);
+ }
+ else
{
- hFile->Read(buff32, imagesize, 1); // read in the pixels
+ bfmask[0]=0x00FF0000;
+ bfmask[1]=0x0000FF00;
+ bfmask[2]=0x000000FF;
+ }
+ if (bf.bfOffBits != 0L)
+ hFile->Seek(off + bf.bfOffBits, SEEK_SET);
+ if (dwCompression == BI_BITFIELDS || dwCompression == BI_RGB)
+ {
+ int32_t imagesize=4*head.biHeight*head.biWidth;
+ uint8_t* buff32 = (uint8_t*)malloc(imagesize);
+ if (buff32)
+ {
+ hFile->Read(buff32, imagesize, 1); // read in the pixels
#if CXIMAGE_SUPPORT_ALPHA
- if (dwCompression == BI_RGB)
- {
- AlphaCreate();
- if (AlphaIsValid())
+ if (dwCompression == BI_RGB)
{
- bool bAlphaOk = false;
- uint8_t* p;
- for (int32_t y = 0; y < head.biHeight; y++)
+ AlphaCreate();
+ if (AlphaIsValid())
{
- p = buff32 + 3 + head.biWidth * 4 * y;
- for (int32_t x = 0; x < head.biWidth; x++)
+ bool bAlphaOk = false;
+ uint8_t* p;
+ for (int32_t y = 0; y < head.biHeight; y++)
{
- if (*p)
- bAlphaOk = true;
- AlphaSet(x, y, *p);
- p+=4;
+ p = buff32 + 3 + head.biWidth * 4 * y;
+ for (int32_t x = 0; x < head.biWidth; x++)
+ {
+ if (*p)
+ bAlphaOk = true;
+ AlphaSet(x, y, *p);
+ p+=4;
+ }
}
+ // fix if alpha pixels are all zero
+ if (!bAlphaOk)
+ AlphaInvert();
}
- // fix if alpha pixels are all zero
- if (!bAlphaOk)
- AlphaInvert();
}
- }
#endif //CXIMAGE_SUPPORT_ALPHA
- Bitfield2RGB(buff32, bfmask[0], bfmask[1], bfmask[2], 32);
- free(buff32);
+ Bitfield2RGB(buff32, bfmask[0], bfmask[1], bfmask[2], 32);
+ free(buff32);
+ }
+ else
+ {
+ cx_throw("can't allocate memory");
+ }
}
else
{
- cx_throw("can't allocate memory");
+ cx_throw("unknown compression");
}
- }
- else
- {
- cx_throw("unknown compression");
- }
- break;
- case 24 :
- if (bf.bfOffBits != 0L)
- hFile->Seek(off + bf.bfOffBits, SEEK_SET);
- if (dwCompression == BI_RGB)
- {
- hFile->Read(info.pImage, head.biSizeImage, 1); // read in the pixels
- }
- else
- {
- cx_throw("unknown compression");
- }
- break;
- case 16 :
- {
- uint32_t bfmask[3];
- if (dwCompression == BI_BITFIELDS)
+ break;
+ case 24 :
+ if (bf.bfOffBits != 0L)
+ hFile->Seek(off + bf.bfOffBits, SEEK_SET);
+ if (dwCompression == BI_RGB)
{
- hFile->Read(bfmask, 12, 1);
+ hFile->Read(info.pImage, head.biSizeImage, 1); // read in the pixels
}
else
{
- bfmask[0]=0x7C00; bfmask[1]=0x3E0; bfmask[2]=0x1F; //RGB555
+ cx_throw("unknown compression");
}
- // bf.bfOffBits required after the bitfield mask <Cui Ying Jie>
+ break;
+ case 16 :
+ {
+ uint32_t bfmask[3];
+ if (dwCompression == BI_BITFIELDS)
+ {
+ hFile->Read(bfmask, 12, 1);
+ }
+ else
+ {
+ bfmask[0]=0x7C00; bfmask[1]=0x3E0; bfmask[2]=0x1F; //RGB555
+ }
+ // bf.bfOffBits required after the bitfield mask <Cui Ying Jie>
+ if (bf.bfOffBits != 0L)
+ hFile->Seek(off + bf.bfOffBits, SEEK_SET);
+ // read in the pixels
+ hFile->Read(info.pImage, head.biHeight*((head.biWidth+1)/2)*4, 1);
+ // transform into RGB
+ Bitfield2RGB(info.pImage, bfmask[0], bfmask[1], bfmask[2], 16);
+ break;
+ }
+ case 8 :
+ case 4 :
+ case 1 :
if (bf.bfOffBits != 0L)
hFile->Seek(off + bf.bfOffBits, SEEK_SET);
- // read in the pixels
- hFile->Read(info.pImage, head.biHeight*((head.biWidth+1)/2)*4, 1);
- // transform into RGB
- Bitfield2RGB(info.pImage, bfmask[0], bfmask[1], bfmask[2], 16);
- break;
- }
- case 8 :
- case 4 :
- case 1 :
- if (bf.bfOffBits != 0L)
- hFile->Seek(off + bf.bfOffBits, SEEK_SET);
- switch (dwCompression)
- {
- case BI_RGB :
- hFile->Read(info.pImage, head.biSizeImage, 1); // read in the pixels
- break;
- case BI_RLE4 :
+ switch (dwCompression)
{
- uint8_t status_byte = 0;
- uint8_t second_byte = 0;
- int32_t scanline = 0;
- int32_t bits = 0;
- bool low_nibble = false;
- CImageIterator iter(this);
-
- for (bool bContinue = true; bContinue && hFile->Read(&status_byte, sizeof(uint8_t), 1);)
+ case BI_RGB :
+ hFile->Read(info.pImage, head.biSizeImage, 1); // read in the pixels
+ break;
+ case BI_RLE4 :
{
- switch (status_byte)
+ uint8_t status_byte = 0;
+ uint8_t second_byte = 0;
+ int32_t scanline = 0;
+ int32_t bits = 0;
+ bool low_nibble = false;
+ CImageIterator iter(this);
+
+ for (bool bContinue = true; bContinue && hFile->Read(&status_byte, sizeof(uint8_t), 1);)
{
- case RLE_COMMAND :
- hFile->Read(&status_byte, sizeof(uint8_t), 1);
switch (status_byte)
{
- case RLE_ENDOFLINE :
- bits = 0;
- scanline++;
- low_nibble = false;
- break;
- case RLE_ENDOFBITMAP :
- bContinue = false;
- break;
- case RLE_DELTA :
+ case RLE_COMMAND :
+ hFile->Read(&status_byte, sizeof(uint8_t), 1);
+ switch (status_byte)
{
- // read the delta values
- uint8_t delta_x;
- uint8_t delta_y;
- hFile->Read(&delta_x, sizeof(uint8_t), 1);
- hFile->Read(&delta_y, sizeof(uint8_t), 1);
- // apply them
- bits += delta_x / 2;
- scanline += delta_y;
+ case RLE_ENDOFLINE :
+ bits = 0;
+ scanline++;
+ low_nibble = false;
break;
- }
- default :
- hFile->Read(&second_byte, sizeof(uint8_t), 1);
- uint8_t* sline = iter.GetRow(scanline);
- for (int32_t i = 0; i < status_byte; i++) {
- if ((uint8_t*)(sline + bits) < (uint8_t*)(info.pImage + head.biSizeImage))
+ case RLE_ENDOFBITMAP :
+ bContinue = false;
+ break;
+ case RLE_DELTA :
{
- if (low_nibble)
- {
- if (i&1)
- *(sline + bits) |= (second_byte & 0x0f);
- else
- *(sline + bits) |= (second_byte & 0xf0) >> 4;
- bits++;
- }
- else
+ // read the delta values
+ uint8_t delta_x;
+ uint8_t delta_y;
+ hFile->Read(&delta_x, sizeof(uint8_t), 1);
+ hFile->Read(&delta_y, sizeof(uint8_t), 1);
+ // apply them
+ bits += delta_x / 2;
+ scanline += delta_y;
+ break;
+ }
+ default :
+ hFile->Read(&second_byte, sizeof(uint8_t), 1);
+ uint8_t* sline = iter.GetRow(scanline);
+ for (int32_t i = 0; i < status_byte; i++) {
+ if ((uint8_t*)(sline + bits) < (uint8_t*)(info.pImage + head.biSizeImage))
{
- if (i&1)
- *(sline + bits) = (uint8_t)(second_byte & 0x0f) << 4;
+ if (low_nibble)
+ {
+ if (i&1)
+ *(sline + bits) |= (second_byte & 0x0f);
+ else
+ *(sline + bits) |= (second_byte & 0xf0) >> 4;
+ bits++;
+ }
else
- *(sline + bits) = (uint8_t)(second_byte & 0xf0);
+ {
+ if (i&1)
+ *(sline + bits) = (uint8_t)(second_byte & 0x0f) << 4;
+ else
+ *(sline + bits) = (uint8_t)(second_byte & 0xf0);
+ }
}
- }
- if ((i & 1) && (i != (status_byte - 1)))
- hFile->Read(&second_byte, sizeof(uint8_t), 1);
+ if ((i & 1) && (i != (status_byte - 1)))
+ hFile->Read(&second_byte, sizeof(uint8_t), 1);
- low_nibble = !low_nibble;
+ low_nibble = !low_nibble;
+ }
+ if ((((status_byte + 1) >> 1) & 1 ) == 1)
+ hFile->Read(&second_byte, sizeof(uint8_t), 1);
+ break;
}
- if ((((status_byte + 1) >> 1) & 1 ) == 1)
- hFile->Read(&second_byte, sizeof(uint8_t), 1);
break;
- }
- break;
- default :
- {
- uint8_t *sline = iter.GetRow(scanline);
- hFile->Read(&second_byte, sizeof(uint8_t), 1);
- for (unsigned i = 0; i < status_byte; i++)
+ default :
{
- if ((uint8_t*)(sline+bits) < (uint8_t*)(info.pImage+head.biSizeImage))
+ uint8_t *sline = iter.GetRow(scanline);
+ hFile->Read(&second_byte, sizeof(uint8_t), 1);
+ for (unsigned i = 0; i < status_byte; i++)
{
- if (low_nibble)
- {
- if (i&1)
- *(sline + bits) |= (second_byte & 0x0f);
- else
- *(sline + bits) |= (second_byte & 0xf0) >> 4;
- bits++;
- }
- else
+ if ((uint8_t*)(sline+bits) < (uint8_t*)(info.pImage+head.biSizeImage))
{
- if (i&1)
- *(sline + bits) = (uint8_t)(second_byte & 0x0f) << 4;
+ if (low_nibble)
+ {
+ if (i&1)
+ *(sline + bits) |= (second_byte & 0x0f);
+ else
+ *(sline + bits) |= (second_byte & 0xf0) >> 4;
+ bits++;
+ }
else
- *(sline + bits) = (uint8_t)(second_byte & 0xf0);
+ {
+ if (i&1)
+ *(sline + bits) = (uint8_t)(second_byte & 0x0f) << 4;
+ else
+ *(sline + bits) = (uint8_t)(second_byte & 0xf0);
+ }
}
+ low_nibble = !low_nibble;
}
- low_nibble = !low_nibble;
}
+ break;
}
- break;
}
+ break;
}
- break;
- }
- case BI_RLE8 :
- {
- uint8_t status_byte = 0;
- uint8_t second_byte = 0;
- int32_t scanline = 0;
- int32_t bits = 0;
- CImageIterator iter(this);
-
- for (bool bContinue = true; bContinue && hFile->Read(&status_byte, sizeof(uint8_t), 1);)
+ case BI_RLE8 :
{
- switch (status_byte)
+ uint8_t status_byte = 0;
+ uint8_t second_byte = 0;
+ int32_t scanline = 0;
+ int32_t bits = 0;
+ CImageIterator iter(this);
+
+ for (bool bContinue = true; bContinue && hFile->Read(&status_byte, sizeof(uint8_t), 1);)
{
- case RLE_COMMAND :
- hFile->Read(&status_byte, sizeof(uint8_t), 1);
switch (status_byte)
{
- case RLE_ENDOFLINE :
- bits = 0;
- scanline++;
- break;
- case RLE_ENDOFBITMAP :
- bContinue = false;
- break;
- case RLE_DELTA :
+ case RLE_COMMAND :
+ hFile->Read(&status_byte, sizeof(uint8_t), 1);
+ switch (status_byte)
{
- // read the delta values
- uint8_t delta_x;
- uint8_t delta_y;
- hFile->Read(&delta_x, sizeof(uint8_t), 1);
- hFile->Read(&delta_y, sizeof(uint8_t), 1);
- // apply them
- bits += delta_x;
- scanline += delta_y;
+ case RLE_ENDOFLINE :
+ bits = 0;
+ scanline++;
break;
- }
- default :
- hFile->Read((void *)(iter.GetRow(scanline) + bits), sizeof(uint8_t) * status_byte, 1);
- // align run length to even number of bytes
- if ((status_byte & 1) == 1)
- hFile->Read(&second_byte, sizeof(uint8_t), 1);
- bits += status_byte;
+ case RLE_ENDOFBITMAP :
+ bContinue = false;
+ break;
+ case RLE_DELTA :
+ {
+ // read the delta values
+ uint8_t delta_x;
+ uint8_t delta_y;
+ hFile->Read(&delta_x, sizeof(uint8_t), 1);
+ hFile->Read(&delta_y, sizeof(uint8_t), 1);
+ // apply them
+ bits += delta_x;
+ scanline += delta_y;
+ break;
+ }
+ default :
+ hFile->Read((void *)(iter.GetRow(scanline) + bits), sizeof(uint8_t) * status_byte, 1);
+ // align run length to even number of bytes
+ if ((status_byte & 1) == 1)
+ hFile->Read(&second_byte, sizeof(uint8_t), 1);
+ bits += status_byte;
+ break;
+ };
break;
- };
- break;
- default:
- uint8_t *sline = iter.GetRow(scanline);
- hFile->Read(&second_byte, sizeof(uint8_t), 1);
- for (unsigned i = 0; i < status_byte; i++)
- {
- if ((uint8_t*)(sline+bits) < (uint8_t*)(info.pImage+head.biSizeImage))
- {
- *(sline + bits) = second_byte;
- bits++;
- }
- else
+ default:
+ uint8_t *sline = iter.GetRow(scanline);
+ hFile->Read(&second_byte, sizeof(uint8_t), 1);
+ for (unsigned i = 0; i < status_byte; i++)
{
- break;
+ if ((uint8_t*)(sline+bits) < (uint8_t*)(info.pImage+head.biSizeImage))
+ {
+ *(sline + bits) = second_byte;
+ bits++;
+ }
+ else
+ {
+ break;
+ }
}
- }
- break;
- };
+ break;
+ };
+ }
+ break;
}
- break;
+ default:
+ cx_throw("compression type not supported");
}
- default:
- cx_throw("compression type not supported");
}
- }
- if (bTopDownDib)
- Flip(); //<Flanders>
- }
- cx_catch
- {
- if (strcmp(message, ""))
- strncpy(info.szLastError, message, 255);
- if (info.nEscape == -1 && info.dwType == CXIMAGE_FORMAT_BMP)
- return true;
- return false;
+ if (bTopDownDib)
+ Flip(); //<Flanders>
+ }
+ cx_catch
+ {
+ if (strcmp(message, ""))
+ strncpy(info.szLastError, message, 255);
+ if (info.nEscape == -1 && info.dwType == CXIMAGE_FORMAT_BMP)
+ return true;
+ return false;
+ }
+ return true;
}
- return true;
-}
-////////////////////////////////////////////////////////////////////////////////
-/* ReadDibBitmapInfo()
- *
- * Will read a file in DIB format and return a global HANDLE to its
- * BITMAPINFO. This function will work with both "old" and "new"
- * bitmap formats, but will always return a "new" BITMAPINFO.
- */
-bool CxImageBMP::DibReadBitmapInfo(CxFile* fh, BitmapInfoHeader *pdib)
-{
- if ((fh == NULL) || (pdib == NULL))
- return false;
+ ////////////////////////////////////////////////////////////////////////////////
+ /* ReadDibBitmapInfo()
+ *
+ * Will read a file in DIB format and return a global HANDLE to its
+ * BITMAPINFO. This function will work with both "old" and "new"
+ * bitmap formats, but will always return a "new" BITMAPINFO.
+ */
+ bool CxImageBMP::DibReadBitmapInfo(CxFile* fh, BitmapInfoHeader *pdib)
+ {
+ if ((fh == NULL) || (pdib == NULL))