|
Post by Enzo on Dec 15, 2023 15:55:35 GMT
I'm trying to create an editor of pixel art, by taking all pixels value (RBG 255 255 255) and change them through an entire image as well as an entire image set of approx. 1750 images...
To a color set of preprogrammed palettes to the "nearest" color match.
Maybe a console main window type, editing only the values of the .bmp image.
Or
would I go with a graphical window to change these and recapture the image?
FLushing every pixel of loop?
|
|
|
Post by Rod on Dec 15, 2023 16:57:36 GMT
You need to open the file and manipulate the file contents. Drawing on screen would be very slow. Even manipulating the file will take time.
|
|
|
Post by tsh73 on Dec 15, 2023 17:49:21 GMT
I wonder if John (tenochtitlanuk) has recipie of using ImageMagic for that (convert bunch of images for fixed palette) Because it looks like the tool for the job, and it would be much faster. I remember old PaintShopPro had that option (for single file of course) EDIT
here's example I googled, looks working for me C:\progs\ImageMagick-6.9.0-Q16\convert.exe Yrose_32bit.bmp +dither -remap pal.bmp out.bmp that means C:\progs\ImageMagick-6.9.0-Q16\convert.exe source_file.bmp +dither -remap fle_with_limitedcolors.bmp out_file.bmp Left one is source pic, small square is palette used (total color in the palette image was 9) Right one is result (Gimp says resulting file uses 7 colors) Underneath is Gimp-produced palette. (Image Magic selected not to use bright red and bright yellow, so two colors less)
|
|
|
Post by Rod on Dec 15, 2023 19:28:24 GMT
I use Paint Shop Pro all the time and yes it does have pallette matching. I have not found the technique that useful and it easily destroys image quality.
Given we nearly always operate at 24bit color these days I wonder what the need is.
|
|
|
Post by Rod on Dec 16, 2023 13:16:46 GMT
I was working on code that reads bmp files and allows color change. This simply reduces the red color in the image. You could equally do gray scale or in your case segment to a restricted palette. Pick a smallish image because it takes a little while.
You would need to add code to analyse your directories and automatically run through all .bmp files. I have only tested this on 24bit images. If the images have variable color depth more code would be required. Tsh73 has posted such code in the past.
It just lets you see the possibilities. Imagemagic would be much faster. Still wondering why you need to reduce the colors.
WindowWidth = 700 WindowHeight = 400 UpperLeftX = (DisplayWidth-WindowWidth)/2 UpperLeftY = (DisplayHeight-WindowHeight)/2 graphicbox #1.gb1,10,10,300,300 graphicbox #1.gb2,330,10,300,300 open "SET GET Pixel" for graphics_nf_nsb as #1 #1 "trapclose [quit]" global bmpw,bmph,padding,offset,bytes,Blue,Green,Red
[loadbmp] filedialog "Choose an image","*.bmp",file$ if file$<>"" then 'display the original bmp in gb1 loadbmp "original",file$ #1.gb1 "down ; drawbmp original 0 0"
bmpsave "original","test.bmp" unloadbmp "original"
'now open the same bmp file for binary read/write access open "test.bmp" for binary as #bmp
'analyse the file header bytes seek #bmp,10 'picture data offset, where the color data starts 4 bytes of data offset=asc(input$(#bmp,1))+asc(input$(#bmp,1))*256+asc(input$(#bmp,1))*65536+asc(input$(#bmp,1))*16777216 seek #bmp,18 'width 4 bytes of data bmpw=asc(input$(#bmp,1))+asc(input$(#bmp,1))*256+asc(input$(#bmp,1))*65536+asc(input$(#bmp,1))*16777216 seek #bmp,22 'height 4 bytes of data bmph=asc(input$(#bmp,1))+asc(input$(#bmp,1))*256+asc(input$(#bmp,1))*65536+asc(input$(#bmp,1))*16777216 seek #bmp,28 'bits per pixel, ie color depth 2 bytes of data bits=asc(input$(#bmp,1))+asc(input$(#bmp,1))*256
'work out start of picture data and how to move through file pointer=offset
'work out how many bytes in the bits per pixel 24=3 bgr 32=4 abgr bytes=bits/8
'work out padding each raster line must be a 4byte multiple mult=bits/8*bmpw/4 padding = 4*(1-(mult-int(mult))) mod 4 close #bmp end if
[setall] 'this demo updates every pixel of the image open "test.bmp" for binary as #bmp for y=1 to bmph-1 for x=1 to bmpw-1 nul=getpixel(x,y) 'pixel colors are now contained in Red Green Blue globals
'change the color, here we just reduce the red element Red=Red-150 if Red<0 then Red=0 'you would need code to constrain the colors to the 'available palette.
'set amended pixel color in the file nul=setpixel(x,y) next next
'note we need to close the file to have Windows 'write the last update close #bmp
'show what we did, load file as bmp and display loadbmp "newfile","test.bmp" #1.gb2 "down ; drawbmp newfile 0 0" wait
[quit] close #1 end
function setpixel(x,y) 'raster lines are stored bottom up so we invert y y=(bmph-1)-y pointer=offset+x*bytes+y*(bmpw*bytes+padding) 'set pixel color seek #bmp, pointer #bmp chr$(Blue);chr$(Green);chr$(Red); end function
function getpixel(x,y) 'raster lines are stored bottom up so we invert y y=(bmph-1)-y pointer=offset+x*bytes+y*(bmpw*bytes+padding) 'get pixel color stored as BGR Liberty needs RGB seek #bmp, pointer Blue=asc(input$(#bmp,1)) Green=asc(input$(#bmp,1)) Red=asc(input$(#bmp,1)) end function
|
|
|
Post by Enzo on Dec 16, 2023 16:06:02 GMT
Not reducing, just trying to keep the same around 9-10 colors "types" that I've used to a different 9 types, most images contain less then 5 colors each if that, but the code will need to be universal to these types.
These images are mostly 100x100 less of pixels colored; some have more, I wanted to make something that will also output a sprite useable for JB and as well as the outputted recolor, and the option to make, black colored pixels, ("the outline") in a near color the the next colored pixel, plus or minus* a pixel or few to give a nearest tint. (*Left to right only)
|
|
|
Post by Enzo on Dec 16, 2023 16:09:31 GMT
I could give that a try never used image magic before, your saying JB could enable the command line usage of that command and run from a loop all my files?
I'll have to check that out.
I'm also going to look at Rods code and see where the differences are for getting the black pixel recolored.
You're also saying that the pal.bmp enables a nearness of the RBG scale to output?
|
|
|
Post by tsh73 on Dec 16, 2023 19:38:48 GMT
Yes Just enumerate all your files and call ImageMagic (here, convert.exe) on them. Start on small part, make sure to make a backup just in case ;) You've seen the picture It converted source picture to new one, using only colors happening in pal.bmp Now, one have to try and see I pretty sure it could take full-color 100x pixels picture and produce something recognisable. I have no idea how it matches the colors though that should be in the helpfile (and it is. Look for "dither" and "remap" imagemagick.org/script/command-line-options.phpso "+dither" select "closest color" mode instead of dithering (approximating by several dots of different colors) ) But will it be good if source picture is small? If it has limited set of colors itself? One have to try and decide.
|
|
|
Post by Enzo on Dec 19, 2023 13:22:56 GMT
One problem I see is the outline to each item, maybe creating something like rod was saying is the way to go for removing the the outline and replacing with
|
|
|
Post by cundo on Dec 20, 2023 23:28:04 GMT
I used to use IrfanView to do batch resize of my sprites
|
|
|
Post by Enzo on Dec 26, 2023 21:32:00 GMT
After looking at Rods code the other day, that's nearly there with commented parts included for re-color, I'll have to play around with, some color palettes. To answer your question why limited numbers, this is because the art set originally has only a few colors just trying to use a set palette of the same amount for linearity reasons. (i.e, easier to produce a finished product)
|
|