summaryrefslogtreecommitdiff
path: root/thirdparty/etcpak/Error.cpp
blob: 014ecdab66785b9302d48117fdb4d8b26b606c67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <stdint.h>

#include "Error.hpp"
#include "Math.hpp"

float CalcMSE3( const Bitmap& bmp, const Bitmap& out )
{
    float err = 0;

    const uint32_t* p1 = bmp.Data();
    const uint32_t* p2 = out.Data();
    size_t cnt = bmp.Size().x * bmp.Size().y;

    for( size_t i=0; i<cnt; i++ )
    {
        uint32_t c1 = *p1++;
        uint32_t c2 = *p2++;

        err += sq( ( c1 & 0x000000FF ) - ( c2 & 0x000000FF ) );
        err += sq( ( ( c1 & 0x0000FF00 ) >> 8 ) - ( ( c2 & 0x0000FF00 ) >> 8 ) );
        err += sq( ( ( c1 & 0x00FF0000 ) >> 16 ) - ( ( c2 & 0x00FF0000 ) >> 16 ) );
    }

    err /= cnt * 3;

    return err;
}

float CalcMSE1( const Bitmap& bmp, const Bitmap& out )
{
    float err = 0;

    const uint32_t* p1 = bmp.Data();
    const uint32_t* p2 = out.Data();
    size_t cnt = bmp.Size().x * bmp.Size().y;

    for( size_t i=0; i<cnt; i++ )
    {
        uint32_t c1 = *p1++;
        uint32_t c2 = *p2++;

        err += sq( ( c1 >> 24 ) - ( c2 & 0xFF ) );
    }

    err /= cnt;

    return err;
}