Tips For Success

Having the best tools for document imaging is only half of the equation. Our Tech Tips are designed to provide you with valuable information to help succeed by achieving faster results with RasterMaster SDKs or FlexSnap viewers. New time-saving tips are added monthly - you can receive them through Imaging News or our Tech Tips RSS feed.

Watermarking at the Pixel Level

This Tech Tip appeared in Imaging News September 2004.

Watermarking 1-bit black and white images is a simple process of merging two images together. However, when working with multicolor images such as grayscale or full 24-bit color, it's not so easy. A simple merge will often add unwanted elements, such as a white background, from the watermark image file to the final image. Sidestepping this problem involves manipulating the image at the pixel level. Here's how with the RasterMaster imaging SDK

//It will promote both images to 24 bpp in order to have accurate values.

//Then resize the WM image to given size[] values and match the common area

//of the Watermark and Main image at the given Watermark position.

public void imagec_imagec()

{

//Resize and promote image to same bit depth and given sizes

//get the valid watermark crop area. The area the wm shares with

//the main image

//get the corresponding main image y-axis start position

//Get proper buffer sizes with padding so as to not cause exception

//with the imglow_get_raster

//Loop from wm start y to end y. Increment main image ypos to keep up

for (int i=wmstarty; i<wmendy; i++)

{

//get wm raster data

stat = Watermark.IMGLOW_get_raster(i, wmbuff);

//get corresponding main image raster data

stat = Simage.IMGLOW_get_raster(starty, ibuff);

//get the corresponding main image x-axis start position

startx = this.getXStartPos();

//Loop from wm valid x pos to its end pos. Increment main image

//xpos. Replace data based color detection.

for (int ii = wmstartx; ii < wmendx; ii += 3)

{

b = wmbuff[ii];

g = wmbuff[ii + 1];

r = wmbuff[ii + 2];

//Detect watermark color range

if (!((b >= detect[DETECTBLUE][DETECTMIN]) &&

(b <= detect[DETECTBLUE][DETECTMAX]) &&

(g >= detect[DETECTGREEN][DETECTMIN]) &&

(g <= detect[DETECTGREEN][DETECTMAX]) &&

(r >= detect[DETECTRED][DETECTMIN]) &&

(r <= detect[DETECTRED][DETECTMAX])))

{

//Replace main image data with watermark image data

ibuff[startx] = wmbuff[ii];

ibuff[startx+1] = wmbuff[ii+1];

ibuff[startx+2] = wmbuff[ii+2];

}

startx += 3;

}

//Replace main image raster with modified raster

stat = Simage.IMGLOW_put_raster(starty, ibuff);

starty++;

}

}