summaryrefslogtreecommitdiff
path: root/src/image.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/image.cpp')
-rw-r--r--src/image.cpp105
1 files changed, 44 insertions, 61 deletions
diff --git a/src/image.cpp b/src/image.cpp
index afc67ef..2a8108b 100644
--- a/src/image.cpp
+++ b/src/image.cpp
@@ -207,7 +207,7 @@ static Color palette3[] =
};
-Image::Image(int w,int h)
+Image::Image(uint w,uint h)
{
static int hue = Config_getInt(HTML_COLORSTYLE_HUE);
static int sat = Config_getInt(HTML_COLORSTYLE_SAT);
@@ -236,49 +236,49 @@ Image::Image(int w,int h)
palette[3].green = (int)(green2 * 255.0);
palette[3].blue = (int)(blue2 * 255.0);
- data = new uchar[w*h];
- memset(data,0,w*h);
- width = w;
- height = h;
+ m_data = new uchar[w*h];
+ memset(m_data,0,w*h);
+ m_width = w;
+ m_height = h;
}
Image::~Image()
{
- delete[] data;
+ delete[] m_data;
}
-void Image::setPixel(int x,int y,uchar val)
+void Image::setPixel(uint x,uint y,uchar val)
{
- if (x>=0 && x<width && y>=0 && y<height)
- data[y*width+x] = val;
+ if (x<m_width && y<m_height)
+ m_data[y*m_width+x] = val;
}
-uchar Image::getPixel(int x,int y) const
+uchar Image::getPixel(uint x,uint y) const
{
- if (x>=0 && x<width && y>=0 && y<height)
- return data[y*width+x];
+ if (x<m_width && y<m_height)
+ return m_data[y*m_width+x];
else
return 0;
}
-void Image::writeChar(int x,int y,char c,uchar fg)
+void Image::writeChar(uint x,uint y,char c,uchar fg)
{
if (c>=' ')
{
- int xf,yf,ci=c-' ';
- int rowOffset=0;
- int cw = charWidth[ci];
- int cp = charPos[ci];
+ uint xf,yf,ci=c-' ';
+ uint rowOffset=0;
+ uint cw = charWidth[ci];
+ uint cp = charPos[ci];
for (yf=0;yf<charHeight;yf++)
{
unsigned short bitPattern=0;
- int bitsLeft=cw;
- int byteOffset = rowOffset+(cp>>3);
- int bitOffset = cp&7;
+ uint bitsLeft=cw;
+ uint byteOffset = rowOffset+(cp>>3);
+ uint bitOffset = cp&7;
// get the bit pattern for row yf of the character from the font data
while (bitsLeft>0)
{
- int bits=8-bitOffset;
+ uint bits=8-bitOffset;
if (bits>bitsLeft) bits=bitsLeft;
bitPattern<<=bits;
bitPattern|=((fontRaw[byteOffset]<<bitOffset)&0xff)>>(8-bits);
@@ -286,7 +286,7 @@ void Image::writeChar(int x,int y,char c,uchar fg)
bitOffset=0;
byteOffset++;
}
- int mask=1<<(cw-1);
+ uint mask=1<<(cw-1);
// draw character row yf
for (xf=0;xf<cw;xf++)
{
@@ -298,7 +298,7 @@ void Image::writeChar(int x,int y,char c,uchar fg)
}
}
-void Image::writeString(int x,int y,const char *s,uchar fg)
+void Image::writeString(uint x,uint y,const char *s,uchar fg)
{
if (s)
{
@@ -313,7 +313,7 @@ void Image::writeString(int x,int y,const char *s,uchar fg)
uint Image::stringLength(const char *s)
{
- int w=0;
+ uint w=0;
if (s)
{
char c;
@@ -322,9 +322,9 @@ uint Image::stringLength(const char *s)
return w;
}
-void Image::drawHorzLine(int y,int xs,int xe,uchar colIndex,uint mask)
+void Image::drawHorzLine(uint y,uint xs,uint xe,uchar colIndex,uint mask)
{
- int x,i=0,j=0;
+ uint x,i=0,j=0;
for (x=xs;x<=xe;x++,j++)
{
if (j&1) i++;
@@ -332,38 +332,38 @@ void Image::drawHorzLine(int y,int xs,int xe,uchar colIndex,uint mask)
}
}
-void Image::drawHorzArrow(int y,int xs,int xe,uchar colIndex,uint mask)
+void Image::drawHorzArrow(uint y,uint xs,uint xe,uchar colIndex,uint mask)
{
drawHorzLine(y,xs,xe,colIndex,mask);
- int i;
+ uint i;
for (i=0;i<6;i++)
{
- int h=i>>1;
+ uint h=i>>1;
drawVertLine(xe-i,y-h,y+h,colIndex,0xffffffff);
}
}
-void Image::drawVertLine(int x,int ys,int ye,uchar colIndex,uint mask)
+void Image::drawVertLine(uint x,uint ys,uint ye,uchar colIndex,uint mask)
{
- int y,i=0;
+ uint y,i=0;
for (y=ys;y<=ye;y++,i++)
{
if (mask&(1<<(i&0x1f))) setPixel(x,y,colIndex);
}
}
-void Image::drawVertArrow(int x,int ys,int ye,uchar colIndex,uint mask)
+void Image::drawVertArrow(uint x,uint ys,uint ye,uchar colIndex,uint mask)
{
drawVertLine(x,ys,ye,colIndex,mask);
- int i;
+ uint i;
for (i=0;i<6;i++)
{
- int h=i>>1;
+ uint h=i>>1;
drawHorzLine(ys+i,x-h,x+h,colIndex,0xffffffff);
}
}
-void Image::drawRect(int x,int y,int w,int h,uchar colIndex,uint mask)
+void Image::drawRect(uint x,uint y,uint w,uint h,uchar colIndex,uint mask)
{
drawHorzLine(y,x,x+w-1,colIndex,mask);
drawHorzLine(y+h-1,x,x+w-1,colIndex,mask);
@@ -371,44 +371,27 @@ void Image::drawRect(int x,int y,int w,int h,uchar colIndex,uint mask)
drawVertLine(x+w-1,y,y+h-1,colIndex,mask);
}
-void Image::fillRect(int x,int y,int lwidth,int lheight,uchar colIndex,uint mask)
+void Image::fillRect(uint x,uint y,uint width,uint height,uchar colIndex,uint mask)
{
- int xp,yp,xi,yi;
- for (yp=y,yi=0;yp<y+lheight;yp++,yi++)
- for (xp=x,xi=0;xp<x+lwidth;xp++,xi++)
+ uint xp,yp,xi,yi;
+ for (yp=y,yi=0;yp<y+height;yp++,yi++)
+ for (xp=x,xi=0;xp<x+width;xp++,xi++)
if (mask&(1<<((xi+yi)&0x1f)))
setPixel(xp,yp,colIndex);
}
bool Image::save(const char *fileName,int mode)
{
-#if 0
- GifEncoder gifenc(data,
- mode==0 ? palette : palette2,
- width,height,
- mode==0 ? 3 : 4,
- 0);
- QFile file(fileName);
- if (file.open(IO_WriteOnly))
- {
- gifenc.writeGIF(file);
- return TRUE;
- }
- else
- {
- return FALSE;
- }
-#endif
static bool useTransparency = Config_getBool(FORMULA_TRANSPARENT);
uchar* buffer;
size_t bufferSize;
LodePNG_Encoder encoder;
LodePNG_Encoder_init(&encoder);
- int numCols = mode==0 ? 8 : 16;
+ uint numCols = mode==0 ? 8 : 16;
Color *pPal = mode==0 ? palette :
useTransparency ? palette2 :
palette3 ;
- int i;
+ uint i;
for (i=0;i<numCols;i++,pPal++)
{
LodePNG_InfoColor_addPalette(&encoder.infoPng.color,
@@ -416,7 +399,7 @@ bool Image::save(const char *fileName,int mode)
}
encoder.infoPng.color.colorType = 3;
encoder.infoRaw.color.colorType = 3;
- LodePNG_encode(&encoder, &buffer, &bufferSize, data, width, height);
+ LodePNG_encode(&encoder, &buffer, &bufferSize, m_data, m_width, m_height);
LodePNG_saveFile(buffer, bufferSize, fileName);
free(buffer);
LodePNG_Encoder_cleanup(&encoder);
@@ -489,7 +472,7 @@ void ColoredImage::hsl2rgb(double h,double s,double l,
*pBlue = b;
}
-ColoredImage::ColoredImage(int width,int height,
+ColoredImage::ColoredImage(uint width,uint height,
const uchar *greyLevels,const uchar *alphaLevels,
int saturation,int hue,int gamma)
{
@@ -497,7 +480,7 @@ ColoredImage::ColoredImage(int width,int height,
m_width = width;
m_height = height;
m_data = (uchar*)malloc(width*height*4);
- int i;
+ uint i;
for (i=0;i<width*height;i++)
{
uchar r,g,b,a;