Commits

Anonymous committed 750a90a

90degree rotates

  • Participants
  • Parent commits c744f33

Comments (0)

Files changed (7)

 # BREAK = change breaks existing code
 # BUG	= fixed a bug that was (or could have been) crashing
 
+January 26, 2002
+	special cases for 90 degree transform.rotate()
+	OSX cleanups for commandline (thanks Bob)
+
 January 23, 2002
 	transform.rotate() does alpha if image has alphaplane
 	transform.rotate() no longer "off by one" in the x axis
-import sys
-import os
-import re
-import unittest
+#!/usr/bin/env python
+import sys, os, re, unittest
 
 main_dir = os.path.split(os.path.abspath(sys.argv[0]))[0]
 test_subdir = 'test'
+// CPS.h
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if PRAGMA_STRUCT_ALIGN
+    #pragma options align=mac68k
+#elif PRAGMA_STRUCT_PACKPUSH
+    #pragma pack(push, 2)
+#elif PRAGMA_STRUCT_PACK
+    #pragma pack(2)
+#endif
+
+
+struct CPSProcessSerNum
+{
+	UInt32		lo;
+	UInt32		hi;
+};
+
+typedef struct CPSProcessSerNum	CPSProcessSerNum;
+
+enum
+{
+	kCPSNoProcess		=	0,
+	kCPSSystemProcess	=	1,
+	kCPSCurrentProcess	=	2
+};
+
+
+enum
+{
+	bfCPSIntraProcessSwitch =	1,
+	bfCPSDeathBySignal	=	2
+};
+
+typedef UInt16	CPSEventFlags;
+
+
+enum
+{
+	kCPSBlueApp	=	0,
+	kCPSBlueBox	=	1,
+	kCPSCarbonApp	=	2,
+	kCPSYellowApp	=	3,
+	kCPSUnknownApp	=	4
+};
+
+typedef UInt32	CPSAppFlavour;
+
+
+enum
+{
+	kCPSBGOnlyAttr		=	1024,
+	kCPSUIElementAttr	=	65536,
+	kCPSHiddenAttr		=	131072,
+	kCPSNoConnectAttr	=	262144,
+	kCPSFullScreenAttr	=	524288,
+	kCPSClassicReqAttr	=	1048576,
+	kCPSNativeReqAttr	=	2097152
+};
+
+typedef UInt32	CPSProcAttributes;
+
+
+struct CPSProcessInfoRec
+{
+	CPSProcessSerNum 	Parent;
+	UInt64			LaunchDate;
+	CPSAppFlavour		Flavour;
+	CPSProcAttributes	Attributes;
+	UInt32			ExecFileType;
+	UInt32			ExecFileCreator;
+	UInt32			UnixPID;
+};
+
+typedef struct CPSProcessInfoRec	CPSProcessInfoRec;
+
+
+enum
+{
+	kCPSNotifyChildDeath	=	1,
+	kCPSNotifyNewFront	=	2,
+	kCPSNotifyAppBirth	=	4,
+	kCPSNotifyAppDeath	=	8,
+	kCPSNotifyLaunch	=	9,
+	kCPSNotifyServiceReq	=	16,
+	kCPSNotifyAppHidden	=	32,
+	kCPSNotifyAppRevealed	=	64,
+	kCPSNotifyFGEnabled	=	128,
+	kCPSNotifyLaunchStart	=	256,
+	kCPSNotifyAppReady	=	512,
+	kCPSNotifyLaunchFail	=	1024,
+	kCPSNotifyAppDeathExt	=	2048,
+	kCPSNotifyLostKeyFocus	=	4096
+};
+
+typedef UInt32	CPSNotificationCodes;
+
+
+enum
+{
+	bfCPSLaunchInhibitDaemon	=	128,
+	bfCPSLaunchDontSwitch		=	512,
+	bfCPSLaunchNoProcAttr		=	2048,
+	bfCPSLaunchAsync		=	65536,
+	bfCPSLaunchStartClassic		=	131072,
+	bfCPSLaunchInClassic		=	262144,
+	bfCPSLaunchInstance		=	524288,
+	bfCPSLaunchAndHide		=	1048576,
+	bfCPSLaunchAndHideOthers	=	2097152
+};
+
+typedef UInt32	CPSLaunchOptions;
+
+
+typedef	UInt8	*CPSLaunchRefcon;
+
+
+typedef	UInt8	*CPSLaunchData;
+
+
+enum
+{
+	bfCPSExtLaunchWithData	=	2,
+	bfCPSExtLaunchByParent	=	4,
+	bfCPSExtLaunchAsUidGid	=	8
+};
+
+typedef UInt32	CPSLaunchPBFields;
+
+
+struct CPSLaunchPB
+{
+	CPSLaunchPBFields	Contents;
+	CPSLaunchData		pData;
+	UInt32			DataLen;
+	UInt32			DataTag;
+	UInt32			RefCon;
+	CPSProcessSerNum	Parent;
+	UInt32			ChildUID;
+	UInt32			ChildGID;
+};
+
+typedef struct CPSLaunchPB	CPSLaunchPB;
+
+
+enum
+{
+	bfCPSKillHard		=	1,
+	bfCPSKillAllClassicApps	=	2
+};
+
+typedef UInt32	CPSKillOptions;
+
+
+enum
+{
+	kCPSLaunchService	=	0,
+	kCPSKillService		=	1,
+	kCPSHideService		=	2,
+	kCPSShowService		=	3,
+	kCPSPrivService		=	4,
+	kCPSExtDeathNoteService	=	5
+};
+
+typedef UInt32	CPSServiceReqType;
+
+
+struct CPSLaunchRequest
+{
+	CPSProcessSerNum	TargetPSN;
+	CPSLaunchOptions 	Options;
+	CPSProcAttributes 	ProcAttributes;
+	UInt8			*pUTF8TargetPath;
+	UInt32			PathLen;
+};
+
+typedef struct CPSLaunchRequest	CPSLaunchRequest;
+
+
+struct CPSKillRequest
+{
+	CPSProcessSerNum	TargetPSN;
+	CPSKillOptions		Options;
+};
+
+typedef struct CPSKillRequest	CPSKillRequest;
+
+
+struct CPSHideRequest
+{
+	CPSProcessSerNum 	TargetPSN;
+};
+
+typedef struct CPSHideRequest	CPSHideRequest;
+
+
+struct CPSShowRequest
+{
+	CPSProcessSerNum 	TargetPSN;
+};
+
+typedef struct CPSShowRequest	CPSShowRequest;
+
+
+struct CPSExtDeathNotice
+{
+	CPSProcessSerNum 	DeadPSN;
+	UInt32			Flags;
+	UInt8			*pUTF8AppPath;
+	UInt32			PathLen;
+};
+
+typedef struct CPSExtDeathNotice	CPSExtDeathNotice;
+
+
+union CPSRequestDetails
+{
+	CPSLaunchRequest 	LaunchReq;
+	CPSKillRequest 		KillReq;
+	CPSHideRequest 		HideReq;
+	CPSShowRequest 		ShowReq;
+	CPSExtDeathNotice 	DeathNotice;
+};
+
+typedef union CPSRequestDetails	CPSRequestDetails;
+
+
+struct CPSServiceRequest
+{
+	CPSServiceReqType 	Type;
+	SInt32			ID;
+	CPSRequestDetails 	Details;
+};
+
+typedef struct CPSServiceRequest	CPSServiceRequest;
+
+
+enum
+{
+	kCPSProcessInterruptKey	=	0,
+	kCPSAppSwitchFwdKey	=	1,
+	kCPSAppSwitchBackKey	=	2,
+	kCPSSessionInterruptKey	=	3,
+	kCPSScreenSaverKey	=	4,
+	kCPSDiskEjectKey	=	5,
+	kCPSSpecialKeyCount	=	6
+};
+
+typedef SInt32	CPSSpecialKeyID;
+
+
+extern Boolean	CPSEqualProcess( CPSProcessSerNum *psn1, CPSProcessSerNum *psn2);
+
+extern OSErr	CPSGetCurrentProcess( CPSProcessSerNum *psn);
+
+extern OSErr	CPSGetFrontProcess( CPSProcessSerNum *psn);
+
+extern OSErr	CPSGetNextProcess( CPSProcessSerNum *psn);
+
+extern OSErr	CPSGetNextToFrontProcess( CPSProcessSerNum *psn);
+
+extern OSErr	CPSGetProcessInfo( CPSProcessSerNum *psn, CPSProcessInfoRec *info, char *path, int maxPathLen, int *len, char *name, int maxNameLen);
+
+extern OSErr	CPSPostHideMostReq( CPSProcessSerNum *psn);
+
+extern OSErr	CPSPostHideReq( CPSProcessSerNum *psn);
+
+extern OSErr	CPSPostKillRequest( CPSProcessSerNum *psn, CPSKillOptions options);
+
+extern OSErr	CPSPostShowAllReq( CPSProcessSerNum *psn);
+
+extern OSErr	CPSPostShowReq( CPSProcessSerNum *psn);
+
+extern OSErr	CPSSetFrontProcess( CPSProcessSerNum *psn);
+
+extern OSErr	CPSReleaseKeyFocus( CPSProcessSerNum *psn);
+
+extern OSErr	CPSStealKeyFocus( CPSProcessSerNum *psn);
+
+extern OSErr 	CPSSetProcessName ( CPSProcessSerNum *psn, char *processname);
+
+extern OSErr 	CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
+
+
+
+
+#if PRAGMA_STRUCT_ALIGN
+    #pragma options align=reset
+#elif PRAGMA_STRUCT_PACKPUSH
+    #pragma pack(pop)
+#elif PRAGMA_STRUCT_PACK
+    #pragma pack()
+#endif
+
+#ifdef __cplusplus
+}
+#endif
 #import <unistd.h>
 #import <Cocoa/Cocoa.h>
 #import <Carbon/Carbon.h>
+#import "CPS.h"
 
-extern int NXArgc;
-extern char **NXArgv;
 @interface SDLMain : NSObject
 @end
 
 /* Create a window menu */
 void setupWindowMenu(void)
 {
-    NSMenu		*windowMenu;
+    NSMenu	*windowMenu;
     NSMenuItem	*windowMenuItem;
     NSMenuItem	*menuItem;
 
 
 void StartTheDamnApplication (void)
 {
+    CPSProcessSerNum PSN;
+    //OSErr err;
     NSImage *pygameIcon;
     global_pool = [[NSAutoreleasePool alloc] init];
     [NSApplication sharedApplication];
+    if (!CPSGetCurrentProcess(&PSN))
+        if (!CPSSetProcessName(&PSN,"pygame"))
+            if (!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103))
+                if (!CPSSetFrontProcess(&PSN))
+                    [NSApplication sharedApplication];
     [NSApp setMainMenu:[[NSMenu alloc] init]];
     setupWindowMenu();
     sdlMain = [[SDLMain alloc] init];
 	if(!cdrom_drivedata[cd_id])
 	{
 		cdrom_drivedata[cd_id] = SDL_CDOpen(cd_id);
-		if(!cdrom_drivedata[cd_id])
+                if(!cdrom_drivedata[cd_id])
 			return RAISE(PyExc_SDLError, SDL_GetError());
 	}
 	RETURN_NONE
 		DisplaySurfaceObject = PySurface_New(surf);
 
 
-	/*set the default icon. we may not want to do this on darwin?*/
+#if !defined(darwin)
 	if(!icon_was_set)
 	{
 		SDL_Surface* icon;
 			}
 		}
 	}
+#endif
 
 	Py_INCREF(DisplaySurfaceObject);
 	return DisplaySurfaceObject;
 }
 
 
+static SDL_Surface* rotate90(SDL_Surface *src, int angle)
+{
+    int numturns = (angle / 90) % 4;
+    int dstwidth, dstheight;
+    SDL_Surface* dst;
+    char *srcpix, *dstpix, *srcrow, *dstrow;
+    int srcstepx, srcstepy, dststepx, dststepy;
+    int loopx, loopy;
 
+    if(numturns<0)
+        numturns = 4+numturns;
+printf("ROT90: angle=%d  numturns=%d\n", angle, numturns);    
+    if(!(numturns % 2))
+    {
+        dstwidth = src->w;
+        dstheight = src->h;
+    }
+    else
+    {
+        dstwidth = src->h;
+        dstheight = src->w;
+    }
+printf("ROT90: src=%d,%d   dst=%d,%d\n", src->w,src->h,dstwidth,dstheight);
+    
+    dst = newsurf_fromsurf(src, dstwidth, dstheight);
+    if(!dst)
+        return NULL;
+    srcrow = (char*)src->pixels;
+    dstrow = (char*)dst->pixels;
+    srcstepx = dststepx = src->format->BytesPerPixel;
+    srcstepy = src->pitch;
+    dststepy = dst->pitch;
+    
+    switch(numturns)
+    {
+    /*case 0: we don't need to change anything*/
+    case 1:
+        srcrow += ((src->w-1)*srcstepx);
+        srcstepy = -srcstepx;
+        srcstepx = src->pitch;
+        break;
+    case 2:
+        srcrow += ((src->h-1)*srcstepy) + ((src->w-1)*srcstepx);
+        srcstepx = -srcstepx;
+        srcstepy = -srcstepy;
+        break;
+    case 3:
+        srcrow += ((src->h-1)*srcstepy);
+        srcstepx = -srcstepy;
+        srcstepy = src->format->BytesPerPixel;
+        break;
+    }
+
+    switch(src->format->BytesPerPixel)
+    {
+    case 1:
+        for(loopy=0; loopy<dstheight; ++loopy)
+        {
+            dstpix = dstrow; srcpix = srcrow;
+            for(loopx=0; loopx<dstwidth; ++loopx)
+            {
+                *dstpix = *srcpix;
+                srcpix += srcstepx; dstpix += dststepx;
+            }
+            dstrow += dststepy; srcrow += srcstepy;
+        }break;
+    case 2:
+        for(loopy=0; loopy<dstheight; ++loopy)
+        {
+            dstpix = dstrow; srcpix = srcrow;
+            for(loopx=0; loopx<dstwidth; ++loopx)
+            {
+                *(Uint16*)dstpix = *(Uint16*)srcpix;
+                srcpix += srcstepx; dstpix += dststepx;
+            }
+            dstrow += dststepy; srcrow += srcstepy;
+        }break;
+    case 3:
+        for(loopy=0; loopy<dstheight; ++loopy)
+        {
+            dstpix = dstrow; srcpix = srcrow;
+            for(loopx=0; loopx<dstwidth; ++loopx)
+            {
+                dstpix[0] = srcpix[0]; dstpix[1] = srcpix[1]; dstpix[2] = srcpix[2];
+                srcpix += srcstepx; dstpix += dststepx;
+            }
+            dstrow += dststepy; srcrow += srcstepy;
+        }break;
+    case 4:
+        for(loopy=0; loopy<dstheight; ++loopy)
+        {
+            dstpix = dstrow; srcpix = srcrow;
+            for(loopx=0; loopx<dstwidth; ++loopx)
+            {
+                *(Uint32*)dstpix = *(Uint32*)srcpix;
+                srcpix += srcstepx; dstpix += dststepx;
+            }
+            dstrow += dststepy; srcrow += srcstepy;
+        }break;
+    }
+printf("ROT90:\n");
+    return dst;
+}
 
 
 static void rotate(SDL_Surface *src, SDL_Surface *dst, Uint32 bgcolor, double sangle, double cangle)
 	if(surf->format->BytesPerPixel <= 0 || surf->format->BytesPerPixel > 4)
 		return RAISE(PyExc_ValueError, "unsupport Surface bit depth for transform");
 
+        if(!(((int)angle)%90))
+        {
+            newsurf = rotate90(surf, (int)angle);
+            if(!newsurf) return NULL;
+            return PySurface_New(newsurf);
+        }
+        
+        
 	radangle = angle*.01745329251994329;
 	sangle = sin(radangle);
 	cangle = cos(radangle);