![]() |
_CLEARCOLOR evety color EXCEPT ...? - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: Chatting and Socializing (https://qb64phoenix.com/forum/forumdisplay.php?fid=11) +--- Forum: General Discussion (https://qb64phoenix.com/forum/forumdisplay.php?fid=2) +--- Thread: _CLEARCOLOR evety color EXCEPT ...? (/showthread.php?tid=3643) |
_CLEARCOLOR evety color EXCEPT ...? - madscijr - 04-27-2025 Hey all. I know _CLEARCOLOR can be used multiple times if you want more than one color transparent, but is there a way to -quickly- copy only pixels of a given color to another image? This would need to be fast, like for animation. I think a command like "_CLEARCOLOR ExceptColor~&" would be useful for this. Or do we just have to compare POINT for every pixel? RE: _CLEARCOLOR evety color EXCEPT ...? - hsiangch_ong - 04-27-2025 (04-27-2025, 03:21 PM)madscijr Wrote: Or do we just have to compare POINT for every pixel?what i would do is use _red, _green and _blue as well as point. sometimes _alpha in addition. because point is unreliable. have one "target" color to compare each of the color registers. then use abs with a threshold. could use one threshold for all registers, or a separate threshold for each register for finer control. sadly for typical 32-bit images it could be a bit sloppy. it could produce dots spread out in far portions of the image. which could look ugly for an user. Code: (Select All) dim as long targetcolor, readcolor RE: _CLEARCOLOR evety color EXCEPT ...? - Petr - 04-27-2025 (04-27-2025, 03:21 PM)madscijr Wrote: Hey all. I know _CLEARCOLOR can be used multiple times if you want more than one color transparent, but is there a way to -quickly- copy only pixels of a given color to another image? This would need to be fast, like for animation. I think a command like "_CLEARCOLOR ExceptColor~&" would be useful for this. Or do we just have to compare POINT for every pixel? That is why it is recommended to use the _Mem commands. It is much faster than Point and PSet. However, you must watch the area that is read/written and take into account the type of image. An 8bit image uses the palette index number in the range 0 to 255 as information about the pixel color, so the size of one pixel of an 8bit image is equal to 1byte. (_Unsigned _Byte specifically). While a 32bit image uses 4bytes in memory: (RGBA) The following is an example - how to copy one color from one image to another FAST. I wrote a classic solution and then the same with _Mem. Code: (Select All)
Note that I intentionally set the program to execute the action 10 times in a row to highlight the difference in speed between PSET/POINT vs _MemGet and _MemPut. In my case, the speed difference is 100x. Furthermore, when processing graphics (and other data), if you want it really fast, use loops DO... LOOP, While...Wend - they are faster than For...Next. When it comes to copying a square memory area, there are even faster _MEM methods than writing 4 bytes at 1 step per loop. RE: _CLEARCOLOR evety color EXCEPT ...? - madscijr - 04-27-2025 Thanks for your replies - I'll look at these in more detail when at the PC as this seems to be more to consider than I expected, but I think this will work for me. Thanks again! RE: _CLEARCOLOR evety color EXCEPT ...? - TempodiBasic - 04-27-2025 Hi Quote:This would need to be fast, like for animation.can you be more specific with an example? Maybe the path is NOT _clearcolor in the meanwhile I had 2 study with _Clearcolor and _SetAlpha I took the third example from the wiki and going on I develop this first snippet... BUT I brought with me a conceptual error that is in that example.... as result of running the code we must get that the foreground parts of the image copied over the screen always overwrite the background image of the screen, while increasing the alpha channel from 0 to 255, we must see the presence of the background of the image copied over the screen covering the background image of the screen. This doesn't happen because in the code it has been used _Setalpha without a specific color OR range of colors so all the colors of the image copied over the screen (including its background color that before by _Clearcolor made transparent) change their degree of transparency. So all the image changes from transparent to opaque with no blending between image of the screen and the background of image pasted over it. I must say that wiki says clearly that _Setalpha changes the alpha channel of all the colors of the image, also those that have been treated with _clearcolor before . here the code Code: (Select All)
it remains a good example of how to exclude a color of an image to avoid to be copied to another one.So going on in the wiki I found the right information in page _SetAlpha and I keep informations from the example about the specific : how to give the range of colors to treat with _setalpha without affecting all the colors of the image here the code in which finally the background of the image copied on the screen goes ranging from transparent to opaque Code: (Select All)
I have found no day for _Clearcolor and _Setalpha keywords also if it seems a recurrent issue dealing with them making mask or use _clearcolor setting _cleacolor printing to image handle [/url][url=https://qb64phoenix.com/forum/showthread.php?tid=3606&highlight=_clearcolor]setalpha and clearcolor I think that it is useful to have more example about how to specify the range of colors to treat with _Setalpha. the range from Color1& TO Color2& must be continue? (i.e. from _RGB32(255,0,0) TO _RGB32(0,255,0) means that all colors with values between full Red and full Green are treated by _Setalpha?) for different colors must I use an array with handles of colors and apply _setalpha on each one at a time? (i.e. simulating the action of Palette Using and _SetPalette of legacy graphic screens?) in the example taken from the wiki why topcolor = _RGBA(0,0,0,0)- _RGBA(1,1,1,0) and not only _RGBA(1,1,1,0) that is the next one after black transparent? Is it possible to claim a day for _Clearcolor and _Setalpha in the keyword of day? a good day like this _Putimage day |