Re: NSImage to JPEG file?

2019-01-17 Thread Alastair Houghton
On 16 Jan 2019, at 20:17, Jens Alfke  wrote:
> 
>> On Jan 16, 2019, at 9:59 AM, Carl Hoefs  
>> wrote:
>> 
>> But all of that would come "for free" if NSImage inherited from NSData, no?
> 
> Well, that wouldn’t make sense, because an NSImage isn’t a piece of data. It 
> can have multiple data representations (JPEG, PNG, PDF…) and it might not 
> have any at all if it was created directly in-memory with a pixmap. It’s a 
> thing that can create a data representation.

Quite.  This point is worth emphasising, actually.  A very common mistake 
people make when trying to write OO programs is using inheritance where there 
isn’t an is-a relationship.

NSImage definitely *is not* an NSData, and so should not inherit from it.

(Indeed, it could even have a custom NSImageRep backing it that does the 
drawing on the fly; indeed, there is actually a built-in version of this in the 
current version of Cocoa, where you can specify a block that gets used to 
render the image whenever the system feels it’s necessary.)

This confusion isn’t helped by the fact that certain commonly used OO languages 
(I’m looking at you, C++) muddy the waters by trying to use inheritance for 
multiple different purposes (e.g. interfaces, typically via pure virtual 
classes; mixins and the like for *implementation* purposes - which largely only 
works because of multiple inheritance and/or templates, depending on how the 
mixin is built).

Kind regards,

Alastair.

--
http://alastairs-place.net

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSImage to JPEG file?

2019-01-16 Thread Jens Alfke


> On Jan 16, 2019, at 9:59 AM, Carl Hoefs  
> wrote:
> 
> But all of that would come "for free" if NSImage inherited from NSData, no?

Well, that wouldn’t make sense, because an NSImage isn’t a piece of data. It 
can have multiple data representations (JPEG, PNG, PDF…) and it might not have 
any at all if it was created directly in-memory with a pixmap. It’s a thing 
that can create a data representation.

—Jens
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


NSImage to JPEG file?

2019-01-16 Thread Greg Weston

>> That would be poor API design. If it had -writeToFile, then it would also 
>> need -writeToStream:, -writeToFileHandle:, -writeToFileDescriptor:, 
>> -writeToNSURLSessionDataDelegate:, etc.
>> Providing the data itself means you can then use existing APIs on other 
>> classes to put the data anywhere you want.
> 
> But all of that would come "for free" if NSImage inherited from NSData, no?

No. Because there’s no guarantee that the “data” that define an NSImage - or 
its representation(s) - conform to any specific commodity format.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSImage to JPEG file?

2019-01-16 Thread Carl Hoefs


> On Jan 16, 2019, at 10:43 AM, Jens Alfke  wrote:
> 
>> On Jan 16, 2019, at 8:32 AM, Carl Hoefs > > wrote:
>> 
>> It was the NSData tie-in I didn't know. (I was expecting NSImage to have 
>> innate export capabilities
> 
> That would be poor API design. If it had -writeToFile, then it would also 
> need -writeToStream:, -writeToFileHandle:, -writeToFileDescriptor:, 
> -writeToNSURLSessionDataDelegate:, etc.
> Providing the data itself means you can then use existing APIs on other 
> classes to put the data anywhere you want.

But all of that would come "for free" if NSImage inherited from NSData, no?

-Carl


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSImage to JPEG file?

2019-01-16 Thread Jens Alfke


> On Jan 16, 2019, at 8:32 AM, Carl Hoefs  
> wrote:
> 
> It was the NSData tie-in I didn't know. (I was expecting NSImage to have 
> innate export capabilities

That would be poor API design. If it had -writeToFile, then it would also need 
-writeToStream:, -writeToFileHandle:, -writeToFileDescriptor:, 
-writeToNSURLSessionDataDelegate:, etc.
Providing the data itself means you can then use existing APIs on other classes 
to put the data anywhere you want.

—Jens
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSImage to JPEG file?

2019-01-16 Thread Carl Hoefs
Thanks Wim and Gerd. It was the NSData tie-in I didn't know. (I was expecting 
NSImage to have innate export capabilities, but this works too.)

-Carl


> On Jan 16, 2019, at 7:56 AM, Wim Lewis  wrote:
> 
> On Tue, Jan 15, 2019 at 08:10:58PM -0700, Carl Hoefs wrote:
>> Using NSBitmapImageRep, is it possible to write the JPEG representation out 
>> to a .JPG file on disk?
> 
> The normal way is to get the JPEG representation as a NSData and then 
> write that NSData to disk using (e.g.) -writeToFile:options:error:.
> 
> The ImageIO functions allow you to stream the data to disk (instead of 
> creating a complete representation in memory before writing), which can 
> be more efficient, but in my experience this is rarely a concern.
> 

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSImage to JPEG file?

2019-01-15 Thread Carl Hoefs
Using NSBitmapImageRep, is it possible to write the JPEG representation out to 
a .JPG file on disk?

-Carl

> On Jan 15, 2019, at 4:01 PM, Jens Alfke  wrote:
> 
> It’s been a long time since I worked with NSImages, but it’s easy to get a 
> JPEG representation using just plain AppKit. 
> 
> Just look through the representations for an NSBitmapImageRep, then call [rep 
> representationUsingType: NSBitmapImageFileTypeJPEG options: 0].
> 
> —Jens
> 
> PS: _Please_ don’t reply to digests. It messes up the subject line and the 
> message threading.
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> 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:
> https://lists.apple.com/mailman/options/cocoa-dev/newslists%40autonomy.caltech.edu
> 
> This email sent to newsli...@autonomy.caltech.edu

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSImage to JPEG file?

2019-01-15 Thread Jens Alfke
It’s been a long time since I worked with NSImages, but it’s easy to get a JPEG 
representation using just plain AppKit. 

Just look through the representations for an NSBitmapImageRep, then call [rep 
representationUsingType: NSBitmapImageFileTypeJPEG options: 0].

—Jens

PS: _Please_ don’t reply to digests. It messes up the subject line and the 
message threading.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSImage to JPEG file?

2019-01-14 Thread Alex Zavatone
I will send you something.

Sent from my iPhone

> On Jan 14, 2019, at 2:17 PM, Carl Hoefs  
> wrote:
> 
> I have a background macOS daemon process (aka Foundation-based "command line 
> tool") that needs to write out a JPEG file to local disk. The image resides 
> in an NSImage object (or alternatively, an NSData of raw RGB image data). 
> 
> Short of resorting to something like libjpeg, what is the ObjC way to do this?
> 
> -Carl
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> 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:
> https://lists.apple.com/mailman/options/cocoa-dev/zav%40mac.com
> 
> This email sent to z...@mac.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSImage to JPEG file?

2019-01-14 Thread Carl Hoefs
Got it working!
Thanks, that's the tip I needed. 
-Carl


> On Jan 14, 2019, at 1:26 PM, Vince DeMarco  wrote:
> 
> Use ImageIO.
> 
> create a CGImageDestinationRef and add the CGImage to it.
> 
> Vince
> 
> 
> 
>> On Jan 14, 2019, at 12:17 PM, Carl Hoefs  
>> wrote:
>> 
>> I have a background macOS daemon process (aka Foundation-based "command line 
>> tool") that needs to write out a JPEG file to local disk. The image resides 
>> in an NSImage object (or alternatively, an NSData of raw RGB image data). 
>> 
>> Short of resorting to something like libjpeg, what is the ObjC way to do 
>> this?
>> 
>> -Carl
>> 
>> ___
>> 
>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>> 
>> 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:
>> https://lists.apple.com/mailman/options/cocoa-dev/demarco%40apple.com
>> 
>> This email sent to dema...@apple.com
> 

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSImage to JPEG file?

2019-01-14 Thread Vince DeMarco
Use ImageIO.

create a CGImageDestinationRef and add the CGImage to it.

Vince



> On Jan 14, 2019, at 12:17 PM, Carl Hoefs  
> wrote:
> 
> I have a background macOS daemon process (aka Foundation-based "command line 
> tool") that needs to write out a JPEG file to local disk. The image resides 
> in an NSImage object (or alternatively, an NSData of raw RGB image data). 
> 
> Short of resorting to something like libjpeg, what is the ObjC way to do this?
> 
> -Carl
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> 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:
> https://lists.apple.com/mailman/options/cocoa-dev/demarco%40apple.com
> 
> This email sent to dema...@apple.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


NSImage to JPEG file?

2019-01-14 Thread Carl Hoefs
I have a background macOS daemon process (aka Foundation-based "command line 
tool") that needs to write out a JPEG file to local disk. The image resides in 
an NSImage object (or alternatively, an NSData of raw RGB image data). 

Short of resorting to something like libjpeg, what is the ObjC way to do this?

-Carl

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com