Negative
trcurvello

How can I make to take off the negative of a photo???

imaxcs
trcurvello

using allegro

Andrei Ellman

Find the inverted value of each pixel. Assuming your picture is an image that has 8-bits for each of R,G and B channels, subtract the channel's value from 255 for the 3 channels in the pixel, and do this for all pixels in the image.

AE.

trcurvello

How I do this in the code???

Matt Smith
for (y=0 ; y<bmp->h ; y++)
   for (x=0 ; x<bmp->w ; x++) {
      c = _getpixel(bmp, x, y);
      r = getr(c); g = getg(c); b = getb(c);
      
      _putpixel(bmp, x, y, makecol(255-r, 255-g, 255-b) );
   }

untested, all vars are ints (except bmp of course)

James Stanley

That's not actually a negative though, that's just inverted. A negative is something that might be called solarized. I believe they're different. I could be wrong.

Jakub Wasilewski
Quote:

A negative is something that might be called solarized. I believe they're different. I could be wrong.

Hm, maybe find out then ;).

Arthur Kalliokoski

"Solarization" refers to extreme overexposure of photographic film, I think it occurred to old TV cameras too. You could see normal parts of the picture the way it was supposed to be, but something extremely bright made some spots dark again. If you see old TV clips from game shows or something from the '50's or '60's, you might notice "flares" with weird effects coming from jewelry reflections of the stage lights etc.

Jonatan Hedborg

In pseudo code, you could probably do something like this:
For each pixel
{
Get Rgb value for pixel
Covert to HSV
Add ("rotate") 180 to Hue (ie, 200 + 180 = 20)
Convert back to Rgb
Write to target image
}

Untested, but i guess that's how it works.

James Stanley
Quote:

Hm, maybe find out [en.wikipedia.org] then ;).

Fair enough :).

Or, another pseudo-code:
For each pixel
{
Get RGB values for pixel (with getr, getg, getb)
Take each from 255 (r=255-getr)
write to target image
}

Andrei Ellman
James Stanley said:

That's not actually a negative though, that's just inverted.

A negative involves inverting all the R, G, and B values, not just the lightness. What you had in mind would result in the correct lightness, but the colours would still be inverted. The algorithm in question for what you had in mind would look something like this.

For each pixel
{
Get Rgb value for pixel
Covert to HSL
H = 1.0f - H
Convert back to Rgb
Write to target image
}

If this algorithm was applied to the output (or input) of Jonatan's pseudocode, you'd basically end up with the same effect as Matt Smith's code which is what the negative of an image is.

Arthur Kalliokoski said:

"Solarization" refers to extreme overexposure of photographic film, I think it occurred to old TV cameras too.

Not to mention with my phone's digital camera add-on whenever the sun happens to be in one of my photos.

James Stanley said:

For each pixel
{
Get RGB values for pixel (with getr, getg, getb)
Take each from 255 (r=255-getr)
write to target image
}

Which is basically the same code that Matt Smith wrote earlier.

AE.

Mr. Big

The correct formulae are:

Rn = 255 - R
Gn = 255 - G
Bn = 255 - B

Red becomes cyan, green becomes magenta, blue becomes yellow, dark becomes bright and vice versa:

(255, 0, 0) <-> (255 - 255, 255 - 0, 255 - 0) <-> (0, 255, 255)
(0, 255, 0) <-> (255 - 0, 255 - 255, 255 - 0) <-> (255, 0, 255)
(0, 0, 255) <-> (255 - 0, 255 - 0, 255 - 255) <-> (255, 255, 0)
(10, 10, 10) <-> (255 - 10, 255 - 10, 255 - 10) <-> (245, 245, 245)

Fladimir da Gorf

Just do: color = ~color. Much easier...

Jakub Wasilewski
Quote:

Just do: color = ~color. Much easier...

Yeah, especially fun when alpha 255 becomes alpha 0 and you stop seeing anything when blitting with alpha :)).

Andrei Ellman
Quote:

Rn = 255 - R
Gn = 255 - G
Bn = 255 - B

Is it just me or does this thread have an exceptionally high echo???

AE.

Mr. Big

\o/!
I've just noticed that my solution has already been proposed 3 times in this thread.
The reason is, I didn't really bother reading all the posts.
I saw somebody mentioning 'HSV' and 'HSL' and thought, "what the...?", so I've decided to post the correct solution. ;D

Thread #587672. Printed from Allegro.cc