Okay, i realised that post I made above was a bit wrong. Anyway I knocked up a quick working watermark adder in Basic and had a go at converting it to C. I havent tested this yet, but I think it ought to work. As long as I'm not doing bad stuff with the memory (as I usually do).
Code:
#define Uint8 unsigned char
#define Uint16 unsigned short
#define Uint32 unsigned int
#define COLOUR_MARK 0x00FFFFFF
#define COLOUR_HILIGHT 0x00FF0000
#define ERROR_DRAW_OUT_OF_BOUNDS 1
#define ERROR_UNEQUAL_DIMENSIONS 2
struct image
{
Uint16 w, h;
Uint32 *pixel;
}typedef struct image image;
/*
This function draws a watermark to an image
x_pos / y_pos = start point on image to draw the watermark
*pic = pointer to image
*mark = pointer to watermark image
*/
int AddWatermark(Uint32 *pic, Uint32 *mark, Uint16 x_pos, Uint16 y_pos)
{
if(x_pos + mark.w > pic.w) return ERROR_DRAW_OUT_OF_BOUNDS;
if(y_pos + mark.h > pic.h) return ERROR_DRAW_OUT_OF_BOUNDS;
Uint8 r, g, b;
Uint16 x, y;
Uint16 scanline = pic.w*4;
Uint32 *m_ptr = mark.pixel;
Uint32 *p_ptr = pic.pixel+(y_pos*scanline)+(x_pos*4);
for(y=0; y<mark.h; y++)
{
for(x=0; x<mark.w; x++)
{
if(*m_ptr == COLOUR_MARK)
{
r = (*p_ptr >> 16) & 255; //Get colour elements
g = (*p_ptr >> 8) & 255;
b = *p_ptr & 255;
if(r < 255) r+=1; //Add watermark to elements
if(g < 255) g+=1;
if(b < 255) b+=1;
*ptr = (r<<16)+(g<<8)+b; //Write data back to pixel
}
p_ptr+=4;
m_ptr+=4;
}
p_ptr += scanline;
}
return 0;
}
/* This function hilights pixels on a watermarked image that don't match the original
*origin = handle for unaltered image
*marked = handle for watermarked image
*/
int GetWatermark(Uint32 *origin, *marked)
{
if(origin.w != marked.w) return ERROR_UNEQUAL_DIMENSIONS;
if(origin.h != marked.h) return ERROR_UNEQUAL_DIMENSIONS;
Uint32 *o_ptr = origin.pixel;
Uint32 *m_ptr = marked.pixel;
Uint16 x, y;
for(y=0; y<origin.h; y++)
for(x=0; x<origin.w; x++, o_ptr+=4, m_ptr+=4)
if(! (*m_ptr - *o_ptr)) //Hilight pixels that don't match the original
*m_ptr = COLOUR_HILIGHT;
}
Also something I was wondering was if someone were to hide text in watermarks, that would pretty much be uncrackable to anyone that dident have the original image right? Seems like it could make some kickass encryption