<commit_before><html>
    <head>
        <!-- Copyright <NAME> 2013 -->
        <title>Photoshop blend mode comparison</title>
        <script type="text/javascript" src="../util2d.js"></script>
        <script type="text/javascript">

            // Generate input values, these are the same values used in Photoshop layers, input1.png and input2.png
            var inputs = [];
            for (var i = 0; i < 26; i++) {
                inputs.push(i * 10);
            }
            inputs.push(255);

            // Compare blendFunction with reference data from Photoshop CS5, the reference data was generated with
            // input1.png as base layer and input2.png on top with 100% opacity and given blend mode selected.
            function testBlendFunction(name, blendFunction) {
                var img = new Image();
                img.onload = function() {
                    var canvas = document.createElement("canvas");
                    canvas.width = 27;
                    canvas.height = 27;
                    var ctx = canvas.getContext("2d");
                    ctx.drawImage(this, 0, 0);
                    var data = ctx.getImageData(0, 0, canvas.width, canvas.height).data;
                    var errorTotal = 0.;
                    var errorMax = 0.;
                    for (var x = 0; x < 27; x++)
                        for (var y = 0; y < 27; y++) {
                            var result = Math.round(blendFunction(inputs[x], inputs[y]));
                            var error = Math.abs(data[(x + y * 27) * 4] - result);
                            errorTotal += error;
                            errorMax = errorMax < error ? error : errorMax;
                            if (error > 2)
                                console.log(name + ":" + inputs[x] + ", " + inputs[y] + " func " + result + " vs. ps " +
                                        data[(x + y * 27) * 4]);
                        }

                    var averageError = errorTotal / (27 * 27) * (100 / 255);
                    var maximumError = errorMax;
                    document.body.innerHTML += "<div>Testing function <b>" + name + "</b>, average error is <b>" +
                            averageError + " %</b>, maximum error is <b>" + maximumError + " / 255</b></div>";
                };
                img.src = "img/photoshop_cs5_" + name + ".png";
            }

            function runTest() {
                //testBlendFunction("multiply", function(a,b) { return a * (b / 255); });
                testBlendFunction("multiply", colorUtil.blendMultiply);
                testBlendFunction("screen", colorUtil.blendScreen);
                testBlendFunction("overlay", colorUtil.blendOverlay);
                testBlendFunction("hardlight", colorUtil.blendHardLight);
                testBlendFunction("softlight", colorUtil.blendSoftLight);
                testBlendFunction("darken", colorUtil.blendDarken);
                testBlendFunction("lighten", colorUtil.blendLighten);
                testBlendFunction("difference", colorUtil.blendDifference);
                testBlendFunction("exclusion", colorUtil.blendExclusion);
                testBlendFunction("colorburn", colorUtil.blendColorBurn);
                testBlendFunction("linearburn", colorUtil.blendLinearBurn);
                testBlendFunction("vividlight", colorUtil.blendVividLight);
                testBlendFunction("linearlight", colorUtil.blendLinearLight);
                testBlendFunction("pinlight", colorUtil.blendPinLight);
                testBlendFunction("colordodge", colorUtil.blendColorDodge);
                testBlendFunction("lineardodgeadd", colorUtil.blendLinearDodge);
            }

        </script>
    </head>
    <body onload="runTest()" style="background:#DDD;">
    </body>
</html><commit_msg>Display the results visually in photoshop_blend_modes.html test<commit_after><html>
    <head>
        <!-- Copyright <NAME> 2013 -->
        <!-- Copyright <NAME> 2013 -->
        <title>Photoshop blend mode comparison</title>
        <script type="text/javascript" src="../util2d.js"></script>
        <script type="text/javascript">

            // Generate input values, these are the same values used in Photoshop layers, input1.png and input2.png
            var inputs = [];
            for (var i = 0; i < 26; i++) {
                inputs.push(i * 10);
            }
            inputs.push(255);

            // Compare blendFunction with reference data from Photoshop CS5, the reference data was generated with
            // input1.png as base layer and input2.png on top with 100% opacity and given blend mode selected.
            function testBlendFunction(name, blendFunction, callback) {
                var img = new Image();
                img.onload = function() {
                    var canvas = document.createElement("canvas");
                    canvas.width = 27;
                    canvas.height = 27;
                    var ctx = canvas.getContext("2d");
                    ctx.drawImage(this, 0, 0);
                    var data = ctx.getImageData(0, 0, canvas.width, canvas.height).data;
                    var errorTotal = 0.;
                    var errorMax = 0.;
                    var resultData = ctx.createImageData(27, 27); // For displaying the blending code results
                    for (var x = 0; x < 27; x++)
                        for (var y = 0; y < 27; y++) {
                            var result = Math.round(blendFunction(inputs[x], inputs[y]));
                            for (var i = 0; i < 3; ++i) {
                                resultData.data[(x + y * 27) * 4 + i] = result;
                            }
                            resultData.data[(x + y * 27) * 4 + 3] = 255;
                            var error = Math.abs(data[(x + y * 27) * 4] - result);
                            errorTotal += error;
                            errorMax = errorMax < error ? error : errorMax;
                            if (error > 2)
                                console.log(name + ":" + inputs[x] + ", " + inputs[y] + " func " + result + " vs. ps " +
                                        data[(x + y * 27) * 4]);
                        }

                    var averageError = errorTotal / (27 * 27) * (100 / 255);
                    var maximumError = errorMax;
                    var report = document.createElement('div');
                    report.innerHTML = "Testing function <b>" + name + "</b>, average error is <b>" +
                            averageError + " %</b>, maximum error is <b>" + maximumError + " / 255</b>";
                    document.body.appendChild(report);

                    document.body.appendChild(img);
                    var displayOnCanvas = function(imageData) {
                        var dataCanvas = document.createElement('canvas');
                        dataCanvas.width = 27;
                        dataCanvas.height = 27;
                        var ctx = dataCanvas.getContext('2d');
                        ctx.putImageData(imageData, 0, 0);
                        document.body.appendChild(dataCanvas);
                    };
                    displayOnCanvas(resultData);
                    window.setTimeout(callback, 0);
                };
                img.src = "img/photoshop_cs5_" + name + ".png";
            }

            var tests = [
                "Multiply", "Screen", "Overlay", "HardLight", "SoftLight", "Darken", "Lighten", "Difference",
                "Exclusion", "ColorBurn", "LinearBurn", "VividLight", "LinearLight", "PinLight", "ColorDodge",
                "LinearDodge"
            ];

            var testIndex = 0;
            function runTest() {
                // Since image loading is asynchronous, run the next test as a callback from there to ensure tests are
                // run in the same order.
                if (testIndex < tests.length) {
                    testBlendFunction(tests[testIndex].toLowerCase(), colorUtil['blend' + tests[testIndex]], runTest);
                    ++testIndex;
                }
            }

        </script>
    </head>
    <body onload="runTest()" style="background:#DDD;">
    </body>
</html>
{'fraction_non_alphanumeric': 0.11726897889886005, 'fraction_numerical': 0.01819063788503517, 'mean_word_length': 1.4284452296819787, 'pattern_counts': {'":': 2, '<': 57, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6704100', 'n_tokens_mistral': 2248, 'n_tokens_neox': 1994, 'n_words': 537}