int clamp_s(int value, int m_min, int m_max)
{
int mm_ret = value;
if(value < m_min)
{
mm_ret = m_min;
}else if(value > m_max)
{
mm_ret = m_max;
}
return mm_ret;
}
int LiDrewRect_Source(unsigned char * data, int width, int height, int channel, int x0, int y0, int x1, int y1, int shinner,
unsigned char red, unsigned char gree, unsigned char blue)
{
int i = 0;
int j = 0;
int k = 0;
unsigned char * tempUchar = data;
unsigned char color[4] = {red, gree, blue, 0};
int tempx0 = 0;
int tempy0 = 0;
int tempx1 = 0;
int tempy1 = 0;
if(x0 >= x1)
{
tempx0 = x1;
tempx1 = x0;
}else
{
tempx0 = x0;
tempx1 = x1;
}
if(y0 >= y1)
{
tempy0 = y1;
tempy1 = y0;
}else
{
tempy0 = y0;
tempy1 = y1;
}
for(i = tempy0 - shinner; i <= tempy0 + shinner; i ++ )
{
for(j = tempx0 - shinner; j <= tempx1 + shinner; j ++)
{
for(k = 0; k < channel; k ++)
{
tempUchar[(clamp_s(i, 0, height - 1) * width + clamp_s(j, 0, width - 1)) * channel + k] = color[k];
}
}
}
for(i = tempy1 - shinner; i <= tempy1 + shinner; i ++ )
{
for(j = tempx0 - shinner; j <= tempx1 + shinner; j ++)
{
for(k = 0; k < channel; k ++)
{
tempUchar[(clamp_s(i, 0, height - 1) * width + clamp_s(j, 0, width - 1)) * channel + k] = color[k];
}
}
}
for(i = tempy0 - shinner; i <= tempy1 + shinner; i ++ )
{
for(j = tempx0 - shinner; j <= tempx0 + shinner; j ++)
{
for(k = 0; k < channel; k ++)
{
tempUchar[(clamp_s(i, 0, height - 1) * width + clamp_s(j, 0, width - 1)) * channel + k] = color[k];
}
}
}
for(i = tempy0 - shinner; i <= tempy1 + shinner; i ++ )
{
for(j = tempx1 - shinner; j <= tempx1 + shinner; j ++)
{
for(k = 0; k < channel; k ++)
{
tempUchar[(clamp_s(i, 0, height - 1) * width + clamp_s(j, 0, width - 1)) * channel + k] = color[k];
}
}
}
return 0;
}