Jump to content
shadowrecon

Changing a colors brightness?

Recommended Posts

Anyone have any ideas on settings a color to a different brightness ? I've wrote a function to change to opacity but it can only make the color darker. I'd like a function that does the opposite.

[scar]

function opacity(color: integer; percent: extended): integer;

Var

R,g,b: integer;

Begin

Percent := percent / 100;

Colortorgb(color,r,g,b);

Result := Rgbtocolor(

Round((1 - percent)*r),

Round((1 - percent)*g),

Round((1 - percent)*b));

End;

[/scar]

Link to comment
Share on other sites

http://www.easyrgb.com/index.php?X=MATH&H=18#text18

 

The next revisions of the samples repository will contain a library sample which demonstrates drawing on bitmaps in scar from libraries, and exporting bitmaps from scar to the library and the other way around. but I'll need to upload a new beta before I can implement all of that properly.

Link to comment
Share on other sites

http://www.easyrgb.com/index.php?X=MATH&H=18#text18

 

The next revisions of the samples repository will contain a library sample which demonstrates drawing on bitmaps in scar from libraries, and exporting bitmaps from scar to the library and the other way around. but I'll need to upload a new beta before I can implement all of that properly.

Thanks for the link! Right now for bitmaps I'm just using the DC, and creating a canvas and setting the handle to the dc which works really good so far. My lib takes 5ms and scar takes 9 seconds to do the same procedure on a 50 x 50 bitmap :)

Link to comment
Share on other sites

Yeah that's the whole reason I had to write a lib. Because the time it took to convert and replace 2500 pixels. In your example of bitmaps could you possibly make a scanline version? Because I tried using scanline but couldn't get it to work right and from what or read it is a heck of alot faster then canvas.pixels[]

Link to comment
Share on other sites

So if certain things run slow make sure they aren't in a scar library?

 

Make sure they are... Though, you'll only ever need this for very high performance algorithms that need to change or check tons of data or make huge calculations.

 

---------- Post added at 11:14 PM ---------- Previous post was at 11:10 PM ----------

 

Yeah that's the whole reason I had to write a lib. Because the time it took to convert and replace 2500 pixels. In your example of bitmaps could you possibly make a scanline version? Because I tried using scanline but couldn't get it to work right and from what or read it is a heck of alot faster then canvas.pixels[]

 

Take a look at this topic I wrote when I was 16 :P It should give you a good idea on how to use scanlines: http://forums.freddy1990.com/index.php/topic,8.0.html

It uses a TBitmap, but the upcoming sample will show you how to get a bitmap from SCAR to a TBitmap in a library.

Link to comment
Share on other sites

Make sure they are... Though, you'll only ever need this for very high performance algorithms that need to change or check tons of data or make huge calculations.

 

---------- Post added at 11:14 PM ---------- Previous post was at 11:10 PM ----------

 

 

Take a look at this topic I wrote when I was 16 :P It should give you a good idea on how to use scanlines: http://forums.freddy1990.com/index.php/topic,8.0.html

It uses a TBitmap, but the upcoming sample will show you how to get a bitmap from SCAR to a TBitmap in a library.

There are tutorials around on bitmaps, canvases, etc.

 

So Freddy how is what he's doing a high performance algorithm? Explain I'm brain dead atm, and also

 

Offtopic: Does anyone know any good websites to learn algebra, or just math in general. I like to learn thoroughly, I don't like just skimming a topic then using it later and not understanding it fully. Help...

 

Thanks for the link Freddy looks indepth - http://forums.freddy1990.com/index.php/topic,8.0.html

Edited by LordJashin
Link to comment
Share on other sites

The algorithm he wants to write is extremely CPU intensive because of the "heavy" calculations required to convert the RGB values to HSL and back. Normally this wouldn't be a problem, but he has to do it for every pixel on a bitmap, if you have a small bitmap, let's say 50*50, that's 2500 times you have to perform all of those calculations. That would still execute at acceptable speeds in SCAR, but if you examine a more realistic example, lets say a 1000*500 bitmap, that's 500000 pixels.

 

EDIt: The new sample is up, make sure you have the latest beta copy.

Edited by Freddy
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...