/* MDIWndProc */ LRESULT CALLBACK MDIWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HANDLE hInfo; PINFO pInfo; MSG msg; EventRecord macEvent; LONG thePoints = GetMessagePos(); PAINTSTRUCT ps; msg.hwnd = hwnd; msg.message = message; msg.wParam = wParam; msg.lParam = lParam; msg.time = GetMessageTime(); msg.pt.x = LOWORD(thePoints); msg.pt.y = HIWORD(thePoints); WinEventToMacEvent(&msg, &macEvent); switch (message) { case WM_CREATE: case WM_MDICREATE: break; case WM_DESTROY: hInfo = (HANDLE)GetWindowLong(hwnd, GWL_USERDATA); if (hInfo) { if ((pInfo = (PINFO)LocalLock(hInfo)) != NULL){ if (pInfo->gi) // close the graphic import component CloseComponent(pInfo->gi); // Destroy our port association DestroyPortAssociation((CGrafPort *)GetHWNDPort(pInfo->hwndChildWindow)); } LocalUnlock(hInfo); } break; // Draw our graphic case WM_PAINT: BeginPaint(hwnd, &ps); hInfo = (HANDLE)GetWindowLong(hwnd, GWL_USERDATA); if (hInfo) { if ((pInfo = (PINFO)LocalLock(hInfo)) != NULL) GraphicsImportDraw(pInfo->gi); LocalUnlock(hInfo); } EndPaint(hwnd, &ps); break; default: return DefMDIChildProc(hwnd, message, wParam, lParam); } return DefMDIChildProc(hwnd, message, wParam, lParam); }
void DrawImage( void ) { OSErr err = noErr; Handle hOpenTypeList = NewHandle(0); long numTypes = 0; FSSpec theFSSpec; Rect bounds; GraphicsImportComponent importer = 0; BuildGraphicsImporterValidFileTypes( hOpenTypeList, &numTypes ); HLock( hOpenTypeList ); err = GetOneFileWithPreview(numTypes, (OSTypePtr)*hOpenTypeList, &theFSSpec, NULL); DisposeHandle( hOpenTypeList ); if ( err ) return; // locate and open a graphics importer component which can be used to draw the // selected file. If a suitable importer is not found the ComponentInstance // is set to NULL. err = GetGraphicsImporterForFile( &theFSSpec, // specifies the file to be drawn &importer ); // pointer to the returned GraphicsImporterComponent // get the native size of the image associated with the importer err = GraphicsImportGetNaturalBounds( importer, // importer instance &bounds ); // returned bounds OffsetRect( &bounds, 10, 45 ); window = NewCWindow( NULL, &bounds, "\pDraw Image", true, documentProc, (WindowPtr)-1, true, 0); // set the graphics port for drawing err = GraphicsImportSetGWorld( importer, // importer instance GetWindowPort( window ), // destination graphics port or GWorld NULL ); // destination GDevice, set to NULL uses GWorlds device // draw the image err = GraphicsImportDraw( importer ); // close the importer instance CloseComponent( importer ); }
// I let Quicktime handle image import since it supports most popular // image formats such as: // *.psd, *.bmp, *.tif, *.png, *.jpg, *.gif, *.pct, *.pcx //------------------------------------------------------------------------ bool pixel_map::load_from_qt(const char *filename) { FSSpec fss; OSErr err; // get file specification to application directory err = HGetVol(nil, &fss.vRefNum, &fss.parID); if (err == noErr) { CopyCStringToPascal(filename, fss.name); GraphicsImportComponent gi; err = GetGraphicsImporterForFile (&fss, &gi); if (err == noErr) { ImageDescriptionHandle desc; GraphicsImportGetImageDescription(gi, &desc); // For simplicity, all images are currently converted to 32 bit. // create an empty pixelmap short depth = 32; create ((**desc).width, (**desc).height, (org_e)depth, 0xff); DisposeHandle ((Handle)desc); // let Quicktime draw to pixelmap GraphicsImportSetGWorld(gi, m_pmap, nil); GraphicsImportDraw(gi); // Well, this is a hack. The graphics importer sets the alpha channel of the pixelmap to 0x00 // for imported images without alpha channel but this would cause agg to draw an invisible image. // set alpha channel to 0xff unsigned char * buf = m_buf; for (unsigned int size = 0; size < m_img_size; size += 4) { *buf = 0xff; buf += 4; } } } return err == noErr; }
GLuint texture_load(const char *filename) { FSSpec fss; ComponentInstance gi; Rect rect; GWorldPtr world; int width; int height; int pitch; unsigned char *buffer; GLuint id; NativePathNameToFSSpec(filename, &fss); GetGraphicsImporterForFile(&fss, &gi); GraphicsImportGetNaturalBounds(gi, &rect); width = rect.right; height = rect.bottom; pitch = width * 4; buffer = malloc(pitch * height); QTNewGWorldFromPtr(&world, k32ARGBPixelFormat, &rect, NULL, NULL, 0, buffer, pitch); GraphicsImportSetGWorld(gi, world, NULL); GraphicsImportDraw(gi); DisposeGWorld(world); CloseComponent(gi); id = texture_load_data(buffer, width, height, 4, -pitch, GL_RGBA, ARGB_FORMAT, ARGB_TYPE); free(buffer); return id; }
osg::Image* QuicktimeImportExport::doImport(unsigned char* data, unsigned int sizeData, const std::string& fileTypeHint) { GWorldPtr gworld = 0; OSType pixelFormat; int rowStride; GraphicsImportComponent gicomp = 0; Rect rectImage; GDHandle origDevice = 0; CGrafPtr origPort = 0; ImageDescriptionHandle desc = 0; int depth = 32; unsigned int xsize, ysize; unsigned char* imageData = 0; // Data Handle for file data ( & load data from file ) Handle dataRef = getPtrDataRef(data, sizeData, fileTypeHint); try { OSErr err = noErr; // GraphicsImporter - Get Importer for our filetype GetGraphicsImporterForDataRef(dataRef, 'ptr ', &gicomp); // GWorld - Get Texture Info err = GraphicsImportGetNaturalBounds(gicomp, &rectImage); if (err != noErr) { throw QTImportExportException(err, "GraphicsImportGetNaturalBounds failed"); } xsize = (unsigned int)(rectImage.right - rectImage.left); ysize = (unsigned int)(rectImage.bottom - rectImage.top); // ImageDescription - Get Image Description err = GraphicsImportGetImageDescription(gicomp, &desc); if (err != noErr) { throw QTImportExportException(err, "GraphicsImportGetImageDescription failed"); } // ImageDescription - Get Bit Depth HLock(reinterpret_cast<char **>(desc)); // GWorld - Pixel Format stuff pixelFormat = k32ARGBPixelFormat; // Make sure its forced...NOTE: i'm pretty sure this cannot be RGBA! // GWorld - Row stride rowStride = xsize * 4; // (width * depth_bpp / 8) // GWorld - Allocate output buffer imageData = new unsigned char[rowStride * ysize]; // GWorld - Actually Create IT! QTNewGWorldFromPtr(&gworld, pixelFormat, &rectImage, 0, 0, 0, imageData, rowStride); if (!gworld) { throw QTImportExportException(-1, "QTNewGWorldFromPtr failed"); } // Save old Graphics Device and Graphics Port to reset to later GetGWorld (&origPort, &origDevice); // GraphicsImporter - Set Destination GWorld (our buffer) err = GraphicsImportSetGWorld(gicomp, gworld, 0); if (err != noErr) { throw QTImportExportException(err, "GraphicsImportSetGWorld failed"); } // GraphicsImporter - Set Quality Level err = GraphicsImportSetQuality(gicomp, codecLosslessQuality); if (err != noErr) { throw QTImportExportException(err, "GraphicsImportSetQuality failed"); } // Lock pixels so that we can draw to our memory texture if (!GetGWorldPixMap(gworld) || !LockPixels(GetGWorldPixMap(gworld))) { throw QTImportExportException(0, "GetGWorldPixMap failed"); } //*** Draw GWorld into our Memory Texture! GraphicsImportDraw(gicomp); // Clean up UnlockPixels(GetGWorldPixMap(gworld)); SetGWorld(origPort, origDevice); // set graphics port to offscreen (we don't need it now) DisposeGWorld(gworld); CloseComponent(gicomp); DisposeHandle(reinterpret_cast<char **>(desc)); DisposeHandle(dataRef); } catch (QTImportExportException& e) { setError(e.what()); if (gworld) { UnlockPixels(GetGWorldPixMap(gworld)); SetGWorld(origPort, origDevice); // set graphics port to offscreen (we don't need it now) DisposeGWorld(gworld); } if (gicomp) CloseComponent(gicomp); if (desc) DisposeHandle(reinterpret_cast<char **>(desc)); if (imageData) delete[] imageData; if (dataRef) DisposeHandle(dataRef); return NULL; } unsigned int bytesPerPixel = depth / 8; unsigned int glpixelFormat; switch(bytesPerPixel) { case 3 : glpixelFormat = GL_RGB; break; case 4 : glpixelFormat = GL_RGBA; break; default : delete[] imageData; setError("unknown pixelformat"); return NULL; break; } unsigned char* swizzled = pepareBufferForOSG(imageData, bytesPerPixel, xsize, ysize); delete[] imageData; osg::Image* image = new osg::Image(); image->setFileName(fileTypeHint.c_str()); image->setImage(xsize,ysize,1, bytesPerPixel, glpixelFormat, GL_UNSIGNED_BYTE, swizzled, osg::Image::USE_NEW_DELETE ); return image; }
void DisplayJPEGAndDisposeHandle( Handle imageData ) { OSErr err; Rect naturalBounds; MatrixRecord matrix; SInt32 gapH, gapV; Fixed scaleH, scaleV; Rect boundsRect; GraphicsImportComponent grip; Rect windowPortRect; static char gifSentinel[] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}; static char jpegSentinel[] = {0xFF,0xD9,0xFF,0xD9,0xFF,0xD9,0xFF,0xD9,0xFF,0xD9,0xFF,0xD9,0xFF,0xD9,0xFF,0xD9}; Ptr sentinel; Size sentinelSize; if( !imageData ) { ofLogNotice() << "NO IMAGE DATA" << endl; } else { ofImage image; //ofPixels pixels(); //pixels = imageData; //image.setFromPixels((const unsigned char *)imageData); //string image //image.saveImage(ofToDataPath(ofGetTimestampString()+".jpg", OF_IMAGE_QUALITY_BEST)); ofLogError() << "WE HAVE DATA!" << endl; } return; again: ofLogError() << "Again called"; if( 'G' == **imageData ) { grip = gripG; // for GIF: // FF FF FF FF will ensure that the bit parser aborts, since you can't // have two consecutive all-ones symbols in the LZW codestream -- // you can sometimes have one (say, a 9-bit code), but after consuming // it the code width increases (so we're now using 10-bit codes) // and the all-ones code won't be valid for a while yet. sentinel = gifSentinel; sentinelSize = sizeof(gifSentinel); } else { grip = gripJ; // for JPEG: // FF D9 FF D9 will ensure (a) that the bit-parser aborts, since FF D9 // is an "unstuffed" FF and hence illegal in the entropy-coded datastream, // and (b) be long enough to stop overreads. sentinel = jpegSentinel; sentinelSize = sizeof(jpegSentinel); } //•• add sentinel pattern to the end of the handle. err = PtrAndHand( sentinel, imageData, sentinelSize ); err = GraphicsImportSetDataHandle( grip, imageData ); if( err ) { ofLogNotice() << "GraphicsImportSetDataHandle Error" << endl; goto bail; } err = GraphicsImportGetNaturalBounds( grip, &naturalBounds ); if( err ) { ofLogNotice() << "GraphicsImportGetNaturalBounds Error" << endl; goto bail; } //GetPortBounds( GetWindowPort( window ), &windowPortRect ); gapH = windowPortRect.right - naturalBounds.right; gapV = windowPortRect.bottom - naturalBounds.bottom; if( gapH >= 0 ) { gapH = ((UInt16)Random()) % gapH; scaleH = fixed1; } else { gapH = 0; scaleH = FixDiv( windowPortRect.right, naturalBounds.right ); } if( gapV >= 0 ) { gapV = ((UInt16)Random()) % gapV; scaleV = fixed1; } else { gapV = 0; scaleV = FixDiv( windowPortRect.bottom, naturalBounds.bottom ); } // need to use smaller scale of the two, and then recalc the other gap. if( scaleH > scaleV ) { scaleH = scaleV; gapH = windowPortRect.right - FixMul(scaleH, naturalBounds.right); gapH = ((UInt16)Random()) % gapH; } else if( scaleH < scaleV ) { scaleV = scaleH; gapV = windowPortRect.bottom - FixMul(scaleV, naturalBounds.bottom); gapV = ((UInt16)Random()) % gapV; } SetIdentityMatrix( &matrix ); ScaleMatrix( &matrix, scaleH, scaleV, 0, 0 ); TranslateMatrix( &matrix, gapH<<16, gapV<<16 ); err = GraphicsImportSetMatrix( grip, &matrix ); if( err ) goto bail; err = GraphicsImportDraw( grip ); if( err ) goto bail; err = GraphicsImportGetBoundsRect( grip, &boundsRect ); if( err ) goto bail; InsetRect( &boundsRect, -1, -1 ); //SetPortWindowPort( window ); FrameRect( &boundsRect ); if( scanForAnotherImageMarker(imageData)) { ofLogError() << "again: scanForAnotherImageMarker" << endl; goto again; } bail: DisposeHandle( imageData ); //gDrewJPEG = true; }
GLuint platformLoadTextureFile(string theFilename, bool generateMipmaps, int *width, int *height) { #ifdef QuickTimeInstalled GLuint textureName; // the "name" by which OpenGL knows the texture unsigned char *pImageBuffer; // the buffer that contains the image data GWorldPtr pGWorld; // a gworld to load the image into int imageDepth; FSSpec fsspecImage; // FSSpec of the image to load #ifdef __APPLE__ CFURLRef imageURL; FSRef imagefsRef; #endif OSStatus err = noErr; // err return value long rowStride; // length, in bytes, of a pixel row in the image GraphicsImportComponent giComp; // component for importing image MatrixRecord matrix; Rect rectImage; // rectangle of source image PixMapHandle hPixMap; // handle to image pix map ImageDescriptionHandle hImageDesc; // handle to image description used to get image depth long imageWidth; long imageHeight; float imageAspect; long textureWidth; long textureHeight; // get the full path to the texture file string fileLocation; fileLocation = pathToResourceDirectory() + theFilename; #ifdef __APPLE__ // create a URL to the file from the C string imageURL = CFURLCreateWithBytes (kCFAllocatorDefault, (UInt8 *)fileLocation.c_str(), fileLocation.length(), kCFStringEncodingASCII, NULL); if (imageURL == NULL) { cout << "error getting URL for image file (image file may not exist): " << theFilename << endl; return 0; } // get a FSRef from the URL if (!CFURLGetFSRef(imageURL, &imagefsRef)) { cout << "error getting FSRef for image file:: " << theFilename << endl; CFRelease(imageURL); return 0; } // get the FSSpec from the FSRef if (FSGetCatalogInfo (&imagefsRef, kFSCatInfoNone, NULL, NULL, &fsspecImage, NULL)) { cout << "error getting FSSpec for image file: " << theFilename << endl; CFRelease(imageURL); return 0; } // release the URL (not needed any more) CFRelease(imageURL); #endif #ifdef _WIN32 // get an FSSpec from the pathname if (NativePathNameToFSSpec ((char *)fileLocation.c_str(), &fsspecImage, kErrorIfFileNotFound)) { cout << "error getting FSSpec for image file: " << fileLocation << endl; return 0; } #endif // save the onscreen graphics port GDHandle origDevice; CGrafPtr origPort; GetGWorld (&origPort, &origDevice); // get an importer for the file err = GetGraphicsImporterForFileWithFlags (&fsspecImage, &giComp, kDontUseValidateToFindGraphicsImporter); if (err != noErr) return 0; // get the image bounds err = GraphicsImportGetNaturalBounds (giComp, &rectImage); if (err != noErr) return 0; // create a handle for the image description and lock it hImageDesc = (ImageDescriptionHandle) NewHandle (sizeof (ImageDescriptionHandle)); HLock ((Handle) hImageDesc); // retrieve the image description err = GraphicsImportGetImageDescription (giComp, &hImageDesc); if (err != noErr) return 0; // find width and height imageWidth = (int) (rectImage.right - rectImage.left); imageHeight = (int) (rectImage.bottom - rectImage.top); // now calculate the aspect ratio (width/height), used to restore image correctly imageAspect = ((float) imageWidth) / ((float) imageHeight); // get the image's pixel depth imageDepth = (**hImageDesc).depth; // find nearest acceptable texture size (width and height) for the image textureWidth = GetTextureDimFromImageDim (imageWidth); textureHeight = GetTextureDimFromImageDim (imageHeight); // pass the optimised (and scaled) size back out to the caller *width = textureWidth; *height = textureHeight; // set texture rectangle for creation of GWorld #ifdef __APPLE__ SetRect (&rectImage, 0, 0, (int) textureWidth, (int) textureHeight); #endif #ifdef _WIN32 MacSetRect (&rectImage, 0, 0, (int) textureWidth, (int) textureHeight); #endif // set stride in bytes width of image * 4 bytes per pixel rowStride = textureWidth * 4; // build new buffer exact size of image (stride * height) pImageBuffer = (unsigned char *) NewPtr (rowStride * textureHeight); // check we got the buffer we wanted if (pImageBuffer == NULL) { // failed - release the component and return an error CloseComponent(giComp); return 0; } // create a new gworld using our unpadded buffer, setting the pixel type correctly for the expected image depth #ifdef __BIG_ENDIAN__ QTNewGWorldFromPtr (&(pGWorld), k32ARGBPixelFormat, &rectImage, NULL, NULL, 0, pImageBuffer, rowStride); #else QTNewGWorldFromPtr (&(pGWorld), k32RGBAPixelFormat, &rectImage, NULL, NULL, 0, pImageBuffer, rowStride); #endif // could we allocate the GWorld? if (pGWorld == NULL) { // failed - release the buffer, component and return an error DisposePtr ((Ptr) pImageBuffer); CloseComponent(giComp); return 0; } // build a transformation matrix to scale the image to the texture size // this also flips the image horizontally, so that texture coordinates map correctly float horizontalScale = (float) textureWidth / (float) imageWidth; float verticalScale = (float) textureHeight / (float) imageHeight; SetIdentityMatrix (&matrix); ScaleMatrix (&matrix, X2Fix(horizontalScale), X2Fix(-verticalScale), 0, 0); TranslateMatrix (&matrix, 0, X2Fix((float)textureHeight)); // set the matrix as the importer matrix err = GraphicsImportSetMatrix(giComp, &matrix); // set the destination of the importer component if (err == noErr) err = GraphicsImportSetGWorld (giComp, pGWorld, NULL); // ensure lossless decompression (if the CODEC supports this) if (err == noErr) err = GraphicsImportSetQuality(giComp, codecLosslessQuality); if (err != noErr) { // failed - release the GWorld, buffer, component and return an error DisposeGWorld (pGWorld); DisposePtr ((Ptr) pImageBuffer); CloseComponent(giComp); return 0; } // get the address of the GWorld's pixmap hPixMap = GetGWorldPixMap (pGWorld); // if everything looks good draw the image to the locked pixmap if ((hPixMap) && (LockPixels (hPixMap))) GraphicsImportDraw (giComp); else { // the pixmap doesn't exist, or we couldn't lock it // release the GWorld, buffer, component and return an error DisposeGWorld (pGWorld); DisposePtr ((Ptr) pImageBuffer); CloseComponent(giComp); return 0; } // for images without an alpha channel, initialise the alpha bytes since QuickTime won't if (imageDepth < 32) { #ifdef __BIG_ENDIAN__ for( unsigned char *p = pImageBuffer; p < pImageBuffer + (rowStride * textureHeight); p+=4) *p = 0xFF; #else for( unsigned char *p = pImageBuffer+3; p < pImageBuffer + (rowStride * textureHeight) +3; p+=4) *p = 0xFF; #endif } // unlock the pixmap UnlockPixels (hPixMap); // dump the component CloseComponent(giComp); // set image width in groups (pixels), accounts for border this ensures proper image alignment row to row glPixelStorei (GL_UNPACK_ROW_LENGTH, textureWidth); // generate a "name" for the texture glGenTextures (1, &textureName); // create the texture in OpenGL glBindTexture(GL_TEXTURE_2D, textureName); // tell OpenGL about the texture and have GLU build mipmaps #ifdef __BIG_ENDIAN__ glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, textureWidth, textureHeight, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, pImageBuffer); #else glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, textureWidth, textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, pImageBuffer); #endif if (generateMipmaps) #ifdef __BIG_ENDIAN__ if (gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, textureWidth, textureHeight, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, pImageBuffer) != 0) #else if (gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, textureWidth, textureHeight, GL_RGBA, GL_UNSIGNED_BYTE, pImageBuffer) != 0) #endif // good time to check for errors? openGLCheckError(); // finished with the GWorld but not the image buffer (it's used by OpenGL as the "live" image buffer) DisposeGWorld (pGWorld); // restore the current graphics port we saved earlier SetGWorld(origPort, origDevice); // all done - return the texture name return textureName; #endif // QuickTimeInstalled }
//============================================================================= // QutTexture_CreateGWorldFromFile : Create a GWorld from a file. //----------------------------------------------------------------------------- GWorldPtr QutTexture_CreateGWorldFromFile(const FSSpec *theFSSpec, TQ3PixelType pixelType) { CTabHandle colourTableHnd; ImageDescriptionHandle imageDescHnd; ComponentInstance theImporter; GWorldPtr theGWorld; TQ3Uns32 theDepth; Rect theRect; OSErr theErr; // Initialise ourselves theImporter = NULL; theGWorld = NULL; imageDescHnd = NULL; colourTableHnd = NULL; theDepth = (pixelType == kQ3PixelTypeARGB16 || pixelType == kQ3PixelTypeRGB16) ? 16 : 32; // Create the importer theErr = GetGraphicsImporterForFile(theFSSpec, &theImporter); // Query the importer for the information we need if (theErr == noErr) { GraphicsImportGetBoundsRect(theImporter, &theRect); theErr = GraphicsImportGetImageDescription(theImporter, &imageDescHnd); if (theErr == noErr) theErr = GetImageDescriptionCTable(imageDescHnd, &colourTableHnd); } // Create the GWorld if (theErr == noErr) theErr = NewGWorld(&theGWorld, theDepth, &theRect, colourTableHnd, NULL, useTempMem | kQ3NativeEndianPixMap ); // Draw the image into the GWorld if (theErr == noErr) { GraphicsImportSetGWorld(theImporter, theGWorld, NULL); GraphicsImportDraw(theImporter); } // Clean up if (theImporter != NULL) CloseComponent(theImporter); if (imageDescHnd != NULL) DisposeHandle((Handle) imageDescHnd); if (colourTableHnd != NULL) DisposeCTable(colourTableHnd); return(theGWorld); }
static void QTDR_DrawFrame (short theTrackWidth, short theTrackHeight, long theNumSample, GWorldPtr theGWorld) { Handle myHandle = NULL; char myData[kPICTFileHeaderSize]; static PicHandle myPicture = NULL; static GWorldPtr myGWorld = NULL; static GraphicsImportComponent myImporter = NULL; Rect myRect; RGBColor myColor; ComponentResult myErr = noErr; MacSetRect(&myRect, 0, 0, theTrackWidth, theTrackHeight); if (myPicture == NULL) { myErr = NewGWorld(&myGWorld, kPixelDepth, &myRect, NULL, NULL, (GWorldFlags)0); if (myErr != noErr) goto bail; // read a picture from our resource file myPicture = GetPicture(kPictureID); if (myPicture == NULL) goto bail; // use Munger to prepend a 512-byte header onto the picture data; this converts the PICT // resource data into in-memory PICT file data (see Ice Floe 14 for an explanation of this) myHandle = (Handle)myPicture; Munger(myHandle, 0, NULL, 0, myData, kPICTFileHeaderSize); // get a graphics importer for the picture myErr = OpenADefaultComponent(GraphicsImporterComponentType, kQTFileTypePicture, &myImporter); if (myErr != noErr) goto bail; // configure the graphics importer myErr = GraphicsImportSetGWorld(myImporter, myGWorld, NULL); if (myErr != noErr) goto bail; myErr = GraphicsImportSetDataHandle(myImporter, myHandle); if (myErr != noErr) goto bail; myErr = GraphicsImportSetBoundsRect(myImporter, &myRect); if (myErr != noErr) goto bail; // draw the picture into the source GWorld myErr = GraphicsImportDraw(myImporter); if (myErr != noErr) goto bail; } // set the blend amount (0 = fully transparent; 0xffff = fully opaque) myColor.red = (theNumSample - 1) * (0xffff / kNumVideoFrames - 1); myColor.green = (theNumSample - 1) * (0xffff / kNumVideoFrames - 1); myColor.blue = (theNumSample - 1) * (0xffff / kNumVideoFrames - 1); OpColor(&myColor); // blend the picture (in the source GWorld) into the empty rectangle (in the destination GWorld) CopyBits((BitMapPtr)*GetGWorldPixMap(myGWorld), (BitMapPtr)*GetGWorldPixMap(theGWorld), &myRect, &myRect, blend, NULL); if (theNumSample == kNumVideoFrames) goto bail; return; bail: if (myHandle != NULL) DisposeHandle(myHandle); if (myPicture != NULL) ReleaseResource((Handle)myPicture); if (myImporter != NULL) CloseComponent(myImporter); }
/********************> LoadTGA() <*****/ bool upload_image(const unsigned char* filePath, bool hasalpha) { if(visibleloading){ loadscreencolor=1; pgame->LoadingScreen(); } #if 1 // for Windows, just use TGA loader for now char fileName[ 256]; CopyPascalStringToC( filePath, fileName); /* // change extension to .TGA int len = strlen( fileName); if (len > 3) { fileName[ len - 3] = 't'; fileName[ len - 2] = 'g'; fileName[ len - 1] = 'a'; } */ // return (LoadTGA( fileName) != NULL); return (LoadImage(fileName, texture)); #else OSStatus err; ComponentResult cr; /*FSRef fsref; Boolean isdir; err = FSPathMakeRef((const UInt8*)filePath, &fsref, &isdir); if(err)return; FSSpec fsspec; err = FSGetCatalogInfo(&fsref, kFSCatInfoNone, NULL, NULL, &fsspec, NULL); if(err)return; */ //Boolean isdir; FSSpec fsspec; //err = FSMakeFSSpec (0, 0, (const unsigned char*)filePath, &fsspec); err = FSMakeFSSpec (0, 0, filePath, &fsspec); //err=FSPathMakeFSSpec((const UInt8*)filePath,&fsspec,&isdir);*/ if(err)return; GraphicsImportComponent gi; err = GetGraphicsImporterForFile(&fsspec, &gi); if(err)return; Rect natbounds; cr = GraphicsImportGetNaturalBounds(gi, &natbounds); size_t buffersize = 4 * natbounds.bottom * natbounds.right; //void* buf = malloc(buffersize); texture.sizeX=natbounds.right; texture.sizeY=natbounds.bottom; /*if(hasalpha)*/texture.bpp = 32; //if(!hasalpha)texture.bpp = 24; GWorldPtr gw; err = QTNewGWorldFromPtr(&gw, k32ARGBPixelFormat, &natbounds, NULL, NULL, 0, texture.data, 4 * natbounds.right); if(err)return; cr = GraphicsImportSetGWorld(gi, gw, NULL); natbounds.top = natbounds.bottom; natbounds.bottom = 0; cr = GraphicsImportSetBoundsRect(gi, &natbounds); cr = GraphicsImportDraw(gi); err = CloseComponent(gi); if(err)return; /*glTexImage2D(textureTarget, 0, GL_RGBA, natbounds.right, natbounds.top, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, buf); */ //free(buf); DisposeGWorld(gw); // Loop Through The Image Data GLuint imageSize; // Used To Store The Image Size When Setting Aside Ram GLuint temp; // Temporary Variable GLuint bytesPerPixel; // Temporary Variable bytesPerPixel=texture.bpp/8; imageSize = texture.sizeX * texture.sizeY * bytesPerPixel; int alltrans=10; for( GLuint i = 0; i < int( imageSize ); i += 4 ) { // Swaps The 1st And 3rd Bytes ('R'ed and 'B'lue) temp = texture.data[i]; // Temporarily Store The Value At Image Data 'i' texture.data[i] = texture.data[i + 1]; // Set The 1st Byte To The Value Of The 3rd Byte texture.data[i + 1] = texture.data[i + 2]; // Set The 3rd Byte To The Value In 'temp' (1st Byte Value) texture.data[i + 2] = texture.data[i + 3]; texture.data[i + 3] = temp; } int tempplace; tempplace=0; if(!hasalpha){ for( GLuint i = 0; i < int( imageSize ); i += 4 ) { texture.data[i + 3] = 255; /*texture.data[tempplace] = texture.data[i]; // Set The 1st Byte To The Value Of The 3rd Byte texture.data[tempplace + 1] = texture.data[i + 1]; // Set The 3rd Byte To The Value In 'temp' (1st Byte Value) texture.data[tempplace + 2] = texture.data[i + 2]; tempplace+=3;*/ } } if(texdetail>1){ int which=0; float temp; float howmany; for( GLuint k = 0; k < int( imageSize); k += bytesPerPixel*texture.sizeX*texdetail ) { for( GLuint i = 0; i < int( imageSize/texture.sizeY ); i += bytesPerPixel*texdetail ) { for( GLuint b = 0; b < bytesPerPixel ; b ++ ){ temp=0; howmany=0; for( GLuint l = 0; l < texdetail*texture.sizeX ; l +=texture.sizeX ){ for( GLuint j = 0; j < texdetail ; j ++ ) { temp += (int)texture.data[k+i+j*bytesPerPixel+l*bytesPerPixel+b]; // Set The 1st Byte To The Value Of The 3rd Byte howmany++; } } texture.data[which+b]=GLubyte(temp/howmany); } which+=bytesPerPixel; } } texture.sizeX/=texdetail; texture.sizeY/=texdetail; } return true; #endif }
LRESULT CALLBACK QTFrame_MovieWndProc (HWND theWnd, UINT theMessage, UINT wParam, LONG lParam) { WPARAM myWidth, myHeight; MovieController myMC = NULL; Movie myMovie = NULL; WindowObject myWindowObject = NULL; MSG myMsg = {0}; EventRecord myMacEvent; Boolean myIsHandled = false; // get the window object, movie, and movie controller for this window myWindowObject = QTFrame_GetWindowObjectFromWindow(theWnd); if (myWindowObject != NULL) { myMC = (**myWindowObject).fController; myMovie = (**myWindowObject).fMovie; } // give the movie controller this message first if ((!gShuttingDown) && (theMessage != WM_COMMAND)) { LONG myPoints = GetMessagePos(); myMsg.hwnd = theWnd; myMsg.message = theMessage; myMsg.wParam = wParam; myMsg.lParam = lParam; myMsg.time = GetMessageTime(); myMsg.pt.x = LOWORD(myPoints); myMsg.pt.y = HIWORD(myPoints); // translate a Windows event to a Mac event WinEventToMacEvent(&myMsg, &myMacEvent); // let the application-specific code have a chance to intercept the event myIsHandled = QTApp_HandleEvent(&myMacEvent); // pass the Mac event to the movie controller, but only if the movie window isn't minimized if (!myIsHandled) if (myMC != NULL) if (!IsIconic(theWnd)) myIsHandled = MCIsPlayerEvent(myMC, (EventRecord *)&myMacEvent); } switch (theMessage) { case WM_CREATE: { LONG myStyles; // create a new window object associated with the new window QTFrame_CreateWindowObject(theWnd); // disable the maximize button myStyles = GetWindowLong(theWnd, GWL_STYLE); myStyles &= ~WS_MAXIMIZEBOX; SetWindowLong(theWnd, GWL_STYLE, myStyles); } break; case WM_WINDOWPOSCHANGING: // don't show the window until we have created a movie and // can therefore properly size the window to contain the movie if (gWeAreCreatingWindow) { WINDOWPOS *lpWindowPos = (WINDOWPOS*)lParam; lpWindowPos->flags &= ~SWP_SHOWWINDOW; } break; case WM_WINDOWPOSCHANGED: // if a movie window has become minimized, stop the movie if (IsIconic(theWnd)) StopMovie(myMovie); break; case WM_SIZE: // resize the movie and controller to fit the window myWidth = LOWORD(lParam); myHeight = HIWORD(lParam); // we do NOT want to resize the movie controller if the window is minimized, // if there is no movie controller, or if we are in the middle of resizing the window if (!gWeAreSizingWindow && (myMC != NULL) && (wParam != SIZE_MINIMIZED)) { Rect myRect; myRect.top = 0; myRect.left = 0; myRect.right = myWidth; myRect.bottom = myHeight; MCSetControllerBoundsRect(myMC, &myRect); } break; case WM_MOUSEMOVE: // for QuickTime movies (but NOT for QuickTime VR movies), set the cursor to the arrow cursor if (myWindowObject != NULL) if (!(**myWindowObject).fIsQTVRMovie) SetCursor(LoadCursor(NULL, IDC_ARROW)); break; case WM_PUMPMOVIE: // we receive this message only to task the movie break; case WM_LBUTTONDOWN: // do any application-specific mouse-button handling, but only if the message hasn't already been handled if (!myIsHandled) QTApp_HandleContentClick(theWnd, &myMacEvent); break; case WM_CHAR: // do any application-specific key press handling QTApp_HandleKeyPress((char)wParam); break; case WM_PAINT: { // do any application-specific drawing in the window PAINTSTRUCT myPaintStruct; BeginPaint(theWnd, &myPaintStruct); // if the window contains an image, draw it using GraphicsImportDraw if (myWindowObject != NULL) if ((**myWindowObject).fGraphicsImporter != NULL) GraphicsImportDraw((**myWindowObject).fGraphicsImporter); QTApp_Draw(theWnd); EndPaint(theWnd, &myPaintStruct); } break; case WM_MDIACTIVATE: // activate or deactivate the movie controller in the specified window QTFrame_ActivateController(theWnd, (HWND)theWnd == (HWND)lParam); break; case WM_COMMAND: { switch (LOWORD(wParam)) { case IDM_FILESAVE: case IDM_FILESAVEAS: QTFrame_HandleFileMenuItem(theWnd, LOWORD(wParam)); break; case IDM_EDITUNDO: case IDM_EDITCUT: case IDM_EDITCOPY: case IDM_EDITPASTE: case IDM_EDITCLEAR: case IDM_EDITSELECTALL: case IDM_EDITSELECTNONE: QTFrame_HandleEditMenuItem(theWnd, LOWORD(wParam)); break; default: // do any application-specific menu handling QTApp_HandleMenu((UInt16)LOWORD(wParam)); break; } break; } // case WM_COMMAND case WM_GETMINMAXINFO: QTFrame_CalcWindowMinMaxInfo(theWnd, (LPMINMAXINFO)lParam); return(0); case WM_CLOSE: // prepare to close the window, making sure that any changed data is saved or explicitly discarded; // we can still cancel the window closing here if (myWindowObject != NULL) { // if the window's data is "dirty", give the user a chance to save it if ((**myWindowObject).fIsDirty) { int myItem; char myText[256]; UINT myAction; // get the title of the window GetWindowText(theWnd, myText, sizeof(myText)); // specify the action myAction = gShuttingDown ? IDS_SAVEONQUIT : IDS_SAVEONCLOSE; // display the "Save changes" dialog box myItem = QTFrame_ShowCautionAlert(theWnd, myAction, MB_ICONEXCLAMATION, MB_YESNOCANCEL, gAppName, myText); switch (myItem) { case kSaveChanges: // save the data in the window QTFrame_UpdateMovieFile(theWnd); break; case kCancelClose: // do not close the window and do not quit the application gShuttingDown = false; return(0); case kDontSaveChanges: // discard any unsaved changes (that is, don't do anything) break; default: // unexpected item selected; just return return(0); } } } // if (myWindowObject != NULL) // if we got to this point, it's okay to close and destroy the window SendMessage(ghWndMDIClient, WM_MDIDESTROY, (WPARAM)theWnd, 0L); break; case WM_DESTROY: // when we get this message, // the window has been removed from the screen and its associated data must be destroyed if (myWindowObject != NULL) QTFrame_CloseWindowObject(myWindowObject); SetWindowLong(theWnd, GWL_USERDATA, 0); // destroy the port association DestroyPortAssociation((CGrafPtr)GetHWNDPort(theWnd)); break; } return(DefMDIChildProc(theWnd, theMessage, wParam, lParam)); }
GWorldPtr OpenImage (void) { unsigned long rowStride; GraphicsImportComponent giComp; NavReplyRecord replyNav; NavTypeListHandle hTypeList = (NavTypeListHandle) NewHandleClear (sizeof (NavTypeList) + sizeof (OSType) * 13); FSSpec fsspecImage; AEKeyword theKeyword; DescType actualType; Size actualSize; OSStatus err = noErr; Rect rectImage; GDHandle origDevice; CGrafPtr origPort; PixMapHandle hPixMap; ImageDescriptionHandle hImageDesc; MatrixRecord matrix; GWorldPtr pGWorld; unsigned char * pImageBuffer; long imageWidth; long imageHeight; float imageAspect; long imageDepth; long textureWidth; long textureHeight; GetGWorld (&origPort, &origDevice); // save onscreen graphics port HLock ((Handle) hTypeList); (**hTypeList).osTypeCount = 14; (**hTypeList).osType[0] = 'qtif'; (**hTypeList).osType[1] = 'SGI '; (**hTypeList).osType[2] = '8BPS'; (**hTypeList).osType[3] = 'GIF '; (**hTypeList).osType[4] = 'GIFf'; (**hTypeList).osType[5] = 'JPEG'; (**hTypeList).osType[6] = 'JPG '; (**hTypeList).osType[7] = 'PICT'; (**hTypeList).osType[8] = 'PNTG'; (**hTypeList).osType[9] = 'grip'; (**hTypeList).osType[10] = 'BMPp'; (**hTypeList).osType[11] = 'TIFF'; (**hTypeList).osType[12] = 'TEXT'; (**hTypeList).osType[13] = '????'; err = NavChooseFile (NULL, &replyNav, NULL, NULL, NULL, NULL, hTypeList, NULL); if ((err == noErr) && (replyNav.validRecord)) err = AEGetNthPtr (&(replyNav.selection), 1, typeFSS, &theKeyword, &actualType, &fsspecImage, sizeof (fsspecImage), &actualSize); NavDisposeReply (&replyNav); if (err != noErr) return NULL; GetGraphicsImporterForFile (&fsspecImage, &giComp); if (err != noErr) return NULL; // create GWorld err = GraphicsImportGetNaturalBounds (giComp, &rectImage); if (err != noErr) return NULL; hImageDesc = (ImageDescriptionHandle) NewHandle (sizeof (ImageDescriptionHandle)); HLock ((Handle) hImageDesc); err = GraphicsImportGetImageDescription (giComp, &hImageDesc); if (err != noErr) return NULL; imageWidth = rectImage.right - rectImage.left; imageHeight = rectImage.bottom - rectImage.top; imageAspect = ((float) imageWidth) / ((float) imageHeight); imageDepth = (**hImageDesc).depth; // bits if (imageDepth <= 16) imageDepth = 16; else imageDepth = 32; #if 1 textureWidth = imageWidth;//40;//imageWidth;//256; textureHeight = imageHeight;//40 * imageHeight / imageWidth;//imageHeight;//256; #else textureWidth = imageWidth;//256; textureHeight = imageHeight;//256; #endif SetRect (&rectImage, 0, 0, textureWidth, textureHeight); // l, t, r. b reset to texture rectangle rowStride = textureWidth * imageDepth / 8; pImageBuffer = (unsigned char *) NewPtrClear (rowStride * (textureHeight)); if (imageDepth == 32) QTNewGWorldFromPtr (&(pGWorld), k32ARGBPixelFormat, &rectImage, NULL, NULL, 0, pImageBuffer, rowStride); else QTNewGWorldFromPtr (&(pGWorld), k16BE555PixelFormat, &rectImage, NULL, NULL, 0, pImageBuffer, rowStride); if (NULL == pGWorld) return NULL; // decompress to gworld SetIdentityMatrix (&matrix); ScaleMatrix (&matrix, X2Fix ((float) textureWidth / (float) imageWidth), X2Fix ((float) textureHeight / (float) imageHeight), X2Fix (0.0), X2Fix (0.0)); err = GraphicsImportSetMatrix(giComp, &matrix); if (err != noErr) return NULL; err = GraphicsImportSetGWorld (giComp, pGWorld, NULL); if (err != noErr) return NULL; err = GraphicsImportSetQuality(giComp, codecLosslessQuality); if (err != noErr) return NULL; hPixMap = GetGWorldPixMap (pGWorld); if ((hPixMap) && (LockPixels (hPixMap))) // lock offscreen pixel map GraphicsImportDraw (giComp); else return NULL; // modify alpha if ( imageDepth == 32 ) { unsigned long i; unsigned long * pixel = (unsigned long *)GetPixBaseAddr( hPixMap ); for (i = 0; i < textureWidth * textureHeight; i++) { if ((*pixel & 0x00FFFFFF) == 0x00FF00) // mask only color bits and look for green *pixel = 0x00000000;//0x00303040; // replace green with dark gray transparent (to help filtering) else *pixel |= 0xFF000000; // ensure alpha is set for opaque pixels pixel++; } } else { unsigned short i; unsigned short * pixel = (unsigned short *)GetPixBaseAddr( hPixMap ); for (i = 0; i < textureWidth * textureHeight; i++) { if ((*pixel & 0x7FFF) == 0x03E0) // mask only color bits and look for green *pixel = 0x0000;//0x0363; // replace green with dark gray transparent (to help filtering) else *pixel |= 0x8000; // ensure alpha is set for opaque pixels pixel++; } } return pGWorld; }
// ----------------------------------------------------------------------------- // CreateCGImageWithQTFromFile // ----------------------------------------------------------------------------- // OSStatus CreateCGImageWithQTFromFile( FSRef* inFSRef, CGImageRef* outImage ) { OSStatus err; GraphicsImportComponent importer; FSSpec fileSpec; GWorldPtr gWorld = NULL; Rect bounds; CGDataProviderRef provider; CGColorSpaceRef colorspace; long width; long height; long rowbytes; Ptr dataPtr; // Make an FSRef into an FSSpec err = FSGetCatalogInfo( inFSRef, kFSCatInfoNone, NULL, NULL, &fileSpec, NULL ); require_noerr( err, CantMakeFSSpec ); err = GetGraphicsImporterForFile( &fileSpec, &importer ); require_noerr( err, CantGetImporter ); err = GraphicsImportGetNaturalBounds( importer, &bounds ); require_noerr( err, CantGetBounds ); // Allocate the buffer width = RECT_WIDTH( bounds ); height = RECT_HEIGHT( bounds ); rowbytes = width * 4; dataPtr = NewPtr( height * rowbytes ); require_action( dataPtr != NULL, CantAllocBuffer, err = memFullErr ); err = NewGWorldFromPtr( &gWorld, 32, &bounds, NULL, NULL, NULL, dataPtr, rowbytes ); require_noerr( err, CantCreateGWorld ); err = GraphicsImportSetGWorld( importer, gWorld, GetGWorldDevice( gWorld) ); require_noerr( err, CantSetGWorld ); err = GraphicsImportDraw( importer ); require_noerr( err, CantDraw ); provider = CGDataProviderCreateWithData( NULL, dataPtr, height * rowbytes, GWorldImageBufferRelease ); require_action( provider != NULL, CantCreateProvider, err = memFullErr ); colorspace = CGColorSpaceCreateDeviceRGB(); require_action( colorspace != NULL, CantCreateColorSpace, err = memFullErr ); *outImage = CGImageCreate( width, height, 8, 32, rowbytes, colorspace, kCGImageAlphaPremultipliedFirst, provider, NULL, false, kCGRenderingIntentDefault ); require_action( *outImage != NULL, CantCreateImage, err = memFullErr ); CantCreateImage: CGColorSpaceRelease( colorspace ); CantCreateColorSpace: CGDataProviderRelease( provider ); CantCreateProvider: CantDraw: CantSetGWorld: if ( gWorld != NULL ) DisposeGWorld( gWorld ); CantCreateGWorld: CantAllocBuffer: CantGetBounds: CantGetImporter: CantMakeFSSpec: return err; }
bool LoadTexture(IplTexture *tex, const char *filename, const char *subdir) { ComponentInstance fileImporter; OSErr error; ImageDescriptionHandle imageInfo; ComponentResult err; CFStringRef name = CFStringCreateWithCStringNoCopy(NULL, filename, kCFStringEncodingASCII, NULL); CFStringRef _subdir = CFStringCreateWithCStringNoCopy(NULL, subdir, kCFStringEncodingASCII, NULL); CFURLRef texture_url = CFBundleCopyResourceURL( CFBundleGetMainBundle(), name, NULL, _subdir); // Create the data reference so we can get the file's graphics importer. Handle dataRef; OSType dataRefType; dataRef = NewHandle(sizeof(AliasHandle)); // The second parameter to QTNewDataReferenceFromCFURL is flags. // It should be set to 0. error = QTNewDataReferenceFromCFURL(texture_url, 0, &dataRef, &dataRefType); if(error != noErr) { //DisposeHandle(dataRef); //CFRelease(texture_url); return false; } // Get the importer for the file so we can read the information. error = GetGraphicsImporterForDataRef(dataRef, dataRefType, &fileImporter); // Retrieve information about the image imageInfo = (ImageDescriptionHandle)NewHandle(sizeof(ImageDescription)); err = GraphicsImportGetImageDescription(fileImporter, &imageInfo); unsigned width = ((**imageInfo).width); unsigned height = ((**imageInfo).height); IplImage *im = tex->getIm(); if (im && (im->width != width || im->height!=height)) cvReleaseImage(&im); if (im==0) { im = cvCreateImage(cvSize(width,height), IPL_DEPTH_8U, 4); //memset(im->imageData, 0x8f, 30*im->widthStep ); //memset(im->imageData+ 50*im->widthStep, 0xff, 30*im->widthStep); tex->setImage(im); //return true; } tex->update(); void *imageData = im->imageData; // Get the boundary rectangle of the image Rect imageRect; err = GraphicsImportGetNaturalBounds(fileImporter, &imageRect); // Create an offscreen buffer to hold the image. // Apparently QuickTime requires a GWorld to // decompress a texture file. long bytesPerRow = im->widthStep; //static GWorldPtr offscreenBuffer=0; if (offscreenBuffer==0) { error = QTNewGWorldFromPtr(&offscreenBuffer, k32RGBAPixelFormat, &imageRect, NULL, NULL, kNativeEndianPixMap, imageData, bytesPerRow); assert(error == noErr); } // Draw the image into the offscreen buffer err = GraphicsImportSetGWorld(fileImporter, offscreenBuffer, NULL); assert(err == noErr); err = GraphicsImportDraw(fileImporter); assert(err == noErr); // Cleanup error = CloseComponent(fileImporter); DisposeHandle((Handle)imageInfo); DisposeHandle(dataRef); DisposeGWorld(offscreenBuffer); return true; }
void QTCmpr_CompressImage (WindowObject theWindowObject) { Rect myRect; GraphicsImportComponent myImporter = NULL; ComponentInstance myComponent = NULL; GWorldPtr myImageWorld = NULL; // the graphics world we draw the image in PixMapHandle myPixMap = NULL; ImageDescriptionHandle myDesc = NULL; Handle myHandle = NULL; OSErr myErr = noErr; if (theWindowObject == NULL) return; ////////// // // get a graphics importer for the image file and determine the natural size of the image; // note that the image file *already* has a graphics importer associated with it (namely // (**theWindowObject).fGraphicsImporter), but we create a new one so that the existing one // can be used to redraw the image in the callback procedure QTCmpr_FilterProc // ////////// myErr = GetGraphicsImporterForFile(&(**theWindowObject).fFileFSSpec, &myImporter); if (myErr != noErr) goto bail; myErr = GraphicsImportGetNaturalBounds(myImporter, &myRect); if (myErr != noErr) goto bail; ////////// // // create an offscreen graphics world and draw the image into it // ////////// myErr = QTNewGWorld(&myImageWorld, 0, &myRect, NULL, NULL, kICMTempThenAppMemory); if (myErr != noErr) goto bail; // get the pixmap of the GWorld; we'll lock the pixmap, just to be safe myPixMap = GetGWorldPixMap(myImageWorld); if (!LockPixels(myPixMap)) goto bail; // set the current port and draw the image GraphicsImportSetGWorld(myImporter, (CGrafPtr)myImageWorld, NULL); GraphicsImportDraw(myImporter); ////////// // // configure and display the standard image compression dialog box // ////////// // open the standard compression dialog component myComponent = OpenDefaultComponent(StandardCompressionType, StandardCompressionSubType); if (myComponent == NULL) goto bail; // set the picture to be displayed in the dialog box; passing NULL for the rect // means use the entire image; passing 0 for the flags means to use the default // system method of displaying the test image, which is currently a combination // of cropping and scaling; personally, I prefer scaling (your mileage may vary) SCSetTestImagePixMap(myComponent, myPixMap, NULL, scPreferScaling); // install the custom procs, if requested // we can install two kinds of custom procedures for use in connection with // the standard dialog box: (1) a modal-dialog filter function, and (2) a hook // function to handle the custom button in the dialog box if (gUseExtendedProcs) QTCmpr_InstallExtendedProcs(myComponent, (long)myPixMap); // request image compression settings from the user; in other words, put up the dialog box myErr = SCRequestImageSettings(myComponent); if (myErr == scUserCancelled) goto bail; ////////// // // compress the image // ////////// myErr = SCCompressImage(myComponent, myPixMap, NULL, &myDesc, &myHandle); if (myErr != noErr) goto bail; ////////// // // save the compressed image in a new file // ////////// QTCmpr_PromptUserForDiskFileAndSaveCompressed(myHandle, myDesc); bail: if (gUseExtendedProcs) QTCmpr_RemoveExtendedProcs(); if (myPixMap != NULL) if (GetPixelsState(myPixMap) & pixelsLocked) UnlockPixels(myPixMap); if (myImporter != NULL) CloseComponent(myImporter); if (myComponent != NULL) CloseComponent(myComponent); if (myDesc != NULL) DisposeHandle((Handle)myDesc); if (myHandle != NULL) DisposeHandle(myHandle); if (myImageWorld != NULL) DisposeGWorld(myImageWorld); }