shadowrecon Posted April 4, 2012 Share Posted April 4, 2012 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] Quote Link to comment Share on other sites More sharing options...
FHannes Posted April 4, 2012 Share Posted April 4, 2012 Why not convert it to HSL, change the luminosity and convert it back? Quote Link to comment Share on other sites More sharing options...
shadowrecon Posted April 4, 2012 Author Share Posted April 4, 2012 The reason is I'm working on this plugin and I'm going to be changing every pixel in the bmp and I know how to convert a color to rgb and back but have no clue how to convert it to HSL and back. That would be a lot easier tho. Quote Link to comment Share on other sites More sharing options...
FHannes Posted April 4, 2012 Share Posted April 4, 2012 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. Quote Link to comment Share on other sites More sharing options...
shadowrecon Posted April 4, 2012 Author Share Posted April 4, 2012 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 Quote Link to comment Share on other sites More sharing options...
FHannes Posted April 4, 2012 Share Posted April 4, 2012 The pascalscript engine SCAR uses is very slow compared to native code. Usually it's not such a big problem, but when you need to write high-performance algorithms, it is. Quote Link to comment Share on other sites More sharing options...
LordJashin Posted April 4, 2012 Share Posted April 4, 2012 The pascalscript engine SCAR uses is very slow compared to native code. Usually it's not such a big problem, but when you need to write high-performance algorithms, it is. So if certain things run slow make sure they aren't in a scar library? Quote Link to comment Share on other sites More sharing options...
shadowrecon Posted April 4, 2012 Author Share Posted April 4, 2012 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[] Quote Link to comment Share on other sites More sharing options...
FHannes Posted April 4, 2012 Share Posted April 4, 2012 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 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. Quote Link to comment Share on other sites More sharing options...
LordJashin Posted April 4, 2012 Share Posted April 4, 2012 (edited) 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 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 April 4, 2012 by LordJashin Quote Link to comment Share on other sites More sharing options...
FHannes Posted April 4, 2012 Share Posted April 4, 2012 (edited) 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 April 4, 2012 by Freddy Quote Link to comment Share on other sites More sharing options...
shadowrecon Posted April 9, 2012 Author Share Posted April 9, 2012 Thanks freddy all of this information has been really helpful! Quote Link to comment Share on other sites More sharing options...