We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have a small .bmp file that weighs 1296 bytes. When I do this string, it saves it as a .bmp files that weighs 558 bytes:
loadImage(dataPath("test.bmp")).save(dataPath("test2.bmp"));
I assume this is because it saves it with a different bit depth. What can I do to make it save with bit depth of the original image? I need it to have same everything as the original file for technical reasons. Here's my test file: https://www.dropbox.com/s/1b08oe0j3w8kc78/test.bmp
And here's what I get: https://www.dropbox.com/s/kqjulvbhai9t0qm/test2.bmp
edit: I'm not looking for just copying the image, which obviously can be done by copying the file over. I want to be able to edit them with functions like .get() and .set() and then save the result in the same format and with same characteristics as the input file.
edit2: Also I'm not looking for any size or efficiency advantages at all - an old videogame I'm working with just refuses to work with test2.bmp, while it can take test.bmp perfectly. And, from a bit of testing with different files I've concluded that the difference between input and output file that Processing introduces is what causes it.
Answers
Check javaDocs for File. I believe there is a
copy()
function for files. as an alternative, you can open the file as a binary stream and save it as such.Kf
Actually, sorry for not clarifying, I want to be able to open it up, and use functions like .get() and .set() to edit the picture and save the edited result in exactly the same format and with same characteristics as the input file.
Maybe there's a way to use .get() function on a PImage object and then use saveBytes() to save it? Since it's .bmp I think it shouldn't be too hard...
(identify is part of imagemagick)
test.bmp is 256 colours, test2.bmp isn't. but both are 8 bits deep. so the first image contains a 256-colour palette, most of which it doesn't use.
with a bigger image, using 256 colours will be more efficient, but these things are tiny so you don't get the benefits.
As I said, I need the result file to be the same as the input file for technical reasons. I don't care about size or efficiency here at all. Those technical reasons being that I'm trying to create a tool for mod developers of a game called "Cortex Command", which is pretty old, and it just refuses to work well with images that Processing outputs.
So far this exact difference between input and output files seems to be the problem of this.
It is possible to write something that writes the data out as a 256 colour bitmap, same as the input, but you'd need to do everything yourself.
http://www.dragonwins.com/domains/getteched/bmp/bmpfileformat.htm
Allright then. Not the way to solve the problem I wanted to use, but still, thanks for the link!
When you use a graphic program like irfanview , gimp or photoshop you might be able to load any processing generated image and save it with exact the properties you need (256 colors etc.)
I know I can re-save it using other software, but that would be something I want my Processing sketch to do on itself alone. I'm thinking about automating the process, and re-saving every result image by hand using some other program would take a lot of time.
Also, currently working with the saveBytes idea. Never dug into binary and byte stuff deep enough, so that's a good practice.
This code from PImage in saveImageIO might be related to your issue?:
https://github.com/processing/processing/blob/e83ae2054a3d3c52b1663385673fdfb26abcc96b/core/src/processing/core/PImage.java#L3221
Just a guess based on searching the source code for "bmp", but perhaps your source BMPs have an alpha channel, and which is getting stripped out by Processing -- hence the reduced file size and the compatibility problems.
No, it's the palette. Run xxd on the file and you can see it after the two headers. I'm not sure it's used but it's there.
Actually, you've got me wondering whether that's right now given that I did it in a rush at lunchtime...
there's definitely a palette in there (you can see it in gimp)
Yes, it's most definitely the palette. I figured that out too when working on custom code to make it work. Apparently the game uses its own palette for every image file it uses. I ended up just copying the first 1078 bytes(54 for header, 1024 for palette) from one of the sprites and pasting that at the beginning of every file my code outputs, with needed changes like file size and width/height of the image.
I managed to accomplish my goal with saveBytes() already, just saying. I don't think that I should mark any replies as answers since that would confuse people with the same question. (forgive my possible dorkiness, not an often forum dweller .-.)
Coming back to my irfanView approach: irfanView has a batch Mode which means you can apply an operation to a bunch of images at once
Glad you worked out a solution!
Is this something simple enough that you could share it as a few lines of example code, in case someone else does have a similar problem?
It's quite a long set of code, actually, but I'll still paste it in, because someone might need it later. It also requires an additional "palette" file, so I'll link that too:
https://www.dropbox.com/s/r3u1gb8cm234qc4/palette?dl=0
is this right? the first 10 values for this is
which seems wrong (specifically the value for 1, which i guess is rare)
is shorter and returns
I don't know if its wrong or not, since I was bruteforcing that part heavily to find the right values for every possible image width, and then lazily came up with a formula that follows the sequence of numbers I found to work. Images with width of 1 were an exception to that sequence, so I had to put the width==1? part for that.
The reasons for the complicated formula is because at first I excluded the "width+" at the start and brute forced the rest, which is why I was confused. And now, seeing that it's this simple kind of a pattern, I feel embarrassed. LOL
Also I just realized that instead of making header byte by byte, I could also copy it from the palette, then simply change file size and width/height values. That palette file I included even has the same header. Mess of a coder I am! :D
There also is a new forum
What forum? Where? When? Why? o_o
I don’t know 4 weeks or so
https://discourse.processing.org/
It’s also the Forum link of processing main web page
Oh. Thanks, good to know.
Well, the idea that this exact message will end up as permanently archived very soon is at least fun...
I think they wait till here is no activity anymore and then archive it / set it passive