Permalink
Browse files

cleaning up stuff

  • Loading branch information...
grahamboree committed Oct 7, 2012
1 parent 119048d commit c1cdd80c73f376beb08f0e11108f86f6e8f80fe2
@@ -46,7 +46,7 @@ class CImageIterator
public:
// Constructors
- CImageIterator(void);
+ CImageIterator();
CImageIterator(CxImage *image);
// Operators
@@ -57,8 +57,8 @@ class CImageIterator
void Reset();
void Upset();
- void SetRow(uint8_t *buf, int32_t n);
- void GetRow(uint8_t *buf, int32_t n);
+ void SetRow(uint8_t* buf, int32_t n);
+ void GetRow(uint8_t* buf, int32_t n);
uint8_t* GetRow();
uint8_t* GetRow(int32_t n);
@@ -77,11 +77,11 @@ class CImageIterator
BOOL NextStep();
BOOL PrevStep();
- void SetY(int32_t y); /* AD - for interlace */
int32_t GetY();
+ void SetY(int32_t y); /* AD - for interlace */
- BOOL GetCol(uint8_t* pCol, uint32_t x);
- BOOL SetCol(uint8_t* pCol, uint32_t x);
+ BOOL GetCol(uint8_t* outCol, uint32_t inColIndex);
+ BOOL SetCol(uint8_t* inCol, uint32_t inColIndex);
};
//////////////////////////////////////////////////////////////////////////
@@ -124,171 +124,255 @@ inline CImageIterator::CImageIterator(void)
Itx = Ity = 0;
Stepx = Stepy = 0;
}
+
/////////////////////////////////////////////////////////////////////
inline CImageIterator::CImageIterator(CxImage *imageImpl): ima(imageImpl)
{
- if (ima) IterImage = ima->GetBits();
+ if (ima)
+ IterImage = ima->GetBits();
Itx = Ity = 0;
Stepx = Stepy = 0;
}
+
/////////////////////////////////////////////////////////////////////
inline CImageIterator::operator CxImage* ()
{
return ima;
}
+
/////////////////////////////////////////////////////////////////////
inline BOOL CImageIterator::ItOK ()
{
- if (ima) return ima->IsInside(Itx, Ity);
- else return FALSE;
+ if (ima)
+ {
+ return ima->IsInside(Itx, Ity);
+ }
+ else
+ {
+ return FALSE;
+ }
}
+
/////////////////////////////////////////////////////////////////////
inline void CImageIterator::Reset()
{
- if (ima) IterImage = ima->GetBits();
- else IterImage=0;
+ if (ima)
+ IterImage = ima->GetBits();
+ else
+ IterImage = 0;
Itx = Ity = 0;
}
/////////////////////////////////////////////////////////////////////
inline void CImageIterator::Upset()
{
Itx = 0;
- Ity = ima->GetHeight()-1;
- IterImage = ima->GetBits() + ima->GetEffWidth()*(ima->GetHeight()-1);
+ Ity = ima->GetHeight() - 1;
+ IterImage = ima->GetBits() + ima->GetEffWidth() * (ima->GetHeight() - 1);
}
+
/////////////////////////////////////////////////////////////////////
inline BOOL CImageIterator::NextRow()
{
- if (++Ity >= (int32_t)ima->GetHeight()) return 0;
+ if (++Ity >= (int32_t)ima->GetHeight())
+ return 0;
IterImage += ima->GetEffWidth();
return 1;
}
+
/////////////////////////////////////////////////////////////////////
inline BOOL CImageIterator::PrevRow()
{
- if (--Ity < 0) return 0;
+ if (--Ity < 0)
+ return 0;
IterImage -= ima->GetEffWidth();
return 1;
}
+
+//////////////////////////////////////////////////////////////////////////
/* AD - for interlace */
inline void CImageIterator::SetY(int32_t y)
{
- if ((y < 0) || (y > (int32_t)ima->GetHeight())) return;
+ if ((y < 0) || (y > (int32_t)ima->GetHeight()))
+ return;
Ity = y;
IterImage = ima->GetBits() + ima->GetEffWidth()*y;
}
+
/////////////////////////////////////////////////////////////////////
inline void CImageIterator::SetRow(uint8_t *buf, int32_t n)
{
- if (n<0) n = (int32_t)ima->GetEffWidth();
- else n = min(n,(int32_t)ima->GetEffWidth());
+ if (n<0)
+ {
+ n = (int32_t)ima->GetEffWidth();
+ }
+ else
+ {
+ n = min(n, (int32_t)ima->GetEffWidth());
+ }
- if ((IterImage!=NULL)&&(buf!=NULL)&&(n>0)) memcpy(IterImage,buf,n);
+ if ((IterImage!=NULL)&&(buf!=NULL)&&(n>0))
+ {
+ memcpy(IterImage,buf,n);
+ }
}
+
/////////////////////////////////////////////////////////////////////
inline void CImageIterator::GetRow(uint8_t *buf, int32_t n)
{
if ((IterImage!=NULL)&&(buf!=NULL)&&(n>0))
+ {
memcpy(buf,IterImage,min(n,(int32_t)ima->GetEffWidth()));
+ }
}
+
/////////////////////////////////////////////////////////////////////
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)ima->GetEffWidth()) return 1;
+ if (++Itx < (int32_t)ima->GetEffWidth())
+ {
+ return 1;
+ }
else
- if (++Ity < (int32_t)ima->GetHeight()){
+ {
+ if (++Ity < (int32_t)ima->GetHeight())
+ {
IterImage += ima->GetEffWidth();
Itx = 0;
return 1;
- } else
+ }
+ else
+ {
return 0;
+ }
+ }
}
+
/////////////////////////////////////////////////////////////////////
inline BOOL CImageIterator::PrevByte()
{
- if (--Itx >= 0) return 1;
- else
- if (--Ity >= 0){
- IterImage -= ima->GetEffWidth();
- Itx = 0;
- return 1;
- } else
- return 0;
+ if (--Itx >= 0)
+ {
+ return 1;
+ }
+ else
+ {
+ if (--Ity >= 0)
+ {
+ IterImage -= ima->GetEffWidth();
+ Itx = 0;
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
+ }
}
+
/////////////////////////////////////////////////////////////////////
inline BOOL CImageIterator::NextStep()
{
Itx += Stepx;
- if (Itx < (int32_t)ima->GetEffWidth()) return 1;
- else {
+ if (Itx < (int32_t)ima->GetEffWidth())
+ {
+ return 1;
+ }
+ else
+ {
Ity += Stepy;
- if (Ity < (int32_t)ima->GetHeight()){
+ if (Ity < (int32_t)ima->GetHeight())
+ {
IterImage += ima->GetEffWidth();
Itx = 0;
return 1;
- } else
+ }
+ else
+ {
return 0;
+ }
}
}
/////////////////////////////////////////////////////////////////////
inline BOOL CImageIterator::PrevStep()
{
Itx -= Stepx;
- if (Itx >= 0) return 1;
- else {
+ if (Itx >= 0)
+ {
+ return 1;
+ }
+ else
+ {
Ity -= Stepy;
- if (Ity >= 0 && Ity < (int32_t)ima->GetHeight()) {
+ if (Ity >= 0 && Ity < (int32_t)ima->GetHeight())
+ {
IterImage -= ima->GetEffWidth();
Itx = 0;
return 1;
- } else
+ }
+ else
+ {
return 0;
+ }
}
}
/////////////////////////////////////////////////////////////////////
-inline BOOL CImageIterator::GetCol(uint8_t* pCol, uint32_t x)
+inline BOOL CImageIterator::GetCol(uint8_t* outCol, uint32_t inColIndex)
{
- if ((pCol==0)||(ima->GetBpp()<8)||(x>=ima->GetWidth()))
+ if ((outCol == NULL) ||
+ (ima->GetBpp() < 8) ||
+ (inColIndex >= ima->GetWidth()))
+ {
return 0;
+ }
uint32_t h = ima->GetHeight();
//uint32_t line = ima->GetEffWidth();
- uint8_t bytes = (uint8_t)(ima->GetBpp()>>3);
+ uint8_t bytes = (uint8_t)(ima->GetBpp() >> 3);
uint8_t* pSrc;
- for (uint32_t y=0;y<h;y++){
- pSrc = ima->GetBits(y) + x*bytes;
- for (uint8_t w=0;w<bytes;w++){
- *pCol++=*pSrc++;
+ for (uint32_t y = 0; y < h; y++)
+ {
+ pSrc = ima->GetBits(y) + inColIndex * bytes;
+ for (uint8_t w = 0; w < bytes; w++)
+ {
+ *outCol++=*pSrc++;
}
}
return 1;
}
/////////////////////////////////////////////////////////////////////
-inline BOOL CImageIterator::SetCol(uint8_t* pCol, uint32_t x)
+inline BOOL CImageIterator::SetCol(uint8_t* inCol, uint32_t inColIndex)
{
- if ((pCol==0)||(ima->GetBpp()<8)||(x>=ima->GetWidth()))
+ if ((inCol == 0) ||
+ (ima->GetBpp() < 8) ||
+ (inColIndex >= ima->GetWidth()))
+ {
return 0;
+ }
uint32_t h = ima->GetHeight();
//uint32_t line = ima->GetEffWidth();
- uint8_t bytes = (uint8_t)(ima->GetBpp()>>3);
+ uint8_t bytes = (uint8_t)(ima->GetBpp() >> 3);
uint8_t* pSrc;
- for (uint32_t y=0;y<h;y++){
- pSrc = ima->GetBits(y) + x*bytes;
- for (uint8_t w=0;w<bytes;w++){
- *pSrc++=*pCol++;
+ for (uint32_t y = 0; y < h; y++)
+ {
+ pSrc = ima->GetBits(y) + inColIndex * bytes;
+ for (uint8_t w = 0; w < bytes; w++)
+ {
+ *pSrc++=*inCol++;
}
}
return 1;
View
@@ -61,16 +61,19 @@ class CxFile
virtual bool Flush() = 0;
virtual int32_t GetC() = 0;
virtual char* GetS(char* string, int32_t n) = 0;
- virtual bool PutC(uint8_t c)
- {
- // Default implementation
- size_t nWrote = Write(&c, 1, 1);
- return (bool)(nWrote == 1);
- }
+ virtual bool PutC(uint8_t c);
virtual size_t Read(void* buffer, size_t size, size_t count) = 0;
virtual int32_t Scanf(const char* format, void* output) = 0;
virtual bool Seek(int32_t offset, int32_t origin) = 0;
virtual int32_t Size() = 0;
virtual int32_t Tell() = 0;
virtual size_t Write(const void* buffer, size_t size, size_t count) = 0;
};
+
+//////////////////////////////////////////////////////////////////////////
+inline bool CxFile::PutC(uint8_t c)
+{
+ // Default implementation
+ size_t nWrote = Write(&c, 1, 1);
+ return (nWrote == 1);
+}
@@ -20,8 +20,9 @@
#if CXIMAGE_SUPPORT_RAW
-extern "C" {
- #include "../../raw/libdcr.h"
+extern "C"
+{
+#include "../../raw/libdcr.h"
}
class CxImageRAW: public CxImage
@@ -3368,7 +3368,7 @@ int32_t CxImage::OptimalThreshold(int32_t method, RECT * pBox, CxImage* pContra
for (k=gray_min; k<=i; k++)
if (p[k] > 0)
L -= p[k]*log(p[k] / w1) / w1;
- for (k; k <= gray_max; k++)
+ for (; k <= gray_max; k++)
if (p[k] > 0)
L -= p[k] * log(p[k] / w2) / w2;
if (L3max < L || th3 < 0) {
@@ -3383,7 +3383,7 @@ int32_t CxImage::OptimalThreshold(int32_t method, RECT * pBox, CxImage* pContra
for (k=gray_min;k<=i;k++)
vdiff += p[k]*(i-k)*(i-k);
double vsum = vdiff;
- for (k;k<=gray_max;k++){
+ for (;k<=gray_max;k++){
double dv = p[k]*(k-i)*(k-i);
vdiff -= dv;
vsum += dv;

0 comments on commit c1cdd80

Please sign in to comment.