Thursday, April 30, 2009

Copyrighter v0.4 - Multithreading implemented!

by Hasan Karagülmez
So yeah, there you have it, Copyrighter has got multithreading now! :)

copyrighter v0.4 mainwindow
click for larger image

You don't have to do anything to take advantage, just download the new zip-package HERE (366kB zip-file).

A sample, copyrightimage, xml-file and preview image are included, as well as a small readme text-file.

The executable itself is only 83.5kB, 2.5kB smaller than v0.3 :)

Additional information
Due to the architecture in place, multithreading was a relatively easy affair and I'm also pretty happy with the performance improvements. Testing on my Quad-core 2.4GHz Q6600 processor shows an improvement of around 2 times compared to the v0.3 of Copyrighter.

I've tested this with a batch of 3440 images (!!!), with image-sizes varying from 800x533 pixels (a typical size I use for uploading images to the web) to about 2523x660 pixels, with filesizes varying of 84kB to about 556kB. I get almost 1100 images per minute with Copyrighter v0.4, versus almost 500 images per minute with version 0.3.

Yes, I'm pretty happy with this kind of performance :)

In this version, all the work is done on seperate threads, away from the UI-thread, which keeps the main program also nice and responsive :) Copyrighter v0.3 did all the work on the user-interface (UI) thread (which is why v0.3 hangs when processing), so that's fixed now!

In fact, whilst it is processing, you can just drag-and-drop a new batch of images and they'll be processed as well. I've had it up to 24 simultaneous threads without a problem, processing different batches :)

Copyrighter v0.4 divides the work over the present (logical) processors in the system. Copryrighter starts with 2 threads (used in the main window), and when images are dropped, the amount of work is divided over the available processors. So, on my quad-core machine, there are 4 logical processors, and so (at most) 4 threads are created which will do the work. Copyrighter will then have 6 threads.

If you've got a dual-core machine, the amount of work will be spread out over 2 additional threads, so Copyrighter will have then have 4 threads.

When you drag-and-drop, that work will again be spread out over the available processors. So, in my quad-core machine, if Copyrighter was at 6 threads, it will then have 10 threads after an additional drag-and-drop.

When all work finishes, Copyrighter will fall back to the default 2 threads.

Final Words
That's it really :)

The working is still the same, so please check the blog-entry regarding v0.3 for extensive information.

Basically, just drag-and-drop images onto the main program-window, images are outputted in a subdirectory called "Processed".

I've always wanted to implement multithreading in Copyrighter and I'm glad I did. I hope this program can help you, let me know what you think - I'd really appreciate it :)

Tuesday, April 21, 2009

Copyrighter v0.3 - Batch Processor for Images

by Hasan Karagülmez
Well, after recently getting my driver's licence, I of course immediately went driving around programming some more :)

This is actually a tool I've created before (hence it's version 0.3) but haven´t given it that much attention, mostly due to time constraints... Anyway, the goal of this tool, as the name suggests, was originally created to add a copyright picture to a series of pictures and add borders.

I´ve also created it to make myself work with a couple of programming aspects, such as Design Patterns (Decorator, Chain-of-Responsibility, Strategy, Singleton, Factory patterns are all used here) and keep on working with C++ and Win32, as I do C# for a living :)

Well, enough of the chit-chat, how is it used?


UPDATE: v0.4 is available! Click Here

I'll give this one upfront :)

You can download Copyrighter v0.3 from here (400kB zip file).

The executable itself is only 86 kB, and startup is instant. A sample copyright-image, preview-image and XML-file are included in the zip.

Images are processed by dragging and dropping onto the Copyrighter Window. Images of type TIFF, BMP (bitmap´s), PNG and of course JPG (jpeg´s) are all accepted.

Processed images come in a subfolder of the executable, called "Processed". So, if the executable location is C:\Copyrighter v0.3.exe, the images will be outputted to C:\Processed\.

Copyrighter uses an XML-file with the "modifydescriptor.xml" which tells it what to do with each image.

The result of the current modifydescriptor.xml file is always displayed on the main window (click for larger image):

copyrighterv0.3 mainimage

To achieve the border effect in this sample, one thin white border and one big black border, the following XML can be used:

<?xml version="1.0" encoding="UTF-8"?>
<modify type="solidcolourborder" percentage="3" colour="Black" />
<modify type="solidcolourborder" width="5" colour="White" />
<modify type="image" opacity="1.0" />
<modify type="copyrightimage" opacity="0.80" filename="example.png" percentage="25" position="bottomright" />

Pretty simple huh?

As you can see, Copyrighter works with so-called "modifiers" to identify the action that should take place.

So, in this sample, there are two borders with a solidcolour, an image, and the copyrightimage - all described with modify-elements.

Let's delve in a little bit further.

The solidcolourborder creates a border with a specific colour.

The size of the border can be described in two ways:

  1. as a percentage of the size of the image, via the percentage attribute
  2. as an absolute value, via the width attribute.

In the example, the first solidcolourborder uses a percentage via percentage="3", and the second uses an absolute value with width="1".

The last attribute for a solidcolourborder is the colour. You can use any colour such as "blue" or "green", etc. A list of available colours with their names is available here. Casing is not important, so you're free to write "blue" or "Blue".

Image describes where the processed image comes in the stack of modifiers.
There is only one attribute which can be set, which is the opacity. Any value between 0.0 (completely transparent) and 1.0 (opaque). You can leave this at 1.0 :)

Copyrightimage is the modifier which describes how the copyrightimage should be superimposed on the image. As you can see, it comes after the image modifier, because it is on top of the actual image.

There are a couple of attributes which can be set for the copyrightimage-modifier

  • opacity, any value between 0.0 and 1.0 can be used. I find that 0.8 creates a nice blend with the actual image, but you're of course free to use what you want.

  • filename, the filename of the image that should be used as the copyrightimage. If you want to use transparency, make sure you use the PNG-format using at least 16-bit to preserve transparency.

  • percentage, to describe how big the copyrightimage should be, as a percentage of the of the actual image.

  • position, the place where the copyrightimage should be placed. There are a couple of options, namely: "topleft", "topright",
    "bottomleft", "bottomright" and "middle".

There is one more modifier that you can use, which has not handled yet, and the is the widescreenborder. It uses the same attributes as the solidcolourborder, e.g.:

<modify type="widescreenborder" percentage="5" colour="Black" />

Which will create borders only on the top and bottom of an image, the same effect you will see with widescreen movies.

For example, the following XML:

<?xml version="1.0" encoding="UTF-8"?>
<modify type="widescreenborder" percentage="5" colour="Black" />
<modify type="image" opacity="1.0" />
<modify type="copyrightimage" opacity="0.80" filename="example.png" percentage="25" position="bottomright" />

Would yield the following result (click for larger image):
copyrighter v0.3 widescreenborder

Because this is just another modifier, you are free to mix all results. For example, you can use a widescreenborder-modifier with solidcolourborder-modifiers.

<?xml version="1.0" encoding="UTF-8"?>
<modify type="widescreenborder" width="10" colour="Navy" />
<modify type="solidcolourborder" percentage="3" colour="Orange" />
<modify type="solidcolourborder" width="5" colour="LawnGreen" />
<modify type="image" opacity="1.0" />
<modify type="copyrightimage" opacity="0.80" filename="example.png" percentage="25" position="bottomright" />

...yields the following result (click for larger image):

copyrighter v0.3 mixedmodifiers

Advanced users, setting colour
If you don't want to use a colour out of the linked list of colors, and you know about hexadecimals and RGB values, you can also set a very specific colour in a different way.

Let's take the colour FFDE8384.

This should be splitted up in 1 byte values, and you need two hexadecimals to describe one byte.

FF - this is actually the opacity of the colour, you can leave this at FF, which means the colour is fully opaque (i.e. no transparency at all) all the way to 00 for fully transparant.
DE - Red, 222 decimal
83 - Green, 131 decimal
84 - Blue, 132 decimal

FF000000 would be black (red, green, and blue are all 0). FFFFFFFF would be white (red, green and blue are all 255: the "brightest" setting).

You don't need to play around with hexadecimals to set a colour though, there are numerous online colourpickers you can choose from.

Some online colourpickers use a leading hash-symbol, e.g. "#A9BF34". Just make sure you substitute "#" with "FF" when setting it as a value in the XML, so it would be "FFA9BF34". Also make sure that the value is in ALL CAPS.

If you do not get the colour right, the entire modifier will be ignored, which means that the border will not be shown :)

If you've got questions or problems regarding this, feel free to comment! I'm happy to help you out.

Known issues
As this is still a pretty early version, there might be some issues you'll encounter.

  • User Interface hangs when processing
    Copyrighter currently becomes unresponse as it's processing files. Please wait for it to finish.

  • Preview might show (slight) inconsistencies
    For example, the border on the left-hand side of the image might appear smaller than the right-hand side. This is usually not a real problem, it's just that the preview is slighty skewed.
    If you are unsure, simply try a single image and see what the result is like, it's likely just fine.

  • You cannot border the copyrightimage
    Currently you cannot put a border around the copyrightimage. If you try to do so, the copyrightimage will disappear.

  • Display only reads the modifydescriptor.xml file during program start-up.

  • This means that if you change the contents of modifydescriptor.xml whilst Copyrighter is running, the new results will NOT be shown in the current window. However, it will affect the processed files.
    Close and re-open Copyrighter to view the result of a modified modifydescriptor.xml in the preview window.

  • Using a percentage might fail
    When using a lot of modifiers mixing widescreenborder and solidcolourborders, using a percentage with solidcolourborders might not work correctly. Use the width instead of percentage instead in this case.

Final Words
Well, thanks for looking and if you use this program just drop me a line or place a comment, I'd really appreciate it :)

If you need some help creating a copyright-image, let me know, perhaps I can help you out. If you've found a certain bug not yet listed, post a reply or e-mail and I'll see what I can do. If you´ve got some kind of border in mind that you´d like to see implemented, also, let me know - maybe I can implement it.

All my images on that use a border have been created with Copyrighter if you want to view more samples.

If you've got any questions, also feel free to place a comment or e-mail to Srand0 AT yahoo DOT com. That's a zero in Srand0 btw :)



Tuesday, April 7, 2009

Driver's Licence GET!!!!

by Hasan Karagülmez
Passed the practical exam today for my Driver's Licence YAY!!!! :D