Is there a function to get the color pallet of a sprite?

W

Wraithious

Guest
Hi, so I looked in the manual but didn't see anything on extracting color pallets,
what I'm trying to do is if the user loads a pencil art drawing (or single color pen), I'm going to use a hue altering based shader to turn the sprite into color, I figure if I can get the grayscale color pallet I can select ranges and assign them rgb values and feed them into the shader to convert the sprite to color without having to use draw_getpixel for every pixel in the sprite to get the sprite's pallet, or is that what I'm going to have to do?
 

jo-thijs

Member
You really shouldn't use draw_getpixel for this.
You can draw the sprite to a surface and then use surface_getpixel_ext instead, which should be way faster.
 
W

Wraithious

Guest
You really shouldn't use draw_getpixel for this.
You can draw the sprite to a surface and then use surface_getpixel_ext instead, which should be way faster.
Ok thanks that makes more sense, I will try that out!
 
W

Wraithious

Guest
IUf you could get the player to do all their drawings as GIFs or PNGs, then it's really easy to get the palette - just read the data from the file itself.
yes, I'm going to set it up to only allow .png's to be loaded, but how can I read the pallet data from the file?

that would be the perfect way, I would then split the range from darkest to lightest, divide that into 3 groups, then let the player decide which color (red, green or blue) should represent each group, and say they chose blue for the lightest group, I'd add then set blue to 255, add green and red and set their values to what their pallet value is with the shader, that's the ultimate plan anyway
 
This can also be done with buffers if I remember correctly. I'm pretty sure converting a surface to a buffer, then reading the raw data is faster then 'surface_getpixel_ext'
 
W

Wraithious

Guest
This can also be done with buffers if I remember correctly. I'm pretty sure converting a surface to a buffer, then reading the raw data is faster then 'surface_getpixel_ext'
So I like the idea of trying to use a buffer, I'm guessing use a buffer_save_async? and then use an asyncronus load/save event to retrieve it via a ds map, but can i save a LARGE array in a buffer? a 200 x 200 image holding array would look like this: colsmake[0...40,000], and tht's really not a very large image, I was aiming for a max alowable size to be 1024x768, or maybe 640 x 480

with the code I have now, with just using a for loop, it takes 4 seconds (4 core amd apu style processors, not the best but not the worst) to convert a 50 x 50 image, and 58 seconds to convert a 200 x 200 image which of course pauses the game the entire time, I tried making a loading bar to show the progress so the player doesnt think the game broke and can go eat a doughnut while waiting lol, but since the game freezes until the script is done it doesnt work.
So is it possible to put this in a buffer? and how should I go about doing it?


Create event
Code:
if(global.graytocol1=1 && instance_exists(base_picture))//base picture
{j=base_picture.bbox_right-base_picture.bbox_left;//gets width
k=base_picture.bbox_bottom-base_picture.bbox_top;//gets height
drwatx=base_picture.bbox_left//;gets x position on screen
m=base_picture.bbox_left;
drwaty=base_picture.bbox_top;//gets y position on screen
n=base_picture.bbox_top;
l=(j*k);//gets total number of pixels
depth=base_picture.depth-10;
}
for(i=0;i<l;i+=1){colsmake[i]=0;}// sets aray index to hold all pixels
Choose the scheme sets variable global.palrgb with the arrow buttons
there are 6 choices of converting light medium and dark areas of the image
to different colors:
Clipboard02.png

My script is basically what i need to store in the buffer, but how?:
for(i=0;i<l;i+=1; )
{colspicked=draw_getpixel(m,n);//gets every pixels color
colsr=colspicked & 255;colsg=(colspicked >> 8)& 255;colsb=(colspicked >> 16)& 255;p=colsr+colsg+colsb;//seperates to rgb
if p<=255 cbit=1;if p>255 && p<=510 cbit=2;if p>510 cbit=3;//1=dark,2=medium,3=light
if(global.palrgb=1)//deligates the new colors
{if cbit=1 colsmake=make_colour_rgb(255,colsg,colsb);
if cbit=2 colsmake=make_colour_rgb(colsr,255,colsb);
if cbit=3 colsmake=make_colour_rgb(colsr,colsg,255);}
if(global.palrgb=2)
{if cbit=1 colsmake=make_colour_rgb(255,colsg,colsb);
if cbit=2 colsmake=make_colour_rgb(colsr,colsg,255);
if cbit=3 colsmake=make_colour_rgb(colsr,255,colsb);}
if(global.palrgb=3)
{if cbit=1 colsmake=make_colour_rgb(colsr,255,colsb);
if cbit=2 colsmake=make_colour_rgb(255,colsg,colsb);
if cbit=3 colsmake=make_colour_rgb(colsr,colsg,255);}
if(global.palrgb=4)
{if cbit=1 colsmake=make_colour_rgb(colsr,255,colsb);
if cbit=2 colsmake=make_colour_rgb(colsr,colsg,255);
if cbit=3 colsmake=make_colour_rgb(255,colsg,colsb);}
if(global.palrgb=5)
{if cbit=1 colsmake=make_colour_rgb(colsr,colsg,255);
if cbit=2 colsmake=make_colour_rgb(colsr,255,colsb);
if cbit=3 colsmake=make_colour_rgb(255,colsg,colsb);}
if(global.palrgb=6)
{if cbit=1 colsmake=make_colour_rgb(colsr,colsg,255);
if cbit=2 colsmake=make_colour_rgb(255,colsg,colsb);
if cbit=3 colsmake=make_colour_rgb(colsr,255,colsb);}
if m<drwatx+j && n<=drwaty+k m+=1;if(m=drwatx+j){m=drwatx;if n<drwaty+k n+=1;}
if(i>=l-1){m=drwatx;n=drwaty;colorize=1;}}//activates the draw event when finished

Draw event:
Code:
if(colorize=1 && global.effect=8)
{for(o=0;o<l;o+=1;)
{draw_point_colour(m,n,colsmake[o]);
if m<drwatx+j && n<=drwaty+k m+=1;
if(m=drwatx+j){m=drwatx;if n<drwaty+k n+=1;
if n=drwaty+k n=drwaty;}}
}
 
Last edited by a moderator:
Top