Board index » delphi » Fast way to modify hue, sat, lum of RGB bitmap

Fast way to modify hue, sat, lum of RGB bitmap

Hello,

does anybody know a fast way to modify the hue, sat and lum of a rgb bitmap?
I know the scanline property, I know the RGBtoHSL and HSLtoRGB
transformations.
But when I use two formulas for every pixel of a 4 Megapixel bitmap, it's
not so fast.

I hope there exists a better formula to modify the HSL values of a RGB value
for every pixel then the way:

get RGB values from Scanline
RGBtoHSL
Modify HSL
HSLtoRGB
set RGB values in Scanline

Does anybody have a better way to do this? A fast specialized lookup table?

thank you,

Rolf

 

Re:Fast way to modify hue, sat, lum of RGB bitmap


Rolf,

Not sure if it would be faster, but you could certainly set up an 8 x 8 x
8 table of 24-bit colours, presetting that table to all the possible
translations.  It would take (I think) about 50MB of memory.  Would
setting up the table take longer than doing the maths?

One other possibility to speed setting up the table might be to only
actually calculate half the values in R, G and B and interpolate the
others....

Cheers,
David

Quote
"Rolf Hansen" <rolfnos...@nospambitspaper.de> wrote in message

news:3d0eeaf1$1_1@dnews...
Quote
> Hello,

> does anybody know a fast way to modify the hue, sat and lum of a rgb
bitmap?
> I know the scanline property, I know the RGBtoHSL and HSLtoRGB
> transformations.
> But when I use two formulas for every pixel of a 4 Megapixel bitmap,
it's
> not so fast.

> I hope there exists a better formula to modify the HSL values of a RGB
value
> for every pixel then the way:

> get RGB values from Scanline
> RGBtoHSL
> Modify HSL
> HSLtoRGB
> set RGB values in Scanline

> Does anybody have a better way to do this? A fast specialized lookup
table?

> thank you,

> Rolf

Re:Fast way to modify hue, sat, lum of RGB bitmap


[sorry if this post appears twice, doesn't seem to appear first time]

Just a matrix to convert from RGB to HSL will do fine. If you use floating
point arithmic this is supposedly faster than integer arithmic these days.

Lookup tables worked fine in the old days, but nowadays that's not true
anymore. Reason: memory lookup is WAY slower than processor speed.

Perhaps you can find an algorithm that does a matrix multiply in assembler,
perhaps even using MMX technology.

It would have to do something like

var
  RtoH: array[0..2, 0..2] of double;
  HSL, RGB: array[0..2] of double;
...
procedure RGBtoHSL();
begin
  HSL[0] = RtoH[0, 0] * RGB[0] + RtoH[1, 0] * RGB[1] + RtoH[2, 0] * RGB[2];
  HSL[1] = RtoH[0, 1] * RGB[0] + RtoH[1, 1] * RGB[1] + RtoH[2, 1] * RGB[2];
  HSL[2] = RtoH[0, 2] * RGB[0] + RtoH[1, 2] * RGB[1] + RtoH[2, 2] * RGB[2];
end;

Since there's some alignment in it, in theory this could be made blazingly
fast with MMX.

Whenever you need the HSL rounded results you just round the values to
byte/integer again. This depends on your colourdepth. Do this as the very
last step (so after any Gamma corrections etc).

I could give you more info on the conversion matrix, but please try to find
it yourself first.. I must have it somewhere in a book.

Kind regards,

Nils Haeck
www.abc-view.com

Quote
Rolf Hansen <rolfnos...@nospambitspaper.de> wrote in message

news:3d0eeaf1$1_1@dnews...
Quote
> Hello,

> does anybody know a fast way to modify the hue, sat and lum of a rgb
bitmap?
> I know the scanline property, I know the RGBtoHSL and HSLtoRGB
> transformations.
> But when I use two formulas for every pixel of a 4 Megapixel bitmap, it's
> not so fast.

> I hope there exists a better formula to modify the HSL values of a RGB
value
> for every pixel then the way:

> get RGB values from Scanline
> RGBtoHSL
> Modify HSL
> HSLtoRGB
> set RGB values in Scanline

> Does anybody have a better way to do this? A fast specialized lookup
table?

> thank you,

> Rolf

Re:Fast way to modify hue, sat, lum of RGB bitmap


Just a matrix to convert from RGB to HSL will do fine. If you use floating
point arithmic this is supposedly faster than integer arithmic these days.

Lookup tables worked fine in the old days, but nowadays that's not true
anymore. Reason: memory lookup is WAY slower than processor speed.

Perhaps you can find an algorithm that does a matrix multiply in assembler,
perhaps even using MMX technology.

It would have to do something like

var
  RtoH: array[0..2, 0..2] of double;
  HSL, RGB: array[0..2] of double;
...
procedure RGBtoHSL();
begin
  HSL[0] = RtoH[0, 0] * RGB[0] + RtoH[1, 0] * RGB[1] + RtoH[2, 0] * RGB[2];
  HSL[1] = RtoH[0, 1] * RGB[0] + RtoH[1, 1] * RGB[1] + RtoH[2, 1] * RGB[2];
  HSL[2] = RtoH[0, 2] * RGB[0] + RtoH[1, 2] * RGB[1] + RtoH[2, 2] * RGB[2];
end;

Since there's some alignment in it, in theory this could be made blazingly
fast with MMX.

Whenever you need the HSL rounded results you just round the values to
byte/integer again. This depends on your colourdepth. Do this as the very
last step (so after any Gamma corrections etc).

I could give you more info on the conversion matrix, but please try to find
it yourself first.. I must have it somewhere in a book.

Kind regards,

Nils Haeck
www.abc-view.com

It depends in what kind of color depth you want to work.

Quote
Rolf Hansen <rolfnos...@nospambitspaper.de> wrote in message

news:3d0eeaf1$1_1@dnews...
Quote
> Hello,

> does anybody know a fast way to modify the hue, sat and lum of a rgb
bitmap?
> I know the scanline property, I know the RGBtoHSL and HSLtoRGB
> transformations.
> But when I use two formulas for every pixel of a 4 Megapixel bitmap, it's
> not so fast.

> I hope there exists a better formula to modify the HSL values of a RGB
value
> for every pixel then the way:

> get RGB values from Scanline
> RGBtoHSL
> Modify HSL
> HSLtoRGB
> set RGB values in Scanline

> Does anybody have a better way to do this? A fast specialized lookup
table?

> thank you,

> Rolf

Re:Fast way to modify hue, sat, lum of RGB bitmap


[sorry if this post appears twice, doesn't seem to appear first time]

Just a matrix to convert from RGB to HSL will do fine. If you use floating
point arithmic this is supposedly faster than integer arithmic these days.

Lookup tables worked fine in the old days, but nowadays that's not true
anymore. Reason: memory lookup is WAY slower than processor speed.

Perhaps you can find an algorithm that does a matrix multiply in assembler,
perhaps even using MMX technology.

It would have to do something like

var
  RtoH: array[0..2, 0..2] of double;
  HSL, RGB: array[0..2] of double;
...
procedure RGBtoHSL();
begin
  HSL[0] = RtoH[0, 0] * RGB[0] + RtoH[1, 0] * RGB[1] + RtoH[2, 0] * RGB[2];
  HSL[1] = RtoH[0, 1] * RGB[0] + RtoH[1, 1] * RGB[1] + RtoH[2, 1] * RGB[2];
  HSL[2] = RtoH[0, 2] * RGB[0] + RtoH[1, 2] * RGB[1] + RtoH[2, 2] * RGB[2];
end;

Since there's some alignment in it, in theory this could be made blazingly
fast with MMX.

Whenever you need the HSL rounded results you just round the values to
byte/integer again. This depends on your colourdepth. Do this as the very
last step (so after any Gamma corrections etc).

I could give you more info on the conversion matrix, but please try to find
it yourself first.. I must have it somewhere in a book.

Kind regards,

Nils Haeck
www.abc-view.com

Re:Fast way to modify hue, sat, lum of RGB bitmap


Quote
>   HSL[0] = RtoH[0, 0] * RGB[0] + RtoH[1, 0] * RGB[1] + RtoH[2, 0] * RGB[2];
>   HSL[1] = RtoH[0, 1] * RGB[0] + RtoH[1, 1] * RGB[1] + RtoH[2, 1] * RGB[2];
>   HSL[2] = RtoH[0, 2] * RGB[0] + RtoH[1, 2] * RGB[1] + RtoH[2, 2] * RGB[2];

Nope, you cannot transform  RGB->HSV and back by any matrixes.
If some book tells else, the author is wrong.

--
Andrew Rybenkov.

create labels, logos, image lists
for your programs and websites with
  "Imagizer: Click and Get It",
  http://www.geocities.com/arybenkov/imagizer/

Other Threads