// LERC 1 compression static CPLErr CompressLERC(buf_mgr &dst, buf_mgr &src, const ILImage &img, double precision) { CntZImage zImg; // Fill data into zImg #define FILL(T) CntZImgFill(zImg, (T *)(src.buffer), img) switch (img.dt) { case GDT_Byte: FILL(GByte); break; case GDT_UInt16: FILL(GUInt16); break; case GDT_Int16: FILL(GInt16); break; case GDT_Int32: FILL(GInt32); break; case GDT_UInt32: FILL(GUInt32); break; case GDT_Float32: FILL(float); break; case GDT_Float64: FILL(double); break; default: break; } #undef FILL Byte *ptr = (Byte *)dst.buffer; // if it can't compress in output buffer it will crash if (!zImg.write(&ptr, precision)) { CPLError(CE_Failure,CPLE_AppDefined,"MRF: Error during LERC compression"); return CE_Failure; } // write changes the value of the pointer, we can find the size by testing how far it moved dst.size = ptr - (Byte *)dst.buffer; CPLDebug("MRF_LERC","LERC Compressed to %d\n", (int)dst.size); return CE_None; }