[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Roughie... feeling towards a TIFF class
From: |
Sather User |
Subject: |
Roughie... feeling towards a TIFF class |
Date: |
Mon, 5 Sep 2011 12:34:59 +0930 (CST) |
While I'm making a noise, very preliminary and very, very rough, but
roughie.sa does correctly print the resolution tags of a test file.
The files other than roughie.sa go in the $(SATHER_LIBDIR)/tiff
directory.
tiff.module
-----------
-external C_TIFF "-ltiff $(SATHER_LIBDIR)/tiff/c_tiff.c"
-has tiff.sa TIFF TIFFTAG EXIFTAG
----------------------------------------------------------------
c_tiff.c
--------
#include <tiff.h>
#include <tiffio.h>
int tiff_checkret(TIFF* arg)
{
if (arg == 0)
{
return 0;
}
else
{
return 1;
}
}
void wideness(TIFF* arg)
{
int w;
int i;
printf("%s\n","WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW");
i = TIFFGetField(arg, TIFFTAG_IMAGEWIDTH, &w);
printf("%s\n","XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
printf("____________return val = %d\n", i);
printf("____________width = %d\n", w);
}
float xresolution(TIFF* arg)
{
int i;
float n;
i = TIFFGetField(arg, TIFFTAG_XRESOLUTION, &n);
if (i==0)
return -1.0;
return n;
}
float yresolution(TIFF* arg)
{
int i;
float n;
i = TIFFGetField(arg, TIFFTAG_YRESOLUTION, &n);
if (i==0)
return -1.0;
return n;
}
int xposition(TIFF* arg)
{
int i, p;
i = TIFFGetField(arg, TIFFTAG_XPOSITION, &p);
if (i==0) return -1;
return p;
}
int yposition(TIFF* arg)
{
int i, p;
i = TIFFGetField(arg, TIFFTAG_YPOSITION, &p);
if (i==0) return -1;
return p;
}
/*
char * imdesc(TIFF* arg)
{
char * c;
c = TIFFGetField(arg, TIFFTAG_IMAGEDESCRIPTION, &p);
hum hum;
}
*/
int exififd(TIFF* arg)
{
int i;
int e;
i = TIFFGetField(arg, TIFFTAG_EXIFIFD, &e);
if (i==0) return -1;
return e;
}
-----------------------------------------------------------------------
tiff.sa
-------
class TIFFTAG is
const imagewidth:=265, imagelength, bitspersample, compression;
const minsamplevalue:=280, maxsamplevalue, xresolution, yresolution,
planarconfig, pagename, xposition, yposition;
const imagedescription:=270;
const resolutionunit:=296;
const software:=305, datetime;
const artist:=315, hostcomputer;
const whitepoint:=318;
const sampleformat:=339, sminsamplevalue, smaxsamplevalue;
const jpegifoffset:=513, jpegifbytecount;
const exififd:=34665;
end;
class EXIFTAG is
-- In a different IFD. See TIFFTAG::exififd.
const brightnessvalue:=37379;
const subjectdistance:=37382;
const colorspace:=40961, pixelxdimension, pixelydimension;
end;
external C class C_TIFF is
const C_header:STR := "<tiff.h> <tiffio.h>";
TIFFOpen(filename, mode:STR):EXT_OB;
TIFFClose(t:EXT_OB);
tiff_checkret(d:EXT_OB):INT;
TIFFPrintDirectory(tiff:EXT_OB, fd:EXT_OB, flags:C_INT);
TIFFGetField(tiff:EXT_OB, tag:C_INT, out ret:C_PTR):C_INT;
wideness(tiff:EXT_OB);
xresolution(tiff:EXT_OB):C_FLOAT;
yresolution(tiff:EXT_OB):C_FLOAT;
xposition(tiff:EXT_OB):C_INT;
yposition(tiff:EXT_OB):C_INT;
imdesc(tiff:EXT_OB):EXT_OB;
exififd(tiff:EXT_OB):C_INT;
end;
class TIFF is
attr fd:EXT_OB; -- this is the TIFF pointer (TIFF*), badly named
create(name, mode:STR):SAME is
n::=C_TIFF::TIFFOpen(name, mode);
-- check if the open was successful
if C_TIFF::tiff_checkret(n) /= 0 then
t::=new;
t.fd := n;
return t
end;
return void
end;
close is
C_TIFF::TIFFClose(fd)
end;
TIFFPrintDirectory is
f:FILE:=FILE::stdout;
C_TIFF::TIFFPrintDirectory(self.fd, f.fp, #(0))
end;
TIFFGetField(tag:INT, out ret:C_PTR):INT is
i:C_INT := C_TIFF::TIFFGetField(self.fd, #C_INT(tag), out ret);
j:INT := i.int;
#OUT+"******** retval = "+j+"\n";
return i.int
end;
xresolution:FLT is
x:C_FLOAT := C_TIFF::xresolution(self.fd);
return x.flt
end;
yresolution:FLT is
y:C_FLOAT := C_TIFF::yresolution(self.fd);
return y.flt
end;
xposition:INT is
x:C_INT := C_TIFF::xposition(self.fd);
return x.int
end;
yposition:INT is
y:C_INT := C_TIFF::yposition(self.fd);
return y.int
end;
imdesc:STR is
cs:EXT_OB := C_TIFF::imdesc(self.fd);
return STR::create_from_c_string(cs)
end;
exififd:C_INT is return C_TIFF::exififd(self.fd) end;
end;
-------------------------------------------------------------------
roughie.sa (test program)
------------------------
class MAIN is
shared infile:STR := "myimage.tif";
main is
t :TIFF:= #(infile, "r");
if void(t) then
#OUT+"TIFF open failed\n";
return
end;
#OUT+"x-Resolution = "+t.xresolution+"\n";
#OUT+"y-Resolution = "+t.yresolution+"\n";
#OUT+"Exif dir = "+t.exififd.int.str+"\n";
#OUT+"x-Position = "+t.xposition+"\n";
#OUT+"y-Position = "+t.yposition+"\n";
if t.xposition = -1 then
-- Insert tags and values into the file, writing it somewhere.
end;
t.close;
return 0
end
end
--
Michael Talbot-Wilson
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Roughie... feeling towards a TIFF class,
Sather User <=