mrDarker
2025-08-16 df45966c52bac2eb465cf05c1d6328bf0d00c5ac
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// SISBuffer.cpp: implementation of the CSISBuffer class.
//
//////////////////////////////////////////////////////////////////////
 
#include "stdafx.h"
#include "SISBuffer.h"
 
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
 
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
 
 
 
int CSISBuffer::GetVar(int x, int y, int min)
{
    int a= GetPixel(x, y);
    int mmt;
    
    for(int yy= y- 1; yy < y+ 1; yy++)
    {
        for(int xx= x- 1; xx < x+ 1; xx++)
        {
            mmt= abs((int)GetPixel(xx, yy)- a);
            if(mmt > min)
                min= mmt;
        }
    }
    return min;
}
 
float CSISBuffer::GetMeanBright()
{
    int bright= 0;
    
    int yi, xi;
    int cnt= 0;
    
    for(yi= 0; yi< GetHeight(); yi++)
    {
        for(xi= 0; xi < GetWidth(); xi++)
        {
            //    if(GetPixel(xi, yi) > 40 && GetPixel(xi, yi) < 200)
            {
                bright+= GetPixel(xi, yi);
                cnt++;
            }
        }
    }
    if(cnt < 1)
        cnt= 1;
    return (float)bright/cnt;
}
 
void CSISBuffer::AdjustBright(CSISBuffer &buffer)
{
    double ratio= buffer.GetMeanBright()/GetMeanBright();
    int yi, xi;
    int val;
    for(yi= 0; yi< GetHeight(); yi++)
    {
        for(xi= 0; xi < GetWidth(); xi++)
        {
            if(GetPixel(xi, yi) > 200)
            {
                continue;
            }
            if(GetPixel(xi, yi) < 40)
            {
                continue;
            }
            val= (int)(ratio*GetPixel(xi, yi));
            if(val > 255)
            {
                val= 255;
            }
            SetPixel(xi, yi, (BYTE)val);
        }
    }
}