AtmoZoneDefinition.cpp 5.79 KB
Newer Older
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105

#include "AtmoDefs.h"

#if defined (WIN32)
#  include <windows.h>
#else
#  include <vlc_codecs.h>
#endif

#include <math.h>
#include <stdio.h>
#include "AtmoZoneDefinition.h"

CAtmoZoneDefinition::CAtmoZoneDefinition(void)
{
}

CAtmoZoneDefinition::~CAtmoZoneDefinition(void)
{
}

void CAtmoZoneDefinition::Fill(unsigned char value)
{
  for(int i=0; i < IMAGE_SIZE; i++)
      m_BasicWeight[i] = value;
}

// max weight to left
void CAtmoZoneDefinition::FillGradientFromLeft()
{
   int index = 0;
   unsigned char col_norm;
   for(int row=0; row < CAP_HEIGHT; row++) {
       for(int col=0; col < CAP_WIDTH; col++) {
           // should be a value between 0 .. 255?
           col_norm = (255 * (CAP_WIDTH-col-1)) / (CAP_WIDTH-1);
           m_BasicWeight[index++] = col_norm;
       }
   }
}

// max weight to right
void CAtmoZoneDefinition::FillGradientFromRight()
{
   int index = 0;
   unsigned char col_norm;
   for(int row=0; row < CAP_HEIGHT; row++) {
      for(int col=0; col < CAP_WIDTH; col++) {
          col_norm = (255 * col) / (CAP_WIDTH-1); // should be a value between 0 .. 255?
          m_BasicWeight[index++] = col_norm;
       }
   }
}

// max weight from top
void CAtmoZoneDefinition::FillGradientFromTop()
{
   int index = 0;
   unsigned char row_norm;
   for(int row=0; row < CAP_HEIGHT; row++) {
       row_norm = (255 * (CAP_HEIGHT-row-1)) / (CAP_HEIGHT-1); // should be a value between 0 .. 255?
       for(int col=0; col < CAP_WIDTH; col++) {
           m_BasicWeight[index++] = row_norm;
       }
   }
}

// max weight from bottom
void CAtmoZoneDefinition::FillGradientFromBottom()
{
   int index = 0;
   unsigned char row_norm;
   for(int row=0; row < CAP_HEIGHT; row++) {
       row_norm = (255 * row) / (CAP_HEIGHT-1); // should be a value between 0 .. 255?
       for(int col=0; col < CAP_WIDTH; col++) {
           m_BasicWeight[index++] = row_norm;
       }
   }
}


int CAtmoZoneDefinition::LoadGradientFromBitmap(char *pszBitmap)
{
  // transform 256 color image (gray scale!)
  // into m_basicWeight or use the GREEN value of a 24bit image!
  // channel of a true color bitmap!
  BITMAPINFO bmpInfo;
  BITMAPFILEHEADER  bmpFileHeader;

  /*
#define ATMO_LOAD_GRADIENT_OK  0
#define ATMO_LOAD_GRADIENT_FAILED_SIZE    1
#define ATMO_LOAD_GRADIENT_FAILED_HEADER  2
  */


   FILE *bmp = fopen(pszBitmap, "rb");
   if(!bmp)
     return ATMO_LOAD_GRADIENT_FILENOTFOND;

    if(fread(&bmpFileHeader, sizeof(BITMAPFILEHEADER), 1, bmp) != 1)
    {
        fclose(bmp);
        return ATMO_LOAD_GRADIENT_FAILED_SIZE;
    }
106
107
108
109
110
#ifdef _ATMO_VLC_PLUGIN_
    if(bmpFileHeader.bfType != VLC_TWOCC('M','B'))
#else
    if(bmpFileHeader.bfType != MakeWord('M','B'))
#endif
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
    {
        fclose(bmp);
        return ATMO_LOAD_GRADIENT_FAILED_HEADER;
    }

    if(fread(&bmpInfo, sizeof(BITMAPINFO), 1, bmp) != 1)
    {
        fclose(bmp);
        return ATMO_LOAD_GRADIENT_FAILED_SIZE;
    }

    if(bmpInfo.bmiHeader.biCompression != BI_RGB)
    {
        fclose(bmp);
        return ATMO_LOAD_GRADIENT_FAILED_FORMAT;
    }
    if((bmpInfo.bmiHeader.biBitCount != 8) && (bmpInfo.bmiHeader.biBitCount != 24))
    {
        fclose(bmp);
        return ATMO_LOAD_GRADIENT_FAILED_FORMAT;
    }

    int width = bmpInfo.bmiHeader.biWidth;
    int height = bmpInfo.bmiHeader.biHeight;
    ATMO_BOOL invertDirection = (height > 0);
    height = abs(height);
    if((width != CAP_WIDTH) || (height != CAP_HEIGHT))
    {
        fclose(bmp);
        return ATMO_LOAD_GRADIENT_FAILED_SIZE;
    }

    fseek(bmp, bmpFileHeader.bfOffBits, SEEK_SET);

    int imageSize = width * height * bmpInfo.bmiHeader.biBitCount/8;

    unsigned char *pixelBuffer = (unsigned char *)malloc(imageSize);
    if(fread(pixelBuffer,imageSize,1,bmp) != 1)
    {
        fclose(bmp);
        return ATMO_LOAD_GRADIENT_FAILED_SIZE;
    }

    if(bmpInfo.bmiHeader.biBitCount == 8)
    {
        int ydest;
        for(int y=0;y < CAP_HEIGHT; y++) {
            if(invertDirection) {
                ydest = (CAP_HEIGHT - y - 1);
            } else {
                ydest = y;
            }
            for(int x=0;x < CAP_WIDTH; x++) {
                // palette should be grey scale - so that index 0 is black and
                // index 255 means white!
                // everything else would produce funny results!
                m_BasicWeight[ydest * CAP_WIDTH + x] =
                    pixelBuffer[y * CAP_WIDTH + x];
            }
        }
    }

    if(bmpInfo.bmiHeader.biBitCount == 24)
    {
        int ydest;
        for(int y=0;y < CAP_HEIGHT; y++) {
            if(invertDirection) {
                ydest = (CAP_HEIGHT - y - 1);
            } else {
                ydest = y;
            }
            for(int x=0;x < CAP_WIDTH; x++) {
                // use the green value as reference...
                m_BasicWeight[ydest * CAP_WIDTH + x] =
                    pixelBuffer[y * CAP_WIDTH * 3 + (x*3) + 1 ];
            }
        }
    }
    free(pixelBuffer);
    fclose(bmp);

    return ATMO_LOAD_GRADIENT_OK;
}


void CAtmoZoneDefinition::UpdateWeighting(int *destWeight,
                                          int WidescreenMode,
                                          int newEdgeWeightning)
{
  /*
    use the values in m_BasicWeight and newWeightning to
    update the direct control array for the output thread!
  */

  int index = 0;
  for(int row=0; row < CAP_HEIGHT; row++) {
      for(int col=0; col < CAP_HEIGHT; col++) {
          if ((WidescreenMode == 1) && ((row <= CAP_HEIGHT/8) || (row >= (7*CAP_HEIGHT)/8)))
          {
             destWeight[index] = 0;
          } else {
212
   		     destWeight[index] = (int)(255.0 * (float)pow( ((float)m_BasicWeight[index])/255.0 , newEdgeWeightning));
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
          }
          index++;
      }
  }
}

void CAtmoZoneDefinition::setZoneNumber(int num)
{
    m_zonenumber = num;
}

int CAtmoZoneDefinition::getZoneNumber()
{
    return m_zonenumber;
}