Alien-FreeImage
view release on metacpan or search on metacpan
src/Source/FreeImage/PSDParser.cpp view on Meta::CPAN
const long JFIF_startpos = io->tell_proc(handle);
if(_dib) {
FreeImage_Unload(_dib);
}
if(_Format == 1) {
// kJpegRGB thumbnail image
_dib = FreeImage_LoadFromHandle(FIF_JPEG, io, handle);
if(isBGR) {
SwapRedBlue32(_dib);
}
// HACK: manually go to end of thumbnail, because (for some reason) LoadFromHandle consumes more bytes then available!
io->seek_proc(handle, block_end, SEEK_SET);
}
else {
// kRawRGB thumbnail image
// ### Unimplemented (should be trivial)
// skip the thumbnail part
io->seek_proc(handle, iTotalData, SEEK_CUR);
return iResourceSize;
}
nBytes += (block_end - JFIF_startpos);
return nBytes;
}
//---------------------------------------------------------------------------
psdICCProfile::psdICCProfile() : _ProfileSize(0), _ProfileData(NULL) {
}
psdICCProfile::~psdICCProfile() {
clear();
}
void psdICCProfile::clear() { SAFE_DELETE_ARRAY(_ProfileData); _ProfileSize = 0;}
int psdICCProfile::Read(FreeImageIO *io, fi_handle handle, int size) {
int nBytes = 0, n;
clear();
_ProfileData = new (std::nothrow) BYTE[size];
if(NULL != _ProfileData) {
n = (int)io->read_proc(_ProfileData, 1, size, handle);
_ProfileSize = size;
nBytes += n * sizeof(BYTE);
}
return nBytes;
}
//---------------------------------------------------------------------------
/**
Invert only color components, skipping Alpha/Black
(Can be useful as public/utility function)
*/
static
BOOL invertColor(FIBITMAP* dib) {
FREE_IMAGE_TYPE type = FreeImage_GetImageType(dib);
const unsigned Bpp = FreeImage_GetBPP(dib)/8;
if((type == FIT_BITMAP && Bpp == 4) || type == FIT_RGBA16) {
const unsigned width = FreeImage_GetWidth(dib);
const unsigned height = FreeImage_GetHeight(dib);
BYTE *line_start = FreeImage_GetScanLine(dib, 0);
const unsigned pitch = FreeImage_GetPitch(dib);
const unsigned triBpp = Bpp - (Bpp == 4 ? 1 : 2);
for(unsigned y = 0; y < height; y++) {
BYTE *line = line_start;
for(unsigned x = 0; x < width; x++) {
for(unsigned b=0; b < triBpp; ++b) {
line[b] = ~line[b];
}
line += Bpp;
}
line_start += pitch;
}
return TRUE;
}
else {
return FreeImage_Invert(dib);
}
}
//---------------------------------------------------------------------------
psdParser::psdParser() {
_bThumbnailFilled = false;
_bDisplayInfoFilled = false;
_bResolutionInfoFilled = false;
_bResolutionInfoFilled_v2 = false;
_bCopyright = false;
_GlobalAngle = 30;
_ColourCount = -1;
_TransparentIndex = -1;
_fi_flags = 0;
_fi_format_id = FIF_UNKNOWN;
}
psdParser::~psdParser() {
}
bool psdParser::ReadLayerAndMaskInfoSection(FreeImageIO *io, fi_handle handle) {
bool bSuccess = false;
BYTE DataLength[4];
int nBytes = 0;
int n = (int)io->read_proc(&DataLength, sizeof(DataLength), 1, handle);
int nTotalBytes = psdGetValue( DataLength, sizeof(DataLength) );
BYTE data[1];
( run in 0.461 second using v1.01-cache-2.11-cpan-62a16548d74 )