Example #1
0
  /**
   * Write the device independent image array stored in the specified loader to the specified output
   * stream using the specified file format.
   */
  public static void save(OutputStream os, int format, ImageLoader loader) {
    if (format < 0 || format >= FORMATS.length) SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT);
    if (FORMATS[format] == null) SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT);
    if (loader.data == null || loader.data.length < 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);

    LEDataOutputStream stream = new LEDataOutputStream(os);
    FileFormat fileFormat = null;
    try {
      Class clazz = Class.forName(FORMAT_PACKAGE + '.' + FORMATS[format] + FORMAT_SUFFIX);
      fileFormat = (FileFormat) clazz.newInstance();
    } catch (Exception e) {
      SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT);
    }
    if (format == SWT.IMAGE_BMP_RLE) {
      switch (loader.data[0].depth) {
        case 8:
          fileFormat.compression = 1;
          break;
        case 4:
          fileFormat.compression = 2;
          break;
      }
    }
    fileFormat.unloadIntoStream(loader, stream);
  }
Example #2
0
 static FileFormat getFileFormat(LEDataInputStream stream, String format) throws Exception {
   Class clazz = Class.forName(FORMAT_PACKAGE + '.' + format + FORMAT_SUFFIX);
   FileFormat fileFormat = (FileFormat) clazz.newInstance();
   if (fileFormat.isFileFormat(stream)) return fileFormat;
   return null;
 }