bool checkImageFileSize(const FileName &name, const ImageInfo &imgInfo, bool error) { FileName ext = name.getExtension(); FileName dataFname; if ( ext.contains("hed")) dataFname = name.removeLastExtension().addExtension("img"); else if (ext.contains("inf")) dataFname = name.removeLastExtension(); else if (ext.contains("tif") || ext.contains("jpg") || ext.contains("hdf") || ext.contains("h5")) return true; else dataFname = name; size_t expectedSize = imgInfo.adim.nzyxdim*gettypesize(imgInfo.datatype) + imgInfo.offset; size_t actualSize = dataFname.removeAllPrefixes().removeFileFormat().getFileSize(); bool result = (actualSize >= expectedSize); if (error && !result) REPORT_ERROR(ERR_IO_SIZE, formatString("Image Extension: File %s has wrong size.\n" "Expected size (at least) %u bytes. Actual size %u bytes.", name.c_str(), expectedSize, actualSize)); return result; }
void processImage(const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut) { ImageGeneric img; switch (operation) { case HEADER_PRINT: img.read(fnImg, _HEADER_ALL); img.print(); break; case HEADER_EXTRACT: img.read(fnImg, _HEADER_ALL); rowOut = img.getGeometry(); if (round_shifts) roundShifts(rowOut); rowOut.setValue(MDL_IMAGE, fnImgOut); break; case HEADER_ASSIGN: rowOut = rowIn; if (round_shifts) roundShifts(rowOut); img.readApplyGeo(fnImg, rowOut, params); img.setDataMode(_HEADER_ALL); img.write(fnImg, ALL_IMAGES, fnImg.isInStack(), WRITE_REPLACE); break; case HEADER_RESET: img.read(fnImg, _HEADER_ALL); img.initGeometry(); img.write(fnImg, ALL_IMAGES, fnImg.isInStack(), WRITE_REPLACE); break; case HEADER_SAMPLINGRATE: { img.read(fnImg, _HEADER_ALL); if (sampling < 0) { double samplingRead; img.image->MDMainHeader.getValue(MDL_SAMPLINGRATE_X, samplingRead); std::cout << samplingRead << std::endl; } else { img.image->MDMainHeader.setValue(MDL_SAMPLINGRATE_X, sampling); img.image->MDMainHeader.setValue(MDL_SAMPLINGRATE_Y, sampling); img.image->MDMainHeader.setValue(MDL_SAMPLINGRATE_Z, sampling); img.write(fnImg, ALL_IMAGES, fnImg.isInStack(), WRITE_REPLACE); std::cout << "New sampling rate (Angstrom) = " << sampling << std::endl; } } break; case HEADER_TREE: { XmippH5File H5File; FileName filename = fnImg.removeAllPrefixes().removeFileFormat(); if (H5File.isHdf5(filename.c_str())) { H5File.openFile(fnImg.removeAllPrefixes().removeFileFormat(), H5F_ACC_RDONLY); H5File.showTree(); } else REPORT_ERROR(ERR_IMG_UNKNOWN, "Unknown file format to display its data structure."); } break; } }