int imFileFormatJP2::WriteImageData(void* data) { int count = imFileLineBufferCount(this); imCounterTotal(this->counter, count, "Writing JP2..."); /* first time count */ int depth = imColorModeDepth(this->file_color_mode); if (imColorModeHasAlpha(this->user_color_mode) && imColorModeHasAlpha(this->file_color_mode)) { jas_image_setcmpttype(image, depth-1, JAS_IMAGE_CT_OPACITY); depth--; } for (int d = 0; d < depth; d++) jas_image_setcmpttype(image, d, JAS_IMAGE_CT_COLOR(d)); int row = 0, plane = 0; for (int i = 0; i < count; i++) { imFileLineBufferWrite(this, data, row, plane); int ret = 1; if (this->file_data_type == IM_BYTE) ret = iJP2WriteLine(image, row, plane, (imbyte*)this->line_buffer); else ret = iJP2WriteLine(image, row, plane, (imushort*)this->line_buffer); if (!ret) return IM_ERR_ACCESS; if (!imCounterInc(this->counter)) return IM_ERR_COUNTER; imFileLineBufferInc(this, &row, &plane); } char outopts[512] = ""; imAttribTable* attrib_table = AttribTable(); float* ratio = (float*)attrib_table->Get("CompressionRatio"); if (ratio) sprintf(outopts, "rate=%g", (double)(1.0 / *ratio)); // The counter continuous because in Jasper all image writing is done here. BAD! ijp2_counter = this->counter; ijp2_abort = 0; ijp2_message = NULL; /* other counts */ int err = jas_image_encode(image, stream, 0 /*JP2 format always */, outopts); ijp2_counter = -1; if (err) return IM_ERR_ACCESS; jas_stream_flush(stream); return IM_ERR_NONE; }
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; }
int imFileFormatSGI::ReadImageData(void* data) { int count = imFileLineBufferCount(this); imCounterTotal(this->counter, count, "Reading 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++) { if (this->comp_type == SGI_VERBATIM) { imBinFileRead(handle, this->line_buffer, this->line_buffer_size/this->bpc, this->bpc); if (imBinFileError(handle)) return IM_ERR_ACCESS; } else { int row_index = row + plane*this->height; imBinFileSeekTo(handle, this->starttab[row_index]); imBinFileRead(handle, compressed_buffer, this->lengthtab[row_index] / this->bpc, this->bpc); if (imBinFileError(handle)) return IM_ERR_ACCESS; if (this->bpc == 1) iSGIDecodeScanLine((imbyte*)this->line_buffer, compressed_buffer, this->width); else iSGIDecodeScanLine((imushort*)this->line_buffer, (imushort*)compressed_buffer, this->width); } imFileLineBufferRead(this, data, row, plane); if (!imCounterInc(this->counter)) return IM_ERR_COUNTER; imFileLineBufferInc(this, &row, &plane); } return IM_ERR_NONE; }
int imFileFormatJP2::ReadImageData(void* data) { int count = imFileLineBufferCount(this); imCounterTotal(this->counter, count, NULL); int alpha_plane = -1; if (imColorModeHasAlpha(this->user_color_mode) && imColorModeHasAlpha(this->file_color_mode)) alpha_plane = imColorModeDepth(this->file_color_mode) - 1; int row = 0, plane = 0; for (int i = 0; i < count; i++) { int cmpno; if (plane == alpha_plane) cmpno = jas_image_getcmptbytype(image, JAS_IMAGE_CT_OPACITY); else cmpno = jas_image_getcmptbytype(image, JAS_IMAGE_CT_COLOR(plane)); if (cmpno == -1) return IM_ERR_DATA; int ret = 1; if (this->file_data_type == IM_BYTE) ret = iJP2ReadLine(image, row, cmpno, (imbyte*)this->line_buffer); else ret = iJP2ReadLine(image, row, cmpno, (imushort*)this->line_buffer); if (!ret) return IM_ERR_ACCESS; imFileLineBufferRead(this, data, row, plane); if (!imCounterInc(this->counter)) return IM_ERR_COUNTER; imFileLineBufferInc(this, &row, &plane); } 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; }
int imFileFormatRAW::ReadImageData(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, "Reading RAW..."); int row = 0, plane = 0; for (int i = 0; i < count; i++) { if (ascii) { for (int col = 0; col < line_count; col++) { if (this->file_data_type == IM_FLOAT) { float value; if (!imBinFileReadFloat(handle, &value)) return IM_ERR_ACCESS; ((float*)this->line_buffer)[col] = value; } else { int value; if (!imBinFileReadInteger(handle, &value)) return IM_ERR_ACCESS; if (this->file_data_type == IM_INT) ((int*)this->line_buffer)[col] = value; else if (this->file_data_type == IM_SHORT) ((short*)this->line_buffer)[col] = (short)value; else if (this->file_data_type == IM_USHORT) ((imushort*)this->line_buffer)[col] = (imushort)value; else ((imbyte*)this->line_buffer)[col] = (unsigned char)value; } } } else { imBinFileRead(this->handle, (imbyte*)this->line_buffer, line_count, type_size); if (imBinFileError(this->handle)) return IM_ERR_ACCESS; } imFileLineBufferRead(this, data, row, plane); if (!imCounterInc(this->counter)) return IM_ERR_COUNTER; imFileLineBufferInc(this, &row, &plane); if (this->padding) imBinFileSeekOffset(this->handle, this->padding); } return IM_ERR_NONE; }