7 # include <vlc_codecs.h>
12 #include "AtmoZoneDefinition.h"
14 CAtmoZoneDefinition::CAtmoZoneDefinition(void)
18 CAtmoZoneDefinition::~CAtmoZoneDefinition(void)
22 void CAtmoZoneDefinition::Fill(unsigned char value
)
24 for(int i
=0; i
< IMAGE_SIZE
; i
++)
25 m_BasicWeight
[i
] = value
;
30 void CAtmoZoneDefinition::FillGradientFromLeft(int start_row
,int end_row
)
33 unsigned char col_norm
;
34 index
= start_row
* CAP_WIDTH
;
35 for(int row
=start_row
; row
< end_row
; row
++) {
36 for(int col
=0; col
< CAP_WIDTH
; col
++) {
37 // should be a value between 0 .. 255?
38 col_norm
= (255 * (CAP_WIDTH
-col
-1)) / (CAP_WIDTH
-1);
39 m_BasicWeight
[index
++] = col_norm
;
44 // max weight to right
45 void CAtmoZoneDefinition::FillGradientFromRight(int start_row
,int end_row
)
48 unsigned char col_norm
;
49 index
= start_row
* CAP_WIDTH
;
50 for(int row
=start_row
; row
< end_row
; row
++) {
51 for(int col
=0; col
< CAP_WIDTH
; col
++) {
52 col_norm
= (255 * col
) / (CAP_WIDTH
-1); // should be a value between 0 .. 255?
53 m_BasicWeight
[index
++] = col_norm
;
58 // max weight from top
59 void CAtmoZoneDefinition::FillGradientFromTop(int start_col
,int end_col
)
62 unsigned char row_norm
;
64 for(int row
=0; row
< CAP_HEIGHT
; row
++) {
65 index
= row
* CAP_WIDTH
+ start_col
;
67 row_norm
= (255 * (CAP_HEIGHT
-row
-1)) / (CAP_HEIGHT
-1); // should be a value between 0 .. 255?
68 for(int col
=start_col
; col
< end_col
; col
++) {
69 m_BasicWeight
[index
++] = row_norm
;
74 // max weight from bottom
75 void CAtmoZoneDefinition::FillGradientFromBottom(int start_col
,int end_col
)
78 unsigned char row_norm
;
79 for(int row
=0; row
< CAP_HEIGHT
; row
++) {
80 index
= row
* CAP_WIDTH
+ start_col
;
81 row_norm
= (255 * row
) / (CAP_HEIGHT
-1); // should be a value between 0 .. 255?
82 for(int col
=start_col
; col
< end_col
; col
++) {
83 m_BasicWeight
[index
++] = row_norm
;
88 #if !defined(_ATMO_VLC_PLUGIN_)
90 void CAtmoZoneDefinition::SaveZoneBitmap(char *fileName
)
96 BITMAPFILEHEADER bmpFileHeader
;
97 ZeroMemory(&bmpInfo
, sizeof(BITMAPINFO
));
98 bmpInfo
.bmiHeader
.biSize
=sizeof(BITMAPINFOHEADER
);
101 bmpInfo
.bmiHeader
.biHeight
= -CAP_HEIGHT
;
102 bmpInfo
.bmiHeader
.biWidth
= CAP_WIDTH
;
103 bmpInfo
.bmiHeader
.biSizeImage
= abs(bmpInfo
.bmiHeader
.biHeight
) * bmpInfo
.bmiHeader
.biWidth
* 3;
105 unsigned char *pBuf
= (unsigned char *)malloc(bmpInfo
.bmiHeader
.biSizeImage
);
106 for(int y
=0; y
< CAP_HEIGHT
; y
++ )
108 for(int x
=0; x
< CAP_WIDTH
; x
++)
110 pBuf
[y
* CAP_WIDTH
* 3 + x
* 3 ] = 0;
111 pBuf
[y
* CAP_WIDTH
* 3 + x
* 3 + 1 ] = m_BasicWeight
[y
* CAP_WIDTH
+ x
];
112 pBuf
[y
* CAP_WIDTH
* 3 + x
* 3 + 2] = 0;
116 bmpInfo
.bmiHeader
.biCompression
= BI_RGB
;
117 bmpInfo
.bmiHeader
.biPlanes
= 1;
118 bmpInfo
.bmiHeader
.biBitCount
= 24;
120 bmpFileHeader
.bfReserved1
=0;
121 bmpFileHeader
.bfReserved2
=0;
122 bmpFileHeader
.bfSize
=sizeof(BITMAPFILEHEADER
)+sizeof(BITMAPINFOHEADER
)+bmpInfo
.bmiHeader
.biSizeImage
;
123 bmpFileHeader
.bfType
= MakeIntelWord('M','B');
124 bmpFileHeader
.bfOffBits
=sizeof(BITMAPFILEHEADER
)+sizeof(BITMAPINFOHEADER
);
128 fp
= fopen(fileName
,"wb");
129 fwrite(&bmpFileHeader
,sizeof(BITMAPFILEHEADER
),1,fp
);
130 fwrite(&bmpInfo
.bmiHeader
,sizeof(BITMAPINFOHEADER
),1,fp
);
131 fwrite(pBuf
,bmpInfo
.bmiHeader
.biSizeImage
,1,fp
);
135 void CAtmoZoneDefinition::SaveWeightBitmap(char *fileName
,int *weight
)
137 if(!fileName
|| !weight
) return;
141 BITMAPFILEHEADER bmpFileHeader
;
142 ZeroMemory(&bmpInfo
, sizeof(BITMAPINFO
));
143 bmpInfo
.bmiHeader
.biSize
=sizeof(BITMAPINFOHEADER
);
146 bmpInfo
.bmiHeader
.biHeight
= -CAP_HEIGHT
;
147 bmpInfo
.bmiHeader
.biWidth
= CAP_WIDTH
;
148 bmpInfo
.bmiHeader
.biSizeImage
= abs(bmpInfo
.bmiHeader
.biHeight
) * bmpInfo
.bmiHeader
.biWidth
* 3;
150 unsigned char *pBuf
= (unsigned char *)malloc(bmpInfo
.bmiHeader
.biSizeImage
);
151 for(int y
=0; y
< CAP_HEIGHT
; y
++ )
153 for(int x
=0; x
< CAP_WIDTH
; x
++)
155 pBuf
[y
* CAP_WIDTH
* 3 + x
* 3 ] = 0;
156 pBuf
[y
* CAP_WIDTH
* 3 + x
* 3 + 1 ] = (unsigned char)weight
[y
* CAP_WIDTH
+ x
];
157 pBuf
[y
* CAP_WIDTH
* 3 + x
* 3 + 2] = 0;
161 bmpInfo
.bmiHeader
.biCompression
= BI_RGB
;
162 bmpInfo
.bmiHeader
.biPlanes
= 1;
163 bmpInfo
.bmiHeader
.biBitCount
= 24;
165 bmpFileHeader
.bfReserved1
=0;
166 bmpFileHeader
.bfReserved2
=0;
167 bmpFileHeader
.bfSize
=sizeof(BITMAPFILEHEADER
)+sizeof(BITMAPINFOHEADER
)+bmpInfo
.bmiHeader
.biSizeImage
;
168 bmpFileHeader
.bfType
= MakeIntelWord('M','B');
169 bmpFileHeader
.bfOffBits
=sizeof(BITMAPFILEHEADER
)+sizeof(BITMAPINFOHEADER
);
173 fp
= fopen(fileName
,"wb");
174 fwrite(&bmpFileHeader
,sizeof(BITMAPFILEHEADER
),1,fp
);
175 fwrite(&bmpInfo
.bmiHeader
,sizeof(BITMAPINFOHEADER
),1,fp
);
176 fwrite(pBuf
,bmpInfo
.bmiHeader
.biSizeImage
,1,fp
);
185 int CAtmoZoneDefinition::LoadGradientFromBitmap(char *pszBitmap
)
187 // transform 256 color image (gray scale!)
188 // into m_basicWeight or use the GREEN value of a 24bit image!
189 // channel of a true color bitmap!
191 BITMAPFILEHEADER bmpFileHeader
;
194 ATMO_LOAD_GRADIENT_FILENOTFOND
195 #define ATMO_LOAD_GRADIENT_OK 0
196 #define ATMO_LOAD_GRADIENT_FAILED_SIZE 1
197 #define ATMO_LOAD_GRADIENT_FAILED_HEADER 2
201 FILE *bmp
= fopen(pszBitmap
, "rb");
203 return ATMO_LOAD_GRADIENT_FILENOTFOND
;
205 if(fread(&bmpFileHeader
, sizeof(BITMAPFILEHEADER
), 1, bmp
) != 1)
208 return ATMO_LOAD_GRADIENT_FAILED_SIZE
;
211 if(bmpFileHeader
.bfType
!= MakeIntelWord('M','B'))
214 return ATMO_LOAD_GRADIENT_FAILED_HEADER
;
217 if(fread(&bmpInfo
, sizeof(BITMAPINFO
), 1, bmp
) != 1)
220 return ATMO_LOAD_GRADIENT_FAILED_SIZE
;
223 if(bmpInfo
.bmiHeader
.biCompression
!= BI_RGB
)
226 return ATMO_LOAD_GRADIENT_FAILED_FORMAT
;
228 if((bmpInfo
.bmiHeader
.biBitCount
!= 8) && (bmpInfo
.bmiHeader
.biBitCount
!= 24))
231 return ATMO_LOAD_GRADIENT_FAILED_FORMAT
;
234 int width
= bmpInfo
.bmiHeader
.biWidth
;
235 int height
= bmpInfo
.bmiHeader
.biHeight
;
236 ATMO_BOOL invertDirection
= (height
> 0);
237 height
= abs(height
);
238 if((width
!= CAP_WIDTH
) || (height
!= CAP_HEIGHT
))
241 return ATMO_LOAD_GRADIENT_FAILED_SIZE
;
244 fseek(bmp
, bmpFileHeader
.bfOffBits
, SEEK_SET
);
246 int imageSize
= width
* height
* bmpInfo
.bmiHeader
.biBitCount
/8;
248 unsigned char *pixelBuffer
= (unsigned char *)malloc(imageSize
);
249 if(fread(pixelBuffer
,imageSize
,1,bmp
) != 1)
252 return ATMO_LOAD_GRADIENT_FAILED_SIZE
;
255 if(bmpInfo
.bmiHeader
.biBitCount
== 8)
258 for(int y
=0;y
< CAP_HEIGHT
; y
++) {
259 if(invertDirection
) {
260 ydest
= (CAP_HEIGHT
- y
- 1);
264 for(int x
=0;x
< CAP_WIDTH
; x
++) {
265 // palette should be grey scale - so that index 0 is black and
266 // index 255 means white!
267 // everything else would produce funny results!
268 m_BasicWeight
[ydest
* CAP_WIDTH
+ x
] =
269 pixelBuffer
[y
* CAP_WIDTH
+ x
];
274 if(bmpInfo
.bmiHeader
.biBitCount
== 24)
277 for(int y
=0;y
< CAP_HEIGHT
; y
++) {
278 if(invertDirection
) {
279 ydest
= (CAP_HEIGHT
- y
- 1);
283 for(int x
=0;x
< CAP_WIDTH
; x
++) {
284 // use the green value as reference...
285 m_BasicWeight
[ydest
* CAP_WIDTH
+ x
] =
286 pixelBuffer
[y
* CAP_WIDTH
* 3 + (x
*3) + 1 ];
293 return ATMO_LOAD_GRADIENT_OK
;
297 void CAtmoZoneDefinition::UpdateWeighting(int *destWeight
,
299 int newEdgeWeightning
)
302 use the values in m_BasicWeight and newWeightning to
303 update the direct control array for the output thread!
307 for(int row
=0; row
< CAP_HEIGHT
; row
++) {
308 for(int col
=0; col
< CAP_WIDTH
; col
++) {
309 if ((WidescreenMode
== 1) && ((row
<= CAP_HEIGHT
/8) || (row
>= (7*CAP_HEIGHT
)/8)))
311 destWeight
[index
] = 0;
313 destWeight
[index
] = (int)(255.0 * (float)pow( ((float)m_BasicWeight
[index
])/255.0 , newEdgeWeightning
));
320 void CAtmoZoneDefinition::setZoneNumber(int num
)
325 int CAtmoZoneDefinition::getZoneNumber()