buffer_getpixel for Game Maker Studio

Posted by Misu on May 9, 2017, 1:09 p.m.

Are you a game maker user?

Need a faster surface_getpixel?

You come to the right place!​

This asset comes with a small list of scripts that will help you get a pixel color super fast and its totally free.​

How to use each command:

buffer_getpixel_begin(surface) = creates the buffer for checking using a specified surface id

(or surface drawing) and returns you a buffer index.

(NOTE: application_surface only picks the regular Draw events;

not the GUI events.)

If your surface image is static, you can set it to create event,

otherwise, set it in the event that you will get the pixel.

buffer_getpixel(ind,x,y,width,height) = Gets the RGB of a pixel within the specified buffer id (surface).

buffer_getpixel_ext(ind,x,y,width,height) = Gets the RGBA of a pixel within the specified buffer id.

buffer_getpixel_r(ind x,y,width,height) = Gets the Red value of a pixel

buffer_getpixel_g(ind x,y,width,height) = Gets the Green value of a pixel

buffer_getpixel_b(ind x,y,width,height) = Gets the Blue value of a pixel

buffer_getpixel_a(ind x,y,width,height) = Gets the Alpha value of a pixel

//////////////////////////////////////////////////////////////////////////////

The file comes with the scripts and a demonstration of how it works (for dynamic images);

In case your image does not need to update the drawing at all, here's an example on how it works for static images (performance is more noticeable from this):

Code:

//CREATE EVENT
var ss = surface_create(800,450);
surface_set_target(ss);
draw_clear(0)
draw_sprite(spr_0,0,x,y)
surface_reset_target()

WIDE = surface_get_width(ss);
HIGH = surface_get_height(ss);

buff = buffer_getpixel_begin(ss);
/////////////////////////////////////////////////////////////////////////////
//DRAW EVENT (or any other event)
var pixel = buffer_getpixel(buff,16,16,WIDE,HIGH);

draw_text(64,8,string(pixel));
/////////////////////////////////////////////////////////////////////////////
//GAME END EVENT
buffer_getpixel_end(buff)

LINK:

https://marketplace.yoyogames.com/assets/5344/buffer_getpixel

Try it out if you like and give feedback.

Any problems, doubts, questions, do reply back if you like!

Comments

Requiem 7 years, 8 months ago

surface_getpixel is notoriously slow, so it's great to see a functional replacement!

twisterghost 7 years, 8 months ago

That's really awesome. Thanks for sharing this, I'll have to bookmark it and in case I have a use case.

twisterghost 7 years, 8 months ago

Do you have any benchmarking between this and the native equivalent?

Mairu 7 years, 8 months ago

Any chance you'll upload it to somewhere other than the marketplace?

Misu 7 years, 8 months ago

Thanks for all the feedbacks, everyone! :)

Mairu, is it because you dont have an account in the marketplace? If thats the case I would consider giving a mirror link. Although making an account on that site is really easy and simple thing to do. Dont see why you wont consider trying. Anyway here are the two mirror links.

(GMS1): https://www.dropbox.com/s/f05sshi6rzae7l1/buffer_getpix.gmz?dl=0

(GMS2): https://www.dropbox.com/s/zdymfm931p16pc3/buffer_getpix.yyz?dl=0

Mairu 7 years, 8 months ago

I am interested in it, but I don't need it right now. I find it easier to manage files on my computer than my marketplace library so the less I add to it the better. Thank you for the alternative links!