本文整理汇总了C++中CxMemFile类的典型用法代码示例。如果您正苦于以下问题:C++ CxMemFile类的具体用法?C++ CxMemFile怎么用?C++ CxMemFile使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CxMemFile类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: strcpy
/**
* exports the image into a RGBA buffer, Useful for OpenGL applications.
* \param buffer: output memory buffer pointer. Must be NULL,
* the function allocates and fill the memory,
* the application must free the buffer, see also FreeMemory().
* \param size: output memory buffer size.
* \param bFlipY: direction of Y axis. default = false.
* \return true if everything is ok
*/
bool CxImage::Encode2RGBA(uint8_t * &buffer, int32_t &size, bool bFlipY)
{
if (buffer!=NULL){
strcpy(info.szLastError,"the buffer must be empty");
return false;
}
CxMemFile file;
file.Open();
if(Encode2RGBA(&file,bFlipY)){
buffer=file.GetBuffer();
size=file.Size();
return true;
}
return false;
}
示例2: strcpy
/**
* Saves to memory buffer the image in a specific format.
* \param buffer: output memory buffer pointer. Must be NULL,
* the function allocates and fill the memory,
* the application must free the buffer, see also FreeMemory().
* \param size: output memory buffer size.
* \param imagetype: file format, see ENUM_CXIMAGE_FORMATS
* \return true if everything is ok
*/
bool CxImage::Encode(BYTE * &buffer, long &size, DWORD imagetype)
{
if (buffer!=NULL){
strcpy(info.szLastError,"the buffer must be empty");
return false;
}
CxMemFile file;
file.Open();
if(Encode(&file,imagetype)){
buffer=file.GetBuffer();
size=file.Size();
return true;
}
return false;
}
示例3: IGEXCEPTION
//.........这里部分代码省略.........
int nSubLayerHeight = 0;
if (p_rcSubLayer)
{
// Encode sub-layer
nSubLayerWidth = p_rcSubLayer->right - p_rcSubLayer->left + 1;
nSubLayerHeight = p_rcSubLayer->bottom - p_rcSubLayer->top + 1;
cxSubLayer.Create (nSubLayerWidth, nSubLayerHeight, 24);
cxSubLayer.AlphaCreate (255);
BYTE *pLayerBits = NULL;
BYTE *pSubLayerBits = NULL;
for (int i = 0; i < nSubLayerHeight; i++)
{
pSubLayerBits = cxSubLayer.GetBits (i);
pLayerBits = pLayer->GetBits (p_rcSubLayer->top + i) + 3 * p_rcSubLayer->left;
::memcpy (pSubLayerBits, pLayerBits, nSubLayerWidth * 3);
}
BYTE *pLayerAlpha = NULL;
BYTE *pSubLayerAlpha = NULL;
for (int i = 0; i < nSubLayerHeight; i++)
{
pLayerAlpha = pLayer->AlphaGetPointer (p_rcSubLayer->left, p_rcSubLayer->top + i);
pSubLayerAlpha = cxSubLayer.AlphaGetPointer (0, i);
::memcpy (pSubLayerAlpha, pLayerAlpha, nSubLayerWidth);
}
pEncodingLayer = &cxSubLayer;
int nSubLayerSectionIndex = findLayerSectionIndex (&igHeader, pLayerSections, nSubLayerOwnerId, bIsSubLayerOwner);
if (nSubLayerSectionIndex < 0)
throw IGEXCEPTION (CxImageIGException, "EncodeLayer", "findLayerSectionIndex failed");
pLayerSections [nSubLayerSectionIndex].pnSubLayers [pLayerSections [nSubLayerSectionIndex].nSubLayers++] = nLayerSectionIndex;
}
ProgressSetRange (pLayer->GetHeight(), 0);
ProgressSetMessage (L"Encoding layer...");
// fill layer offset and size
pLayerSections [nLayerSectionIndex].nSubLayers = 0;
pLayerSections [nLayerSectionIndex].ptOffset.x = p_rcSubLayer ? p_rcSubLayer->left : pLayer->info.xOffset;
pLayerSections [nLayerSectionIndex].ptOffset.y = p_rcSubLayer ? p_rcSubLayer->top : pLayer->info.yOffset;
pLayerSections [nLayerSectionIndex].ptSize.x = p_rcSubLayer ? p_rcSubLayer->right - p_rcSubLayer->left + 1 : pLayer->GetWidth();
pLayerSections [nLayerSectionIndex].ptSize.y = p_rcSubLayer ? p_rcSubLayer->bottom - p_rcSubLayer->top + 1 : pLayer->GetHeight();
if (nLayerSectionIndex == igHeader.nNbLayers)
pLayerSections [nLayerSectionIndex].commonHeader.nSectionId = (BYTE)igHeader.nNbSections;
pLayerSections [nLayerSectionIndex].commonHeader.nId = nLayerIdx;
pLayerSections [nLayerSectionIndex].commonHeader.eSectionType = IGSECTION_LAYER;
// set byte offset
if (igHeader.nNbSections == 0)
pLayerSections [nLayerSectionIndex].commonHeader.nFirstByteOffset = sizeof (IGHEADER) + sizeof (IGSECTIONHEADER_LAYER) * CXIMAGEIG_MAX_NBLAYERS + sizeof (IGSECTIONHEADER_SELECTION) * CXIMAGEIG_MAX_NBSELECTIONS;
else
pLayerSections [nLayerSectionIndex].commonHeader.nFirstByteOffset = findSectionFirstByteOffset (&igHeader, pLayerSections, pSelectionSections, pLayerSections [nLayerSectionIndex].commonHeader.nSectionId);
igHeader.nNbLayers = nLayerSectionIndex + 1;
if (igHeader.nNbSelections == 0)
{
igHeader.nNbSections = pLayerSections [nLayerSectionIndex].commonHeader.nSectionId + 1;
igHeader.nNbSelections = igHeader.nNbSections - igHeader.nNbLayers;
}
else
{
if (pSelectionSections [igHeader.nNbSelections - 1].commonHeader.nSectionId == pLayerSections [nLayerSectionIndex].commonHeader.nSectionId + 1)
igHeader.nNbSections = igHeader.nNbSelections + igHeader.nNbLayers;
else
{
igHeader.nNbSections = pLayerSections [nLayerSectionIndex].commonHeader.nSectionId + 1;
igHeader.nNbSelections = igHeader.nNbSections - igHeader.nNbLayers;
}
}
// write layer pixels
if (!file.Seek (pLayerSections [nLayerSectionIndex].commonHeader.nFirstByteOffset, SEEK_SET))
throw IGEXCEPTION (CxImageIGException, "EncodeLayer", "file.Seek failed");
// set max JPEG quality
float fCurQuality = pEncodingLayer->GetJpegQualityF();
pEncodingLayer->SetJpegQualityF (100.0f);
// JPEG encoding
BYTE *pBuf = new BYTE [CXIMAGEIG_INIT_LAYERSIZE];
CxMemFile memFile (pBuf, CXIMAGEIG_INIT_LAYERSIZE);
if (!pEncodingLayer->Encode (&memFile, CXIMAGEIG_LAYERFORMAT))
throw IGEXCEPTION (CxImageIGException, "EncodeLayer", "pEncodingLayer->Encode failed");
BYTE *pBufImg = memFile.GetBuffer();
long nSizeBufImg = memFile.Tell();
// reset JPEG quality
pEncodingLayer->SetJpegQualityF (fCurQuality);
file.Write (pBufImg, nSizeBufImg, 1);
delete [] pBufImg;
pLayerSections [nLayerSectionIndex].commonHeader.nSizeBuf = nSizeBufImg;
// write layer alpha
if (!pEncodingLayer->pAlpha)
pEncodingLayer->AlphaCreate(255);
int nNbPixels = pEncodingLayer->GetWidth() * pEncodingLayer->GetHeight();
file.Write (pEncodingLayer->pAlpha, nNbPixels, 1);
pLayerSections [nLayerSectionIndex].commonHeader.nEndByteOffset = pLayerSections [nLayerSectionIndex].commonHeader.nFirstByteOffset + nSizeBufImg + nNbPixels;
// write new headers
if (!encodeHeader (&file, &igHeader))
throw IGEXCEPTION (CxImageIGException, "EncodeLayer", "encodeHeader failed");
if (!encodeSections (&file, &igHeader, pLayerSections, pSelectionSections))
throw IGEXCEPTION (CxImageIGException, "EncodeLayer", "encodeSections failed");
delete [] pLayerSections;
delete [] pSelectionSections;
return true;
}
示例4: memset
bool CxImagePCX::Encode(CxFile * hFile)
{
if (EncodeSafeCheck(hFile)) return false;
try {
PCXHEADER pcxHeader;
memset(&pcxHeader,0,sizeof(pcxHeader));
pcxHeader.Manufacturer = PCX_MAGIC;
pcxHeader.Version = 5;
pcxHeader.Encoding = 1;
pcxHeader.Xmin = 0;
pcxHeader.Ymin = 0;
pcxHeader.Xmax = (WORD)head.biWidth-1;
pcxHeader.Ymax = (WORD)head.biHeight-1;
pcxHeader.Hres = (WORD)info.xDPI;
pcxHeader.Vres = (WORD)info.yDPI;
pcxHeader.Reserved = 0;
pcxHeader.PaletteType = head.biClrUsed==0;
switch(head.biBitCount){
case 24:
case 8:
{
pcxHeader.BitsPerPixel = 8;
pcxHeader.ColorPlanes = head.biClrUsed==0 ? 3 : 1;
#if CXIMAGE_SUPPORT_ALPHA
if (AlphaIsValid() && head.biClrUsed==0) pcxHeader.ColorPlanes =4;
#endif //CXIMAGE_SUPPORT_ALPHA
pcxHeader.BytesPerLine = (WORD)head.biWidth;
break;
}
default: //(4 1)
pcxHeader.BitsPerPixel = 1;
pcxHeader.ColorPlanes = head.biClrUsed==16 ? 4 : 1;
pcxHeader.BytesPerLine = (WORD)((head.biWidth * pcxHeader.BitsPerPixel + 7)>>3);
}
if (pcxHeader.BitsPerPixel == 1 && pcxHeader.ColorPlanes == 1){
pcxHeader.ColorMap[0][0] = pcxHeader.ColorMap[0][1] = pcxHeader.ColorMap[0][2] = 0;
pcxHeader.ColorMap[1][0] = pcxHeader.ColorMap[1][1] = pcxHeader.ColorMap[1][2] = 255;
}
if (pcxHeader.BitsPerPixel == 1 && pcxHeader.ColorPlanes == 4){
RGBQUAD c;
for (int i = 0; i < 16; i++){
c=GetPaletteColor(i);
pcxHeader.ColorMap[i][0] = c.rgbRed;
pcxHeader.ColorMap[i][1] = c.rgbGreen;
pcxHeader.ColorMap[i][2] = c.rgbBlue;
}
}
pcxHeader.BytesPerLine = (pcxHeader.BytesPerLine + 1)&(~1);
if (hFile->Write(&pcxHeader, sizeof(pcxHeader), 1) == 0 )
throw "cannot write PCX header";
CxMemFile buffer;
buffer.Open();
BYTE c,n;
long x,y;
if (head.biClrUsed==0){
for (y = head.biHeight-1; y >=0 ; y--){
for (int p=0; p<pcxHeader.ColorPlanes; p++){
c=n=0;
for (x = 0; x<head.biWidth; x++){
if (p==0)
PCX_PackPixels(GetPixelColor(x,y).rgbRed,c,n,buffer);
else if (p==1)
PCX_PackPixels(GetPixelColor(x,y).rgbGreen,c,n,buffer);
else if (p==2)
PCX_PackPixels(GetPixelColor(x,y).rgbBlue,c,n,buffer);
#if CXIMAGE_SUPPORT_ALPHA
else if (p==3)
PCX_PackPixels(AlphaGet(x,y),c,n,buffer);
#endif //CXIMAGE_SUPPORT_ALPHA
}
PCX_PackPixels(-1-(head.biWidth&0x1),c,n,buffer);
}
}
hFile->Write(buffer.GetBuffer(false),buffer.Size(),1);
} else if (head.biBitCount==8) {
for (y = head.biHeight-1; y >=0 ; y--){
c=n=0;
for (x = 0; x<head.biWidth; x++){
PCX_PackPixels(GetPixelIndex(x,y),c,n,buffer);
}
PCX_PackPixels(-1-(head.biWidth&0x1),c,n,buffer);
}
hFile->Write(buffer.GetBuffer(false),buffer.Size(),1);
if (head.biBitCount == 8){
hFile->PutC(0x0C);
BYTE* pal = (BYTE*)malloc(768);
RGBQUAD c;
for (int i=0;i<256;i++){
//.........这里部分代码省略.........