/*=============================================== ParseBWCursor ================================================*/ void PTCursorView::ParseBWCursor( RFMap *inMap, ResIDT inResID, SUOffscreen **outBW, SUOffscreen **outMask, Point *outHotSpot ) { CursHandle h = nil; SUOffscreen *bw = nil, *mask = nil; try { /************************************************** get the raw resource handle **************************************************/ RFResource *theRes = inMap->FindResource( ImageType_Cursor, inResID, false ); ThrowIfNil_( theRes ); h = (CursHandle) theRes->GetResData(); ThrowIfNil_( h ); ::HLock( (Handle) h ); // 2 rowBytes x 16 rows x 2 images + sizeof(Point) if ( ::GetHandleSize( (Handle) h ) != BWCursor_Bytes ) LException::Throw( err_CorruptedResource ); /************************************************** create the bw bitmap **************************************************/ bw = SUOffscreen::CreateBuffer( Cursor_Width, Cursor_Height, 1 ); ThrowIfMemFail_( bw ); //bw->AssignPalette( oneBitTable ); bw->CopyFromRawData( (UInt8*) &(**h).data, BWCursor_RowBytes ); /************************************************** create the mask bitmap **************************************************/ mask = SUOffscreen::CreateBuffer( Cursor_Width, Cursor_Height, 1 ); ThrowIfMemFail_( bw ); mask->CopyFromRawData( (UInt8*) &(**h).mask, BWCursor_RowBytes ); /************************************************** and return stuff to the caller **************************************************/ *outBW = bw; *outMask = mask; *outHotSpot = (**h).hotSpot; } catch( ... ) { SUMiscUtils::DisposeHandle( h ); if ( bw ) delete ( bw ); if ( mask ) delete( mask ); throw; } SUMiscUtils::DisposeHandle( h ); }
/*================================== ParseColorPattern ===================================*/ void PTPatternView::ParseColorPattern( Handle inPattern, SUOffscreen **outColor, SUOffscreen **outBW ) { // See IM V-79 for details StSaveGWorld save1; StHandleLocker save2( inPattern ); PixPatPtr p = (PixPatPtr) *inPattern; CTabHandle theTable = nil; SUOffscreen *tempColorBuffer = nil, *colorBuffer = nil, *bwBuffer = nil; try { if ( p->patType != 1 ) LException::Throw( err_InvalidImageFormat ); /******************************************* first handle the b&w pattern ********************************************/ bwBuffer = this->BWPatternToOffscreen( p->pat1Data ); /******************************************* now the color pattern ********************************************/ PixMapPtr theMap = (PixMapPtr)( *inPattern + (SInt32) p->patMap ); UInt8 * theData = (UInt8*)( *inPattern + (SInt32) p->patData ); SInt32 depth = theMap->pixelSize; SInt32 width = theMap->bounds.right - theMap->bounds.left; SInt32 height = theMap->bounds.bottom - theMap->bounds.top; SInt32 rowBytes = theMap->rowBytes & 0x3FFF; // clear flags if ( (depth != 1) && (depth != 2) && (depth != 4) && (depth != 8) ) LException::Throw( err_InvalidImageDepth ); if ( (width <= 3) || (width > 64) || (height <= 3) || (height > 64) ) LException::Throw( err_InvalidImageSize ); theTable = SUColorUtils::NewColorTableFromPtr( depth, (UInt8*)( *inPattern + (SInt32)theMap->pmTable) ); tempColorBuffer = SUOffscreen::CreateBuffer( width, height, depth, theTable ); tempColorBuffer->CopyFromRawData( theData, rowBytes ); // now switch to a 32-bit buffer colorBuffer = SUOffscreen::CreateBuffer( width, height, 32 ); colorBuffer->CopyFrom( tempColorBuffer ); } catch( ... ) { delete colorBuffer; delete bwBuffer; delete tempColorBuffer; if ( theTable ) ::DisposeCTable( theTable ); throw; } *outColor = colorBuffer; *outBW = bwBuffer; if ( theTable ) ::DisposeCTable( theTable ); delete tempColorBuffer; }
/*==================================== InitializeOneMember =====================================*/ Boolean PTFamilyView::InitializeOneMember( RFMap *inMap, ResType inResType, ResIDT inResID, SInt32 inWidth, SInt32 inHeight, SInt32 inDepth, SInt32 inOffset, SInt32 inRowBytes, PaneIDT inSamplePaneID, Boolean /* inIsMask */ ) { StSaveResFile aSaver; SUOffscreen *theBuffer = nil; Boolean isUsed = false; /* icon families use the standard color table for their depth */ CTabHandle theTable = SUColorUtils::GetColorTable( inDepth ); try { /****************************************** create the offscreen buffer *******************************************/ theBuffer = SUOffscreen::CreateBuffer( inWidth, inHeight, inDepth, theTable ); /****************************************** if we have a resource, load the data into the offscreen buffer *******************************************/ RFResource *theResource = inMap->FindResource( inResType, inResID, false ); if ( theResource ) { Handle h = theResource->GetResData(); if ( h ) { ::HLock( h ); theBuffer->CopyFromRawData( (UInt8*) *h + inOffset, inRowBytes ); SUMiscUtils::DisposeHandle( h ); isUsed = true; } } /****************************************** initialize the sample pane *******************************************/ PTDraggableTargetBox *thePane = (PTDraggableTargetBox*) this->FindPaneByID( inSamplePaneID ); ThrowIfNil_( thePane ); mSamplePaneList[ mNumSamplePanes++ ] = thePane; thePane->SetUsedFlag( isUsed, redraw_Dont ); // true if the resource exists thePane->SetBuffer( theBuffer, redraw_Dont ); theBuffer = nil; // so we don't delete it below } catch( ... ) { if ( theBuffer ) delete theBuffer; if ( theTable ) ::DisposeCTable( theTable ); throw; } if ( theTable ) ::DisposeCTable( theTable ); return( isUsed ); }