Ejemplo n.º 1
0
int
s_image_read_line(s_image * image,
                  int line,
                  unsigned char * buf)
{
  if (image->data) {
    int bpr = image->width*image->components;
    memcpy(buf, image->data + bpr*line, bpr);
    return 1;
  }
  else if (image->opendata && image->openfuncs.read_line_func) {
    int ret = image->openfuncs.read_line_func(image->opendata, line, buf);
    /* for some file formats, the line read order can be important when
       fetching data from the file. If read-line fails, fall back to
       reading the entire image */

    if (!ret && image->oktoreadall && image->openfilename) {
      /* close old image handle first */
      image->openfuncs.close_func(image->opendata);
      image->opendata = NULL;

      /* just load everything and call function again to read line */
      image->data = simage_read_image(image->openfilename,
                                      &image->width,
                                      &image->height,
                                      &image->components);

      if (image->data) {
        return s_image_read_line(image, line, buf);
      }
    }
    return ret;
  }
  return 0;
}
Ejemplo n.º 2
0
GLubyte*
glmReadSimage(const char* filename, GLboolean alpha, int* w, int* h, int* type)
{
    int numcomponents;
    GLubyte *buffer = simage_read_image(filename, w, h, &numcomponents);
    switch(numcomponents) {
    case 1:
	*type = GL_LUMINANCE;
	break;
    case 2:
	*type = GL_LUMINANCE_ALPHA;
	break;
    case 3:
	*type = GL_RGB;
	break;
    case 4:
	*type = GL_RGBA;
	break;
    }
    return buffer;
}