summaryrefslogtreecommitdiff
path: root/src/TIFFOutputImage.cxx
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2007-05-18 19:17:59 +0200
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2007-05-18 19:17:59 +0200
commita7784b543b1bf2052b301457b5b7d4f64d20595e (patch)
tree1cc86f0b8b742e6c8a20cc204a8428b3fcfde5a5 /src/TIFFOutputImage.cxx
parent9256a7ef7644f12c5e2f20400b7bf8943433e080 (diff)
add 16bit output support
Diffstat (limited to 'src/TIFFOutputImage.cxx')
-rw-r--r--src/TIFFOutputImage.cxx27
1 files changed, 18 insertions, 9 deletions
diff --git a/src/TIFFOutputImage.cxx b/src/TIFFOutputImage.cxx
index 156079c..b8effed 100644
--- a/src/TIFFOutputImage.cxx
+++ b/src/TIFFOutputImage.cxx
@@ -10,7 +10,8 @@
#include "TIFFOutputImage.H"
-TIFFOutputImage::TIFFOutputImage(const char *f) {
+TIFFOutputImage::TIFFOutputImage(const char *f, int b) {
+ bitspersample = (b==16)?16:8;
file = strdup(f);
tiff = NULL;
row = NULL;
@@ -32,12 +33,12 @@ TIFFOutputImage::init_internal(int w1, int h1) {
row = NULL;
}
- row = (unsigned char*) malloc(sizeof(char) * 4 * w1);
+ row = (unsigned char*) malloc(sizeof(char) * (bitspersample / 8) * 4 * w1);
if (!row) {
perror("malloc");
return 1;
}
- memset(row, 0, sizeof(char) * 4 * w1);
+ memset(row, 0, sizeof(char) * (bitspersample / 8) * 4 * w1);
if (tiff) {
TIFFClose(tiff);
@@ -54,7 +55,7 @@ TIFFOutputImage::init_internal(int w1, int h1) {
TIFFSetField(tiff, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(tiff, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
TIFFSetField(tiff, TIFFTAG_ROWSPERSTRIP, 1);
- TIFFSetField(tiff, TIFFTAG_BITSPERSAMPLE, 8);
+ TIFFSetField(tiff, TIFFTAG_BITSPERSAMPLE, bitspersample);
TIFFSetField(tiff, TIFFTAG_SAMPLESPERPIXEL, 4);
return 0;
@@ -62,17 +63,25 @@ TIFFOutputImage::init_internal(int w1, int h1) {
int
TIFFOutputImage::set_pixel_internal(int x, int r, int g, int b) {
- row[x*4+0] = (unsigned char) (r / 255);
- row[x*4+1] = (unsigned char) (g / 255);
- row[x*4+2] = (unsigned char) (b / 255);
- row[x*4+3] = 255;
+ if (bitspersample == 8) {
+ row[x*4+0] = (unsigned char) (r / 255);
+ row[x*4+1] = (unsigned char) (g / 255);
+ row[x*4+2] = (unsigned char) (b / 255);
+ row[x*4+3] = 255;
+ } else if (bitspersample == 16) {
+ unsigned short *row16 = (unsigned short*) row;
+ row16[x*4+0] = (unsigned short) r;
+ row16[x*4+1] = (unsigned short) g;
+ row16[x*4+2] = (unsigned short) b;
+ row16[x*4+3] = 65025;
+ }
return 0;
}
int
TIFFOutputImage::next_line_internal() {
- TIFFWriteEncodedStrip(tiff, line -1 , row, W * 4);
+ TIFFWriteEncodedStrip(tiff, line - 1 , row, W * (bitspersample / 8) * 4);
memset(row, 0, sizeof(char) * 4 * W);
return 0;