예제 #1
0
int imFileFormatRAS::WriteImageData(void* data)
{
  imCounterTotal(this->counter, this->height, "Writing RAS...");

  imbyte* compressed_buffer = NULL;
  if (this->comp_type == RAS_BYTE_ENCODED)  // point to the extra buffer
    compressed_buffer = (imbyte*)this->line_buffer + this->line_buffer_size+2;

  for (int row = 0; row < this->height; row++)
  {
    imFileLineBufferWrite(this, data, row, 0);

    if (this->bpp > 8)
      FixRGB();

    if (this->comp_type == RAS_BYTE_ENCODED)
    {
      int compressed_size = iRASEncodeScanLine(compressed_buffer, (imbyte*)this->line_buffer, this->line_raw_size);
      imBinFileWrite(handle, compressed_buffer, compressed_size, 1);
    }
    else
    {
      imBinFileWrite(handle, this->line_buffer, this->line_raw_size, 1);
    }

    if (imBinFileError(handle))
      return IM_ERR_ACCESS;     

    if (!imCounterInc(this->counter))
      return IM_ERR_COUNTER;
  }

  return IM_ERR_NONE;
}
예제 #2
0
int imFileFormatLED::WriteImageData(void* data)
{
  imCounterTotal(this->counter, this->height, "Writing LED...");

  for (int row = 0; row < this->height; row++)
  {
    imFileLineBufferWrite(this, data, row, 0);

    for (int col = 0; col < this->width; col++)
    {
      if (!imBinFilePrintf(handle, ",%d", (int)((imbyte*)this->line_buffer)[col]))
        return IM_ERR_ACCESS;
    }
  
    imBinFileWrite(handle, (void*)"\n", 1, 1);
    if (imBinFileError(handle))
      return IM_ERR_ACCESS;     

    if (!imCounterInc(this->counter))
      return IM_ERR_COUNTER;
  }

  imBinFileWrite(handle, (void*)")", 1, 1);
  if (imBinFileError(handle))
    return IM_ERR_ACCESS;     

  return IM_ERR_NONE;
}
예제 #3
0
int imFileFormatSGI::WriteImageData(void* data)
{
  int count = imFileLineBufferCount(this);

  imCounterTotal(this->counter, count, "Writing SGI...");

  imbyte* compressed_buffer = NULL;
  if (this->comp_type == SGI_RLE)  // point to the extra buffer
    compressed_buffer = (imbyte*)this->line_buffer + this->line_buffer_size;

  int row = 0, plane = 0;
  for (int i = 0; i < count; i++)
  {
    imFileLineBufferWrite(this, data, row, plane);

    if (this->comp_type == SGI_VERBATIM)
      imBinFileWrite(handle, this->line_buffer, this->line_buffer_size/this->bpc, this->bpc);
    else
    {
      int length;
      if (this->bpc == 1)
        length = iSGIEncodeScanLine(compressed_buffer, (imbyte*)this->line_buffer, this->width);
      else
        length = iSGIEncodeScanLine((imushort*)compressed_buffer, (imushort*)this->line_buffer, this->width);

      int row_index = row + plane*this->height;
      this->starttab[row_index] = imBinFileTell(handle);
      this->lengthtab[row_index] = length*this->bpc;

      imBinFileWrite(handle, compressed_buffer, length, this->bpc);
    }

    if (imBinFileError(handle))
      return IM_ERR_ACCESS;     

    if (!imCounterInc(this->counter))
      return IM_ERR_COUNTER;

    imFileLineBufferInc(this, &row, &plane);
  }

  if (this->comp_type == SGI_RLE)
  {
    imBinFileSeekTo(this->handle, 512);
    int tablen = this->height * imColorModeDepth(this->file_color_mode);
    imBinFileWrite(handle, this->starttab, tablen, 4);
    imBinFileWrite(handle, this->lengthtab, tablen, 4);
  }

  return IM_ERR_NONE;
}
예제 #4
0
unsigned long imBinFilePrintf(imBinFile* bfile, char *format, ...)
{
    va_list arglist;
    va_start(arglist, format);
    char buffer[4096];
    int size = vsnprintf(buffer, 4096, format, arglist);
    return imBinFileWrite(bfile, buffer, size, 1);
}
예제 #5
0
int imFileFormatLED::WritePalette()
{
  int c;
  unsigned char r, g, b;

  imBinFileWrite(handle, (void*)"[\n", 2, 1);

  /* convert the color map from the IM format */
  for (c = 0; c < this->palette_count; c++)
  {
    imColorDecode(&r, &g, &b, this->palette[c]);
    imBinFilePrintf(handle, "%d = \"%d %d %d\"", c, (int)r, (int)g, (int)b);

    if (c != this->palette_count - 1)
      imBinFileWrite(handle, (void*)",\n", 2, 1);
  }

  imBinFileWrite(handle, (void*)"]\n", 2, 1);

  if (imBinFileError(handle))
    return IM_ERR_ACCESS;

  return IM_ERR_NONE;
}
예제 #6
0
int imFileFormatLED::New(const char* file_name)
{
  /* opens the binary file for writing */
  handle = imBinFileNew(file_name);
  if (!handle)
    return IM_ERR_OPEN;

  imBinFileWrite(handle, (void*)"LEDImage = IMAGE", 16, 1);

  /* tests if everything was ok */
  if (imBinFileError(handle))
  {
    imBinFileClose(handle);
    return IM_ERR_ACCESS;
  }

  return IM_ERR_NONE;
}
예제 #7
0
int imFileFormatRAS::WritePalette()
{
  int c;
  unsigned char ras_colors[256 * 3];

  /* convert the color map to the IM format */
  for (c = 0; c < this->palette_count; c++)
  {
    imColorDecode(&ras_colors[c], &ras_colors[c+this->palette_count], &ras_colors[c+2*this->palette_count], this->palette[c]);
  }

  /* writes the color palette */
  imBinFileWrite(handle, ras_colors, this->palette_count * 3, 1);

  if (imBinFileError(handle))
    return IM_ERR_ACCESS;

  return IM_ERR_NONE;
}
예제 #8
0
int imFileFormatPFM::WriteImageData(void* data)
{
  imCounterTotal(this->counter, this->height, "Writing PFM...");

  int line_raw_size = imImageLineSize(this->width, this->file_color_mode, this->file_data_type);

  for (int row = 0; row < this->height; row++)
  {
    imFileLineBufferWrite(this, data, row, 0);

    imBinFileWrite(handle, this->line_buffer, line_raw_size, 1);

    if (imBinFileError(handle))
      return IM_ERR_ACCESS;     

    if (!imCounterInc(this->counter))
      return IM_ERR_COUNTER;
  }

  return IM_ERR_NONE;
}
예제 #9
0
int imFileFormatSGI::WriteImageInfo()
{
  unsigned int dword_value;
  unsigned short word_value;
  unsigned char dummy[404];
  memset(dummy, 0, 404);

  this->comp_type = SGI_VERBATIM;
  if (imStrEqual(this->compression, "RLE"))
    this->comp_type = SGI_RLE;

  unsigned int color_map_id = SGI_NORMAL;

  this->file_color_mode = imColorModeSpace(this->user_color_mode);

  int dimension = 2;
  if (this->file_color_mode == IM_BINARY)
    this->convert_bpp = -1; // expand 1 to 255
  else if (this->file_color_mode == IM_RGB)
  {
    dimension = 3;
    if (imColorModeHasAlpha(this->user_color_mode))
      this->file_color_mode |= IM_ALPHA;
  }

  this->file_data_type = this->user_data_type;

  this->bpc = 1;
  int max = 255;
  if (this->file_data_type == IM_USHORT)
  {
    max = 65535;
    this->bpc = 2;
  }

  this->starttab = NULL;
  this->lengthtab = NULL;

  /* writes the SGI file header */
  word_value = SGI_ID;
  imBinFileWrite(handle, &word_value, 1, 2); /* identifier */
  imBinFileWrite(handle, &this->comp_type, 1, 1); /* storage */
  imBinFileWrite(handle, &this->bpc, 1, 1); /* bpc */
  word_value = (imushort)dimension;
  imBinFileWrite(handle, &word_value, 1, 2); /* dimension */
  word_value = (unsigned short)this->width;
  imBinFileWrite(handle, &word_value, 1, 2); /* image width */
  word_value = (unsigned short)this->height;
  imBinFileWrite(handle, &word_value, 1, 2); /* image height */
  word_value = (imushort)imColorModeDepth(this->file_color_mode);
  imBinFileWrite(handle, &word_value, 1, 2); /* depth */
  dword_value = 0;
  imBinFileWrite(handle, &dword_value, 1, 4); /* min */
  dword_value = max;
  imBinFileWrite(handle, &dword_value, 1, 4); /* max */
  imBinFileWrite(handle, dummy, 4, 1); /* dummy */

  /* tests if everything was ok */
  if (imBinFileError(handle))
    return IM_ERR_ACCESS;

  int size;
  char* image_name = (char*)AttribTable()->Get("Description", NULL, &size);
  if (image_name)
  {
    if (size < 80)
    {
      imBinFileWrite(handle, image_name, size, 1); 
      imBinFileWrite(handle, dummy, 80-size, 1); 
    }
    else
    {
      imBinFileWrite(handle, image_name, 79, 1); 
      imBinFileWrite(handle, (void*)"\0", 1, 1); 
    }
  }
  else
    imBinFileWrite(handle, dummy, 80, 1); /* empty image name */

  dword_value = color_map_id;
  imBinFileWrite(handle, &dword_value, 1, 4); /* color_map_id */
  imBinFileWrite(handle, dummy, 404, 1); /* dummy */

  /* tests if everything was ok */
  if (imBinFileError(handle))
    return IM_ERR_ACCESS;

  if (this->comp_type == SGI_RLE)
  {
    int tablen = this->height * imColorModeDepth(this->file_color_mode);
    this->starttab = (unsigned int *)malloc(tablen*4);
    this->lengthtab = (unsigned int *)malloc(tablen*4);

    /* writes the empty compression control information */
    /* we will write again at the end */
    imBinFileWrite(handle, this->starttab, tablen*4, 1);
    imBinFileWrite(handle, this->lengthtab, tablen*4, 1);

    // allocates more than enough since compression algoritm can be ineficient
    this->line_buffer_extra = 2*imImageLineSize(this->width, this->file_color_mode, this->file_data_type);
  }

  /* tests if everything was ok */
  if (imBinFileError(handle))
    return IM_ERR_ACCESS;

  return IM_ERR_NONE;
}
예제 #10
0
int imFileFormatRAW::WriteImageData(void* data)
{
  int count = imFileLineBufferCount(this);
  int line_count = imImageLineCount(this->width, this->file_color_mode);
  int type_size = iFileDataTypeSize(this->file_data_type, this->switch_type);

  // treat complex as 2 real
  if (this->file_data_type == IM_CFLOAT) 
  {
    type_size /= 2;
    line_count *= 2;
  }

  int ascii;
  if (imStrEqual(this->compression, "ASCII"))
    ascii = 1;
  else
    ascii = 0;

  imCounterTotal(this->counter, count, "Writing RAW...");

  int row = 0, plane = 0;
  for (int i = 0; i < count; i++)
  {
    imFileLineBufferWrite(this, data, row, plane);

    if (ascii)
    {
      for (int col = 0; col < line_count; col++)
      {
        if (this->file_data_type == IM_FLOAT)
        {
          float value = ((float*)this->line_buffer)[col];

          if (!imBinFilePrintf(handle, "%f ", (double)value))
            return IM_ERR_ACCESS;
        }
        else
        {
          int value;
          if (this->file_data_type == IM_INT)
            value = ((int*)this->line_buffer)[col];
          else if (this->file_data_type == IM_SHORT)
            value = ((short*)this->line_buffer)[col];
          else if (this->file_data_type == IM_USHORT)
            value = ((imushort*)this->line_buffer)[col];
          else
            value = ((imbyte*)this->line_buffer)[col];

          if (!imBinFilePrintf(handle, "%d ", value))
            return IM_ERR_ACCESS;
        }
      }

      imBinFileWrite(handle, (void*)"\n", 1, 1);
    }
    else
    {
      imBinFileWrite(this->handle, (imbyte*)this->line_buffer, line_count, type_size);
    }

    if (imBinFileError(this->handle))
      return IM_ERR_ACCESS;

    if (!imCounterInc(this->counter))
      return IM_ERR_COUNTER;

    imFileLineBufferInc(this, &row, &plane);

    if (this->padding)
      imBinFileSeekOffset(this->handle, this->padding);
  }

  this->image_count++;
  return IM_ERR_NONE;
}
예제 #11
0
int imFileFormatRAS::WriteImageInfo()
{
  this->file_data_type = IM_BYTE;
  this->file_color_mode = imColorModeSpace(this->user_color_mode);

  if (imStrEqual(this->compression, "RLE"))
    this->comp_type = RAS_BYTE_ENCODED;
  else
    this->comp_type = RAS_STANDARD;

  // Force the palette, even for Binary and Gray.
  this->map_type = RAS_EQUAL_RGB;

  if (this->file_color_mode == IM_BINARY)
  {
    this->bpp = 1;
    this->convert_bpp = 1;
  }
  else if (this->file_color_mode == IM_RGB)
  {
    this->file_color_mode |= IM_PACKED;
    this->map_type = RAS_NONE;
    this->bpp = 24;

    if (imColorModeHasAlpha(this->user_color_mode))
    {
      this->file_color_mode |= IM_ALPHA;
      this->bpp = 32;
    }
  }
  else
    this->bpp = 8;

  this->file_color_mode |= IM_TOPDOWN;

  this->line_raw_size = imFileLineSizeAligned(this->width, this->bpp, 2);
  this->line_buffer_extra = 2; // room enough for padding

  if (this->comp_type == RAS_BYTE_ENCODED)
  {
    // allocates more than enough since compression algoritm can be ineficient
    this->line_buffer_extra += 2*this->line_raw_size;
  }

  /* writes the RAS file header */

  unsigned int dword_value = RAS_ID;
  imBinFileWrite(handle, &dword_value, 1, 4); /* identifier */
  dword_value = this->width;
  imBinFileWrite(handle, &dword_value, 1, 4); /* image width */
  dword_value = this->height;
  imBinFileWrite(handle, &dword_value, 1, 4); /* image height */
  dword_value = this->bpp;
  imBinFileWrite(handle, &dword_value, 1, 4); /* bits per pixel */
  dword_value = this->height * this->line_raw_size;
  imBinFileWrite(handle, &dword_value, 1, 4); /* image lenght */
  dword_value = this->comp_type;
  imBinFileWrite(handle, &dword_value, 1, 4); /* compression information */
  dword_value = this->map_type;
  imBinFileWrite(handle, &dword_value, 1, 4); /* palette information */
  dword_value = (this->map_type == RAS_NONE)? 0: this->palette_count * 3;
  imBinFileWrite(handle, &dword_value, 1, 4); /* palette lenght */

  /* tests if everything was ok */
  if (imBinFileError(handle))
    return IM_ERR_ACCESS;

  if (this->map_type != RAS_NONE)
    return WritePalette();

  return IM_ERR_NONE;
}
예제 #12
0
static int file_write(jas_stream_obj_t *obj, char *buf, int cnt)
{
  imBinFile* file_bin = (imBinFile*)obj;
  return imBinFileWrite(file_bin, buf, cnt, 1);
}