Paulie Posted August 20, 2006 Posted August 20, 2006 I have C# code for color management, unfortunatley, looking at this, I might as well be reading chinese unsafe { byte * p = (byte *)(void *)Scan0; int nOffset = stride - b.Width*3; byte red, green, blue; for(int y=0;y < b.Height;++y) { for(int x=0; x < b.Width; ++x ) { blue = p[0]; green = p[1]; red = p[2]; p[0] = p[1] = p[2] = (byte)(.299 * red + .587 * green + .114 * blue); p += 3; } p += nOffset; } } If someone could talk me throught this code, i'd give them money(Not really)
Excalibur Posted August 20, 2006 Posted August 20, 2006 First, allow me to start off by commending you in your expression of FOAMY! Second, its pretty self explanitory, some of the C# functions cant be ported to AutoIt, as its a different logic of the flow of data through the program, also AutoIt isnt as advanced. And I'm not guru of C#, BUT, I do know a bit of C++ and I'm a pro in Java, so I'll do my best.byte * p, is a pointer to whatever scan0 is. Dont know what to tell you to do with that, other then to send all the data that scan0 is to the function, instead of a pointer, *shrugs* I have limited use of pointers with AutoIt. But I have no idea what the Scan0 object is. Nor do I know what the 'b' object is that width is being referenced from.Other then those two inconsistencies, all you need to do is get the data, once you have the data they are refering to, its simple. If you explain those parts more, I think it would be easier for people to assist if you explained that reference, or perhaps what program you cut this out of.beyond that, the rest is pretty self explanitory$Scan0 = <What ever data Scan0 is>;$Height = <what ever b.width is>;$Width = <whatever b.height is>;$nOffset = $stride - ($width*3)$y = 0$x = 0Do Do $x = $x + 1; While $x < $WidthWhile $y < $Height Thats the outside structure, and as I get to this point, what is actually going on here is that its moving a pointer in memory and manupulateing through the... image data I assume? three bytes at a time, I also assume each three bytes is a color... SO, what you would have to do from this point, is get the data from Scan0, and split it into an array of bytes (im unsure of how to do this in AutoIt) and just go through each byte in the array three at a time.If you need further explination, I will be on tommorrow, I was far too tired to answer this question, Didnt reconize the work when I started answering it. :-P.unsafe{ byte * p = (byte *)(void *)Scan0; int nOffset = stride - b.Width*3; byte red, green, blue; for(int y=0;y < b.Height;++y) { for(int x=0; x < b.Width; ++x ) { blue = p[0]; green = p[1]; red = p[2]; p[0] = p[1] = p[2] = (byte)(.299 * red + .587 * green + .114 * blue); p += 3; } p += nOffset; }} Ooo Ëxçã¿îbúr ooO"Information Is Not Knowledge." ~Albert Einstein
Paulie Posted August 20, 2006 Author Posted August 20, 2006 First, allow me to start off by commending you in your expression of FOAMY! Second, its pretty self explanitory, some of the C# functions cant be ported to AutoIt, as its a different logic of the flow of data through the program, also AutoIt isnt as advanced. And I'm not guru of C#, BUT, I do know a bit of C++ and I'm a pro in Java, so I'll do my best. byte * p, is a pointer to whatever scan0 is. Dont know what to tell you to do with that, other then to send all the data that scan0 is to the function, instead of a pointer, *shrugs* I have limited use of pointers with AutoIt. But I have no idea what the Scan0 object is. Nor do I know what the 'b' object is that width is being referenced from. Other then those two inconsistencies, all you need to do is get the data, once you have the data they are refering to, its simple. If you explain those parts more, I think it would be easier for people to assist if you explained that reference, or perhaps what program you cut this out of. beyond that, the rest is pretty self explanitory $Scan0 = <What ever data Scan0 is>; $Height = <what ever b.width is>; $Width = <whatever b.height is>; $nOffset = $stride - ($width*3) $y = 0 $x = 0 Do Do $x = $x + 1; While $x < $Width While $y < $Height Thats the outside structure, and as I get to this point, what is actually going on here is that its moving a pointer in memory and manupulateing through the... image data I assume? three bytes at a time, I also assume each three bytes is a color... SO, what you would have to do from this point, is get the data from Scan0, and split it into an array of bytes (im unsure of how to do this in AutoIt) and just go through each byte in the array three at a time. If you need further explination, I will be on tommorrow, I was far too tired to answer this question, Didnt reconize the work when I started answering it. :-P. unsafe { byte * p = (byte *)(void *)Scan0; int nOffset = stride - b.Width*3; byte red, green, blue; for(int y=0;y < b.Height;++y) { for(int x=0; x < b.Width; ++x ) { blue = p[0]; green = p[1]; red = p[2]; p[0] = p[1] = p[2] = (byte)(.299 * red + .587 * green + .114 * blue); p += 3; } p += nOffset; } }Thank you for trying to help, and any input you can give is appreciated, I believe however that the most important part is what i have made red in the quote I got this code from this site http://www.codeproject.com/cs/media/csharp...icfilters11.asp Which i randomly found while searching for a way to gray scale an image I have this much in autoit code so far #include <Color.au3> Sleep(2000) Opt('Colormode',1) For $y1 = 00 to 100 For $x1 = 00 to 100 $colorD = PixelGetColor($x1, $y1) $colorH = Hex($ColorD) $Red = _ColorGetRed("0x"&$colorH) $Green = _ColorGetGreen("0x"&$colorH) $Blue = _ColorGetBlue("0x"&$colorH) $Red2 =.299 * $red + .587 * $green + .114 * $blue; } $Blue2 =.299 * $red + .587 * $green + .114 * $blue; }These I need help on $Green2 =.299 * $red + .587 * $green + .114 * $blue;} $color2 = $Blue2&$Green2&$Red2 SetPixel($x1,$y1,$color2) Next Next Func SetPixel ($h_x, $h_y, $h_color) $dc= DllCall ("user32.dll", "int", "GetDC", "hwnd", "") $setpixel= DllCall ("gdi32.dll", "long", "SetPixel", "long", $dc[0], "long", $h_x, "long", $h_y, "long", $h_color) $realesedc= DllCall ("user32.dll", "int", "ReleaseDC", "hwnd", 0, "int", $dc[0]) EndFunc In an attempt to gray scale the desktop without taking screenshots It is oddly very red tinted when you run this, an opposed to gray How to make it gray, I may never know... yes i know that this method with set pixel would take fifteen YEARS to do the whole desktop, but that can be refined once it actually works Once again, any help/ideas are appreciated and will be credited in my final code
themax90 Posted August 20, 2006 Posted August 20, 2006 (edited) $Red2 =.299 * $red + .587 * $green + .114 * $blue; } $Blue2 =.299 * $red + .587 * $green + .114 * $blue; }These I need help on $Green2 =.299 * $red + .587 * $green + .114 * $blue;}Isn't the original (byte)(.299) ....etcIf it's mathmatical link I think, I believe it is byte*.299I may be wrong.Edit : NVM I think it's just declaring the Variable as a Byte. I just don't know C++ well enough. Sorry. Edited August 20, 2006 by AutoIt Smith
Paulie Posted August 20, 2006 Author Posted August 20, 2006 Anyone else have other ideas on this?*Bump*
flyingboz Posted August 20, 2006 Posted August 20, 2006 (edited) Just a stab here, but shouldn't the scaling values for r2,b2,g2 different depending on which component you're scaling? In other words, I'm not surprised it's redshifted , when every red value is only dropped to ~60%, while the other values are dropped much more. EDIT: Pls ignore this mathematically deficient post. Edited August 20, 2006 by flyingboz Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.
flyingboz Posted August 20, 2006 Posted August 20, 2006 Ahh.... It just hit me. You are calculating color2 as being the entire color... However, that is the rgb value that R,G, and B are supposed to be in grayscale. Therefore: $gray = _GrayScale($red,$green,$blue) $color2 = "0x" & Hex($gray,2) & Hex($gray,2) & Hex($gray,2) ;now your SetPixel won't just be calling a 0xRR0000 value, such that you were always being redshifted. func _GrayScale($r,$g,$B) Return Int($r * .299 + $g *.587 + $b *.114) EndFunc Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.
Paulie Posted August 20, 2006 Author Posted August 20, 2006 (edited) Just a stab here, but shouldn't the scaling values for r2,b2,g2 different depending on which component you're scaling?In other words, I'm not surprised it's redshifted , when every red value is only dropped to ~60%, while the other values are dropped much more.actually, red is scaled to 30% and green is 60% blue is like 11-12% Edited August 20, 2006 by Paulie
Paulie Posted August 20, 2006 Author Posted August 20, 2006 NICE thanks so much man that woks grreat here is my final code #include <Color.au3> Sleep(2000) For $y1 = 50 to 900 For $x1 = 50 to 200 $colorD = PixelGetColor($x1, $y1) $colorH = Hex($ColorD) $Red = _ColorGetRed("0x"&$colorH) $Green = _ColorGetGreen("0x"&$colorH) $Blue = _ColorGetBlue("0x"&$colorH) $gray = _GrayScale($red,$green,$blue) $color2 = "0x" & Hex($gray,2) & Hex($gray,2) & Hex($gray,2) SetPixel($x1,$y1,$color2) Next Next Func SetPixel ($h_x, $h_y, $h_color) $dc= DllCall ("user32.dll", "int", "GetDC", "hwnd", "") $setpixel= DllCall ("gdi32.dll", "long", "SetPixel", "long", $dc[0], "long", $h_x, "long", $h_y, "long", $h_color) $realesedc= DllCall ("user32.dll", "int", "ReleaseDC", "hwnd", 0, "int", $dc[0]) EndFunc func _GrayScale($r,$g,$B) Return Int($r * .299 + $g *.587 + $b *.114) EndFunc How did you get that?
Excalibur Posted August 20, 2006 Posted August 20, 2006 Does anyone know a way to make something like this go any faster? I have tinkered alot with altering pixels and things on the screen for cool effects, but they go to fraking slow... I would imagine you'd have to deal with some higher level advanced buffering and drawing images off screen and such poosibly? Ooo Ëxçã¿îbúr ooO"Information Is Not Knowledge." ~Albert Einstein
Paulie Posted August 20, 2006 Author Posted August 20, 2006 (edited) Does anyone know a way to make something like this go any faster? I have tinkered alot with altering pixels and things on the screen for cool effects, but they go to freaking slow... I would imagine you'd have to deal with some higher level advanced buffering and drawing images off screen and such possibly?I agree, it does go REALLY slow, but how can you optimize it? Its fast on a small area, so maybe if we divide the desktop into areas of like 25x25 pixels, and had it set it in goups of 25, like this: #include <Color.au3> Sleep(2000) For $y1 = 0 to @DesktopHeight step 25 For $x1 = 0 to @DesktopWidth step 25 For $SquareX = $x1 to $x1 + 25 For $SquareY = $y1 to $y1 + 25 $colorD = PixelGetColor($SquareX, $SquareY) $colorH = Hex($ColorD) $Red = _ColorGetRed("0x"&$colorH) $Green = _ColorGetGreen("0x"&$colorH) $Blue = _ColorGetBlue("0x"&$colorH) $gray = _GrayScale($red,$green,$blue) $color2 = "0x" & Hex($gray,2) & Hex($gray,2) & Hex($gray,2) SetPixel($SquareX,$SquareY,$color2) Next Next Next Next Func SetPixel ($h_x, $h_y, $h_color) $dc= DllCall ("user32.dll", "int", "GetDC", "hwnd", "") $setpixel= DllCall ("gdi32.dll", "long", "SetPixel", "long", $dc[0], "long", $h_x, "long", $h_y, "long", $h_color) $realesedc= DllCall ("user32.dll", "int", "ReleaseDC", "hwnd", 0, "int", $dc[0]) EndFunc func _GrayScale($r,$g,$B) Return Int($r * .299 + $g *.587 + $b *.114) EndFunc Edited August 20, 2006 by Paulie
flyingboz Posted August 20, 2006 Posted August 20, 2006 NICEthanks so much man that woks grreatYou're welcome (assuming that you weren't referring to chinese cookware) it's slower than molasses running uphill in FebruaryIf you want to do the whole desktop, I'd recommend integrating a command line windows converter that has the grayscale function implemented..no need to reinvent the wheel.Of course, if you want to develop a UDF for handling windows, snapshots, or areas of the screen that aren't images that's blazingly fast and works well w/ au3, I'd love to see the result of your labor Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.
Paulie Posted August 20, 2006 Author Posted August 20, 2006 You're welcome (assuming that you weren't referring to chinese cookware) If you want to do the whole desktop, I'd recommend integrating a command line windows converter that has the grayscale function implemented..no need to reinvent the wheel.Of course, if you want to develop a UDF for handling windows, snapshots, or areas of the screen that aren't images that's blazingly fast and works well w/ au3, I'd love to see the result of your labor No... i was talking about your code and another problem with this is the fact that the "setpixel" function doesn't work on something that is constantly refreshingi wait 15 minutes for it to turn my screen gray scale only to have it go away when i scroll up or switch active windows
buzz44 Posted August 21, 2006 Posted August 21, 2006 Why do you want to do the whole desktop? Do you want to do what Windows does when you click "Log Off" and the screen fades to greyscale? If so, I think you might be able to take a screenshot of the screen, apply it to be on top and then fade it to greyscale.How fast can you do the screen in C++/#? qq
flyingboz Posted August 21, 2006 Posted August 21, 2006 I assumed the goal was to gray out the wallpaper , hence the earlier suggestion to make a grayscale copy of the image using a dedicated converter...Many, many tools do this, irfanview, imagemagick, etc,etc,etc. For comparison, a 10MB bitmap image on my 3GHz Xeon converts using irfanview in less than a second. Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now