discuss-gnustep
[Top][All Lists]
Advanced

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

tiff image blues


From: Marko Riedel
Subject: tiff image blues
Date: Wed, 5 Mar 2003 13:26:29 +0100 (CET)

Hi folks,

perhaps the following remarks may be of use to you.

I am trying to display TIFF images quickly.

1. For some reason I could not get NSImageView to work with my setup,
as it seems to draw the whole image every time.

2. Therefore I designed my own view that uses compositeToPoint. This
works fine, but not when the application is set to display on a remote
X server over the network. I was shocked to discover that

(a) NSImage always uses an off-screen window to cache the image, even
when there exists a perfectly suitable bitmap image rep. among its
representations and

(b) NSImage draws the entire cache during the first composite
operation, as opposed to the rectangle that was asked for. This means
that the entire image goes over the network, making the first
composite operation very slow.

3. I was not satisfied with this and decided to ask the bitmap image
rep. to draw itself. The first display was much faster, but subsequent
displays that were triggered by a scroll view were slow, because the
bitmap would re-draw itself in its entirety every time!

4. I decided to take advantage of the fact that you can index bitmap
image planes to obtain a horizontal strip of the image. Hence you can
restrict drawing to those lines of the image that were asked
for. An inefficiency remains: the left or right portions of the strip
may not have been demanded, but they are drawn anyway.

5. I now have a solution that performs reasonably well regardless of
whether the X server runs on the local host or somewhere on the
network. The code is included with this message.

Best regards,

-- 
+------------------------------------------------------------+
| Marko Riedel, EDV Neue Arbeit gGmbH, mriedel@neuearbeit.de |
| http://www.geocities.com/markoriedelde/index.html          |
+------------------------------------------------------------+

- (void)drawRect:(NSRect)aRect
{
    if(image!=nil){
        /*
        [image compositeToPoint:aRect.origin
               fromRect:aRect
               operation:NSCompositeCopy];
        */
        NSBitmapImageRep *prep, *rep =
            [[image representations] objectAtIndex:0];
        unsigned char *planes[5];
        int offset;

        [rep getBitmapDataPlanes:planes];

        offset = [rep pixelsHigh];
        offset -= (int)aRect.origin.y;
        offset -= (int)aRect.size.height;

        offset *= [rep bytesPerRow];

        planes[0] += offset;
        planes[1] += offset;
        planes[2] += offset;
        planes[3] += offset;
        planes[4] += offset;


        prep = [[NSBitmapImageRep alloc]
                   initWithBitmapDataPlanes:planes
                   pixelsWide:[rep pixelsWide]
                   pixelsHigh:aRect.size.height
                   bitsPerSample:[rep bitsPerSample]
                   samplesPerPixel:[rep samplesPerPixel]
                   hasAlpha:[rep hasAlpha]
                   isPlanar:[rep isPlanar]
                   colorSpaceName:[rep colorSpaceName]
                   bytesPerRow:[rep bytesPerRow]
                   bitsPerPixel:[rep bitsPerPixel]];

        PStranslate(0, aRect.origin.y);

        [prep draw];
    }
}




reply via email to

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