pixel_to_vec or pixel_for_bmap bug?

Posted By: openfire2691

pixel_to_vec or pixel_for_bmap bug? - 09/15/08 00:59

I'm trying to write a script in C-Script that will return the amount of pixels of each color on the screen. For some reason, though, it isn't working. Here's my script:

Code:
 function calculate_colors()
{
	var temp_pixel;
	filehandle = file_open_write ("address.txt"); 
	var format;
	var h = 0;
	var w = 0;
	over_canvas.visible = off;
	wait(2);
	bmap_for_screen(tempy, 1, 0);
	wait(1);
	format = bmap_lock(tempy, 0);
	while(h < bmap_height(tempy))
	{
		while(w < bmap_width(tempy))
		{
			temp_pixel = pixel_to_vec(temp, NULL, format, pixel_for_bmap(tempy, w, h));
			colorpercents[6] += (temp_pixel.green == 75);
			colorpercents[(temp_pixel.red == 255) + ((temp_pixel.green == 255) * 2) + ((temp_pixel.blue == 255) * 4)] += 1;
//Order of colors in array colorpercents is: Other, Red, Green, Yellow, Blue, Purple, Orange, White
			w += 1;
			wait(1);
		}
		w = 0;
		h += 1;
		wait(1);
	}
	over_canvas.visible = on;
	file_var_write(filehandle, colorpercents[0]); //these next few commands write the results of the color scan into an outside document so I can analyze them
	file_var_write(filehandle, colorpercents[1]);
	file_var_write(filehandle, colorpercents[2]);
	file_var_write(filehandle, colorpercents[3]);
	file_var_write(filehandle, colorpercents[4]);
	file_var_write(filehandle, colorpercents[5]);
	file_var_write(filehandle, colorpercents[6]);
	file_var_write(filehandle, colorpercents[7]);
	file_var_write(filehandle, temp_pixel.red); //these three lines write the red, green, and blue values of the last pixel scanned into the same document
	file_var_write(filehandle, temp_pixel.green);
	file_var_write(filehandle, temp_pixel.blue);
	over_canvas.bmap = tempy;
	bmap_unlock(tempy);
	file_close(filehandle);
}


The problem is that the values in temp_pixel are always messed up. The red and green values are always 0, and the blue value changes. For example, it's 63.999 for white, 62 for red, 63.969 for yellow, .030 for blue, and 1.969 for green. Is there some reason for this? I've been going over this script for days and can't find anything wrong. Maybe a bug?
Posted By: openfire2691

Re: pixel_to_vec or pixel_for_bmap bug? - 09/15/08 01:29

Here's a developement. I was documenting the different values of temp_pixel.blue based on the different colors it was reading, and here were my results:

red = 62;
orange = 63.156;
yellow = 63.969;
green = 1.969;
blue = .030;
purple = 62.030;
white = 63.999;

The interesting thing about these findings is that red, green, and blue have their own set values, while the yellow, purple and white are all just the sum of the red, green, and blue values (ex. red = 62, green = 1.969, yellow = 62 + 1.969 = 63.969). Orange is a little different because I made it 255 red and only 75 green. I don't know what this means, but I thought it might be important.
© 2024 lite-C Forums