MCPcopy Create free account
hub / github.com/danoon2/Boxedwine / pixelmatch

Function pixelmatch

source/util/pixelMatch.cpp:135–179  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

133}
134
135U32 pixelmatch(const U8* img1, U32 stride1, const U8* img2, U32 stride2, U32 width, U32 height, U8* output = nullptr, double threshold = 0.1, bool includeAA = false) {
136 // maximum acceptable square distance between two colors;
137 // 35215 is the maximum possible value for the YIQ difference metric
138 double maxDelta = 35215 * threshold * threshold;
139 U32 diff = 0;
140
141 // compare each pixel of one image against the other one
142 for (U32 y = 0; y < height; y++) {
143 for (U32 x = 0; x < width; x++) {
144
145 // allow input images to include different padding in their strides
146 U32 pos1 = y * stride1 + x * 4;
147 U32 pos2 = y * stride2 + x * 4;
148
149 // but write the output as tightly-packed
150 U32 posOut = (y * width + x) * 4;
151
152 // squared YUV distance between colors at this pixel position
153 double delta = colorDelta(img1, img2, pos1, pos2);
154
155 // the color difference is above the threshold
156 if (delta > maxDelta) {
157 // check it's a real rendering difference or just anti-aliasing
158 if (!includeAA && (antialiased(img1, x, y, width, height, img2) ||
159 antialiased(img2, x, y, width, height, img1))) {
160 // one of the pixels is anti-aliasing; draw as yellow and do not count as difference
161 if (output) drawPixel(output, posOut, 255, 255, 0);
162
163 } else {
164 // found substantial difference not caused by anti-aliasing; draw it as red
165 if (output) drawPixel(output, posOut, 255, 0, 0);
166 diff++;
167 }
168
169 } else if (output) {
170 // pixels are similar; draw background as grayscale image blended with white
171 U8 val = blend((U8)grayPixel(img1, posOut), 0.1);
172 drawPixel(output, posOut, val, val, val);
173 }
174 }
175 }
176
177 // return the number of different pixels
178 return diff;
179}

Callers 1

bitmapCompareThreadFunction · 0.85

Calls 5

colorDeltaFunction · 0.85
antialiasedFunction · 0.85
drawPixelFunction · 0.85
blendFunction · 0.85
grayPixelFunction · 0.85

Tested by

no test coverage detected