ZDCPixmap sPixmap(ZRef<CGImageRef> iImageRef) { if (not iImageRef) {} else if (ZRef<CGDataProviderRef,false> theProvider = ::CGImageGetDataProvider(iImageRef)) {} else if (ZRef<CFDataRef,false> theDataRef = sAdopt& ::CGDataProviderCopyData(theProvider)) {} else { const PixvalDesc thePixvalDesc( ::CGImageGetBitsPerPixel(iImageRef), ZCONFIG_Endian != ZCONFIG_Endian_Big); const RasterDesc theRasterDesc( thePixvalDesc, ::CGImageGetBytesPerRow(iImageRef), ::CGImageGetHeight(iImageRef), false); ZRef<PixmapRaster> thePixmapRaster = new PixmapRaster(theRasterDesc, iImageRef, theDataRef); // Figure out mask const size_t theBPC = ::CGImageGetBitsPerComponent(iImageRef); const CGImageAlphaInfo theAI = ::CGImageGetAlphaInfo(iImageRef); const uint32 theMask = (1 << theBPC) - 1; uint32 theStart = theMask; uint32 theA; if (theAI & 1) { theA = theMask; theStart = theMask << theBPC; } else if (0 == (theAI & 6) || 6 == (theAI & 6)) { theA = 0; } else { theA = theMask << (theBPC * 3); } const uint32 theB = theStart; const uint32 theG = theB << theBPC; const uint32 theR = theG << theBPC; const PixelDesc thePixelDesc(theR, theG, theB, theA); return ZDCPixmapRep::sCreate( thePixmapRaster, sRectPOD(::CGImageGetWidth(iImageRef), thePixmapRaster->GetRasterDesc().fRowCount), thePixelDesc); } return ZDCPixmap(); }
ZDCPixmapRaster_Simple::ZDCPixmapRaster_Simple(ZRef<ZDCPixmapRaster> iOther) : ZDCPixmapRaster(iOther->GetRasterDesc()) { fCanModify = true; const size_t bufferSize = fRasterDesc.fRowBytes * fRasterDesc.fRowCount; // Oversize the buffer slightly, to allow for some code in ZDCPixmapBlit that // may *read* past the end of a buffer in some situations. fBuffer = new uint8[bufferSize + 4]; fBaseAddress = fBuffer; sMemCopy(fBuffer, iOther->GetBaseAddress(), bufferSize); }
static void sReadImageData(const ZStreamR& iStream, bool iInterlaced, const ZRect& iBounds, ZRef<ZDCPixmapRaster> ioRaster) { uint8 initialCodeSize = iStream.ReadUInt8(); StreamR_Chunk theSIC(iStream); ZStreamR_LZWDecode theSILZW(initialCodeSize, theSIC); ZDCPixmapNS::PixvalDesc sourcePixvalDesc(8, true); void* destBaseAddress = ioRaster->GetBaseAddress(); ZDCPixmapNS::RasterDesc destRasterDesc = ioRaster->GetRasterDesc(); vector<uint8> theRowBufferVector(iBounds.Width()); void* theRowBuffer = &theRowBufferVector[0]; if (iInterlaced) { for (int pass = 0; pass < 4; ++pass) { for (ZCoord currentY = iBounds.top + sInterlaceStart[pass]; currentY < iBounds.bottom; currentY += sInterlaceIncrement[pass]) { theSILZW.Read(theRowBuffer, iBounds.Width()); void* destRowAddress = destRasterDesc.CalcRowAddress(destBaseAddress, currentY); ZDCPixmapNS::sBlitRowPixvals(theRowBuffer, sourcePixvalDesc, 0, destRowAddress, destRasterDesc.fPixvalDesc, iBounds.left, iBounds.Width()); } } } else { for (ZCoord currentY = iBounds.top; currentY < iBounds.bottom; ++currentY) { theSILZW.Read(theRowBuffer, iBounds.Width()); void* destRowAddress = destRasterDesc.CalcRowAddress(destBaseAddress, currentY); ZDCPixmapNS::sBlitRowPixvals(theRowBuffer, sourcePixvalDesc, 0, destRowAddress, destRasterDesc.fPixvalDesc, iBounds.left, iBounds.Width()); } } }