本文整理汇总了C++中TIFFDefaultStripSize函数的典型用法代码示例。如果您正苦于以下问题:C++ TIFFDefaultStripSize函数的具体用法?C++ TIFFDefaultStripSize怎么用?C++ TIFFDefaultStripSize使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了TIFFDefaultStripSize函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: add_tiff_page
int add_tiff_page(struct tiff_info * info, int pagen, unsigned width, unsigned height, int bpp, unsigned dpi)
{
if(pagen)
TIFFWriteDirectory(info->tif);
TIFFSetField(info->tif, TIFFTAG_IMAGEWIDTH, width);
TIFFSetField(info->tif, TIFFTAG_IMAGELENGTH, height);
TIFFSetField(info->tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
TIFFSetField(info->tif, TIFFTAG_SAMPLESPERPIXEL, bpp/8);
TIFFSetField(info->tif, TIFFTAG_BITSPERSAMPLE, 8);
TIFFSetField(info->tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(info->tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
TIFFSetField(info->tif, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(info->tif, (uint32_t)-1));
TIFFSetField(info->tif, TIFFTAG_XRESOLUTION, (float)dpi);
TIFFSetField(info->tif, TIFFTAG_YRESOLUTION, (float)dpi);
TIFFSetField(info->tif, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH);
TIFFSetField(info->tif, TIFFTAG_COMPRESSION, COMPRESSION_PACKBITS);
TIFFSetField(info->tif, TIFFTAG_PAGENUMBER, pagen, info->pagecount);
info->width = width;
info->height = height;
info->pixel_bytes = bpp/8;
info->line_bytes = (width*info->pixel_bytes);
info->bpp = bpp;
return 0;
}
示例2: saver_tiff
gint
saver_tiff (GdkImlibImage * im, char *file, GdkImlibSaveInfo * info)
{
TIFF *tif;
unsigned char *data;
int y;
int w;
tif = TIFFOpen(file, "w");
if (tif)
{
TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, im->rgb_width);
TIFFSetField(tif, TIFFTAG_IMAGELENGTH, im->rgb_height);
TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8);
TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_LZW);
{
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 3);
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
w = TIFFScanlineSize(tif);
TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP,
TIFFDefaultStripSize(tif, -1));
for (y = 0; y < im->rgb_height; y++)
{
data = im->rgb_data + (y * im->rgb_width * 3);
TIFFWriteScanline(tif, data, y, 0);
}
}
TIFFClose(tif);
return 1;
}
return 0;
}
示例3: writeTIFF
/**
* Write a TIFF float image.
*/
static int writeTIFF(TIFF * tif, const float *data, size_t w, size_t h,
size_t c)
{
uint32 rowsperstrip;
int ok;
size_t k, i;
float *line;
TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, (uint32) w);
TIFFSetField(tif, TIFFTAG_IMAGELENGTH, (uint32) h);
TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_SEPARATE);
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, (uint16) c);
TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, (uint16) sizeof(float) * 8);
TIFFSetField(tif, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_IEEEFP);
rowsperstrip = TIFFDefaultStripSize(tif, (uint32) h);
TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, rowsperstrip);
TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
ok = 1;
for (k = 0; ok && k < c; k++)
for (i = 0; ok && i < h; i++) {
line = (float *) (data + (i + k * h) * w);
if (TIFFWriteScanline(tif, line, (uint32) i, (tsample_t) k) < 0) {
fprintf(stderr, "writeTIFF: error writing row %i\n", (int) i);
ok = 0;
}
}
return ok;
}
示例4: tiff_write
int tiff_write(char *file, Pic *pic)
{
TIFF *tif;
uint32 samples_per_pixel = 3;
uint32 w = pic->nx;
uint32 h = pic->nx;
uint32 scanline_size = samples_per_pixel * w;
uint32 y;
char *scanline;
tif = TIFFOpen(file, "w");
if( !tif )
return FALSE;
TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, w);
TIFFSetField(tif, TIFFTAG_IMAGELENGTH, h);
/* These are the charateristics of our Pic data */
TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, samples_per_pixel);
TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8);
TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
/*
* Turn on LZW compression.
* Shhhhh! Don't tell Unisys!
*/
TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_LZW);
/*
* Predictors:
* 1 (default) -- No predictor
* 2 -- Horizontal differencing
*/
TIFFSetField(tif, TIFFTAG_PREDICTOR, 2);
if( TIFFScanlineSize(tif) != scanline_size )
{
fprintf(stderr,
"TIFF: Mismatch with library's expected scanline size!\n");
return FALSE;
}
TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(tif, -1));
scanline = pic->pix;
for(y=0; y<h; y++)
{
TIFFWriteScanline(tif, scanline, y, 0);
scanline += w;
}
TIFFClose(tif);
return TRUE;
}
示例5: tiffsv
static void
tiffsv(char* name, int x1, int x2, int y1, int y2)
{
TIFF *tif;
int xsize, ysize;
int xorg, yorg;
uint32 *scrbuf;
xorg = MIN(x1,x2);
yorg = MIN(y1,y2);
if (xorg<0)
xorg = 0;
if (yorg<0)
yorg = 0;
xsize = ABS(x2-x1);
ysize = ABS(y2-y1);
if (xorg+xsize > xmaxscreen)
xsize = xmaxscreen-xorg;
if (yorg+ysize > ymaxscreen)
ysize = ymaxscreen-yorg;
tif = TIFFOpen(name, "w");
TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, (uint32) (xsize+1));
TIFFSetField(tif, TIFFTAG_IMAGELENGTH, (uint32) (ysize+1));
TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8);
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL,
photometric == PHOTOMETRIC_RGB ? 3 : 1);
TIFFSetField(tif, TIFFTAG_PLANARCONFIG, config);
TIFFSetField(tif, TIFFTAG_COMPRESSION, compression);
switch (compression) {
case COMPRESSION_JPEG:
if (photometric == PHOTOMETRIC_RGB && jpegcolormode == JPEGCOLORMODE_RGB)
photometric = PHOTOMETRIC_YCBCR;
TIFFSetField(tif, TIFFTAG_JPEGQUALITY, quality);
TIFFSetField(tif, TIFFTAG_JPEGCOLORMODE, jpegcolormode);
break;
case COMPRESSION_LZW:
if (predictor != 0)
TIFFSetField(tif, TIFFTAG_PREDICTOR, predictor);
break;
}
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, photometric);
TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_BOTLEFT);
rowsperstrip = TIFFDefaultStripSize(tif, rowsperstrip);
TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, rowsperstrip);
scrbuf = (uint32 *)_TIFFmalloc((xsize+1)*(ysize+1)*sizeof (uint32));
readdisplay(xorg, yorg, xorg+xsize, yorg+ysize, scrbuf, RD_FREEZE);
if (photometric == PHOTOMETRIC_RGB) {
if (config == PLANARCONFIG_SEPARATE)
svRGBSeparate(tif, scrbuf, xsize, ysize);
else
svRGBContig(tif, scrbuf, xsize, ysize);
} else
svGrey(tif, scrbuf, xsize, ysize);
(void) TIFFClose(tif);
_TIFFfree((char *)scrbuf);
}
示例6: rut_surface_to_tiff
int
rut_surface_to_tiff (RutSurface *s, const char *filename)
{
TIFF *tif = NULL;
int rows_per_strip, num_strips, strip, row, i;
int result = 1;
char *buffer = NULL;
assert (s);
assert (filename);
/* Open TIFF file */
tif = TIFFOpen (filename, "wb");
if (!tif) goto savefail;
/* Set TIFF tags */
TIFFSetField (tif, TIFFTAG_IMAGEWIDTH, s->cols);
TIFFSetField (tif, TIFFTAG_IMAGELENGTH, s->rows);
TIFFSetField (tif, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_IEEEFP);
TIFFSetField (tif, TIFFTAG_BITSPERSAMPLE, 32);
TIFFSetField (tif, TIFFTAG_SAMPLESPERPIXEL, 1);
TIFFSetField (tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
rows_per_strip = TIFFDefaultStripSize (tif, 0);
TIFFSetField (tif, TIFFTAG_ROWSPERSTRIP, rows_per_strip);
num_strips = TIFFNumberOfStrips (tif);
/* Copy data into TIFF strips */
buffer = malloc (TIFFStripSize (tif));
for (row = 0, strip = 0; strip < num_strips; strip++) {
size_t size = 0;
for (i = 0; (i < rows_per_strip) && (row < s->rows); i++, row++) {
float *src = RUT_SURFACE_PTR (s, row, 0);
char *dest = buffer + i*s->cols*4;
memcpy (dest, src, s->cols * 4);
size += s->cols*4;
}
result = (TIFFWriteEncodedStrip (tif, strip, buffer, size) != -1);
if (!result) {
fprintf (stderr, "Could not write TIFF strip %i/%i to %s\n",
strip+1, num_strips, filename);
}
}
/* Clean up */
free (buffer);
TIFFClose (tif);
return 1;
savefail:
if (tif) TIFFClose (tif);
if (buffer) free (buffer);
fprintf (stderr, "Could not save TIFF to %s\n", filename);
return 0;
}
示例7: tiffcvt
static int
tiffcvt(TIFF* in, TIFF* out)
{
uint32 width, height; /* image width & height */
uint32* raster; /* retrieve RGBA image */
uint16 shortv;
float floatv;
char *stringv;
uint32 longv;
TIFFGetField(in, TIFFTAG_IMAGEWIDTH, &width);
TIFFGetField(in, TIFFTAG_IMAGELENGTH, &height);
raster = (uint32*)_TIFFmalloc(width * height * sizeof (uint32));
if (raster == 0) {
TIFFError(TIFFFileName(in), "No space for raster buffer");
return (0);
}
if (!TIFFReadRGBAImage(in, width, height, raster, 0)) {
_TIFFfree(raster);
return (0);
}
CopyField(TIFFTAG_SUBFILETYPE, longv);
TIFFSetField(out, TIFFTAG_IMAGEWIDTH, width);
TIFFSetField(out, TIFFTAG_IMAGELENGTH, height);
TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, 8);
TIFFSetField(out, TIFFTAG_COMPRESSION, compression);
TIFFSetField(out, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_YCBCR);
if (compression == COMPRESSION_JPEG)
TIFFSetField(out, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RAW);
CopyField(TIFFTAG_FILLORDER, shortv);
TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, 3);
CopyField(TIFFTAG_XRESOLUTION, floatv);
CopyField(TIFFTAG_YRESOLUTION, floatv);
CopyField(TIFFTAG_RESOLUTIONUNIT, shortv);
TIFFSetField(out, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
{ char buf[2048];
char *cp = strrchr(TIFFFileName(in), '/');
sprintf(buf, "YCbCr conversion of %s", cp ? cp+1 : TIFFFileName(in));
TIFFSetField(out, TIFFTAG_IMAGEDESCRIPTION, buf);
}
TIFFSetField(out, TIFFTAG_SOFTWARE, TIFFGetVersion());
CopyField(TIFFTAG_DOCUMENTNAME, stringv);
TIFFSetField(out, TIFFTAG_REFERENCEBLACKWHITE, refBlackWhite);
TIFFSetField(out, TIFFTAG_YCBCRSUBSAMPLING,
horizSubSampling, vertSubSampling);
TIFFSetField(out, TIFFTAG_YCBCRPOSITIONING, YCBCRPOSITION_CENTERED);
TIFFSetField(out, TIFFTAG_YCBCRCOEFFICIENTS, ycbcrCoeffs);
rowsperstrip = TIFFDefaultStripSize(out, rowsperstrip);
TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, rowsperstrip);
return (cvtRaster(out, raster, width, height));
}
示例8: TestWriter
int
TestWriter()
{
int width = 128;
int height = 128;
int samplesperpixel = 4;
char *image = malloc(width * height * samplesperpixel);
if (NULL == image)
{
return -1;
}
size_t linebytes = samplesperpixel * width;
unsigned char *buf = NULL;
TIFF *tif = TIFFOpen("new.tif", "w");
if (NULL == tif)
{
return -1;
}
TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, width);
TIFFSetField(tif, TIFFTAG_IMAGELENGTH, height);
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, samplesperpixel);
TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8);
TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
if (TIFFScanlineSize(tif) == linebytes)
{
buf = _TIFFmalloc(linebytes);
}
else
{
buf = _TIFFmalloc(TIFFScanlineSize(tif));
}
if (NULL == buf)
{
return -1;
}
TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(tif, linebytes));
createCheckerboardImage(image, width, height, samplesperpixel);
unsigned int row;
for (row = 0; row < height; ++row)
{
memcpy(buf, &image[(height - row - 1) * linebytes], linebytes);
if (TIFFWriteScanline(tif, buf, row, 0) < 0)
{
break;
}
}
TIFFClose(tif);
_TIFFfree(buf);
free(image);
return 0;
}
示例9: tifinit
int tifinit(Mytiff * mytiff,const char * const filename){
int myerror;
char * Stripbytes=NULL;
u_int32_t stripbytes,estsize,estbytes;
myerror=0;
mytiff->ndata=mytiff->wd * mytiff->ht;
mytiff->nbytes = mytiff->ndata * mytiff->bytes;
mytiff->tiffp= TIFFOpen(filename,"wl");
if (mytiff->tiffp == 0 ){
fprintf(stderr,"ERROR: %s: %i: failed tiff open of %s!\n",__func__,__LINE__,filename);
fprintf(stderr,"ERROR: %s: tried to open with TIFFOpen(%s,\"wl\"); \n",__func__,filename);
return(101);
}
TIFFSetField(mytiff->tiffp,TIFFTAG_IMAGEWIDTH,mytiff->wd);
TIFFSetField(mytiff->tiffp,TIFFTAG_IMAGELENGTH,mytiff->ht);
TIFFSetField(mytiff->tiffp,TIFFTAG_BITSPERSAMPLE,mytiff->bytes * 8);
TIFFSetField(mytiff->tiffp,TIFFTAG_PLANARCONFIG,1);
TIFFSetField(mytiff->tiffp,TIFFTAG_PHOTOMETRIC,1);
/* only 4-byte float or 2-byte int so far */
if (mytiff->bytes == 4){
TIFFSetField(mytiff->tiffp,TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_IEEEFP);
}else if (mytiff->bytes == 2){
TIFFSetField(mytiff->tiffp,TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT);
}
/* set the number of rows per strip , default or overridden by the environment variable */
Stripbytes=getenv("I12STRIPBYTES");
if (Stripbytes == NULL ){
stripbytes=(D_STRIPBYTES);
}else{
stripbytes=atoi(Stripbytes);
}
estbytes=(stripbytes / (mytiff->wd * mytiff->bytes));
estsize=TIFFDefaultStripSize(mytiff->tiffp,estbytes);
TIFFSetField(mytiff->tiffp,TIFFTAG_ROWSPERSTRIP,estsize);
mytiff->stripnum=TIFFNumberOfStrips(mytiff->tiffp);
mytiff->bytesperstrip=TIFFVStripSize(mytiff->tiffp,mytiff->stripnum);
if (! mytiff->isalloc){
mytiff->buf=(char *) malloc(mytiff->bytesperstrip);
mytiff->isalloc=1;
}
VBPRINT("stripbytes %s requested, stripsize set to: %i rows\n",Stripbytes,estsize);
VBPRINT("bytes per strip is: %i \n",mytiff->bytesperstrip);
return(0);
}
示例10: writeTiffFile
void writeTiffFile(const char* fileName, klRasterBufferPointer buffer)
{
uint32 width = buffer->width();
uint32 height = buffer->height();
uint32 bands = buffer->numBands();
TIFF *out= TIFFOpen(fileName, "w");
int sampleperpixel = bands;
unsigned char *image= buffer->buffer();
TIFFSetField (out, TIFFTAG_IMAGEWIDTH, width); // set the width of the image
TIFFSetField(out, TIFFTAG_IMAGELENGTH, height); // set the height of the image
TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, sampleperpixel); // set number of channels per pixel
TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, 8); // set the size of the channels
//TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT); // set the origin of the image.
TIFFSetField(out, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(out, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
tsize_t linebytes = sampleperpixel * width; // length in memory of one row of pixel in the image.
unsigned char *buf = NULL; // buffer used to store the row of pixel information for writing to file
// Allocating memory to store the pixels of current row
if (TIFFScanlineSize(out)==linebytes)
buf =(unsigned char *)_TIFFmalloc(linebytes);
else
buf = (unsigned char *)_TIFFmalloc(TIFFScanlineSize(out));
// We set the strip size of the file to be size of one row of pixels
TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(out, width*sampleperpixel));
//Now writing image to the file one strip at a time
for (uint32 row = 0; row < height; row++)
{
memcpy(buf, &image[(row)*linebytes], linebytes);
if (TIFFWriteScanline(out, buf, row, 0) < 0)
break;
}
(void) TIFFClose(out);
if (buf)
_TIFFfree(buf);
}
示例11: write_tiff
static void
write_tiff (UcaRingBuffer *buffer,
Options *opts,
guint width,
guint height,
guint bits_per_pixel)
{
TIFF *tif;
guint32 rows_per_strip;
guint n_frames;
guint bits_per_sample;
gsize bytes_per_pixel;
if (opts->filename)
tif = TIFFOpen (opts->filename, "w");
else
tif = TIFFOpen ("frames.tif", "w");
n_frames = uca_ring_buffer_get_num_blocks (buffer);
rows_per_strip = TIFFDefaultStripSize (tif, (guint32) - 1);
bytes_per_pixel = get_bytes_per_pixel (bits_per_pixel);
bits_per_sample = bits_per_pixel > 8 ? 16 : 8;
/* Write multi page TIFF file */
TIFFSetField (tif, TIFFTAG_SUBFILETYPE, FILETYPE_PAGE);
for (guint i = 0; i < n_frames; i++) {
gpointer data;
gsize offset = 0;
data = uca_ring_buffer_get_read_pointer (buffer);
TIFFSetField (tif, TIFFTAG_IMAGEWIDTH, width);
TIFFSetField (tif, TIFFTAG_IMAGELENGTH, height);
TIFFSetField (tif, TIFFTAG_BITSPERSAMPLE, bits_per_sample);
TIFFSetField (tif, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT);
TIFFSetField (tif, TIFFTAG_SAMPLESPERPIXEL, 1);
TIFFSetField (tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField (tif, TIFFTAG_ROWSPERSTRIP, rows_per_strip);
TIFFSetField (tif, TIFFTAG_PAGENUMBER, i, n_frames);
for (guint y = 0; y < height; y++, offset += width * bytes_per_pixel)
TIFFWriteScanline (tif, data + offset, y, 0);
TIFFWriteDirectory (tif);
}
TIFFClose (tif);
}
示例12: timg_writetiff
void timg_writetiff(const char *fname, timg_t *img) {
TIFF *tif = TIFFOpen(fname, "w");
if(tif == 0) {
fprintf(stderr, "timg_writetiff: Failed to open %s\n", fname);
exit(1);
}
int w = img->width;
int h = img->height;
TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, w);
TIFFSetField(tif, TIFFTAG_IMAGELENGTH, h);
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 4);
TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8);
TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
int linebytes = 4*w;
unsigned char *buf = NULL;
if(TIFFScanlineSize(tif) == linebytes) {
buf = (unsigned char*)_TIFFmalloc(linebytes);
} else {
buf = (unsigned char*)_TIFFmalloc(TIFFScanlineSize(tif));
}
if(buf == NULL) {
fprintf(stderr, "timg_writetiff: failed to allocate buf");
exit(1);
}
TIFFSetField(tif,TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(tif, w*4));
int row=0;
for(row=0; row<h; ++row) {
//memcpy(buf, timg_pixelat(img, row, 0), linebytes);
if(TIFFWriteScanline(tif, &(img->pixels[row*img->width]), row, 0) < 0)
break;
}
if(buf)
_TIFFfree(buf);
TIFFClose(tif);
}
示例13: save_pixmap_tiff
int save_pixmap_tiff(struct pixmap *p, int c, int q, int pr, char *name)
{
TIFF *out;
int result = 0,
row_stride,
y;
if (p) {
if ((out = TIFFOpen(name, "w")) != NULL) {
TIFFSetField(out, TIFFTAG_IMAGEWIDTH, p->width);
TIFFSetField(out, TIFFTAG_IMAGELENGTH, p->height);
TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, p->components);
TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, 8);
TIFFSetField(out, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(out, TIFFTAG_PHOTOMETRIC, (p->components == 1) ? PHOTOMETRIC_MINISBLACK : PHOTOMETRIC_RGB);
TIFFSetField(out, TIFFTAG_COMPRESSION, c);
switch (c) {
case COMPRESSION_JPEG:
TIFFSetField(out, TIFFTAG_JPEGQUALITY, q);
TIFFSetField(out, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RAW);
break;
case COMPRESSION_LZW:
case COMPRESSION_DEFLATE:
if (pr != 0)
TIFFSetField(out, TIFFTAG_PREDICTOR, pr);
default:
break;
}
row_stride = p->width * p->components;
TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(out, -1));
for (y = 0; y < p->height; y++) {
if (TIFFWriteScanline(out, &GET_COMP(p, 0, y, 0), y, 0) < 0) {
if (!quiet) fprintf(stderr, "%s: save_pixmap_tiff: error: TIFFWriteScanline\n", __progname);
result = -1;
break;
}
}
TIFFClose(out);
} else
result = -1;
}
return result;
}
示例14: tiff_set_compression
int tiff_set_compression(gx_device_printer *pdev,
TIFF *tif,
uint compression,
long max_strip_size)
{
TIFFSetField(tif, TIFFTAG_COMPRESSION, compression);
if (max_strip_size == 0) {
TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, pdev->height);
}
else {
int rows = max_strip_size /
gdev_mem_bytes_per_scan_line((gx_device *)pdev);
TIFFSetField(tif,
TIFFTAG_ROWSPERSTRIP,
TIFFDefaultStripSize(tif, max(1, rows)));
}
return 0;
}
示例15: writeHeader
/// Write TIFF header
static void writeHeader(TIFF* tif, const V2i& imageSize,
int nchans, bool useFloat,
bool tiled, const V2i& tileSize)
{
uint16 bitsPerSample = 8;
uint16 photometric = PHOTOMETRIC_RGB;
uint16 sampleFormat = SAMPLEFORMAT_UINT;
if(useFloat)
{
bitsPerSample = 8*sizeof(float);
sampleFormat = SAMPLEFORMAT_IEEEFP;
}
if(nchans == 1)
photometric = PHOTOMETRIC_MINISBLACK;
// Write TIFF header
TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, uint32(imageSize.x));
TIFFSetField(tif, TIFFTAG_IMAGELENGTH, uint32(imageSize.y));
TIFFSetField(tif, TIFFTAG_ORIENTATION, uint16(ORIENTATION_TOPLEFT));
TIFFSetField(tif, TIFFTAG_PLANARCONFIG, uint16(PLANARCONFIG_CONTIG));
TIFFSetField(tif, TIFFTAG_RESOLUTIONUNIT, uint16(RESUNIT_NONE));
TIFFSetField(tif, TIFFTAG_XRESOLUTION, 1.0f);
TIFFSetField(tif, TIFFTAG_YRESOLUTION, 1.0f);
TIFFSetField(tif, TIFFTAG_COMPRESSION, uint16(COMPRESSION_LZW));
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, uint16(nchans));
TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, bitsPerSample);
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, photometric);
TIFFSetField(tif, TIFFTAG_SAMPLEFORMAT, sampleFormat);
TIFFSetField(tif, TIFFTAG_SOFTWARE, "Aqsis-2.0 (aka newcore)");
if(tiled)
{
TIFFSetField(tif, TIFFTAG_TILEWIDTH, tileSize.x);
TIFFSetField(tif, TIFFTAG_TILELENGTH, tileSize.y);
}
else
TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(tif, 0));
}