11 # include <vlc_codecs.h>
16 #include "AtmoZoneDefinition.h"
18 CAtmoZoneDefinition::CAtmoZoneDefinition(void)
22 CAtmoZoneDefinition::~CAtmoZoneDefinition(void)
26 void CAtmoZoneDefinition::Fill(unsigned char value)
28 for(int i=0; i < IMAGE_SIZE; i++)
29 m_BasicWeight[i] = value;
34 void CAtmoZoneDefinition::FillGradientFromLeft(int start_row,int end_row)
37 unsigned char col_norm;
38 index = start_row * CAP_WIDTH;
39 for(int row=start_row; row < end_row; row++) {
40 for(int col=0; col < CAP_WIDTH; col++) {
41 // should be a value between 0 .. 255?
42 col_norm = (255 * (CAP_WIDTH-col-1)) / (CAP_WIDTH-1);
43 m_BasicWeight[index++] = col_norm;
48 // max weight to right
49 void CAtmoZoneDefinition::FillGradientFromRight(int start_row,int end_row)
52 unsigned char col_norm;
53 index = start_row * CAP_WIDTH;
54 for(int row=start_row; row < end_row; row++) {
55 for(int col=0; col < CAP_WIDTH; col++) {
56 col_norm = (255 * col) / (CAP_WIDTH-1); // should be a value between 0 .. 255?
57 m_BasicWeight[index++] = col_norm;
62 // max weight from top
63 void CAtmoZoneDefinition::FillGradientFromTop(int start_col,int end_col)
66 unsigned char row_norm;
68 for(int row=0; row < CAP_HEIGHT; row++) {
69 index = row * CAP_WIDTH + start_col;
71 row_norm = (255 * (CAP_HEIGHT-row-1)) / (CAP_HEIGHT-1); // should be a value between 0 .. 255?
72 for(int col=start_col; col < end_col; col++) {
73 m_BasicWeight[index++] = row_norm;
78 // max weight from bottom
79 void CAtmoZoneDefinition::FillGradientFromBottom(int start_col,int end_col)
82 unsigned char row_norm;
83 for(int row=0; row < CAP_HEIGHT; row++) {
84 index = row * CAP_WIDTH + start_col;
85 row_norm = (255 * row) / (CAP_HEIGHT-1); // should be a value between 0 .. 255?
86 for(int col=start_col; col < end_col; col++) {
87 m_BasicWeight[index++] = row_norm;
92 #if !defined(_ATMO_VLC_PLUGIN_)
94 void CAtmoZoneDefinition::SaveZoneBitmap(char *fileName)
100 BITMAPFILEHEADER bmpFileHeader;
101 ZeroMemory(&bmpInfo, sizeof(BITMAPINFO));
102 bmpInfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
105 bmpInfo.bmiHeader.biHeight = -CAP_HEIGHT;
106 bmpInfo.bmiHeader.biWidth = CAP_WIDTH;
107 bmpInfo.bmiHeader.biSizeImage = abs(bmpInfo.bmiHeader.biHeight) * bmpInfo.bmiHeader.biWidth * 3;
109 unsigned char *pBuf = (unsigned char *)malloc(bmpInfo.bmiHeader.biSizeImage);
110 for(int y=0; y < CAP_HEIGHT; y++ )
112 for(int x=0; x < CAP_WIDTH; x++)
114 pBuf[y * CAP_WIDTH * 3 + x * 3 ] = 0;
115 pBuf[y * CAP_WIDTH * 3 + x * 3 + 1 ] = m_BasicWeight[y * CAP_WIDTH + x];
116 pBuf[y * CAP_WIDTH * 3 + x * 3 + 2] = 0;
120 bmpInfo.bmiHeader.biCompression = BI_RGB;
121 bmpInfo.bmiHeader.biPlanes = 1;
122 bmpInfo.bmiHeader.biBitCount = 24;
124 bmpFileHeader.bfReserved1=0;
125 bmpFileHeader.bfReserved2=0;
126 bmpFileHeader.bfSize=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+bmpInfo.bmiHeader.biSizeImage;
127 bmpFileHeader.bfType = MakeIntelWord('M','B');
128 bmpFileHeader.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
132 fp = fopen(fileName,"wb");
133 fwrite(&bmpFileHeader,sizeof(BITMAPFILEHEADER),1,fp);
134 fwrite(&bmpInfo.bmiHeader,sizeof(BITMAPINFOHEADER),1,fp);
135 fwrite(pBuf,bmpInfo.bmiHeader.biSizeImage,1,fp);
139 void CAtmoZoneDefinition::SaveWeightBitmap(char *fileName,int *weight)
141 if(!fileName || !weight) return;
145 BITMAPFILEHEADER bmpFileHeader;
146 ZeroMemory(&bmpInfo, sizeof(BITMAPINFO));
147 bmpInfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
150 bmpInfo.bmiHeader.biHeight = -CAP_HEIGHT;
151 bmpInfo.bmiHeader.biWidth = CAP_WIDTH;
152 bmpInfo.bmiHeader.biSizeImage = abs(bmpInfo.bmiHeader.biHeight) * bmpInfo.bmiHeader.biWidth * 3;
154 unsigned char *pBuf = (unsigned char *)malloc(bmpInfo.bmiHeader.biSizeImage);
155 for(int y=0; y < CAP_HEIGHT; y++ )
157 for(int x=0; x < CAP_WIDTH; x++)
159 pBuf[y * CAP_WIDTH * 3 + x * 3 ] = 0;
160 pBuf[y * CAP_WIDTH * 3 + x * 3 + 1 ] = (unsigned char)weight[y * CAP_WIDTH + x];
161 pBuf[y * CAP_WIDTH * 3 + x * 3 + 2] = 0;
165 bmpInfo.bmiHeader.biCompression = BI_RGB;
166 bmpInfo.bmiHeader.biPlanes = 1;
167 bmpInfo.bmiHeader.biBitCount = 24;
169 bmpFileHeader.bfReserved1=0;
170 bmpFileHeader.bfReserved2=0;
171 bmpFileHeader.bfSize=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+bmpInfo.bmiHeader.biSizeImage;
172 bmpFileHeader.bfType = MakeIntelWord('M','B');
173 bmpFileHeader.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
177 fp = fopen(fileName,"wb");
178 fwrite(&bmpFileHeader,sizeof(BITMAPFILEHEADER),1,fp);
179 fwrite(&bmpInfo.bmiHeader,sizeof(BITMAPINFOHEADER),1,fp);
180 fwrite(pBuf,bmpInfo.bmiHeader.biSizeImage,1,fp);
189 int CAtmoZoneDefinition::LoadGradientFromBitmap(char *pszBitmap)
191 // transform 256 color image (gray scale!)
192 // into m_basicWeight or use the GREEN value of a 24bit image!
193 // channel of a true color bitmap!
195 BITMAPFILEHEADER bmpFileHeader;
198 ATMO_LOAD_GRADIENT_FILENOTFOND
199 #define ATMO_LOAD_GRADIENT_OK 0
200 #define ATMO_LOAD_GRADIENT_FAILED_SIZE 1
201 #define ATMO_LOAD_GRADIENT_FAILED_HEADER 2
205 FILE *bmp = fopen(pszBitmap, "rb");
207 return ATMO_LOAD_GRADIENT_FILENOTFOND;
209 if(fread(&bmpFileHeader, sizeof(BITMAPFILEHEADER), 1, bmp) != 1)
212 return ATMO_LOAD_GRADIENT_FAILED_SIZE;
215 if(bmpFileHeader.bfType != MakeIntelWord('M','B'))
218 return ATMO_LOAD_GRADIENT_FAILED_HEADER;
221 if(fread(&bmpInfo, sizeof(BITMAPINFO), 1, bmp) != 1)
224 return ATMO_LOAD_GRADIENT_FAILED_SIZE;
227 if(bmpInfo.bmiHeader.biCompression != BI_RGB)
230 return ATMO_LOAD_GRADIENT_FAILED_FORMAT;
232 if((bmpInfo.bmiHeader.biBitCount != 8) && (bmpInfo.bmiHeader.biBitCount != 24))
235 return ATMO_LOAD_GRADIENT_FAILED_FORMAT;
238 int width = bmpInfo.bmiHeader.biWidth;
239 int height = bmpInfo.bmiHeader.biHeight;
240 ATMO_BOOL invertDirection = (height > 0);
241 height = abs(height);
242 if((width != CAP_WIDTH) || (height != CAP_HEIGHT))
245 return ATMO_LOAD_GRADIENT_FAILED_SIZE;
248 fseek(bmp, bmpFileHeader.bfOffBits, SEEK_SET);
250 int imageSize = width * height * bmpInfo.bmiHeader.biBitCount/8;
252 unsigned char *pixelBuffer = (unsigned char *)malloc(imageSize);
253 if(fread(pixelBuffer,imageSize,1,bmp) != 1)
256 return ATMO_LOAD_GRADIENT_FAILED_SIZE;
259 if(bmpInfo.bmiHeader.biBitCount == 8)
262 for(int y=0;y < CAP_HEIGHT; y++) {
263 if(invertDirection) {
264 ydest = (CAP_HEIGHT - y - 1);
268 for(int x=0;x < CAP_WIDTH; x++) {
269 // palette should be grey scale - so that index 0 is black and
270 // index 255 means white!
271 // everything else would produce funny results!
272 m_BasicWeight[ydest * CAP_WIDTH + x] =
273 pixelBuffer[y * CAP_WIDTH + x];
278 if(bmpInfo.bmiHeader.biBitCount == 24)
281 for(int y=0;y < CAP_HEIGHT; y++) {
282 if(invertDirection) {
283 ydest = (CAP_HEIGHT - y - 1);
287 for(int x=0;x < CAP_WIDTH; x++) {
288 // use the green value as reference...
289 m_BasicWeight[ydest * CAP_WIDTH + x] =
290 pixelBuffer[y * CAP_WIDTH * 3 + (x*3) + 1 ];
297 return ATMO_LOAD_GRADIENT_OK;
301 void CAtmoZoneDefinition::UpdateWeighting(int *destWeight,
303 int newEdgeWeightning)
306 use the values in m_BasicWeight and newWeightning to
307 update the direct control array for the output thread!
311 for(int row=0; row < CAP_HEIGHT; row++) {
312 for(int col=0; col < CAP_WIDTH; col++) {
313 if ((WidescreenMode == 1) && ((row <= CAP_HEIGHT/8) || (row >= (7*CAP_HEIGHT)/8)))
315 destWeight[index] = 0;
317 destWeight[index] = (int)(255.0 * (float)pow( ((float)m_BasicWeight[index])/255.0 , newEdgeWeightning));
324 void CAtmoZoneDefinition::setZoneNumber(int num)
329 int CAtmoZoneDefinition::getZoneNumber()