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 imFileFormatJPEG::ReadImageData(void* data) { if (setjmp(this->jerr.setjmp_buffer)) return IM_ERR_ACCESS; imCounterTotal(this->counter, this->dinfo.output_height, "Reading JPEG..."); int row = 0, plane = 0; while (this->dinfo.output_scanline < this->dinfo.output_height) { if (jpeg_read_scanlines(&this->dinfo, (JSAMPARRAY)&this->line_buffer, 1) == 0) return IM_ERR_ACCESS; if (this->fix_adobe_cmyk) iFixAdobeCMYK((unsigned char*)this->line_buffer, this->width); imFileLineBufferRead(this, data, row, plane); if (!imCounterInc(this->counter)) { jpeg_finish_decompress(&this->dinfo); return IM_ERR_COUNTER; } imFileLineBufferInc(this, &row, &plane); } jpeg_finish_decompress(&this->dinfo); return IM_ERR_NONE; }
int imFileFormatJPEG::WriteImageData(void* data) { if (setjmp(this->jerr.setjmp_buffer)) return IM_ERR_ACCESS; imCounterTotal(this->counter, this->dinfo.output_height, "Writing JPEG..."); int row = 0, plane = 0; while (this->cinfo.next_scanline < this->cinfo.image_height) { imFileLineBufferWrite(this, data, row, plane); if (jpeg_write_scanlines(&this->cinfo, (JSAMPARRAY)&this->line_buffer, 1) == 0) return IM_ERR_ACCESS; if (!imCounterInc(this->counter)) { jpeg_finish_compress(&this->cinfo); return IM_ERR_COUNTER; } imFileLineBufferInc(this, &row, &plane); } jpeg_finish_compress(&this->cinfo); return IM_ERR_NONE; }
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; }
int imFileFormatRAS::ReadImageData(void* data) { imCounterTotal(this->counter, this->height, "Reading RAS..."); for (int row = 0; row < this->height; row++) { /* read and decompress the data */ if (this->comp_type != RAS_BYTE_ENCODED) { imBinFileRead(handle, this->line_buffer, this->line_raw_size, 1); if (imBinFileError(handle)) return IM_ERR_ACCESS; } else { if (iRASDecodeScanLine(handle, (imbyte*)this->line_buffer, this->line_raw_size) == IM_ERR_ACCESS) return IM_ERR_ACCESS; } if (this->bpp > 8) FixRGB(); imFileLineBufferRead(this, data, row, 0); if (!imCounterInc(this->counter)) return IM_ERR_COUNTER; } return IM_ERR_NONE; }
static int Swirl(int width, int height, DT *src_map, DT *dst_map, float k, int counter, DTU Dummy, int order) { float xl, yl; float xc = float(width/2.); float yc = float(height/2.); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { swirl_invtransf(x, y, &xl, &yl, k, xc, yc); // if inside the original image broad area if (xl > 0.0 && yl > 0.0 && xl < width && yl < height) { if (order == 1) *dst_map = imBilinearInterpolation(width, height, src_map, xl, yl); else if (order == 3) *dst_map = imBicubicInterpolation(width, height, src_map, xl, yl, Dummy); else *dst_map = imZeroOrderInterpolation(width, height, src_map, xl, yl); } dst_map++; } if (!imCounterInc(counter)) return 0; } return 1; }
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; }
static int houghLine(const imImage* input, imImage* output, int counter) { int ixsize, iysize, ixhalf, iyhalf, thetamax, x, y, rho, theta, rhomax; imbyte *input_map = (imbyte*)input->data[0]; int *output_map = (int*)output->data[0]; ixsize = input->width; iysize = input->height; ixhalf = ixsize/2; iyhalf = iysize/2; thetamax = output->width; /* theta max = 180 */ rhomax = output->height/2; /* rho shift to 0, -rmax <= r <= +rmax */ costab = (double*)malloc(thetamax*sizeof(double)); sintab = (double*)malloc(thetamax*sizeof(double)); for (theta=0; theta < thetamax; theta++) { double th = (M_PI*theta)/thetamax; costab[theta] = cos(th); sintab[theta] = sin(th); } for (y=0; y < iysize; y++) { for (x=0; x < ixsize; x++) { if (input_map[y*ixsize + x]) { for (theta=0; theta < thetamax; theta++) { rho = imRound((x-ixhalf)*costab[theta] + (y-iyhalf)*sintab[theta]); if (rho > rhomax) continue; if (rho < -rhomax) continue; output_map[(rho+rhomax)*thetamax + theta]++; } } } if (!imCounterInc(counter)) { free(costab); costab = NULL; free(sintab); sintab = NULL; return 0; } } free(costab); costab = NULL; free(sintab); sintab = NULL; return 1; }
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; }
static int Rotate(int src_width, int src_height, DT *src_map, int dst_width, int dst_height, DT *dst_map, double cos0, double sin0, int ref_x, int ref_y, int to_origin, int counter, DTU Dummy, int order) { float xl, yl; float sx = float(ref_x); float sy = float(ref_y); float dx = sx; float dy = sy; if (to_origin) { dx = 0; dy = 0; } for (int y = 0; y < dst_height; y++) { for (int x = 0; x < dst_width; x++) { rotate_invtransf(x, y, &xl, &yl, cos0, sin0, dx, dy, sx, sy); // if inside the original image broad area if (xl > 0.0 && yl > 0.0 && xl < src_width && yl < src_height) { if (order == 1) *dst_map = imBilinearInterpolation(src_width, src_height, src_map, xl, yl); else if (order == 3) *dst_map = imBicubicInterpolation(src_width, src_height, src_map, xl, yl, Dummy); else *dst_map = imZeroOrderInterpolation(src_width, src_height, src_map, xl, yl); } dst_map++; } if (!imCounterInc(counter)) return 0; } return 1; }
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 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; }
int imFileFormatLED::ReadImageData(void* data) { int value; imCounterTotal(this->counter, this->height, "Reading LED..."); for (int row = 0; row < this->height; row++) { for (int col = 0; col < this->width; col++) { if (!imBinFileReadInteger(handle, &value)) return IM_ERR_ACCESS; ((imbyte*)this->line_buffer)[col] = (unsigned char)value; } imFileLineBufferRead(this, data, row, 0); if (!imCounterInc(this->counter)) return IM_ERR_COUNTER; } return IM_ERR_NONE; }
static int RotateCenter(int src_width, int src_height, DT *src_map, int dst_width, int dst_height, DT *dst_map, double cos0, double sin0, int counter, DTU Dummy, int order) { float xl, yl; float dcx = float(dst_width/2.); float dcy = float(dst_height/2.); float scx = float(src_width/2.); float scy = float(src_height/2.); for (int y = 0; y < dst_height; y++) { for (int x = 0; x < dst_width; x++) { rotate_invtransf(x, y, &xl, &yl, cos0, sin0, dcx, dcy, scx, scy); // if inside the original image broad area if (xl > 0.0 && yl > 0.0 && xl < src_width && yl < src_height) { if (order == 1) *dst_map = imBilinearInterpolation(src_width, src_height, src_map, xl, yl); else if (order == 3) *dst_map = imBicubicInterpolation(src_width, src_height, src_map, xl, yl, Dummy); else *dst_map = imZeroOrderInterpolation(src_width, src_height, src_map, xl, yl); } dst_map++; } if (!imCounterInc(counter)) return 0; } return 1; }
int imFileFormatECW::ReadImageData(void* data) { imAttribTable* attrib_table = AttribTable(); int i, *attrib_data, view_width, view_height, nBands = imColorModeDepth(this->file_color_mode); // this size is free, can be anything, but we restricted to less than the image size attrib_data = (int*)attrib_table->Get("ViewWidth"); view_width = attrib_data? *attrib_data: this->width; if (view_width > this->width) view_width = this->width; attrib_data = (int*)attrib_table->Get("ViewHeight"); view_height = attrib_data? *attrib_data: this->height; if (view_height > this->height) view_height = this->height; imCounterTotal(this->counter, view_height, "Reading ECW..."); { int xmin, xmax, ymin, ymax, band_start; // full image if not defined. // this size must be inside the image attrib_data = (int*)attrib_table->Get("ViewXmin"); xmin = attrib_data? *attrib_data: 0; if (xmin < 0) xmin = 0; attrib_data = (int*)attrib_table->Get("ViewYmin"); ymin = attrib_data? *attrib_data: 0; if (ymin < 0) ymin = 0; attrib_data = (int*)attrib_table->Get("ViewXmax"); xmax = attrib_data? *attrib_data: this->width-1; if (xmax > this->width-1) xmax = this->width-1; attrib_data = (int*)attrib_table->Get("ViewYmax"); ymax = attrib_data? *attrib_data: this->height-1; if (ymax > this->height-1) ymax = this->height-1; band_start = 0; UINT16* start_plane = (UINT16*)attrib_table->Get("MultiBandSelect"); if (start_plane) band_start = *start_plane; UINT32 *pBandList = (UINT32*)malloc(sizeof(UINT32)*nBands); for(i = 0; i < nBands; i++) pBandList[i] = i+band_start; NCSError eError = NCScbmSetFileView(this->pNCSFileView, nBands, pBandList, xmin, ymin, xmax, ymax, view_width, view_height); free(pBandList); if( eError != NCS_SUCCESS) return IM_ERR_DATA; } // this is necessary to fool line buffer management this->width = view_width; this->height = view_height; this->line_buffer_size = imImageLineSize(this->width, this->file_color_mode, this->file_data_type); NCSEcwCellType eType = NCSCT_UINT8; int type_size = 1; if (this->file_data_type == IM_SHORT) { eType = NCSCT_INT16; type_size = 2; } else if (this->file_data_type == IM_USHORT) { eType = NCSCT_UINT16; type_size = 2; } else if (this->file_data_type == IM_FLOAT) { eType = NCSCT_IEEE4; type_size = 4; } UINT8 **ppOutputLine = (UINT8**)malloc(sizeof(UINT8*)*nBands); UINT8 *ppOutputBuffer = (UINT8*)malloc(type_size*view_width*nBands); for(i = 0; i < nBands; i++) ppOutputLine[i] = ppOutputBuffer + i*type_size*view_width; for (int row = 0; row < view_height; row++) { NCSEcwReadStatus eError = NCScbmReadViewLineBILEx(this->pNCSFileView, eType, (void**)ppOutputLine); if( eError != NCS_SUCCESS) { free(ppOutputLine); free(ppOutputBuffer); return IM_ERR_DATA; } iCopyDataBuffer(ppOutputLine, (imbyte*)this->line_buffer, nBands, view_width, type_size); imFileLineBufferRead(this, data, row, 0); if (!imCounterInc(this->counter)) { free(ppOutputLine); free(ppOutputBuffer); return IM_ERR_COUNTER; } } free(ppOutputLine); free(ppOutputBuffer); 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; }
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; }