int writeimage(char * name, int xres, int yres, unsigned char *imgdata, 
               int format) {
  if (imgdata == NULL) 
    return IMAGENULLDATA;

  switch (format) {
    case RT_FORMAT_PPM:
      return writeppm(name, xres, yres, imgdata);
    
    case RT_FORMAT_SGIRGB:
      return writergb(name, xres, yres, imgdata);

    case RT_FORMAT_JPEG:
      return writejpeg(name, xres, yres, imgdata);

    case RT_FORMAT_PNG:
      return writepng(name, xres, yres, imgdata);

    case RT_FORMAT_WINBMP:
      return writebmp(name, xres, yres, imgdata);

    case RT_FORMAT_TARGA:
    default:
      return writetga(name, xres, yres, imgdata);       
  } 
}
Example #2
0
static PyObject *py_JpegObject_write(py_JpegObject *self, PyObject *args) {
  char *filename;
  if (!PyArg_ParseTuple(args, "s", &filename)) {
    return NULL;
  }
  FILE *file = fopen(filename, "wb");
  if (file == NULL) {
    PyErr_SetString(PyExc_ValueError, "Could not open file for writing");
    return NULL;
  }
  if (0 != writejpeg(file, &self->stuff)) {
    PyErr_SetString(PyExc_IOError, "Could not write jpeg");
    return NULL;
  }
  if (0 != fclose(file)) {
    PyErr_SetFromErrno(PyExc_IOError);
    return NULL;
  }
  Py_RETURN_NONE;
}