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);
140 void CAtmoZoneDefinition::SaveWeightBitmap(char *fileName,int *weight)
142 if(!fileName || !weight) return;
146 BITMAPFILEHEADER bmpFileHeader;
147 ZeroMemory(&bmpInfo, sizeof(BITMAPINFO));
148 bmpInfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
151 bmpInfo.bmiHeader.biHeight = -CAP_HEIGHT;
152 bmpInfo.bmiHeader.biWidth = CAP_WIDTH;
153 bmpInfo.bmiHeader.biSizeImage = abs(bmpInfo.bmiHeader.biHeight) * bmpInfo.bmiHeader.biWidth * 3;
155 unsigned char *pBuf = (unsigned char *)malloc(bmpInfo.bmiHeader.biSizeImage);
156 for(int y=0; y < CAP_HEIGHT; y++ )
158 for(int x=0; x < CAP_WIDTH; x++)
160 pBuf[y * CAP_WIDTH * 3 + x * 3 ] = 0;
161 pBuf[y * CAP_WIDTH * 3 + x * 3 + 1 ] = (unsigned char)weight[y * CAP_WIDTH + x];
162 pBuf[y * CAP_WIDTH * 3 + x * 3 + 2] = 0;
166 bmpInfo.bmiHeader.biCompression = BI_RGB;
167 bmpInfo.bmiHeader.biPlanes = 1;
168 bmpInfo.bmiHeader.biBitCount = 24;
170 bmpFileHeader.bfReserved1=0;
171 bmpFileHeader.bfReserved2=0;
172 bmpFileHeader.bfSize=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+bmpInfo.bmiHeader.biSizeImage;
173 bmpFileHeader.bfType = MakeIntelWord('M','B');
174 bmpFileHeader.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
178 fp = fopen(fileName,"wb");
179 fwrite(&bmpFileHeader,sizeof(BITMAPFILEHEADER),1,fp);
180 fwrite(&bmpInfo.bmiHeader,sizeof(BITMAPINFOHEADER),1,fp);
181 fwrite(pBuf,bmpInfo.bmiHeader.biSizeImage,1,fp);
191 int CAtmoZoneDefinition::LoadGradientFromBitmap(char *pszBitmap)
193 // transform 256 color image (gray scale!)
194 // into m_basicWeight or use the GREEN value of a 24bit image!
195 // channel of a true color bitmap!
196 VLC_BITMAPINFO bmpInfo;
197 BITMAPFILEHEADER bmpFileHeader;
200 ATMO_LOAD_GRADIENT_FILENOTFOND
201 #define ATMO_LOAD_GRADIENT_OK 0
202 #define ATMO_LOAD_GRADIENT_FAILED_SIZE 1
203 #define ATMO_LOAD_GRADIENT_FAILED_HEADER 2
207 FILE *bmp = fopen(pszBitmap, "rb");
209 return ATMO_LOAD_GRADIENT_FILENOTFOND;
211 if(fread(&bmpFileHeader, sizeof(BITMAPFILEHEADER), 1, bmp) != 1)
214 return ATMO_LOAD_GRADIENT_FAILED_SIZE;
217 if(bmpFileHeader.bfType != MakeIntelWord('M','B'))
220 return ATMO_LOAD_GRADIENT_FAILED_HEADER;
223 if(fread(&bmpInfo, sizeof(VLC_BITMAPINFO), 1, bmp) != 1)
226 return ATMO_LOAD_GRADIENT_FAILED_SIZE;
229 if(bmpInfo.bmiHeader.biCompression != BI_RGB)
232 return ATMO_LOAD_GRADIENT_FAILED_FORMAT;
234 if((bmpInfo.bmiHeader.biBitCount != 8) && (bmpInfo.bmiHeader.biBitCount != 24))
237 return ATMO_LOAD_GRADIENT_FAILED_FORMAT;
240 int width = bmpInfo.bmiHeader.biWidth;
241 int height = bmpInfo.bmiHeader.biHeight;
242 ATMO_BOOL invertDirection = (height > 0);
243 height = abs(height);
244 if((width != CAP_WIDTH) || (height != CAP_HEIGHT))
247 return ATMO_LOAD_GRADIENT_FAILED_SIZE;
250 fseek(bmp, bmpFileHeader.bfOffBits, SEEK_SET);
252 int imageSize = width * height * bmpInfo.bmiHeader.biBitCount/8;
254 unsigned char *pixelBuffer = (unsigned char *)malloc(imageSize);
255 if(fread(pixelBuffer,imageSize,1,bmp) != 1)
259 return ATMO_LOAD_GRADIENT_FAILED_SIZE;
262 if(bmpInfo.bmiHeader.biBitCount == 8)
265 for(int y=0;y < CAP_HEIGHT; y++) {
266 if(invertDirection) {
267 ydest = (CAP_HEIGHT - y - 1);
271 for(int x=0;x < CAP_WIDTH; x++) {
272 // palette should be grey scale - so that index 0 is black and
273 // index 255 means white!
274 // everything else would produce funny results!
275 m_BasicWeight[ydest * CAP_WIDTH + x] =
276 pixelBuffer[y * CAP_WIDTH + x];
281 if(bmpInfo.bmiHeader.biBitCount == 24)
284 for(int y=0;y < CAP_HEIGHT; y++) {
285 if(invertDirection) {
286 ydest = (CAP_HEIGHT - y - 1);
290 for(int x=0;x < CAP_WIDTH; x++) {
291 // use the green value as reference...
292 m_BasicWeight[ydest * CAP_WIDTH + x] =
293 pixelBuffer[y * CAP_WIDTH * 3 + (x*3) + 1 ];
300 return ATMO_LOAD_GRADIENT_OK;
304 void CAtmoZoneDefinition::UpdateWeighting(int *destWeight,
306 int newEdgeWeightning)
309 use the values in m_BasicWeight and newWeightning to
310 update the direct control array for the output thread!
314 for(int row=0; row < CAP_HEIGHT; row++) {
315 for(int col=0; col < CAP_WIDTH; col++) {
316 if ((WidescreenMode == 1) && ((row <= CAP_HEIGHT/8) || (row >= (7*CAP_HEIGHT)/8)))
318 destWeight[index] = 0;
320 destWeight[index] = (int)(255.0 * (float)pow( ((float)m_BasicWeight[index])/255.0 , newEdgeWeightning));
327 void CAtmoZoneDefinition::setZoneNumber(int num)
332 int CAtmoZoneDefinition::getZoneNumber()