int imFileFormatPFM::WriteImageInfo() { this->file_data_type = this->user_data_type; this->file_color_mode = imColorModeSpace(this->user_color_mode); if (this->file_color_mode == IM_GRAY) this->image_type = 'f'; else { this->image_type = 'F'; this->file_color_mode |= IM_PACKED; } imBinFilePrintf(handle, "P%c\n", (int)this->image_type); if (imBinFileError(handle)) return IM_ERR_ACCESS; imBinFilePrintf(handle, "%d ", this->width); imBinFilePrintf(handle, "%d\n", this->height); if (imBinCPUByteOrder() == IM_BIGENDIAN) imBinFilePrintf(handle, "1.0\n"); else imBinFilePrintf(handle, "-1.0\n"); /* tests if everything was ok */ if (imBinFileError(handle)) return IM_ERR_ACCESS; return IM_ERR_NONE; }
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; }
int imFileFormatLED::WriteImageInfo() { this->file_data_type = IM_BYTE; this->file_color_mode = imColorModeSpace(this->user_color_mode); this->file_color_mode |= IM_TOPDOWN; if (WritePalette() != IM_ERR_NONE) return IM_ERR_ACCESS; imBinFilePrintf(handle, "(%d, %d\n", this->width, this->height); return IM_ERR_NONE; }
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; }
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; }