示例#1
0
GLImageStructure readImage(const std::string& FileName, ImageType type_hint)
{
  if (type_hint==itUnknown)
  {
    type_hint = getImageType(FileName);
  }
  switch (type_hint)
  {
    case itJPEG:
         return readJPEG(FileName);
    case itPNG:
         return readPNG(FileName);
    case itGIF:
         return readGIF(FileName);
    case itBitmap:
         return readBMP(FileName);
    case itPPM:
         return readPPM(FileName);
  }

  //no supported image here
  GLImageStructure temp_glis;
  temp_glis.setWidth(0);
  temp_glis.setHeight(0);
  temp_glis.setFormat(0);
  temp_glis.setBuffer(NULL);
  return temp_glis;
}
示例#2
0
SbBool ReadGIFImage(const SoInput& in, int &w, int &h, int &nc,  
						unsigned char *&bytes) {

    int ncolors;
    int bgIndex;
    int errCode;
    XColor *colors = (XColor*) malloc(GIF_MAXCOLORMAPSIZE * sizeof(XColor));
    FILE *fp = in.getCurFile();
    fseek(fp, 0, SEEK_SET);
    
    if (fp == NULL) return FALSE;
    
    unsigned char *array = readGIF(fp, 
			    &w, &h, colors, &ncolors, &bgIndex, &errCode);
    if (errCode != GIF_NO_ERROR) { 
	free(colors);
	return FALSE;
    }
    
    nc = 3;
    
    // convert color map image to rgb
    // gif files go top down and we need bottom up.  Switch it.
    bytes = new unsigned char[w*h*nc];
    
    int i, j;
    
    for (j = 0; j < h; ++j)
	for (i = 0; i < w; ++i) {
	    int c = array[j*w+i];
	    int index = ((h-j-1)*w+i)*nc;
	    
	    if (c < 0 || c >= ncolors)
		// store black if out of range
		bytes[index] = bytes[index+1] = bytes[index+2] = 0;
	    else { 
		bytes[index] = colors[c].red / 256;
		bytes[index+1] = colors[c].green / 256;
		bytes[index+2] = colors[c].blue / 256;
	    }
	}
	
    free(colors);
    free(array);
    
    return TRUE;
}