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 }