Anyone worked with super large images in a Cocoa (Mac) app? Think 300k x 300k pixels, in at least 16 bits per channel.

At very least I need to be able to read individual pixels out of a TIFF file.

Making a whole image buffer in CoreGraphics to store the decompressed file is not really feasible. Any suggestions how else I can read a subset of the image without doing this?

@amyworrall I *think* you can use a CGImageSource with a CGDataProvider to get the region of data you’re insterested in, but I’ve never actually done this myself.

@digitalfx @amyworrall DataProviders are one of the avenues I’d explore:
1. Look into CGDataProvider to check if there’s any explicit support for random-access, non-buffered backing.
2. Memory-mapping the file may be an option? This will page in data upon request. (Mac only, not iOS!)
Both depend on whether CG’s TIFF reader tries to consume everything at once.

3. Investigate third-party readers for the file format; some probably support such use cases explicitly.

@digitalfx @amyworrall (This kind of use case is common in some domains, e.g. probably medical imaging, GIS, etc. so it might be worth investigating where this is indeed a common issue and what their standard solutions are.)

@pmdj @digitalfx it's GIS I'm doing :)

Essentially I have my own map rendering software. I'm currently working on a heightmap (in Photoshop), and I want to keep it high res in order to be able to crop bits out of it later. But I need my software to be able to read subsets of it in order to handle re-projecting it.

@amyworrall @digitalfx Yeah, makes sense. To be honest, if it was me I’d probably look for a TIFF reader outside of CoreGraphics that has good support for this kind of usage pattern. It sounds like immediate onward usage as a CGImage might not be important if you’re transforming it anyway? Also, if the files aren’t user-supplied, security is less of a concern with a more obscure library. (Though ideally it’d be written in a memory-safe language…)

@pmdj @digitalfx Yeah, for this case I don't necessarily need it as a CGImage. (Actually most of my pipeline is CIImages anyway. But this particular operation doesn't need to behave like the rest of what I'm doing.)

At the moment the app is just for me, so no security issues. It may turn into a product one day, but I'd have a LOT of work to do before I'm happy with someone else using it! When it's just me, I can tolerate janky bits :)

@amyworrall @digitalfx Yep, sounds fine. I just have a long history of trying to use Apple’s libraries in ways they were not intended to be used, and coming to regret it later. (And I’m definitely not saying you should do it one way or the other; just that if it was me I’d probably head for option 3 pretty soon if 1 or 2 started looking like they were going to be tricky.)