Insightful, profound, generous, witty, genius; all words that might be used somewhere in this blog.
Friday, January 30, 2004
Not polite?
I've just noticed that a few comments have been posted through the HaloScan system which I seem to have had no notification for. Normally when somebody posts a comment I get a mail telling me that it's there but for the last few days and certainly the last few comments made I have had nothing. This may be to do with the recent spate of e-mail viruses and the fact that I've got my Spam checking turned up to its fullest extent so please, if you make a comment and I don't respond straight away, be patient.
Sunday, January 25, 2004
New tips and tricks article
Just posted an article in Tips and Tricks that explains how to create a border on a control.
Wednesday, January 14, 2004
GDI+ FAQ updates
I have added an article on GDI mapping modes and GDI+ transformations and updated the negative-image article to reflect the discoveries of last weekend that I mentioned in the previous entry.
Monday, January 12, 2004
ColorMatrix weirdness
Someone asked me a simple question on Saturday that has had me wracking my brains and pulling out my hair over the weekend. They had a problem with an image containing some text which they had tried to invert to a negative but which came out completely black even though the original text was black on a white background. Obviously, it was expected to show white text on a black background. First of all I thought this was a bug and searched around in the code for errors but could find nothing glaringly obvious. Then I sat down and wrote a simple test that loaded up a picture, drew a checkerboard pattern of black squares on top of the picture and made a negative image using the color matrix as described in my GDI+ FAQ article. Imagine my surprise when the negative image had black squares on it instead of cyan ones. I was even more surprised when every graphic I tried came out black in the negative instead of its inverse color. I tried black, white, red, blue, green, yellow and magenta text and graphics and everything came out black in the negative image.
Suddenly, I realized that the common factor with all of these colors is that they all had one or more elements fully saturated or zero with no intermediate values whatsoever. The answer is of course that when using the color matrix to create a negative image color triplet values are multiplied by -1. These values are also eight bit values and so 255 multiplied by -1 is -255 which overflows the 8 bit value to zero. This means that every color with a fully saturated component will be incorrect in the negative and therefore inverting a negative created with this process will produce an incorrect positive.
In an effort to overcome this problem I decided that the solution was to ensure that there were no elements in the image which had fully saturated values or zeros in any of the pixels. To do this I used the color matrix again this time scaling all the colors to make them a tiny bit darker and then shifting all the colors up by one value. This produces positive images which are imperceptibly changed and which produce perfect negatives every time. I am just in the process of updating the GDI+ FAQ with this information and a little bit of code.
Suddenly, I realized that the common factor with all of these colors is that they all had one or more elements fully saturated or zero with no intermediate values whatsoever. The answer is of course that when using the color matrix to create a negative image color triplet values are multiplied by -1. These values are also eight bit values and so 255 multiplied by -1 is -255 which overflows the 8 bit value to zero. This means that every color with a fully saturated component will be incorrect in the negative and therefore inverting a negative created with this process will produce an incorrect positive.
In an effort to overcome this problem I decided that the solution was to ensure that there were no elements in the image which had fully saturated values or zeros in any of the pixels. To do this I used the color matrix again this time scaling all the colors to make them a tiny bit darker and then shifting all the colors up by one value. This produces positive images which are imperceptibly changed and which produce perfect negatives every time. I am just in the process of updating the GDI+ FAQ with this information and a little bit of code.
Subscribe to:
Posts (Atom)