Take the 2-minute tour ×

I am trying to get an ROI (Region of Interest) from a PGF image file using the libpgf libraries ( http://www.libpgf.org ), and then use that as a texture in opengl. I am able to get a full sized image just fine, but when I try to extract an ROI, I ends up being distorted in some way.

Also I am loading the full sized image and then replacing a portion of the image with the ROI in the right stop because this will be used later to view a video of some sort that contains frames of PGF files that plays on the inside of a cube for a 360 movie, I just have create the wrapper yet.

Is there some way for me to fix this problem?

Code of where I am getting the bitmap for the image either as an ROI or full sized image:

UINT8 * pgfreader::getImage(UINT32 height /*= 0*/, UINT32 width /*= 0*/){
 if(height == 0) height = m_height;
 if(width == 0) width = m_width;
 //pitch = 3*width;
 pitch = ((width * (int)bpp) + 7) / 8; //I have a feeling that it is 
                                       //a problem with my pitch calculation
 //if(buff) delete[] buff;

 UINT8 *buff = new UINT8[height*(pitch)];
 try {

 int map[] = {2,1,0};
 pgf.GetBitmap(pitch, (UINT8 *)buff, 24,map);
 } catch( IOException& e) {
  std::cerr << "FAILED\n";
  return 0;
 } catch( const char * &s){
  std::cerr << "FAILED--ERROR--: " << s <<std::endl;
 return buff; 

Here is where I am trying to extract the ROI:

  std::cout<<"------RE-READING FILE\n";
  int level = 0;

  std::cout<<"------RE-GETTING IMAGE\n";

  UINT8* buff = reader.getImage(150,150);
  std::cout<<"------RE-GOT IMAGE\n";
  glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  glTexSubImage2D(GL_TEXTURE_2D, 0 , 0, 150, 150 , 150 , GL_RGB, GL_UNSIGNED_BYTE, buff);
  delete[] buff;buff=0;

And here is where I am extracting the full image:

glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
PGF::pgfreader reader;
const char * string = "./cube_map1.pgf";
std::cout<<"------OPENING FILE: " << string <<"\n";
std::cout<<"------READING FILE\n";
int level = 0;

std::cout<<"------GETTING IMAGE\n";

UINT8* buff = reader.getImage();
std::cout<<"------GOT IMAGE\n";
if(buff == 0) {std::cout<<"FAILURE at buffer\n"; return; }
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,reader.Width(level), reader.Height(level), 0,GL_RGB,GL_UNSIGNED_BYTE,buff);
std::cout<<"------DONE GETTING IMAGE\n";
delete[] buff;buff=0;

EDIT: Original Image size is 600x450. EDIT2: URL to image before on left after on the right: http://tinypic.com/r/dy17xv/6 EDIT3: The problem was in the PGF image library, thanks for every bodies help.

share|improve this question
"I ends up being distorted in some way" Please Elaborate? A before/after picture would be helpful. –  Tim May 24 '12 at 17:46
The post has been edited for a before and after image of the ROI I am trying to get –  btaidm May 24 '12 at 18:37
I don't know anything about libpgf, but maybe it has the same quirk as Windows bitmaps - replace the +7 in your pitch calculation with +31. –  Mark Ransom May 24 '12 at 18:43
That made it worse... –  btaidm May 24 '12 at 18:53
add comment


Your Answer



Browse other questions tagged or ask your own question.