// // RotateImage.cpp // Version 1.0 // // Created by GREIF Software on 08/02/29. // Copyright GREIF Software 2008. All rights reserved. // #include "rb_plugin.h" #include "REALplugin.h" static REALpicture RotateImage( REALpicture sourcePic, int mode ) { REALpicture destPic = 0; REALpictureDescription pictureDesc; GWorldPtr GWorld1, GWorld2; Rect Rect1, Rect2; OSErr theErr; PixMapHandle PixMap1, PixMap2; Ptr Base1, Loc1, Base2, Loc2; unsigned long pdWidth, pdHeight; long Row1, Row2; int width1, height1, width2, height2; unsigned char Alpha, Red, Green, Blue; if (sourcePic == NULL) return 0; REALLockPictureDescription( sourcePic, &pictureDesc ); pdWidth = pictureDesc.width; pdHeight = pictureDesc.height; REALUnlockPictureDescription( sourcePic ); SetRect( &Rect1, 0, 0, pdWidth, pdHeight ); theErr = NewGWorld( &GWorld1, 32, &Rect1, NULL, NULL, 0 ); if ( theErr != noErr || GWorld1 == NULL ) return 0; SetGWorld( GWorld1, NULL ); REALDrawPicturePrimitive( sourcePic, &Rect1, 0 ); PixMap1 = GetGWorldPixMap( GWorld1 ); LockPixels( PixMap1 ); Base1 = GetPixBaseAddr( PixMap1 ); Row1 = 0x3fff & ( *PixMap1 ) -> rowBytes; width1 = Rect1.right - Rect1.left; height1 = Rect1.bottom - Rect1.top; if ( mode == 1 || mode == 3 ) SetRect( &Rect2, 0, 0, pdHeight, pdWidth ); else SetRect( &Rect2, 0, 0, pdWidth, pdHeight ); theErr = NewGWorld( &GWorld2, 32, &Rect2, NULL, NULL, 0 ); if ( theErr != noErr || GWorld2 == NULL ) { UnlockPixels( PixMap1 ); DisposeGWorld( GWorld1 ); return 0; } SetGWorld( GWorld2, NULL ); PixMap2 = GetGWorldPixMap( GWorld2 ); LockPixels( PixMap2 ); Base2 = GetPixBaseAddr( PixMap2 ); Row2 = 0x3fff & ( *PixMap2 ) -> rowBytes; width2 = Rect2.right - Rect2.left; height2 = Rect2.bottom - Rect2.top; for ( int y = 0; y < height1; y++ ) { for ( int x = 0; x < width1; x++ ) { Loc1 = Base1 + x * 4 + y * Row1; Alpha = *(unsigned char *) Loc1++; Red = *(unsigned char *) Loc1++; Green = *(unsigned char *) Loc1++; Blue = *(unsigned char *) Loc1++; switch (mode) { case 1: Loc2 = Base2 + ((width2-1)-y) * 4 + x * Row2; break; case 2: Loc2 = Base2 + ((width2-1)-x) * 4 + ((height2-1)-y) * Row2; break; case 3: Loc2 = Base2 + y * 4 + ((height2-1)-x) * Row2; break; default: Loc2 = Base2 + x * 4 + y * Row2; } *((unsigned char *) Loc2++) = Alpha; *((unsigned char *) Loc2++) = Red; *((unsigned char *) Loc2++) = Green; *((unsigned char *) Loc2++) = Blue; } } destPic = REALBuildPictureFromGWorld( GWorld2, true ); UnlockPixels( PixMap2 ); UnlockPixels( PixMap1 ); DisposeGWorld( GWorld1 ); return destPic; } REALmethodDefinition RotateImageDefn = { (REALproc) RotateImage, REALnoImplementation, "RotateImage(Pic As Picture, mode As Integer) As Picture" }; void PluginEntry(void) { REALRegisterMethod(&RotateImageDefn); }