Attempting to make an image format

Title^. So far I have a general progress made, as I have the ability to do the following (during runtime/app execution):
read/write a pixel in the struct based upon the block_size (word_size)
read/write a pixel in the struct based upon the order (row major vs column major)
read/write a pixel based upon the width and height of the image

successfully open a file write out the following fields to a file(get some output):
name
order
block_size
width
height

The way I've written out the fields are in logical order, although the name
field is probrably unecessary, but can be used during runtime or identification.

1
2
3
4
5
6
7
8
9
struct ExampleImage{
    char*              ex_name;
    unsigned long long ex_order;
    unsigned long long ex_block_size;
    unsigned long long ex_width;
    unsigned long long ex_height;
//bytes written to file will be implicit...
    void*              ex_data;
};


My Secondary problems are:

How do I integrate a file header (with a magic number and version)?
I want to be able to have different algorithms for each major version
of the image format. I also want the minor version of the format to be
tied to the update (minor bug fix/enhancement).
1
2
3
4
5
6
7
8
9
struct ExampleVersion{
  union{    
  unsigned int version;
   struct{
       unsigned short ver_maj;
       unsigned short ver_min;
  }
 }u_ver;
}


Am I on a good track with the above structures? I don't put my header up here because right now it isn't necessary as I am having problems writing the image i generate up.

My Primary Problems:
Should I be writing the bytes of the image in binary form, instead of text? Each individual pixel is distinct during runtime, but when I write each pixel in a format they all appear the same. (Basically it definitely isn't my image generation algorithm, its has something to do with file IO).


Should I be writing entire image file in binary mode instead? I cannot write my image reader algorithm until I finish this up.


EDIT 1: I fixed the problem where my image data was not reading in correctly XD. The image
file now looks like a binary file (when i use monochrome generation), even though it is opened in text mode.

EDIT 2: Now that I fixed the problem where it wouldn't output bytes properly. I still have the issue of formatting.
Is it a good idea to use the " " character as a delimiter for bytes so that I can check to see
if the image file data is corrupt? Or is this an unecessary thing to do?

EDIT 3: THANKS very much in advance for anyone who can answer any of my questions.
Last edited on
help please?
anyone?
I'd say just save everything in binary format.
lol.
Finally the algorithms are complete. But I cannot still decide on how to make the image format scale using a header. I read somewhere that you can have multiple images in a jpg or png or bmp. I'm guessing they write the header first them append with the images. My algorithm doesn't have a header write now, its pretty much a raw data file. It would be cool if I could attach an image to the forum.
Last edited on
Have you considered looking at how other image formats do it?

Try these for starters. Most graphics file structures don't get any more complicated than this.
http://en.wikipedia.org/wiki/BMP_file_format
http://en.wikipedia.org/wiki/Truevision_TGA
http://en.wikipedia.org/wiki/Graphics_Interchange_Format
Add fields to the header that contain offsets to the various sections in the file, rather than put everything in a strict order.
As for your question of "Is it a good idea to use the " " character as a delimiter for bytes so that I can check to see
if the image file data is corrupt?", I can only recommend you to have a look at t stackoverflow.com where you can find many source codes on the imaging issue.

http://stackoverflow.com/questions/10038653/reading-a-file-in-java-by-a-delimeter
http://www.rasteredge.com/how-to/vb-net-imaging/
http://www.rasteredge.com/how-to/vb-net-imaging/sdk-programming/
Topic archived. No new replies allowed.