AtmoZoneDefinition.cpp
资源名称:vlc-1.0.5.zip [点击查看]
上传用户:kjfoods
上传日期:2020-07-06
资源大小:29949k
文件大小:6k
源码类别:
midi
开发平台:
Unix_Linux
- #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;
- }
- #ifdef _ATMO_VLC_PLUGIN_
- if(bmpFileHeader.bfType != VLC_TWOCC('M','B'))
- #else
- if(bmpFileHeader.bfType != MakeWord('M','B'))
- #endif
- {
- 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_WIDTH; col++) {
- if ((WidescreenMode == 1) && ((row <= CAP_HEIGHT/8) || (row >= (7*CAP_HEIGHT)/8)))
- {
- destWeight[index] = 0;
- } else {
- destWeight[index] = (int)(255.0 * (float)pow( ((float)m_BasicWeight[index])/255.0 , newEdgeWeightning));
- }
- index++;
- }
- }
- }
- void CAtmoZoneDefinition::setZoneNumber(int num)
- {
- m_zonenumber = num;
- }
- int CAtmoZoneDefinition::getZoneNumber()
- {
- return m_zonenumber;
- }