discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Obscure rotation problem in base-1.14/gui-0.12


From: Fred Kiefer
Subject: Re: Obscure rotation problem in base-1.14/gui-0.12
Date: Wed, 06 Jun 2007 15:14:05 +0200
User-agent: Thunderbird 1.5.0.10 (X11/20060911)

First thank you for the excellent test program that you send along with
your bug report.
With that I was able to track down the problem into the image.m file of
the art backend. (Xlib is not able to handle rotation at all and cairo
did it already correctly) What I then did was to replace the
appendTransform call there with prependTransform: and this fixed your
problem.

The strange thing about this change is that it undoes something that
wasn't changed recently, but three years ago. So I don't have a glue,
why it worked for you with the last GNUstep release. Perhaps some other
fix on NSAffineTransform made this error visible and up to then it was
needed?

Cheers,
Fred


Vaisburd, Haim wrote:
> Hi,
> 
> I installed newest packages at last, after that tested PhotoClip application.
> Apparently, the rotation is broken in the latest libraries (I tested only art 
> backend). I attach the application that rotate an image +90 degrees (that is,
> counterclockwise) and displays it.
> 
> The program is complete, but you'd need a testing.jpg file.
> 
> It workes in gui-0.11 but displays image incorrectly in gui-0.12.
> 
> I noticed that [NSAffineTransform -transformPoint:] transforms coordinates as 
> expected (and identical in the old and new version), so the problem is
> somewhere else.
> 
> Thanks in advence for your help.
> 
> --Tima
> 
> -------------- begin ---------------------
> 
> #include <Foundation/Foundation.h>
> #include <AppKit/AppKit.h>
> 
> // Method -imageRotatedBy90 that is being tested
> 
> @interface NSImage (MyTest)
> - (NSImage *) imageRotatedBy90;
> @end
> 
> @implementation NSImage (MyTest)
> 
> - (NSImage *) imageRotatedBy90
> {
>     NSSize canvas_size;
>     NSSize sz = [self size];
>     canvas_size.width  = [self size].height;
>     canvas_size.height = [self size].width;
> 
>     NSAffineTransform * xform = [NSAffineTransform transform];
> 
>     [xform rotateByDegrees: 90];
>     [xform translateXBy: 0 yBy: -sz.height];
> 
>     // equivalent transformation
>     //[xform translateXBy: sz.height yBy: 0];
>     //[xform rotateByDegrees: 90];
> 
>     NSPoint pt[4];
>     pt[0] = NSMakePoint( 1, 1 );
>     pt[1] = NSMakePoint( sz.width - 1, 1 );
>     pt[2] = NSMakePoint( sz.width - 1, sz.height -1 );
>     pt[3] = NSMakePoint( 1, sz.height - 1 );
>     int i;
>     for ( i=0; i < 4; ++i )
>         NSLog( @"%@ -> %@",
>                NSStringFromPoint(pt[i]),
>                NSStringFromPoint([xform transformPoint: pt[i]]) );
> 
>     // Create canvas to draw upon
>     NSImage * canvas = [[NSImage alloc] initWithSize: canvas_size];
>     [canvas lockFocus];
> 
>     [xform concat];
>     
>     // Get NSImageRep of image
>     NSImageRep * rep = [self bestRepresentationForDevice: nil];
> 
>     [rep drawAtPoint: NSZeroPoint];
>     
>     [canvas unlockFocus];
>     return AUTORELEASE(canvas);
> }
> 
> @end
> 
> 
> // Call this method in [NSView -drawRect]
> 
> @interface MyView : NSView
> - (void) drawRect: (NSRect) rect;
> @end
> 
> @implementation MyView
> 
> - (void) drawRect: (NSRect) rect
> {
>     NSString * fileName = @"testimg.jpg";
> 
>     NSImage * image = [[NSImage alloc] initWithContentsOfFile: fileName];
>     if ( image == nil )
>     {
>         NSLog(@"can't load file '%@'\n", fileName);
>         return;
>     }
> 
>     NSImage * rotatedImage = [image imageRotatedBy90];
> 
>     NSPoint origin = NSMakePoint(20, 20);
>     [rotatedImage compositeToPoint: origin operation: NSCompositeCopy];
> 
>     RELEASE(image);
> }
> 
> @end
> 
> // --------------- All the rest is supporting frame ----------------------
> 
> @interface MyDelegate : NSObject
> {
>     NSWindow * my_window;
> }
> 
> - (void) dealloc;
> - (void) createWindow;
> - (void) applicationWillFinishLaunching: (NSNotification *)not;
> - (void) applicationDidFinishLaunching: (NSNotification *)not;
> - (BOOL) applicationShouldTerminateAfterLastWindowClosed: (id)sender;
> @end
> 
> 
> @implementation MyDelegate : NSObject 
> 
> - (void) dealloc
> {
>     RELEASE(my_window);
>     [super dealloc];
> }
> 
> - (void) createWindow
> {
>     // Determine good window size.
>     NSSize screenSize = [[NSScreen mainScreen] frame].size;
>     NSRect rect = NSMakeRect(0,0,
>                              screenSize.width * 4./5.,
>                              screenSize.height * 4./5.);
> 
>     unsigned int styleMask = NSTitledWindowMask
>         | NSClosableWindowMask
>         | NSMiniaturizableWindowMask
>         | NSResizableWindowMask;
> 
> 
>     my_window = [[NSWindow alloc] initWithContentRect: rect
>                                   styleMask: styleMask
>                                   backing: NSBackingStoreRetained
>                                   defer: YES];
>     [my_window setTitle: @"Test imageRotatedBy90"];
>     [my_window setContentView: [[MyView alloc] initWithFrame: rect]];
> }
> 
> 
> - (void) applicationWillFinishLaunching: (NSNotification *)not
> {
>     [self createWindow];
> }
> 
> - (void) applicationDidFinishLaunching: (NSNotification *)not
> {
>     [my_window makeKeyAndOrderFront: nil];
> 
> }
> 
> - (BOOL) applicationShouldTerminateAfterLastWindowClosed: (id)sender
> {
>     return YES;
> }
> 
> @end
> 
> int main (int argc, const char **argv)
> {
>     [NSApplication sharedApplication];
>     [NSApp setDelegate: [MyDelegate new]];
> 
>     return NSApplicationMain (argc, argv);
> }
> 
> -----------  end ----------------
> 
> 
> 
> _______________________________________________
> Discuss-gnustep mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/discuss-gnustep
> 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]