MCPcopy Create free account
hub / github.com/HiLab-git/SimpleCRF / filter

Function filter

dependency/densecrf/examples/lodepng.cpp:5203–5421  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5201}
5202
5203static unsigned filter(unsigned char* out, const unsigned char* in, unsigned w, unsigned h,
5204 const LodePNGColorMode* info, const LodePNGEncoderSettings* settings)
5205{
5206 /*
5207 For PNG filter method 0
5208 out must be a buffer with as size: h + (w * h * bpp + 7) / 8, because there are
5209 the scanlines with 1 extra byte per scanline
5210 */
5211
5212 unsigned bpp = lodepng_get_bpp(info);
5213 /*the width of a scanline in bytes, not including the filter type*/
5214 size_t linebytes = (w * bpp + 7) / 8;
5215 /*bytewidth is used for filtering, is 1 when bpp < 8, number of bytes per pixel otherwise*/
5216 size_t bytewidth = (bpp + 7) / 8;
5217 const unsigned char* prevline = 0;
5218 unsigned x, y;
5219 unsigned error = 0;
5220 LodePNGFilterStrategy strategy = settings->filter_strategy;
5221
5222 /*
5223 There is a heuristic called the minimum sum of absolute differences heuristic, suggested by the PNG standard:
5224 * If the image type is Palette, or the bit depth is smaller than 8, then do not filter the image (i.e.
5225 use fixed filtering, with the filter None).
5226 * (The other case) If the image type is Grayscale or RGB (with or without Alpha), and the bit depth is
5227 not smaller than 8, then use adaptive filtering heuristic as follows: independently for each row, apply
5228 all five filters and select the filter that produces the smallest sum of absolute values per row.
5229 This heuristic is used if filter strategy is LFS_MINSUM and filter_palette_zero is true.
5230
5231 If filter_palette_zero is true and filter_strategy is not LFS_MINSUM, the above heuristic is followed,
5232 but for "the other case", whatever strategy filter_strategy is set to instead of the minimum sum
5233 heuristic is used.
5234 */
5235 if(settings->filter_palette_zero &&
5236 (info->colortype == LCT_PALETTE || info->bitdepth < 8)) strategy = LFS_ZERO;
5237
5238 if(bpp == 0) return 31; /*error: invalid color type*/
5239
5240 if(strategy == LFS_ZERO)
5241 {
5242 for(y = 0; y != h; ++y)
5243 {
5244 size_t outindex = (1 + linebytes) * y; /*the extra filterbyte added to each row*/
5245 size_t inindex = linebytes * y;
5246 out[outindex] = 0; /*filter type byte*/
5247 filterScanline(&out[outindex + 1], &in[inindex], prevline, linebytes, bytewidth, 0);
5248 prevline = &in[inindex];
5249 }
5250 }
5251 else if(strategy == LFS_MINSUM)
5252 {
5253 /*adaptive filtering*/
5254 size_t sum[5];
5255 unsigned char* attempt[5]; /*five filtering attempts, one for each filter type*/
5256 size_t smallest = 0;
5257 unsigned char type, bestType = 0;
5258
5259 for(type = 0; type != 5; ++type)
5260 {

Callers 5

applyMethod · 0.85
applyTransposeMethod · 0.85
applyMethod · 0.85
applyTransposeMethod · 0.85
preProcessScanlinesFunction · 0.85

Calls 6

lodepng_get_bppFunction · 0.85
filterScanlineFunction · 0.85
lodepng_mallocFunction · 0.85
lodepng_freeFunction · 0.85
flog2Function · 0.85
zlib_compressFunction · 0.85

Tested by

no test coverage detected