Skip to content

Commit

Permalink
version 1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Kort authored and gaborcsardi committed Jan 21, 2009
1 parent 8e5f78b commit 9c9d60d
Show file tree
Hide file tree
Showing 20 changed files with 1,459 additions and 10 deletions.
10 changes: 5 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Package: rtiff
Type: Package
Title: A tiff reader for R.
Version: 1.1
Date: 2006-12-05
Version: 1.4
Date: 2009-01-21
Depends: pixmap
Author: Eric Kort
Maintainer: Eric Kort <eric.kort@vai.org>
SystemRequirements: libtiff
Description: This package will read (and, as of version 1.1, write) TIFF format images and return them as a pixmap object. Because the resulting object can be very large for even modestly sized TIFF images, images can be reduced as they are read for improved performance. This package is a wrapper around libtiff (www.libtiff.org), on which it depends (i.e. the libtiff shared library must be on your PATH for the binary to work, and tiffio.h must be on your system to build the package from source). By using libtiff's highlevel TIFFReadRGBAImage function, this package inherently support a wide range of image formats and compression schemes. This package also provides an implementation of the Ridler Autothresholding algorithm for easy generation of binary masks.
License: GPL
Packaged: Tue Dec 5 16:56:06 2006; eric.kort
Description: This package will read (and, as of version 1.1, write) TIFF format images and return them as a pixmap object. Because the resulting object can be very large for even modestly sized TIFF images, images can be reduced as they are read for improved performance. This package is a wrapper around libtiff (www.libtiff.org), on which it depends (i.e. the libtiff shared library must be on your PATH for the binary to work, and tiffio.h must be on your system to build the package from source). By using libtiff's highlevel TIFFReadRGBAImage function, this package inherently support a wide range of image formats and compression schemes. This package also provides an implementation of the Ridler Autothresholding algorithm for easy generation of binary masks.
License: file LICENSE
Packaged: Thu Jan 22 09:17:22 2009; Eric.Kort
27 changes: 27 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
This package depends upon the libtiff package (www.remotesensing.org/libtiff),
which has the following license:

Copyright (c) 1988-1997 Sam Leffler
Copyright (c) 1991-1997 Silicon Graphics, Inc.

Permission to use, copy, modify, distribute, and sell this software and
its documentation for any purpose is hereby granted without fee, provided
that (i) the above copyright notices and this permission notice appear in
all copies of the software and related documentation, and (ii) the names of
Sam Leffler and Silicon Graphics may not be used in any advertising or
publicity relating to the software without the specific, prior written
permission of Sam Leffler and Silicon Graphics.

THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.

IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
OF THIS SOFTWARE.

Any portions of the package which do not depend upon libtiff are placed
under the GNU General Public License, version 3.0 or later.
2 changes: 2 additions & 0 deletions NAMESPACE
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ readTiff,
writeTiff,
autoThreshold,
newPixmapRGB,
updateDescription,
getDescription,
plot.matrix)

S3method(plot, matrix)
5 changes: 5 additions & 0 deletions R/getDescription.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"getDescription" <-
function(fn) {
ret <- .Call("getTiffDescription", fn, PACKAGE="rtiff")
ret
}
Empty file modified R/readTiff.R
100755 → 100644
Empty file.
5 changes: 5 additions & 0 deletions R/updateDescription.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"updateDescription" <-
function(fn, description) {
.Call("updateTTag", fn, description, PACKAGE="rtiff")
return()
}
Empty file modified R/writeTiff.R
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion man/autoThreshold.Rd
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ tif <- readTiff(paste(.path.package("rtiff"), "/tiff/jello.tif", sep=""))
threshold <- autoThreshold(tif@red)
plot(tif)

get(getOption("device"))()
getOption("device")()

plot(tif@red > threshold[3])
}
Expand Down
25 changes: 25 additions & 0 deletions man/getDescription.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
\name{getDescription}
\alias{getDescription}
\title{ Get the description on a TIFF file. }
\description{
Gets the TIFF description field (tag 270) for a TIFF file.
}
\usage{
getDescription(fn)
}
\arguments{
\item{fn}{ The name of the tiff file. }
}
\value{
A string with the description field from the TIFF file.
}
\author{ Eric Kort <eric.kort@vai.org> }
\examples{

library(rtiff)
tif <- readTiff(paste(.path.package("rtiff"), "/tiff/jello.tif", sep=""))
getDescription(paste(.path.package("rtiff"), "/tiff/jello.tif", sep=""))
}
\keyword{ utilities }
\keyword{ IO }
\keyword{ file }
2 changes: 1 addition & 1 deletion man/newPixmapRGB.Rd
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ plot(myPixmap)

#let's scramble the color channels just for fun

get(getOption("device"))()
getOption("device")()
myPixmap <- newPixmapRGB(tif@blue, tif@red, tif@green)
plot(myPixmap)

Expand Down
Empty file modified man/plot.matrix.Rd
100755 → 100644
Empty file.
Empty file modified man/readTiff.Rd
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion man/rtiff.package.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Maintainer: Eric Kort <eric.kort@vai.org>
\references{
www.libtiff.org
}
}
\examples{
library(rtiff)
tif <- readTiff(paste(.path.package("rtiff"), "/tiff/jello.tif", sep=""))
Expand Down
22 changes: 22 additions & 0 deletions man/updateDescription.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
\name{updateDescription}
\alias{updateDescription}
\title{ Set the description on a TIFF file. }
\description{
Sets the TIFF description field (tag 270) for a TIFF file.
}
\usage{
updateDescription(fn, description)
}
\arguments{
\item{fn}{ The name of the tiff file. }
\item{description}{ The text to set the description to. }
}
\value{
None.
}
\author{ Eric Kort <eric.kort@vai.org> }
\examples{
}
\keyword{ utilities }
\keyword{ IO }
\keyword{ file }
Empty file modified man/writeTiff.Rd
100755 → 100644
Empty file.
61 changes: 59 additions & 2 deletions src/rtiff.c
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <math.h>
#include <tiffio.h>
#include "tiffio.h"
#include <R.h>
#include <Rdefines.h>
#include <Rinternals.h>
Expand Down Expand Up @@ -90,6 +90,8 @@ void TiffReadTIFFRGBA (char** fileName, int* dir, int* r, int* g, int* b) {
uint32 *buf;
TIFF* tif;

uint16 count;
char *data;

if((tif = TIFFOpen(*fileName, "r")) == NULL) {
return;
Expand Down Expand Up @@ -123,6 +125,26 @@ void TiffReadTIFFRGBA (char** fileName, int* dir, int* r, int* g, int* b) {
return;
}

SEXP getTiffDescription(SEXP fn) {
char* fileName;
TIFF *tiff;
char* data;
SEXP ans;
fileName = (char*)CHAR(STRING_ELT(fn, 0)) ;
if((tiff = TIFFOpen(fileName, "r")) == NULL){
fprintf(stderr, "Could not open image file\n");
return;
}

TIFFGetField(tiff, 270, &data);
TIFFClose(tiff);

PROTECT(ans=NEW_CHARACTER(1));
SET_STRING_ELT(ans, 0, mkChar(data));
UNPROTECT(1);
return(ans);
}

void writeTiff(SEXP mr, SEXP mg, SEXP mb, SEXP fn)
{
TIFF *output;
Expand All @@ -133,7 +155,8 @@ void writeTiff(SEXP mr, SEXP mg, SEXP mb, SEXP fn)
double *r = REAL(mr);
double *g = REAL(mg);
double *b = REAL(mb);
char* fileName = CHAR(STRING_ELT(fn, 0)) ;
char* fileName;
fileName = (char*)CHAR(STRING_ELT(fn, 0));

// Open the output image
if((output = TIFFOpen(fileName, "w")) == NULL){
Expand Down Expand Up @@ -189,3 +212,37 @@ void reduce(int* r, int* nr, int* w, int* h, double* p)
}
}
}


void updateTTag (SEXP fn, SEXP desc)
{
TIFF *tiff;
char* fileName;
char* description;
// Open the image
fileName = (char*)CHAR(STRING_ELT(fn, 0)) ;
description = (char*)CHAR(STRING_ELT(desc, 0)) ;

if((tiff = TIFFOpen(fileName, "r+")) == NULL){
fprintf(stderr, "Could not open outgoing image\n");
exit(42);
}

const TIFFFieldInfo *fip;
fip = TIFFFieldWithTag(tiff, 270);
if (!fip) {
fprintf(stderr, "Could not get field information\n");
exit(42);
}
if (fip->field_type == TIFF_ASCII) {
if (TIFFSetField(tiff, fip->field_tag, description) != 1)
fprintf( stderr, "Failed to set field.");
} else {
fprintf(stderr, "Description field is not ascii\n");
exit(42);
}
TIFFRewriteDirectory(tiff);
TIFFClose(tiff);
return;
}

0 comments on commit 9c9d60d

Please sign in to comment.