![]() |
Web Development »
Applications & Tools »
General
Intermediate
License: The zlib/libpng License
WaterMarkerBy KochiseAn utility to protect yout pictures with a stamp bitmap |
VC6, Windows, Visual Studio, MFC, Dev
|
||||||||
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||

The Visual C++ 6 .dsw workspace file contains all the projects. Just do a first rebuild all to compile each project. Because some projects needs lib/dll that will be compiled afterward, you'll get some link error. Just wait for the first build session to finish, then do a build all to relink everything once it has been compiled first. You may get some compile warning in the CxImage project (Jasper), but this isn't a problem...
Some times before, I started to create a little site about coding and hardware hacking on my hard drive. I took many pictures to document things, made thumbnails and so. I then presented the result to a friend who spoted me a problem about picture copyright and some stealing issues. He have also the same problem as a horse photographer. Pictures had to be water marked to prevent their stealing.
I then started to browse the web for a little utility that may watermark my picture or his so that we would release our respective work with less fears. But it rapidly appeared that the only available tools were quite expansive for what they offered, in a range from 25$ to something like 50$ ! It just couldn't be possible to cost that much, it is just about some pixel blending, what is available for ages, so where were the difficult problem that deserved such wages ? I'm a coder, so I took the problem in mine little hands...
Quite regular on the CodeProject, I used to use some prefered classes that I reuse regulary. I know them, modified some, here's the list of the ones I used:
The stamping of an image needs only few parameters. The relative position of the stamp from the image's corners, the relative displacement from the corner position, and a tiling option. The transparency of the stamp have also to be handled, comming from the original stamp if it supports alpha channel, or add one if the original stamp haven't. Let's analyse first how CxImage handle pictures.

The origin (hot spot) of the CxImage is the bottom-left corner. X-axis is right-to-left and Y-axis is top-to-down. When positionning a stamp at (0, 0) its location is on the bottom-left corner. The CxImage format can be called being counter cartesian.

Due to the CxImage format, to center the stamp on the center of the image, you have to shift the stamp bottom-left from its half size to center its hot spot, then bring it back top-right from the image's half size. So that the centered stamp's hot spot is now located on the center of the image.

To locate the stamp in a corner, we just have to shift it from the image center position of half of the size of the image minus half the size of the stamp. It will first edge the hot spot of the stamp, then bring it back in the image.

From its corner position, we can shift the stamp from some more pixels. Just remeber the CxImage format is counter cartesian, so to shift right you have to decrease the X-axis (increase to go shift left), and decrease again vertically if you wanted to shift up the stamp (increase to shift down).

We can tile it all around the image, we just have to shift'n-loop the stamp several times of its size across the image relatively to its calculated relative corner position. For this, calculate the start position and end position by dividing the image size by the stamp size. We will start for the lowest position (X and Y, that's to say top-right) and increase each position up to the maximum CxImage formated position (remember, counter cartesian, bottom-left). Be careful about the staring location, the initial shift is not the same starting from the left corner than the right, again not the same starting from the bottom corner than the top.

The PNG format is quite one of the best one. It doesn's compress well photographic images, but kindly beat JPEG pictures on sketches and schematics with flat colours, what is enough for stamps. PNG is always lossless (unlike JPEG that destroy the picture, even with a 100% quality factor), and includes an alpha layer. By using a PNG picture as stamp, you can nicely use its alpha channel to provide nice looking stamps. If you use another stamp format, you can also provide a flat alpha factor.

You can resize the input image at two location : before watermarking and after. By using efficiently these resize factors, you can make looking the stamp half of its size (double the image before stamping, then reduce everything), or the double it (reduce first, double after). It may also be quite interresting to release stamped pictures in a more lightweight format than the original one is quite useful (leaving the original size before stamping, then reducing the result by 50%).
Here's the result of my little brainstorming. It's free, it's there, its source code is provided (so don't bug me about the french language, was too lazy to translate before submission). I'm not a UI master, so I recognize things can be improved in this area. But the purpose was just to provide me and my friend a free little watermarking utility that just performs well.
This code is thrown in the public domain, there's no secret coding receipe or tricks that might be patented. Commercial usage of this utility is PROHIBED ! I released it for free, so I expect any other derivative work to remain free as well. Also please include the original or modified source code with explanations.
1.02 060405 : First release, as is...
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 5 Apr 2006 Editor: |
Copyright 2006 by Kochise Everything else Copyright © CodeProject, 1999-2009 Web21 | Advertise on the Code Project |