• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Doubled Pixels
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Doubled Pixels


  • Subject: Re: Doubled Pixels
  • From: "Gerriet M. Denkmann" <email@hidden>
  • Date: Sun, 25 Jun 2017 16:39:07 +0700

> On 25 Jun 2017, at 09:29, Graham Cox <email@hidden> wrote:
>
> You could get the colorSpaceName from the source image and use that. If
> there’s no conversion needed between the images it’ll probably be faster
> (though seems you are giving yourself the option of creating a grayscale
> version here).

The images are really b&w, but the source image claims to be
NSCalibratedRGBColorSpace.
So I prefer to control the colour here and not rely on the source image.

Which of these two lines is preferable:
        NSString *colorSpaceName = useColour ? NSDeviceRGBColorSpace :
NSDeviceWhiteColorSpace;
        NSString *colorSpaceName = useColour ? NSCalibratedRGBColorSpace :
NSCalibratedWhiteColorSpace;
?


>>      NSInteger bitsPerPixel = samplesPerPixel * bitsPerSample;
>>      NSInteger bytesPerRow = pixelsWide * bitsPerPixel / 8;
>
> In fact you can pass 0 for these last two and the function will calculate
> them for you. It’s better to do that because if there’s the slightest thing
> wrong with the parameters it will give up with an exception.
> The internal calculation can also round up bytesPerRow to something that will
> optimise copying performance.

I changed my code following your suggestion.


>>      [ NSGraphicsContext setCurrentContext: context ];
>
> You may want to save and restore the current context around this, just to be
> sure your method isn’t going to have the unwanted side effect of changing the
> current context. It’s likely OK, but better safe than sorry.

I just did. Turns out that the oldContext seems to be nil. But as you rightly
said: “better safe than sorry”.


>>      NSRect destRect = NSZeroRect; destRect.size = subRect.size;
>
> Just use NSZeroRect for destRect. This is interpreted to mean “the size of
> the destination image”, which is already <subRect>, rounded up. If you set
> the size here and it’s not a whole number for some reason, there is the
> potential for the very edge pixels not to get set, leaving a visible edge at
> the right and bottom of the result.

I tried this. But got a rather small image (just 88 bytes - usually 337 bytes)
and the resulting image looks rather empty. It has the right size, but not a
single pixel is set - all are transparent.

But heading your warning about non-whole numbers, I added at the very start:

- (NSData *)subImagePngDataWithRect: (NSRect)suxRect  useColour: (BOOL)useColour
{
        NSRect subRect = NSIntegralRect(suxRect);
        …
}


> Otherwise, looks good. Does it do the job?

It did. And now it does even better.

Thanks a lot for your help. Very much appreciated!


Kind regards,

Gerriet.

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Doubled Pixels
      • From: Graham Cox <email@hidden>
References: 
 >Doubled Pixels (From: "Gerriet M. Denkmann" <email@hidden>)
 >Re: Doubled Pixels (From: Jens Alfke <email@hidden>)
 >Re: Doubled Pixels (From: "Gerriet M. Denkmann" <email@hidden>)
 >Re: Doubled Pixels (From: Graham Cox <email@hidden>)

  • Prev by Date: Re: Doubled Pixels
  • Next by Date: Re: Doubled Pixels
  • Previous by thread: Re: Doubled Pixels
  • Next by thread: Re: Doubled Pixels
  • Index(es):
    • Date
    • Thread