PcxLoad.cpp
上传用户:yatsl7111
上传日期:2007-01-08
资源大小:1433k
文件大小:25k
- #include "stdafx.h"
- #include "PcxDeclare.h"
- #include "PcxModule.h"
- #include "FuncFromYz.h"
- #include "PcxError.h"
- #include "PcxPalette.h"
- #define PCX_BUF_MAX 124
- #define DIBSCANLINE_WIDTHBYTES(bits) (((bits)+31)/32*4)
- EXERESULT api_Isee_Check_Command_Load(INFOSTR *pInfo)
- {
- // 检验入口参数是否符合接口定义
- ASSERT(pInfo->result == ER_EMPTY);
- ASSERT(::strlen(pInfo->filename));
- // 此时,该文件必需是一个已存在的、有效的PCX文件,并且数据包中
- // 含有该文件的信息(imginfo结构中)
- ASSERT(pInfo->state == PKST_PASSINFO);
- ASSERT(pInfo->imginfo.imgformat == IMF_PCX);
- ASSERT(pInfo->pImgInfo == NULL);
- // 必需设置标准图像格式信息
- ASSERT(pInfo->sDIBInfo.bmi.biSize == sizeof(BITMAPINFOHEADER));
- ASSERT(pInfo->pLineAddr != NULL);
- ASSERT(pInfo->_pbdata != NULL);
- return ER_SUCCESS;
- };
- EXERESULT Isee_Api_Access_Progress(INFOSTR *pInfo, int MaxPreg, int CurrentPreg)
- {
- if (pInfo->fpProgress)
- {
- if ((*pInfo->fpProgress)(MaxPreg, CurrentPreg))
- { // 如果进度函数返回1,则说明用户想中断操作,返回。
- pInfo->result = ER_USERBREAK;
- return ER_USERBREAK;
- }
- }
- return ER_SUCCESS;
- };
- void Pcx_Access_Progress(INFOSTR *pInfo, int MaxPreg = 0, int CurrentPreg = 0)
- {
- if (pInfo->fpProgress)
- {
- if ((*pInfo->fpProgress)(100, 6))
- { // 如果进度函数返回1,则说明用户想中断操作,返回(throw)。
- pInfo->result = ER_USERBREAK;//仅此函数更改返回值
- ApiThrowMyExce(ENO_USERBREAK);//throw 跳到 catch
- }
- }
- }
- BOOL Success(int tag_param)
- {
- return (tag_param == ER_SUCCESS);
- };
- EXERESULT Pcx_Load_sub_1(INFOSTR * pInfo, LPCSTR lpData, int iDataSize);
- EXERESULT Pcx_Load_sub_4(INFOSTR * pInfo, LPCSTR lpData, int iDataSize);
- EXERESULT Pcx_Load_sub_8(INFOSTR * pInfo, LPCSTR lpData, int iDataSize);
- EXERESULT Pcx_Load_sub_24(INFOSTR * pInfo, LPCSTR lpData, int iDataSize);
- void PcxFitPinfo(INFOSTR * pInfo)
- {
- HGLOBAL p = (HGLOBAL)pInfo->pImgInfo;
- // ::GlobalUnlock(p);
- if(p == NULL)return;
- ::GlobalFree(p);
- pInfo->pImgInfo = NULL;
- }
- void Pcx_Load_From_File(INFOSTR * pInfo)
- {
- EXERESULT rt = ER_SUCCESS;//希望能顺利执行!^_^
- rt = api_Isee_Check_Command_Load(pInfo);
- if(! Success(rt))
- {
- pInfo->result = rt;
- return;
- }
- unsigned long bitcount = 0;
- ENUM_EXCE_NO no = ENO_OK;
- HANDLE hf = NULL;
- DWORD filesize = 0;
- HANDLE hMapping = NULL;
- LPSTR lpData = NULL;
- const char * pcStrFileName = pInfo->filename;
- rt = Isee_Api_Access_Progress(pInfo,100,100);//rt 已设
- filesize = (DWORD)pInfo->imginfo.filesize;
- try
- {
- hf = CreateFile(pcStrFileName,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
- if( hf == INVALID_HANDLE_VALUE)
- {
- rt = ER_FILERWERR;
- ApiThrowMyExce(ENO_CREATE_FILE_EX);
- }
- hMapping = CreateFileMapping(hf,NULL,PAGE_READONLY,0,filesize,NULL);
- if(hMapping == NULL)
- {
- rt = ER_MEMORYERR;
- ApiThrowMyExce(ENO_CREATE_MAP_EX);
- }
-
- lpData = (LPSTR)MapViewOfFile(hMapping,FILE_MAP_READ,0,0,0);
- if(lpData == NULL)
- {
- rt = ER_MEMORYERR;
- ApiThrowMyExce(ENO_MAP_VIEW_EX);
- }
- PcxDoWithPalette(pInfo, lpData,filesize);
- bitcount = pInfo->imginfo.bitcount;
- switch(bitcount)
- {
- case 1:
- rt = Pcx_Load_sub_1(pInfo, lpData, filesize);
- break;
- case 4:
- rt = Pcx_Load_sub_4(pInfo, lpData, filesize);
- break;
- case 8:
- rt = Pcx_Load_sub_8(pInfo, lpData, filesize);
- break;
- case 24:
- rt = Pcx_Load_sub_24(pInfo, lpData, filesize);
- break;
- }
- }
- catch(CMyException myExce)
- {
- no = myExce.GetNo();
- CString str;
- }
- switch(no)
- {
- default:
- case ENO_OK:
- case ENO_USERBREAK:
- //rt 已设
- rt = pInfo->result;
- UnmapViewOfFile(lpData);
- case ENO_MAP_VIEW_EX:
- CloseHandle(hMapping);
- case ENO_CREATE_MAP_EX:
- CloseHandle(hf);
- case ENO_CREATE_FILE_EX:
- rt = ER_FILERWERR;
- }
- Isee_Api_Access_Progress(pInfo,100,100);//rt 已设
- //***************************
- PcxFitPinfo(pInfo);
- pInfo->state = PKST_INFOANDBITS;
- pInfo->modify = 0;
- pInfo->result = ER_SUCCESS;
- //不允许中断
- return;
- };
- EXERESULT Pcx_Load_sub_4(INFOSTR * pInfo, LPCSTR lpData, int iDataSize)
- {
- const PCXFILEHEADER *const pcxFileHead=(const PCXFILEHEADER *) lpData;//文件头
- LPCSTR const pImage = lpData + sizeof(PCXFILEHEADER);//图像数据、读取起点
- const struct PcxPalette * const lpPalette = (struct PcxPalette * )pcxFileHead->byPalette;//调色板
- //from yz
- DWORD imgheight = pInfo->imginfo.height; // 图像的高度
- DWORD imgwidth = pInfo->imginfo.width; // 图像的宽度
- DWORD dwDestFormat = _get_desformat(pInfo);//目标格式
- DWORD dwPcxOneScanLineSize = pcxFileHead->wLineBytes;// 每一扫描行的宽度(in byte)
- DWORD dwPcxLineSizeCount = pcxFileHead->wLineBytes * pcxFileHead->byPlanes;
- DWORD dwImageHeightCount, dwImageWidthCount;//用于计数
- //
- char * const pScanLineBuf = (char *)new char[dwPcxLineSizeCount + 16];//16 for 安全
- //解压缓冲区
- if(pScanLineBuf == NULL)
- ApiMyThrowMem();
- WORD * pLineDest = NULL;//目标行首地址、
- WORD * pLineSource = NULL;//源行首地址、
- pLineSource = (WORD *)pScanLineBuf;//源....
- // WORD * pPixDest = NULL;//目标地址、(目标地址分别定义)
- BYTE ch1,ch2;
- char * pScan = NULL;////解压指针
- DWORD ScanLinePoint = 0;//解压计数
- // 以各种格式的调色板数据
- //..放在循环外、以空间换取时间
- WORD descol555[16];
- WORD descol565[16];
- DWORD descol888[16];
- WORD * pDesPixAddr555 = NULL;
- WORD * pDesPixAddr565 = NULL;
- BYTE * pDesPixAddr24 = NULL;
- DWORD * pDesPixAddr888 = NULL;
- int i;
- switch(dwDestFormat) // 标准图像格式(目标格式)
- {
- case DF_16_555:
- {
- for (i=0;i<16;i++) // 初始化色素颜色数据
- descol555[i] = _cnv_rgb_to_555(lpPalette[i].byRed, lpPalette[i].byGreen, lpPalette[i].byBlue);
- }
- break;
- case DF_16_565:
- {
- for (i=0;i<16;i++) // 初始化色素颜色数据
- descol565[i] = _cnv_rgb_to_565(lpPalette[i].byRed, lpPalette[i].byGreen, lpPalette[i].byBlue);
- }
- break;
- case DF_32:
- {
- for (i=0;i<16;i++) // 初始化色素颜色数据
- descol888[i] = _cnv_rgb_to_888(lpPalette[i].byRed, lpPalette[i].byGreen, lpPalette[i].byBlue);
- }
- break;
- default:
- break;
- }
- // int i, j;//, isou;
- // DWORD dwPCXLineSizeCount;
- //char * pSrc = ;
- char k;//解压计数
-
- // char *lpPlane0,*lpPlane1,*lpPlane2,*lpPlane3;//解码指针
- BYTE byPlane0,byPlane1,byPlane2,byPlane3;//码值
- // BYTE byIndex1,byIndex2,byIndex3,byIndex4;//解码值
- // BYTE byIndex5,byIndex6,byIndex7,byIndex8;//解码值
- LPCSTR pSrc = pImage;//读取起点//类似流(?):-)
- for(dwImageHeightCount=0;dwImageHeightCount<imgheight;dwImageHeightCount++)//Pcx 总是正向
- {
- pScan = (char *)(pScanLineBuf);
- ScanLinePoint = 0;
- //while(ScanLinePoint <dwPCXScanLineSize&&!feof(f1))//base 0;Index
- while(ScanLinePoint <dwPcxLineSizeCount)//base 0;Index
- {
- if((pSrc - lpData)>=iDataSize)break;
- ch1=(*pSrc ++)&0xFF;//fgetc() return int;
- if((ch1&0xc0)==0xC0)
- {
- k = ch1&0x3F;
- ch2 = (*pSrc ++)&0xFF;
- while(k--)//&&ScanLinePoint<dwPCXScanLineSize)
- {
- pScan[ScanLinePoint++] = ch2;//
- }
- }
- else
- {
- pScan[ScanLinePoint++] = ch1;
- }
- }//while (pcxLineWidth)//解压一行
- pLineDest = (WORD*)pInfo->pLineAddr[dwImageHeightCount];//当前目标 (行)
- //源在pLineBuf
- pLineSource = (WORD *)pScanLineBuf;//源....
- //源地址总是不变
- //目标 都在此初始化
- pDesPixAddr555 = (WORD * )pLineDest;
- pDesPixAddr565 = (WORD * )pLineDest;
- pDesPixAddr24 = (BYTE * )pLineDest;
- pDesPixAddr888 = (DWORD * )pLineDest;
- dwImageWidthCount = 0;
- for(ScanLinePoint=0;ScanLinePoint<dwPcxOneScanLineSize;ScanLinePoint++)//解码一行
- {
- //****************************************//read 1 byte;
- byPlane0 = *((char *)pScanLineBuf+dwPcxOneScanLineSize*0+ScanLinePoint);
- byPlane1 = *((char *)pScanLineBuf+dwPcxOneScanLineSize*1+ScanLinePoint);
- byPlane2 = *((char *)pScanLineBuf+dwPcxOneScanLineSize*2+ScanLinePoint);
- byPlane3 = *((char *)pScanLineBuf+dwPcxOneScanLineSize*3+ScanLinePoint);
- //****************************************
- //point 1-2 in 1st byte
- int i;
- BYTE byFlag = 1; //掩码
- BYTE byIndex;
- for(i = 7; i>=0;i--)//(高位在前)
- {
- byFlag = 1<<i;
-
- byIndex=0x00;
- byIndex |=((byPlane3 & byFlag)? 0x08:byIndex);
- byIndex |=((byPlane2 & byFlag)? 0x04:byIndex);
- byIndex |=((byPlane1 & byFlag)? 0x02:byIndex);
- byIndex |=((byPlane0 & byFlag)? 0x01:byIndex);
- {
- }
-
- switch(dwDestFormat) // 标准图像格式(目标格式)
- {
- case DF_16_555:
- {
- if(dwImageWidthCount < imgwidth)
- {
- *pDesPixAddr555++ = descol555[byIndex];
- dwImageWidthCount ++;
- }
- break;
- }
- case DF_16_565:
- {
- if(dwImageWidthCount < imgwidth)
- {
- *pDesPixAddr565++ = descol565[byIndex];
- dwImageWidthCount ++;
- }
- break;
- }
- case DF_24:
- {
- if(dwImageWidthCount < imgwidth)
- {
- *pDesPixAddr24++ = lpPalette[byIndex].byBlue;
- *pDesPixAddr24++ = lpPalette[byIndex].byGreen;
- *pDesPixAddr24++ = lpPalette[byIndex].byRed;
- }
- break;
- }
- case DF_32:
- {
- if(dwImageWidthCount < imgwidth)
- {
- *pDesPixAddr888++ = descol888[byIndex];
- dwImageWidthCount ++;
- }
- break;
- }
- case DF_NULL:
- default:
- ASSERT(FALSE);
- pInfo->result = ER_ILLCOMM;
- return ER_ILLCOMM;
- break;
- }//switch(dwDestFormat)
- }//for 每8个像素
- }//for dwScanLineSize;
- }//for imageheight
- delete pScanLineBuf;
- return ER_SUCCESS;
- };
- EXERESULT Pcx_Load_sub_8(INFOSTR * pInfo, LPCSTR lpData, int iDataSize)
- {
- const PCXFILEHEADER *const pcxFileHead=(const PCXFILEHEADER *) lpData;//文件头
- LPCSTR const pImage = lpData + sizeof(PCXFILEHEADER);//图像数据、读取起点
- const struct PcxPalette * lpPalette = NULL;//调色板
- DWORD tempPaletteCount;
- GetPcxPalette((struct PcxImgInfo *)pInfo->pImgInfo, (void ** )&lpPalette, &tempPaletteCount);
- ASSERT(lpPalette != NULL);
- ASSERT(tempPaletteCount == 256);
- //from yz
- DWORD imgheight = pInfo->imginfo.height; // 图像的高度
- DWORD imgwidth = pInfo->imginfo.width; // 图像的宽度
- DWORD dwDestFormat = _get_desformat(pInfo);//目标格式
- DWORD dwPcxOneScanLineSize = pcxFileHead->wLineBytes;// 每一扫描行的宽度(in byte)
- DWORD dwPcxLineSizeCount = pcxFileHead->wLineBytes * pcxFileHead->byPlanes;
- DWORD dwImageHeightCount, dwImageWidthCount;//用于计数
- //
- char * const pScanLineBuf = (char *)new char[dwPcxLineSizeCount + 16];//16 for 安全
- //解压缓冲区
- if(pScanLineBuf == NULL)
- ApiMyThrowMem();
- WORD * pLineDest = NULL;//目标行首地址、
- BYTE * pLineSource = NULL;//源行首地址、
- pLineSource = (BYTE *)pScanLineBuf;//源....
- // WORD * pPixDest = NULL;//目标地址、(目标地址 依格式分别定义)
- BYTE ch1,ch2;
- char * pScan = NULL;////解压指针
- DWORD ScanLinePoint = 0;//解压计数
- // 以各种格式的调色板数据
- //..放在循环外、以空间换取时间
- //WORD descol555[256];
- //WORD descol565[256];
- //DWORD descol888[256];
- //<节约一下吧 ^_^ >
- WORD * descol555 = NULL;
- WORD * descol565 = NULL;
- DWORD * descol888 = NULL;
- WORD * pDesPixAddr555 = NULL;
- WORD * pDesPixAddr565 = NULL;
- BYTE * pDesPixAddr24 = NULL;
- DWORD * pDesPixAddr888 = NULL;
- int i;
- switch(dwDestFormat) // 标准图像格式(目标格式)
- {
- case DF_16_555:
- {
- if(descol555 == NULL)
- ApiMyThrowMem();
- descol555 = new WORD[256];
- for (i=0;i<256;i++) // 初始化色素颜色数据
- descol555[i] = _cnv_rgb_to_555(lpPalette[i].byRed, lpPalette[i].byGreen, lpPalette[i].byBlue);
- }
- break;
- case DF_16_565:
- {
- descol565 = new WORD[256];
- if(descol565 == NULL)
- ApiMyThrowMem();
- for (i=0;i<256;i++) // 初始化色素颜色数据
- descol565[i] = _cnv_rgb_to_565(lpPalette[i].byRed, lpPalette[i].byGreen, lpPalette[i].byBlue);
- }
- break;
- case DF_32:
- {
- descol888 = new DWORD[256];
- if(descol888 == NULL)
- ApiMyThrowMem();
- for (i=0;i<256;i++) // 初始化色素颜色数据
- descol888[i] = _cnv_rgb_to_888(lpPalette[i].byRed, lpPalette[i].byGreen, lpPalette[i].byBlue);
- }
- break;
- default:
- break;
- }
- char k;//解压计数
-
- LPCSTR pSrc = pImage;//读取起点//类似流(?):-)
- for(dwImageHeightCount=0;dwImageHeightCount<imgheight; dwImageHeightCount++)//Pcx 总是正向
- {
- pScan = (char *)(pScanLineBuf);
- ScanLinePoint = 0;
- //while(ScanLinePoint <dwPCXScanLineSize&&!feof(f1))//base 0;Index
- while(ScanLinePoint <dwPcxLineSizeCount)//base 0;Index
- {
- if((pSrc - lpData)>=iDataSize)break;
- ch1=(*pSrc ++)&0xFF;//fgetc() return int;
- if((ch1&0xc0)==0xC0)
- {
- k = ch1&0x3F;
- ch2 = (*pSrc ++)&0xFF;
- while(k--)//&&ScanLinePoint<dwPCXScanLineSize)
- {
- pScan[ScanLinePoint++] = ch2;//
- }
- }
- else
- {
- pScan[ScanLinePoint++] = ch1;
- }
- }//while (pcxLineWidth)//解压一行
- pLineDest = (WORD*)pInfo->pLineAddr[dwImageHeightCount];//当前目标 (行)
- //源在pLineBuf
- pLineSource = (BYTE *)pScanLineBuf;//源....
- //源地址总是不变
- //目标 都在此初始化
- pDesPixAddr555 = (WORD * )pLineDest;
- pDesPixAddr565 = (WORD * )pLineDest;
- pDesPixAddr24 = (BYTE * )pLineDest;
- pDesPixAddr888 = (DWORD * )pLineDest;
- dwImageWidthCount = 0;
- BYTE byIndex = 0;
- for(dwImageWidthCount = 0;dwImageWidthCount<imgwidth;dwImageWidthCount++)//解码一行
- {
- //****************************************//read 1 byte;
- byIndex = *((BYTE *)pLineSource + dwImageWidthCount);
-
- switch(dwDestFormat) // 标准图像格式(目标格式)
- {
- case DF_16_555:
- {
- if(dwImageWidthCount < imgwidth)
- {
- *pDesPixAddr555++ = descol555[byIndex];
- }
- break;
- }
- case DF_16_565:
- {
- if(dwImageWidthCount < imgwidth)
- {
- *pDesPixAddr565++ = descol565[byIndex];
- }
- break;
- }
-
- case DF_24:
- {
- if(dwImageWidthCount < imgwidth)
- {
- *pDesPixAddr24++ = lpPalette[byIndex].byBlue;
- *pDesPixAddr24++ = lpPalette[byIndex].byGreen;
- *pDesPixAddr24++ = lpPalette[byIndex].byRed;
- }
- break;
- }
- case DF_32:
- {
- if(dwImageWidthCount < imgwidth)
- {
- *pDesPixAddr888 = descol888[byIndex];
- pDesPixAddr888 ++;
- }
- break;
- }
- case DF_NULL:
- default:
- ASSERT(FALSE);
- pInfo->result = ER_ILLCOMM;
- return ER_ILLCOMM;
- break;
- }//switch(dwDestFormat)
- }//for dwScanLineSize;
- }//for imageheight
- delete pScanLineBuf;
- switch(dwDestFormat) // 标准图像格式(目标格式)
- {
- case DF_16_555:
- {
- if(descol555 != NULL)
- delete descol555;
- }
- break;
- case DF_16_565:
- {
- if(descol565 != NULL)
- delete descol565;
- }
- break;
- case DF_32:
- {
- if(descol888 != NULL)
- delete descol888;
- }
- break;
- default:
- break;
- }
- return ER_SUCCESS;
- };
- EXERESULT Pcx_Load_sub_24(INFOSTR * pInfo, LPCSTR lpData, int iDataSize)
- {
- const PCXFILEHEADER *const pcxFileHead=(const PCXFILEHEADER *) lpData;//文件头
- LPCSTR const pImage = lpData + sizeof(PCXFILEHEADER);//图像数据、读取起点
- // const struct PcxPalette * const lpPalette = (struct PcxPalette * )pcxFileHead->byPalette;//调色板
- //from yz
- DWORD imgheight = pInfo->imginfo.height; // 图像的高度
- DWORD imgwidth = pInfo->imginfo.width; // 图像的宽度
- DWORD dwDestFormat = _get_desformat(pInfo);//目标格式
- DWORD dwPcxOneScanLineSize = pcxFileHead->wLineBytes;// 每一扫描行的宽度(in byte)
- DWORD dwPcxLineSizeCount = pcxFileHead->wLineBytes * pcxFileHead->byPlanes;
- DWORD dwImageHeightCount, dwImageWidthCount;//用于计数
- //
- char * const pScanLineBuf = (char *)new char[dwPcxLineSizeCount + 16];//16 for 安全
- //解压缓冲区
- if(pScanLineBuf == NULL)
- ApiMyThrowMem();
- WORD * pLineDest = NULL;//目标行首地址、
- WORD * pLineSource = NULL;//源行首地址、
- pLineSource = (WORD *)pScanLineBuf;//源....
- // WORD * pPixDest = NULL;//目标地址、(目标地址分别定义)
- BYTE ch1,ch2;
- char * pScan = NULL;////解压指针
- DWORD ScanLinePoint = 0;//解压计数
- WORD * pDesPixAddr555 = NULL;
- WORD * pDesPixAddr565 = NULL;
- BYTE * pDesPixAddr24 = NULL;
- DWORD * pDesPixAddr888 = NULL;
- // int i;
- // int i, j;//, isou;
- // DWORD dwPCXLineSizeCount;
- //char * pSrc = ;
- char k;//解压计数
-
- // char *lpPlane0,*lpPlane1,*lpPlane2,*lpPlane3;//解码指针
- BYTE byPlane0,byPlane1,byPlane2;//,byPlane3;//码值
- // BYTE byIndex1,byIndex2,byIndex3,byIndex4;//解码值
- // BYTE byIndex5,byIndex6,byIndex7,byIndex8;//解码值
- LPCSTR pSrc = pImage;//读取起点//类似流(?):-)
- for(dwImageHeightCount=0;dwImageHeightCount<imgheight;dwImageHeightCount++)//Pcx 总是正向
- {
- pScan = (char *)(pScanLineBuf);
- ScanLinePoint = 0;
- //while(ScanLinePoint <dwPCXScanLineSize&&!feof(f1))//base 0;Index
- while(ScanLinePoint <dwPcxLineSizeCount)//base 0;Index
- {
- if((pSrc - lpData)>=iDataSize)break;
- ch1=(*pSrc ++)&0xFF;//fgetc() return int;
- if((ch1&0xc0)==0xC0)
- {
- k = ch1&0x3F;
- ch2 = (*pSrc ++)&0xFF;
- while(k--)//&&ScanLinePoint<dwPCXScanLineSize)
- {
- pScan[ScanLinePoint++] = ch2;//
- }
- }
- else
- {
- pScan[ScanLinePoint++] = ch1;
- }
- }//while (pcxLineWidth)//解压一行
- pLineDest = (WORD*)pInfo->pLineAddr[dwImageHeightCount];//当前目标 (行)
- //源在pLineBuf
- pLineSource = (WORD *)pScanLineBuf;//源....
- //源地址总是不变
- //目标 都在此初始化
- pDesPixAddr555 = (WORD * )pLineDest;
- pDesPixAddr565 = (WORD * )pLineDest;
- pDesPixAddr24 = (BYTE * )pLineDest;
- pDesPixAddr888 = (DWORD * )pLineDest;
- dwImageWidthCount = 0;
- for(ScanLinePoint=0;ScanLinePoint<dwPcxOneScanLineSize;ScanLinePoint++)//解码一行
- {
- //****************************************//read 1 byte;
- byPlane0 = *((char *)pScanLineBuf+dwPcxOneScanLineSize*0+ScanLinePoint);
- byPlane1 = *((char *)pScanLineBuf+dwPcxOneScanLineSize*1+ScanLinePoint);
- byPlane2 = *((char *)pScanLineBuf+dwPcxOneScanLineSize*2+ScanLinePoint);
-
- switch(dwDestFormat) // 标准图像格式(目标格式)
- {
- case DF_16_555:
- {
- if(dwImageWidthCount < imgwidth)
- {
- *pDesPixAddr555++ = _cnv_rgb_to_555(byPlane0, byPlane1, byPlane2);
- dwImageWidthCount ++;
- }
- break;
- }
- case DF_16_565:
- {
- if(dwImageWidthCount < imgwidth)
- {
- *pDesPixAddr565++ = _cnv_rgb_to_565(byPlane0, byPlane1, byPlane2);
- dwImageWidthCount ++;
- }
-
- break;
- }
-
- case DF_24:
- {
- if(dwImageWidthCount < imgwidth)
- {
- *pDesPixAddr24++ = byPlane0;
- *pDesPixAddr24++ = byPlane1;
- *pDesPixAddr24++ = byPlane2;
- }
- break;
- }
- case DF_32:
- {
- if(dwImageWidthCount < imgwidth)
- {
- *pDesPixAddr888++ = _cnv_rgb_to_888(byPlane0, byPlane1, byPlane2);
- dwImageWidthCount ++;
- }
- break;
- }
- case DF_NULL:
- default:
- ASSERT(FALSE);
- pInfo->result = ER_ILLCOMM;
- return ER_ILLCOMM;
- break;
- }//switch(dwDestFormat)
- }//for dwScanLineSize;
- }//for imageheight
- delete pScanLineBuf;
- return ER_SUCCESS;
- };
- EXERESULT Pcx_Load_sub_1(INFOSTR * pInfo, LPCSTR lpData, int iDataSize)
- {
- const PCXFILEHEADER *const pcxFileHead=(const PCXFILEHEADER *) lpData;
- LPCSTR const pImage = lpData + sizeof(PCXFILEHEADER);//图像数据、读取起点
- struct PcxPalette * lpPalette = (struct PcxPalette * )pcxFileHead->byPalette;
- //?*** from yz
- DWORD imgheight = pInfo->imginfo.height; // 图像的高度
- DWORD imgwidth = pInfo->imginfo.width; // 图像的宽度
- DWORD pcxLineWidth = pcxFileHead->wLineBytes * pcxFileHead->byPlanes;
- DWORD scansize = pInfo->imginfo.linesize;// 每一扫描行的宽度(in byte)
- DWORD heigCount, widthCount;
- DWORD dwDestFormat = _get_desformat(pInfo);
- PBYTE pCurPixAddr;
- try
- {
- BYTE pix;
- BYTE ch1,ch2;
- char *pScanLineBuf = (char *)new char[pcxLineWidth + 16];//16 for 安全
- if(pScanLineBuf == NULL)
- ApiMyThrowMem();
- char * pScan = NULL;
- WORD * pLineDest = NULL;
- DWORD ScanLinePoint = 0;
- int i, j;//, isou;
- // DWORD dwPCXLineSizeCount;
- //char * pSrc = ;
- char k;
-
- // char *lpPlane0,*lpPlane1,*lpPlane2,*lpPlane3;
- // BYTE byPlane0,byPlane1,byPlane2,byPlane3;
- // char * pReceiveLine; //= new char[dwBmpLineSize];
- LPCSTR pSrc = pImage;//图像数据、读取起点
- for(heigCount=0;heigCount<imgheight;heigCount++)//Pcx 总是正向
- {
- pScan = (char *)(pScanLineBuf);
- ScanLinePoint = 0;
- //while(ScanLinePoint <dwPCXScanLineSize&&!feof(f1))//base 0;Index
- while(ScanLinePoint <pcxLineWidth)//base 0;Index
- {
- if((pSrc - lpData)>=iDataSize)break;
- ch1=(*pSrc ++)&0xFF;//fgetc() return int;
- if((ch1&0xc0)==0xC0)
- {
- k = ch1&0x3F;
- ch2 = (*pSrc ++)&0xFF;
- while(k--)//&&ScanLinePoint<dwPCXScanLineSize)
- {
- pScan[ScanLinePoint++] = ch2;//
- }
- }
- else
- {
- pScan[ScanLinePoint++] = ch1;
- }
- }//line
- pLineDest = (WORD*)pInfo->pLineAddr[heigCount];//目标
- //源在pLineBuf
- pCurPixAddr = (PBYTE)(pScanLineBuf); // 源图像当前行的第一个像素地址
- switch(dwDestFormat)//from yz
- {
- case DF_16_555:
- {
- // 以555位格式的调色板数据
- WORD descol555_0 = 0;
- WORD descol555_1 = 0;
-
- descol555_0 = _cnv_rgb_to_555(lpPalette[0].byRed, lpPalette[0].byGreen, lpPalette[0].byBlue);
- descol555_1 = _cnv_rgb_to_555(lpPalette[1].byRed, lpPalette[1].byGreen, lpPalette[1].byBlue);
- WORD *pDesPixAddr555;
-
- // 正向位图(top-down)
- {
- {
- //pCurPixAddr = pLineBuf; // 源图像当前行的第一个像素地址
- pDesPixAddr555 = (WORD *)pLineDest;// 目标缓冲区当前行第一个像素的地址
- for (widthCount=0;widthCount<imgwidth;widthCount+=8)
- {
- pix = *pCurPixAddr++;
-
- if ((imgwidth-widthCount)<8) // 结尾判断
- j = imgwidth-widthCount;
- else
- j = 8;
-
- for (i=0;i<j;i++)
- {
- if (((BYTE)(0x80>>i))&pix) // 此位被设置
- {
- *pDesPixAddr555++ = descol555_1;
- }
- else
- {
- *pDesPixAddr555++ = descol555_0;
- }
- }
- }
- }
- }
- }
- break;
- case DF_16_565:
- {
- // 以565位格式的调色板数据
- WORD descol565_0 = 0;
- WORD descol565_1 = 0;
-
- descol565_0 = _cnv_rgb_to_565(lpPalette[0].byRed, lpPalette[0].byGreen, lpPalette[0].byBlue);
- descol565_1 = _cnv_rgb_to_565(lpPalette[1].byRed, lpPalette[1].byGreen, lpPalette[1].byBlue);
-
- WORD *pDesPixAddr565;
-
- // 正向位图(top-down)
- {
- {
- pDesPixAddr565 = (WORD *)pLineDest;// 目标缓冲区当前行第一个像素的地址
- for (widthCount=0;widthCount<imgwidth;widthCount+=8)
- {
- pix = *pCurPixAddr++;
-
- if ((imgwidth-widthCount)<8) // 结尾判断
- j = imgwidth-widthCount;
- else
- j = 8;
-
- for (i=0;i<j;i++)
- {
- if (((BYTE)(0x80>>i))&pix) // 此位被设置
- {
- *pDesPixAddr565++ = descol565_1;
- }
- else
- {
- *pDesPixAddr565++ = descol565_0;
- }
- }
- }
- }
- }
- }
- break;
- case DF_24:
- {
- // 24位格式的调色板数据
- BYTE red0, red1, green0, green1, blue0, blue1;
-
- red0 = lpPalette[0].byRed;
- green0 = lpPalette[0].byGreen;
- blue0 = lpPalette[0].byBlue;
- red1 = lpPalette[1].byRed;
- green1 = lpPalette[1].byGreen;
- blue1 = lpPalette[1].byBlue;
-
- PBYTE pDesPixAddr24;
-
- // 正向位图(top-down)
- {
- {
- pDesPixAddr24 = (PBYTE)pLineDest;// 目标缓冲区当前行第一个像素的地址
- for (widthCount=0;widthCount<imgwidth;widthCount+=8)
- {
- pix = *pCurPixAddr++;
-
- if ((imgwidth-widthCount)<8) // 结尾判断
- j = imgwidth-widthCount;
- else
- j = 8;
-
- for (i=0;i<j;i++)
- {
- if (((BYTE)(0x80>>i))&pix) // 此位被设置
- {
- *pDesPixAddr24++ = blue1;
- *pDesPixAddr24++ = green1;
- *pDesPixAddr24++ = red1;
- }
- else
- {
- *pDesPixAddr24++ = blue0;
- *pDesPixAddr24++ = green0;
- *pDesPixAddr24++ = red0;
- }
- }
- }
- }
- }
- }
- break;
- case DF_32:
- {
- // 以888位格式的调色板数据
- DWORD descol888_0 = 0;
- DWORD descol888_1 = 0;
-
- descol888_0 = _cnv_rgb_to_888(lpPalette[0].byRed, lpPalette[0].byGreen, lpPalette[0].byBlue);
- descol888_1 = _cnv_rgb_to_888(lpPalette[1].byRed, lpPalette[1].byGreen, lpPalette[1].byBlue);
-
- DWORD *pDesPixAddr888;
-
- // 正向位图(top-down)
- {
- ///for (heigCount=0;heigCount<imgheight;heigCount++)
- {
- //pCurPixAddr = (PBYTE)(lpSou+heigCount*scansize); // 源图像当前行的第一个像素地址
- pDesPixAddr888 = (DWORD *)pLineDest;// 目标缓冲区当前行第一个像素的地址
- for (widthCount=0;widthCount<imgwidth;widthCount+=8)
- {
- pix = *pCurPixAddr++;
-
- if ((imgwidth-widthCount)<8) // 结尾判断
- j = imgwidth-widthCount;
- else
- j = 8;
-
- for (i=0;i<j;i++)
- {
- if (((BYTE)(0x80>>i))&pix) // 此位被设置
- {
- *pDesPixAddr888++ = descol888_1;
- }
- else
- {
- *pDesPixAddr888++ = descol888_0;
- }
- }
- }
- }
- }
- }
- break;
- case DF_NULL:
- default:
- ASSERT(FALSE);
- pInfo->result = ER_ILLCOMM;
- //return ;
- break;
- }//switch
- }//for height
- delete pScanLineBuf;
-
- }//try
- catch(...)
- {
- throw;
- }
- return ER_SUCCESS;
- };