|
Post by David Drake on Feb 18, 2020 11:58:02 GMT -5
I created the code below for the Rosetta Code task: Grayscale image ( rosettacode.org/wiki/Grayscale_image). The task description is described in detail at the top of the page. Note that I hard-coded the bitmap image (MLcolor.bmp) rather than implementing a file dialog solution. I welcome feedback and comments. nomainwin WindowWidth = 400 WindowHeight = 400 open "Bitmap" for graphics_nf_nsb as #1 h=hwnd(#1) calldll #user32, "GetDC", h as ulong, DC as ulong #1 "trapclose [q]" loadbmp "clr","MLcolor.bmp" #1 "drawbmp clr 1 1;flush" for x = 1 to 150 for y = 1 to 200 calldll #gdi32, "GetPixel", DC as ulong, x as long, y as long, PX as ulong B = int(PX/(256*256)) G = int((PX-B*256*256) / 256) R = int(PX-B*256*256-G*256) L = 0.2126*R+0.7152*G+0.0722*B #1 "down;color ";L;" ";L;" ";L;";set ";x;" ";y next y next x wait
[q] unloadbmp "clr":close #1:end
|
|
|
Post by David Drake on Feb 21, 2020 7:22:24 GMT -5
Before I post this to Rosetta Code, I welcome any comments or improvements from the community.
|
|
|
Post by Rod on Feb 21, 2020 8:05:16 GMT -5
Just needs a [q] end branch. Works well, getpixel is always slow. There have been graphic manipulation programs posted that grab the file and work directly on the color quad bytes. Much much faster but probably too quirky for RC. Your code is just fine for me.
|
|
|
Post by tsh73 on Feb 21, 2020 9:30:39 GMT -5
I wonder if it really implement what's asked in a task? and it links to rosettacode.org/wiki/Basic_bitmap_storageSo my guess that first, "Basic_bitmap_storage" should e implemented And likely reading RGB file is only way.
|
|
|
Post by David Drake on Feb 21, 2020 11:26:35 GMT -5
I wonder if it really implement what's asked in a task? and it links to rosettacode.org/wiki/Basic_bitmap_storageSo my guess that first, "Basic_bitmap_storage" should e implemented And likely reading RGB file is only way. I think other posts to the wiki did something similar to what I did. I guess I need to look into this further.
|
|
|
Post by David Drake on Feb 21, 2020 11:27:19 GMT -5
Just needs a [q] end branch. Works well, getpixel is always slow. There have been graphic manipulation programs posted that grab the file and work directly on the color quad bytes. Much much faster but probably too quirky for RC. Your code is just fine for me. Thanks. Based on my checking into the other posted comments, I'll see about fixing that.
|
|
|
Post by David Drake on Mar 2, 2020 7:08:28 GMT -5
Since there is a question about whether this implementation actually addresses the challenge, I'm going to set it aside. Perhaps someone else can step in and take a swing at it. Thanks for the feedback.
|
|