Giter VIP home page Giter VIP logo

tiff-ios's Introduction

TIFF iOS

Tagged Image File Format Lib

The GeoPackage Libraries were developed at the National Geospatial-Intelligence Agency (NGA) in collaboration with BIT Systems. The government has "unlimited rights" and is releasing this software to increase the impact of government investments by providing developers with the opportunity to take things in new directions. The software use, modification, and distribution rights are stipulated within the MIT license.

Pull Requests

If you'd like to contribute to this project, please make a pull request. We'll review the pull request and discuss the changes. All pull request contributions to this project will be released under the MIT license.

Software source code previously released under an open source license and then modified by NGA staff is considered a "joint work" (see 17 USC § 101); it is partially copyrighted, partially public domain, and as a whole is protected by the copyrights of the non-government authors and must be released according to the terms of the original open source license.

About

TIFF is an iOS Objective-C library for reading and writing Tagged Image File Format files. It was primarily created to provide license friendly TIFF functionality to iOS applications. Implementation is based on the TIFF specification and this JavaScript implementation: https://github.com/constantinius/geotiff.js

Usage

View the latest Appledoc

Read

// NSData *data = ...;
// NSString *file = ...;
// NSInputStream *stream = ...;
// TIFFByteReader *reader = ...;

TIFFImage *tiffImage = [TIFFReader readTiffFromData:data];
// TIFFImage *tiffImage = [TIFFReader readTiffFromFile:file];
// TIFFImage *tiffImage = [TIFFReader readTiffFromStream:stream];
// TIFFImage *tiffImage = [TIFFReader readTiffFromReader:reader];
NSArray<TIFFFileDirectory *> *directories = [tiffImage fileDirectories];
TIFFFileDirectory *directory  = [directories objectAtIndex:0];
TIFFRasters *rasters = [directory readRasters];

Write

int width = 256;
int height = 256;
int samplesPerPixel = 1;
int bitsPerSample = 32;

TIFFRasters *rasters = [[TIFFRasters alloc] initWithWidth:width andHeight:height andSamplesPerPixel:samplesPerPixel andSingleBitsPerSample:bitsPerSample];

int rowsPerStrip = [rasters calculateRowsPerStripWithPlanarConfiguration:(int)TIFF_PLANAR_CONFIGURATION_CHUNKY];

TIFFFileDirectory *directory = [[TIFFFileDirectory alloc] init];
[directory setImageWidth: width];
[directory setImageHeight: height];
[directory setBitsPerSampleAsSingleValue: bitsPerSample];
[directory setCompression: TIFF_COMPRESSION_NO];
[directory setPhotometricInterpretation: TIFF_PHOTOMETRIC_INTERPRETATION_BLACK_IS_ZERO];
[directory setSamplesPerPixel: samplesPerPixel];
[directory setRowsPerStrip: rowsPerStrip];
[directory setPlanarConfiguration: TIFF_PLANAR_CONFIGURATION_CHUNKY];
[directory setSampleFormatAsSingleValue: TIFF_SAMPLE_FORMAT_FLOAT];
[directory setWriteRasters: rasters];

for (int y = 0; y < height; y++) {
    for (int x = 0; x < width; x++) {
        float pixelValue = 1.0; // any pixel value
        [rasters setFirstPixelSampleAtX:x andY:y withValue:[[NSDecimalNumber alloc] initWithFloat:pixelValue]];
    }
}

TIFFImage *tiffImage = [[TIFFImage alloc] init];
[tiffImage addFileDirectory:directory];
NSData *data = [TIFFWriter writeTiffToDataWithImage:tiffImage];
// or
// NSString *file = ...;
// [TIFFWriter writeTiffWithFile:file andImage:tiffImage];

Build

Build & Test

Build this repository using Xcode and/or CocoaPods:

pod install

Open tiff-ios.xcworkspace in Xcode or build from command line:

xcodebuild -workspace 'tiff-ios.xcworkspace' -scheme tiff-ios build

Run tests from Xcode or from command line:

xcodebuild test -workspace 'tiff-ios.xcworkspace' -scheme tiff-ios -destination 'platform=iOS Simulator,name=iPhone 15'

Include Library

Include this repository by specifying it in a Podfile using a supported option.

Pull from CocoaPods:

pod 'tiff-ios', '~> 4.0.2'

Pull from GitHub:

pod 'tiff-ios', :git => 'https://github.com/ngageoint/tiff-ios.git', :branch => 'master'
pod 'tiff-ios', :git => 'https://github.com/ngageoint/tiff-ios.git', :tag => '4.0.2'

Include as local project:

pod 'tiff-ios', :path => '../tiff-ios'

Swift

To use from Swift, import the tiff-ios bridging header from the Swift project's bridging header

#import "tiff-ios-Bridging-Header.h"

Read

// let data: Data = ...
// let file: String = ...
// let stream: NSInputStream = ...
// let reader: TIFFByteReader = ...

let tiffImage: TIFFImage = TIFFReader.readTiff(from: data)
// let tiffImage: TIFFImage = TIFFReader.readTiff(fromFile: file)
// let tiffImage: TIFFImage = TIFFReader.readTiff(from: stream)
// let tiffImage: TIFFImage = TIFFReader.readTiff(from: reader)
let directories: [TIFFFileDirectory] = tiffImage.fileDirectories()
let directory: TIFFFileDirectory = directories[0]
let rasters: TIFFRasters = directory.readRasters()

Write

let width: UInt16 = 256
let height: UInt16 = 256
let samplesPerPixel: UInt16 = 1
let bitsPerSample: UInt16 = 32

let rasters: TIFFRasters = TIFFRasters(width: Int32(width), andHeight: Int32(height), andSamplesPerPixel: Int32(samplesPerPixel), andSingleBitsPerSample: Int32(bitsPerSample))

let rowsPerStrip: UInt16 = UInt16(rasters.calculateRowsPerStrip(withPlanarConfiguration: Int32(TIFF_PLANAR_CONFIGURATION_CHUNKY)))

let directory: TIFFFileDirectory = TIFFFileDirectory()
directory.setImageWidth(width)
directory.setImageHeight(height)
directory.setBitsPerSampleAsSingleValue(bitsPerSample)
directory.setCompression(UInt16(TIFF_COMPRESSION_NO))
directory.setPhotometricInterpretation(UInt16(TIFF_PHOTOMETRIC_INTERPRETATION_BLACK_IS_ZERO))
directory.setSamplesPerPixel(samplesPerPixel)
directory.setRowsPerStrip(rowsPerStrip)
directory.setPlanarConfiguration(UInt16(TIFF_PLANAR_CONFIGURATION_CHUNKY))
directory.setSampleFormatAsSingleValue(UInt16(TIFF_SAMPLE_FORMAT_FLOAT))
directory.writeRasters = rasters

for y in 0..<height {
    for x in 0..<width {
        let pixelValue: Float = 1.0 // any pixel value
        rasters.setFirstPixelSampleAtX(Int32(x), andY: Int32(y), withValue: NSDecimalNumber(value: pixelValue))
    }
}

let tiffImage: TIFFImage = TIFFImage()
tiffImage.addFileDirectory(directory)
let data: Data = TIFFWriter.writeTiffToData(with: tiffImage)
// or
// let file: String = ...
// TIFFWriter.writeTiff(withFile: file, andImage: tiffImage)

tiff-ios's People

Contributors

bosborn avatar btuttle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tiff-ios's Issues

Is it possible convert to MKMapRect ?

Hello everyone,

I have a TIFF file and I want convert that a MKOverlay for MapKit tile. Is it possible ?

If I have north, south, east and west information could help me lot.

Thanks.

KML file with this informations and png images I have implemented and works.

Unable to build pod and project with Xcode 10

I have a project that uses tiff-ios library. It is added via CocoaPods. I am unable to build my project with Xcode 10 because uses a new build system. Other ~10 Pods Xcode builds without any problems. The workaround is to enable Legacy Build System for the project: Xcode->File->Project Settings-> Build System -> Legacy Build System.

Version Information:

  • TIFF iOS Version: 1.1.0
  • TIFF iOS Source: CocoaPods
  • CocoaPods Version: 1.5.3
  • Xcode Version: 10.0 (10A255)
  • Device or Emulator: -
  • iOS Version: -
  • Other Relevant Libraries: -

Expected Results:

  • Project with tiff-ios pod is built successfully

Observed Results:

  • What happened instead?
    Build error occurs
  • How often does this occur?
    Always

Output:

  • Any logs, errors, or output messages?
:-1: Multiple commands produce '/Users/shorben/Library/Developer/Xcode/DerivedData/Sentinel-dotrbepnaqitsofbuoxreaqhcyky/Build/Products/Debug-iphonesimulator/tiff-ios/TIFF.bundle/Info.plist':
1) Target 'tiff-ios-TIFF' (project 'Pods') has copy command from '/Users/shorben/Documents/wsi-sentinel-ios/Pods/tiff-ios/tiff-ios/Info.plist' to '/Users/shorben/Library/Developer/Xcode/DerivedData/Sentinel-dotrbepnaqitsofbuoxreaqhcyky/Build/Products/Debug-iphonesimulator/tiff-ios/TIFF.bundle/Info.plist'
2) Target 'tiff-ios-TIFF' (project 'Pods') has process command with output '/Users/shorben/Library/Developer/Xcode/DerivedData/Sentinel-dotrbepnaqitsofbuoxreaqhcyky/Build/Products/Debug-iphonesimulator/tiff-ios/TIFF.bundle/Info.plist'

Steps to Reproduce:

  1. Create a new project empty project in Xcode (use Xcode 10)
  2. Execute pod init command
  3. Add pod 'tiff-ios', '~> 1.1' to Podfile
  4. Execute pod install command
  5. Open project and build

Build Error Undefined Symbol OBJC_CLASS_$_SFGeometryUtils

Please fill out as much known and relevant information as possible.

Version Information:

  • TIFF iOS Version: 4.01
  • TIFF iOS Source: (e.g. CocoaPods, Source Code Build) Source code build
  • CocoaPods Version:
  • Xcode Version: 14.3
  • Device or Emulator: compiling for iPad Air iOS 16.4.1
  • iOS Version: 16.4.1
  • Other Relevant Libraries:

Expected Results:

  • What did you expect to happen? I did a clean build and now get linker error with undefined symbol.

Observed Results:

  • What happened instead? Can't build my iOS app now that linker fails with tiff-ios lib
  • How often does this occur? Every time.

Output:

  • Any logs, errors, or output messages?

Steps to Reproduce:

  1. Step One
  2. Step Two
  3. ...

Relevant Code:

// Code to reproduce the problem?

Test Files:

  • Links to any files needed for testing?

Additional Information:

  • Any additional configuration, data, or information that might help with the issue?

Deflate decoder is not yet implemented

Please fill out as much known and relevant information as possible.

Version Information:

  • TIFF iOS Version: 4.0.1
  • TIFF iOS Source: (e.g. CocoaPods, Source Code Build) Build from source
  • CocoaPods Version: 4.0.2
  • Xcode Version: 14.2
  • Device or Emulator: iphone 14 ios 16.2
  • iOS Version: 16.2
  • Other Relevant Libraries:

Expected Results:

  • What did you expect to happen? Loaded a geotiff file (that works with android library) and tried to access rasters and it crashes with error "Deflate decoder is not yet implemented"

Observed Results:

  • What happened instead? "Deflate decoder is not yet implemented"
  • How often does this occur? Consistent

Output:

  • Any logs, errors, or output messages?
  • Terminating app due to uncaught exception 'Not Implemented', reason: 'Deflate decoder is not yet implemented'
    *** First throw call stack:
    (
    0 CoreFoundation 0x000000018040e7c8 __exceptionPreprocess + 172
    1 libobjc.A.dylib 0x0000000180051144 objc_exception_throw + 56
    2 CoreFoundation 0x000000018040e6d8 -[NSException initWithCoder:] + 0
    3 tiff_ios 0x000000010079ef38 -[TIFFDeflateCompression decodeData:withByteOrder:] + 96
    4 tiff_ios 0x0000000100792b1c -[TIFFFileDirectory tileOrStripWithX:andY:andSample:] + 1700
    5 tiff_ios 0x0000000100791b3c -[TIFFFileDirectory readRastersWithWindow:andSamples:andRasters:] + 1256
    6 tiff_ios 0x00000001007915f0 -[TIFFFileDirectory readRastersWithWindow:andSamples:andSampleValues:andInterleaveValues:] + 1460
    7 tiff_ios 0x0000000100790d44 -[TIFFFileDirectory readRastersWithWindow:andSamples:] + 112
    8 tiff_ios 0x0000000100790aec -[TIFFFileDirectory readRastersWithWindow:] + 72
    9 tiff_ios 0x0000000100790a04 -[TIFFFileDirectory readRasters] + 72

Steps to Reproduce:

  1. Step One
  2. Step Two
  3. ...

Relevant Code:

ios swift
rasters = directory!.readRasters()

// Code to reproduce the problem?

Test Files:

Additional Information:

  • Any additional configuration, data, or information that might help with the issue?

How to load the TIFFRasters object to display to the user

I am following the instructions in the README in order to load and display a GeoTIFF file in an iOS app.

I can successfully get a TIFFRasters object. I can inspect some properties like so:
width: 9291, height: 6670, pixels: 61970970

My question is, how can I get an image format ready for display from here? I reckon it could be a UIImage or a CIImage, but I see no method to convert to any such format.

Looking at the JS library, I see one can render the image with plotty, what would be the equivalent in iOS, please?

Retrieving origin and resolution for Geo-Data

State your question
Is there a method to retrieve origin and resolution for tiffs that encode geo-data?
for example DEM files?

Additional context
Looking into the Geotiff.js, as referenced by this library:

// when we are actually dealing with geo-data the following methods return
// meaningful results:
const origin = image.getOrigin();
const resolution = image.getResolution();
const bbox = image.getBoundingBox();

have an error when try directory.readRasters()

this is my code:

    let tiffImage: TIFFImage = TIFFReader.readTiff(from: data)
    let directories: [TIFFFileDirectory] = tiffImage.fileDirectories()
    
    for directory in directories {
        let rasters: TIFFRasters = directory.readRasters() <-------ERROR
    }

this is an error:

libc++abi: terminating with uncaught exception of type NSException *** Terminating app due to uncaught exception 'Unsupported Compression', reason: 'JPEG compression not supported: 7' terminating with uncaught exception of type NSException

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.