ximawbmp.cpp

来自「君正早期ucos系统(只有早期的才不没有打包成库),MPLAYER,文件系统,图」· C++ 代码 · 共 99 行

CPP
99
字号
/*
 * File:	ximawbmp.cpp
 * Purpose:	Platform Independent WBMP Image Class Loader and Writer
 * 12/Jul/2002 Davide Pizzolato - www.xdp.it
 * CxImage version 5.99c 17/Oct/2004
 */

#include "ximawbmp.h"

#if CXIMAGE_SUPPORT_WBMP

#include "ximaiter.h"

////////////////////////////////////////////////////////////////////////////////
bool CxImageWBMP::Decode(CxFile *hFile)
{
	if (hFile == NULL) return false;
  CImageIterator iter(this);
	WBMPHEADER wbmpHead;
	int linewidth;
  //try
  //{
	if (hFile->Read(&wbmpHead,sizeof(wbmpHead),1)==0)
	{
			printf("Not a WBMP\n");;
      goto EXIT;
  }
	if (wbmpHead.Type != 0)
	{
			printf("Unsupported WBMP type\n");
			goto EXIT;			
  }
	if (wbmpHead.ImageHeight==0 || wbmpHead.ImageWidth==0)
	{
			printf("Corrupted WBMP\n");
			goto EXIT;
	}

	Create(wbmpHead.ImageWidth, wbmpHead.ImageHeight, 1, CXIMAGE_FORMAT_WBMP);
	if (!IsValid())
	{
		printf("WBMP Create failed\n");
		goto EXIT;
	}
	SetGrayPalette();

	linewidth=(wbmpHead.ImageWidth+7)/8;
 
	iter.Upset();
    for (int y=0; y < wbmpHead.ImageHeight; y++){
		hFile->Read(iter.GetRow(),linewidth,1);
		iter.PrevRow();
    }
  /*
  } catch (char *message) {
	strncpy(info.szLastError,message,255);
	return FALSE;
  }*/
    return true;
EXIT:
	return FALSE;
}
////////////////////////////////////////////////////////////////////////////////
#if CXIMAGE_SUPPORT_ENCODE
////////////////////////////////////////////////////////////////////////////////
bool CxImageWBMP::Encode(CxFile * hFile)
{
	if (EncodeSafeCheck(hFile)) return false;

	//check format limits
	if ((head.biWidth>255)||(head.biHeight>255)||(head.biBitCount!=1)){
		strcpy(info.szLastError,"Can't save this image as WBMP");
		return false;
	}

	WBMPHEADER wbmpHead;
	wbmpHead.Type=0;
	wbmpHead.FixHeader=0;
	wbmpHead.ImageWidth=(BYTE)head.biWidth;
	wbmpHead.ImageHeight=(BYTE)head.biHeight;

    // Write the file header
	hFile->Write(&wbmpHead,sizeof(wbmpHead),1);
    // Write the pixels
	int linewidth=(wbmpHead.ImageWidth+7)/8;
    CImageIterator iter(this);
	iter.Upset();
    for (int y=0; y < wbmpHead.ImageHeight; y++){
		hFile->Write(iter.GetRow(),linewidth,1);
		iter.PrevRow();
    }
	return true;
}
////////////////////////////////////////////////////////////////////////////////
#endif // CXIMAGE_SUPPORT_ENCODE
////////////////////////////////////////////////////////////////////////////////
#endif // CXIMAGE_SUPPORT_WBMP

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?