Thread: reinterpret_cast<char *> --- Help Please

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    12

    reinterpret_cast<char *> --- Help Please

    I am trying to open a .ras image in GIMP that was created in my program. I am able to open the file and view it in Photoshop as a .raw file, but the teacher requires that the grader/teacher view the file in GIMP. (go figure)
    The error message I get is " Can't open file as SUN raster file"

    I'm not sure what is causing the error.

    Here is the code that saves the file. Any hints would be appreciated.

    Code:
     ofstream is2;
        is2.open("newimage.ras", ios:: out);     //the extra space was to eliminate :o
    
        struct rasterfile header;
        
        header.ras_height=Image::GetRow();
        header.ras_width=Image::GetCol();
            
        size = header.ras_width*header.ras_height;
        
        for(i=0; i<size;i++)
          {
    	img[i];
          }
        
        is2.write(reinterpret_cast<char *>(&header),sizeof(struct rasterfile));
        is2.write(colormap, 256*3);
        is2.write(img, size);
    
        cout << "Size: " << sizeof(size);        //prints out 4
        cout<< "header: " << sizeof(struct rasterfile);  //prints out 32
    
        is2.close();
    The "new image" is the same as the old when I open it in Photoshop, so I'm pretty sure its saving it. But I don't know how to force a format that GIMP can read.

    Any help would be greatly appreciated. Thanks in advance

    Sandy

  2. #2
    Registered User raimo's Avatar
    Join Date
    Jun 2002
    Posts
    107
    Have you set the magic number: 0x59a66a95 ?
    See http://www.dcs.ed.ac.uk/home/mxr/gfx/2d/RAS.txt

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    12
    yep, here's the rasterfile initialization:

    Code:
    hader.ras_magic=059a66a95;
    header.ras_width=COL;               //private member set by member
                                                          //function to equal 1116
    header.ras_height=ROW;            //private member set by member
                                                         //functin to equal 100
    header.ras_depth=8;header.ras_length=1;
    header.raw_length=1;
    header.ras_type=0;
    header.ras_maptype=0;
    header.ras_maplength=768;
    the initialization of the struct rasterfile worked in the C coded progam.

    Thanks again!

    Sandy

Popular pages Recent additions subscribe to a feed