![]() |
[GR32] How to add intensity?
I have simple procedure to add color filter to bitmap:
Delphi-Quellcode:
How to add Intensity parameter (0=original color, 100=as above)?
Row.R := (Color.R * Row.R) div 255;
// Repeat for G and B Or maybe is better method to colorize filter? |
Re: [GR32] How to add intensity?
I haven't really understood what you do with this particular filter, but it looks like you're looking for simple linear interpolation, where you can shift beween two values freely.
Delphi-Quellcode:
function Lerp(a, b: Byte; t: Double): Byte;
var tmp: Double; begin tmp := t*a + (1-t)*b; if tmp<0 then result := 0 else if tmp>255 then result := 255 else result := Round(tmp); end; procedure YourFilter(Percent: Integer); begin Row.R := Lerp(Color.R, (Color.R*Row.R) div 255, Percent/100); //... end; |
Re: [GR32] How to add intensity?
Liste der Anhänge anzeigen (Anzahl: 1)
Something similar (Lerp() coloring too much - up to solid color). I mean like this:
![]() :) |
Re: [GR32] How to add intensity?
I would do something like this:
1. You have the "target color" (full brightness and saturation) and the amount you want to blend (between 0 and 1) 2. For each Pixel do: 2.1: multiply the target color with the brightness of the image pixel 2.2: mix the image pixel and the result from 2.1 together, according to the amount. :arrow: (1-x) * image_pixel + x * (color * image_pixel_brightness) The Brigness of a pixel is calculated by adding up all the components and dividung the result by 3. However, there is an advanced formula that weights the colors differently. |
Re: [GR32] How to add intensity?
Hi!
@WojTec: Could you please attach the image instead of including it in the posting? This would decrease loading times and the thread is still useful, even if the image has gone on the other server. Thanks in advance. Bye, Frederic |
Re: [GR32] How to add intensity?
Zitat:
|
Re: [GR32] How to add intensity?
@jfheins, I'm doing something wrong :(:
Delphi-Quellcode:
@fkerber, Ok, I'll remmeber.
var
Row: PBGRAQuad; Color: TBGRAQuad; I, J: Integer; B: Byte; C: TColor; begin Color := ColorToTriple24(AColor); Row := PBGRAQuad(@ASource.Bits[0]); for I := 0 to ASource.Height - 1 do begin for J := 0 to ASource.Width - 1 do begin B := (Row.R + Row.G + Row.B) div 3; C := TColor(Round((1 - (APercent / 100)) * RGB(Row.R, Row.G, Row.B) + (APercent / 100) * (RGB(Color.R, Color.G, Color.B) * B))); Row.R := GetRValue(C); Row.G := GetGValue(C); Row.B := GetBValue(C); Inc(Row); end; end; end; |
Re: [GR32] How to add intensity?
@Medium, when Color is for example clYellow and 3rd parameter is 1, any pixel of output is = Color. This is wrong - should be as is on example image above.
|
Re: [GR32] How to add intensity?
Hi!
Zitat:
You could also do so in the above posting. It's possible by editing the posting (To do this, click on the button "edit" in the upper right corner). Bye, Frederic |
Re: [GR32] How to add intensity?
Zitat:
Regarding the code you posted: You cannot simply multiply with whole combined RGB-values. You must handle each color channel separately. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 01:12 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz