pixmapgroup.cpp
来自「网络泡泡被.net管理」· C++ 代码 · 共 144 行
CPP
144 行
// PixMapGroup.cpp: implementation of the CPixMapGroup class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "PhotoshopReader.h"
#include <io.h>
#include <errno.h>
#include <assert.h>
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CPixMapGroup::CPixMapGroup()
{
}
CPixMapGroup::~CPixMapGroup()
{
}
void CPixMapGroup::Cleanup()
{
int c = m_apPixmap.size();
for(int i=0; i<c; i++)
{
SAFE_DELETE(m_apPixmap[i]);
}
m_apPixmap.clear();
}
BOOL CPixMapGroup::LoadFromPSD(const char *szFile)
{
Cleanup();
int n = AddFromPSD(szFile);
return (n>0);
}
int CPixMapGroup::AddFromPSD(const char *szFile)
{
t_photoshop_image image;
std::filebuf fbuf;
if(0==fbuf.open(szFile, std::ios::in | std::ios::binary))
return 0;
image.read(fbuf);
fbuf.close();
int c = image.get_layer_count();
int ret = c;//GetPixmapCount();
for(int i=0; i<c; i++)
{
PIXMAP* pm = new PIXMAP;
m_apPixmap.push_back(pm);
t_photoshop_layer_ptr layer = image.get_layer(i);
if(!pm->Create(layer->get_width(), layer->get_height()))
{
Cleanup();
return false;
}
GRECT rc = layer->get_rect();
for(int y=0; y<layer->get_height(); y++)
{
for(int x=0; x<layer->get_width(); x++)
{
pm->m_pPix[x + y*layer->get_width()] = layer->get_pixel(x+rc.left,y+rc.top);
}
}
char filename[PATH_SIZE];
CGsFunc::Path_GetPathFile(filename, szFile);
char szName[PATH_SIZE];
sprintf(szName, "%s\\%s", filename, layer->get_name().c_str());
pm->SetKey(KEY(szName));
pm->SetBasePoint(GPOINT(rc.left, rc.top));
}
return c;
}
PIXMAP* CPixMapGroup::AddPixmap()
{
PIXMAP* pm = new PIXMAP;
m_apPixmap.push_back(pm);
return pm;
}
BOOL CPixMapGroup::SaveToPGG(GSFBUF *pfBuf, FLAG fPGM)
{
if(NULL==pfBuf)
return FALSE;
t_PGM_group_head head;
head.num_PGM = m_apPixmap.size();
CGsFunc::GSFBUF_Set(pfBuf);
long pos_start = ftell(pfBuf->p_fstream);
std::vector<long> pos_data;
pos_data.clear();
GSFBUF gsbuf = *pfBuf;
// gsbuf.pos_begin += 20;
for(int i=0; i<m_apPixmap.size(); i++)
{
pos_data.push_back(gsbuf.pos_begin);
m_apPixmap[i]->SaveToPGM(&gsbuf, fPGM);
fseek(pfBuf->p_fstream, 0, SEEK_END);
gsbuf.pos_begin = pfBuf->pos_begin + ftell(pfBuf->p_fstream) - pos_start + 10;
}
head.pos_guide = gsbuf.pos_begin;
for(int j=0; j<pos_data.size(); j++)
{
fwrite(&pos_data[j], sizeof(long), 1, pfBuf->p_fstream);
}
return TRUE;
}
BOOL CPixMapGroup::SaveToPGG(const char *strFile, FLAG fPGM)
{
GSFBUF gsbuf = CGsFunc::GSFBUF_Create(strFile, "wb");
if(gsbuf.p_fstream==NULL)
return FALSE;
char version[16];
strcpy(version, "PGG2003a");
fwrite(version, 1, 16, gsbuf.p_fstream);
gsbuf.pos_begin = 20;
BOOL bRet = SaveToPGG(&gsbuf, fPGM);
fclose(gsbuf.p_fstream);
return bRet;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?