3

I want my 8x8 to come out as raw binary; it should be 8 bytes, or 64 bits. However, it is coming out much larger than that; saving as a PNG gave me 154 bytes; saving as a BMP gave me 64 bytes (8 times bigger than it should be.)

When I created a new image, Photoshop told me it would be 8 bytes, clearly this is not the case after saving.

The very, very lowest I could get it was 12 bytes, by using save for web and saving as wbmp, but I want it to be 8 bytes. It needs to be raw binary data. How can I solve this issue?

EDIT: And for that matter, other low bit amounts come out higher than expected. Why does a 4-bpp 80x16 image come out as 714 bytes instead of 640?

  • Well image formats save more than just raw image data – Cai Dec 17 '16 at 23:25
  • That's what I'm trying to achieve; raw image data. – Accumulator Dec 17 '16 at 23:36
  • Since Photoshop needs to save the file Header that tells programs what your file type is and how it needs to read it. I don't you can just save an image as raw since no program would be able to open it. May I ask for what you want the raw image data ? – SitiSchu Dec 18 '16 at 0:14
  • I'm making a game and trying to make it as small as physically possible; one way to do that is to store raw color indexes instead of "actual colors." which in this case is 1-bit, only 0 and 1. – Accumulator Dec 18 '16 at 1:11
  • Do you have the option "Save as Raw" in your save-as list? It pretty much does as it says. – usr2564301 Dec 18 '16 at 13:08
1

File formats contain a lot of stuff. While its true that your bitmap may be 8 bytes but the container its stored in is not.

For example a PNG file structure needs all kinds of additional data such as a fingerprint, file structure info, compression scheme, and metadata. Even tough much of this can be stripped, Photoshop is by no means optimal, the file will still be much larger than 8 bytes.

Real world analog would be a a bucket. While the bucket is pretty light say 300g its proportional weight is quite small if you fill the bucket with 10 liters of water (3%) or sand (2% lose gravel). However, the relative weight of the container is pretty significant if you want to transport a centiliter of water (3000%).

All containers have a overhead. For example the size of the array must be told somewhere and that alone eats up as such as your image data. On this note its also worth noting that due to the way drives work each file will use up a fixed amount of space say from 512 bytes to several kilobytes or so having ultra small separate files does not make sense.

So what to do?

  • Encode all your image data into a single image file, called an image atlas.
  • Write your image data into your source code. It will still be bigger than 8 bytes due to need of storing the array length. This may be impractical though.
  • Write your own format, but you still get to the container problem. Again best to put multiple datasources into one storage file.
  • 1
    re 2: not necessarily; C language arrays do not store array length anywhere. and by the way, you can automatically generate such C source code in Gimp - use the "XBM" file format: #define bitmap_width 8 #define bitmap_height 8 static unsigned char bitmap_bits[] = { 0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80, 0x00 }; – szulat Dec 18 '16 at 15:29
  • @szulat yes but the person who assembles the picture into a element array need to know what the height and width is to use that array in a meaningful way or and to avoid overflow. In any case it must be annotated somehow that it is a 8 by 8 picture. Even if its hard coded in the reader its still using up 2 bytes of data or maybe this can be encoded in one byte but still it uses some space somewhere. – joojaa Dec 18 '16 at 15:30
  • 2
    @szulat your XMB demo shows exactly what im saying it stores two values for width and height in the source for a total of 10 bytes of memory usage for a whopping 25% container overhead – joojaa Dec 18 '16 at 15:36
  • sure, but on the other hand, if using the same hardcoded algorithm to process a million of 8x8 bitmaps, you already saved 2x2x1000000-2x2 bytes :-] – szulat Dec 18 '16 at 15:36
  • #define uses exactly 0 bytes of compiled code – szulat Dec 18 '16 at 15:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.