Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
eof error while reading TGA file
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
coltson
n00b
n00b


Joined: 15 Oct 2005
Posts: 51

PostPosted: Thu Jan 03, 2013 2:34 am    Post subject: eof error while reading TGA file Reply with quote

Hi, I have an tga file that I try to read in memory to make some modifications and then save it modified.

When I try to read the data from the Tga file into a memory block it reaches the end of the file. Here is the code:
Code:
void TGAManager::readTgaData (char * memoryAdress, int imageSize) {
  fileReader.read (memoryAdress, imageSize );
}

The cause is that the calculated imageSize variable that I pass as second parameter to the read method is storing the wrong value. It should be of about 256KB as image visualization/edition software informs me, but it is calculating approximately 512KB.

Here is the code that calculates the image:

Code:
Image::Image (int width, int height, int bpp) {
    width = width;
    height = height;
    bitsPerPixel = bpp;
    bytesPerPixel = bpp >> 2;
    size = width*height*bytesPerPixel;
}


And here is the code where I extract the width, height and bits per pixel from the file:
Code:
bool TGAManager::extractImageFeatures() {
  width = header[1] * 256 + header[0];
  height = header[3] * 256 + header[2];
  bpp = header[4];
  cout << bpp << endl;
  if (width <= 0 || height <= 0  || (header[4] != 24 && header[4] != 32)) {
    cout << "The data about the file width, height or bpp is incorrect." << endl;
    return false;
  }
  return true;
}


The width and height are correct, so by elimination the problem has to be the bpp. I checked the tutorial I am following and it really is header[4] that I should kook for this information. I always get 32 when has to be 24 for the size of the file to be correct.

Any ideas about what is going on ?
Back to top
View user's profile Send private message
Hu
Watchman
Watchman


Joined: 06 Mar 2007
Posts: 9051

PostPosted: Fri Jan 04, 2013 2:54 am    Post subject: Reply with quote

A byte is 8 bits. The code shown for Image::Image sets bytesPerPixel to be bpp >> 2, which is also bpp / 4. Are you sure it is correct to divide by 4, rather than 8?
Back to top
View user's profile Send private message
coltson
n00b
n00b


Joined: 15 Oct 2005
Posts: 51

PostPosted: Sat Jan 05, 2013 12:05 am    Post subject: Reply with quote

Quote:
Are you sure it is correct to divide by 4, rather than 8?


No it is not, the problem it is me, that have air between my ears. Thanks for the help anyway.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum