Click here to Skip to main content
6,631,404 members and growing! (15,627 online)
Email Password   helpLost your password?
Web Development » Applications & Tools » General     Intermediate License: The zlib/libpng License

WaterMarker

By Kochise

An utility to protect yout pictures with a stamp bitmap
VC6, Windows, Visual Studio, MFC, Dev
Posted:5 Apr 2006
Views:37,202
Bookmarked:40 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
15 votes for this article.
Popularity: 4.82 Rating: 4.10 out of 5
3 votes, 21.4%
1

2
2 votes, 14.3%
3
2 votes, 14.3%
4
7 votes, 50.0%
5

00-Intro.png

Compilation

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...

Introduction

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.

The problem to be solved

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...

The quest for the right classes

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:

  • CWnd Helper Class by Alvaro Mendez (modified) : windows position saving/restore
  • CPathSplit by me : easily split a path
  • CDiskObject by Johan Rosengren : list files in a folder
  • CEditLabel by me (modified CStaticLabel from unknown author) : edit path and change background color to warn user if something went wrong
  • GroupControl by Paul S. Vickery : disable some part of the UI as long as not all field are correct
  • Some personal and private utility classes
  • CSkinProgress by me : display the progress of the watermarking task
  • And the root engine of my utility, CxImage by Davide Pizzolato : basic and advanced image handling

Basic explanations of the stamp positioning algorithm

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.

CxImage picture format

01-CxImage.png

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.

Positioning the stamp at the center of the image

02-Center.png

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.

Positioning the stamp in the corners

03-Corner.png

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.

Relative shifting

04 - Relative.png

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).

Tiling the stamp

05 - Tiling.png

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.

Managing some transludency

06 - Transludency.png

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.

Image resizing

07 - Resizing.png

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%).

Problem solved

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.

License

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.

History

1.02 060405 : First release, as is...

License

This article, along with any associated source code and files, is licensed under The zlib/libpng License

About the Author

Kochise


Member
KOCH David, 31 years old
Coder (embedded C/C++, ASM, Erlang)
Occupation: Software Developer
Location: France France

Other popular Applications & Tools articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 20 of 20 (Total in Forum: 20) (Refresh)FirstPrevNext
Generaltext watermark Pinmemberxijun17:26 22 Apr '06  
GeneralRe: text watermark PinmemberKochise10:41 23 Apr '06  
QuestionRe: text watermark PinmemberSynetech21:48 10 Sep '06  
AnswerRe: text watermark PinmemberKochise22:11 10 Sep '06  
GeneralSorry, but like an typical french PinmemberMessnerEW1:01 11 Apr '06  
GeneralRe: Sorry, but like an typical french PinmemberKochise9:57 11 Apr '06  
GeneralRe: Sorry, but like an typical french PinmemberMessnerEW21:04 11 Apr '06  
GeneralRe: Sorry, but like an typical french PinmemberKochise23:26 11 Apr '06  
GeneralRe: Sorry, but like an typical french PinmemberMessnerEW0:01 12 Apr '06  
GeneralRe: Sorry, but like an typical french PinmemberKochise0:34 12 Apr '06  
GeneralRe: Sorry, but like an typical french PinmemberSynetech21:30 10 Sep '06  
GeneralRe: Sorry, but like an typical french PinmemberKochise22:14 10 Sep '06  
GeneralBlending sorted, what about meta data? PinmemberFred W0:13 7 Apr '06  
GeneralRe: Blending sorted, what about meta data? PinmemberKochise0:19 7 Apr '06  
GeneralCool, now it's OK, thanks to the CP staff ! PinmemberKochise7:09 6 Apr '06  
GeneralIiiiik, what's going on ? PinmemberKochise13:02 5 Apr '06  
GeneralRe: Iiiiik, what's going on ? Pinmember.dan.g.15:16 5 Apr '06  
GeneralRe: Iiiiik, what's going on ? PinmemberKochise20:27 5 Apr '06  
GeneralRe: Iiiiik, what's going on ? Pinmember.dan.g.0:22 6 Apr '06  
GeneralRe: Iiiiik, what's going on ? PinmemberKochise0:52 6 Apr '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin 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