本文整理汇总了C++中TIFFWriteScanline函数的典型用法代码示例。如果您正苦于以下问题:C++ TIFFWriteScanline函数的具体用法?C++ TIFFWriteScanline怎么用?C++ TIFFWriteScanline使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了TIFFWriteScanline函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int
main(int argc, char **argv)
{
TIFF *tif;
int i;
unsigned char buf[3] = { 0, 127, 255 };
/* Test whether we can write tags. */
tif = TIFFOpen(filename, "w");
if (!tif) {
fprintf (stderr, "Can't create test TIFF file %s.\n", filename);
return 1;
}
if (!TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, width)) {
fprintf (stderr, "Can't set ImageWidth tag.\n");
goto failure;
}
if (!TIFFSetField(tif, TIFFTAG_IMAGELENGTH, length)) {
fprintf (stderr, "Can't set ImageLength tag.\n");
goto failure;
}
if (!TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8)) {
fprintf (stderr, "Can't set BitsPerSample tag.\n");
goto failure;
}
if (!TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 3)) {
fprintf (stderr, "Can't set SamplesPerPixel tag.\n");
goto failure;
}
if (!TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, rows_per_strip)) {
fprintf (stderr, "Can't set SamplesPerPixel tag.\n");
goto failure;
}
if (!TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG)) {
fprintf (stderr, "Can't set PlanarConfiguration tag.\n");
goto failure;
}
if (!TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB)) {
fprintf (stderr, "Can't set PhotometricInterpretation tag.\n");
goto failure;
}
for (i = 0; i < NTAGS; i++) {
if (!TIFFSetField(tif, long_tags[i].tag,
long_tags[i].value)) {
fprintf(stderr, "Can't set tag %d.\n",
(int)long_tags[i].tag);
goto failure;
}
}
/* Write dummy pixel data. */
if (!TIFFWriteScanline(tif, buf, 0, 0) < 0) {
fprintf (stderr, "Can't write image data.\n");
goto failure;
}
TIFFClose(tif);
/* Ok, now test whether we can read written values. */
tif = TIFFOpen(filename, "r");
if (!tif) {
fprintf (stderr, "Can't open test TIFF file %s.\n", filename);
return 1;
}
if (CheckLongField(tif, TIFFTAG_IMAGEWIDTH, width) < 0)
goto failure;
if (CheckLongField(tif, TIFFTAG_IMAGELENGTH, length) < 0)
goto failure;
if (CheckLongField(tif, TIFFTAG_ROWSPERSTRIP, rows_per_strip) < 0)
goto failure;
for (i = 0; i < NTAGS; i++) {
if (CheckLongField(tif, long_tags[i].tag,
long_tags[i].value) < 0)
goto failure;
}
TIFFClose(tif);
/* All tests passed; delete file and exit with success status. */
unlink(filename);
return 0;
failure:
/* Something goes wrong; close file and return unsuccessful status. */
TIFFClose(tif);
unlink(filename);
return 1;
}
示例2: R_SaveAsTIFF
int R_SaveAsTIFF(void *d, int width, int height,
unsigned int (*gp)(void *, int, int),
int bgr, const char *outfile, int res, int compression)
{
TIFF *out;
int sampleperpixel;
tsize_t linebytes;
unsigned char *buf, *pscanline;
unsigned int col, i, j;
int have_alpha = 0;
DECLARESHIFTS;
for (i = 0; i < height; i++)
for (j = 0; j < width; j++) {
col = gp(d,i,j);
if (GETALPHA(col) < 255) {
have_alpha = 1;
break;
}
}
sampleperpixel = 3 + have_alpha;
out = TIFFOpen(outfile, "w");
if (!out) {
warning("unable to open TIFF file '%s'", outfile);
return 0;
}
TIFFSetField(out, TIFFTAG_IMAGEWIDTH, width);
TIFFSetField(out, TIFFTAG_IMAGELENGTH, height);
TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, sampleperpixel);
TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, 8);
TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
TIFFSetField(out, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(out, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
#if 0
/* Possible compression values
COMPRESSION_NONE = 1;
COMPRESSION_CCITTRLE = 2;
COMPRESSION_CCITTFAX3 = COMPRESSION_CCITT_T4 = 3;
COMPRESSION_CCITTFAX4 = COMPRESSION_CCITT_T6 = 4;
COMPRESSION_LZW = 5;
COMPRESSION_JPEG = 7;
COMPRESSION_DEFLATE = 32946;
COMPRESSION_ADOBE_DEFLATE = 8;
*/
TIFFSetField(out, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
#endif
if(compression > 1)
TIFFSetField(out, TIFFTAG_COMPRESSION, compression);
if (res > 0) {
TIFFSetField(out, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH);
TIFFSetField(out, TIFFTAG_XRESOLUTION, (float) res);
TIFFSetField(out, TIFFTAG_YRESOLUTION, (float) res);
}
linebytes = sampleperpixel * width;
if (TIFFScanlineSize(out))
buf =(unsigned char *)_TIFFmalloc(linebytes);
else
buf = (unsigned char *)_TIFFmalloc(TIFFScanlineSize(out));
for (i = 0; i < height; i++) {
pscanline = buf;
for(j = 0; j < width; j++) {
col = gp(d, i, j);
*pscanline++ = GETRED(col) ;
*pscanline++ = GETGREEN(col) ;
*pscanline++ = GETBLUE(col) ;
if(have_alpha) *pscanline++ = GETALPHA(col) ;
}
TIFFWriteScanline(out, buf, i, 0);
}
TIFFClose(out);
_TIFFfree(buf);
return 1;
}
示例3: main
//.........这里部分代码省略.........
break;
case TIFF_FLOAT:
case TIFF_DOUBLE:
TIFFSetField(out, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_IEEEFP);
break;
default:
TIFFSetField(out, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_VOID);
break;
}
if (compression == (uint16) -1)
compression = COMPRESSION_PACKBITS;
TIFFSetField(out, TIFFTAG_COMPRESSION, compression);
switch (compression) {
case COMPRESSION_JPEG:
if (photometric == PHOTOMETRIC_RGB
&& jpegcolormode == JPEGCOLORMODE_RGB)
photometric = PHOTOMETRIC_YCBCR;
TIFFSetField(out, TIFFTAG_JPEGQUALITY, quality);
TIFFSetField(out, TIFFTAG_JPEGCOLORMODE, jpegcolormode);
break;
case COMPRESSION_LZW:
case COMPRESSION_DEFLATE:
if (predictor != 0)
TIFFSetField(out, TIFFTAG_PREDICTOR, predictor);
break;
}
switch(interleaving) {
case BAND: /* band interleaved data */
linebytes = width * depth;
buf = (unsigned char *)_TIFFmalloc(linebytes);
break;
case PIXEL: /* pixel interleaved data */
default:
linebytes = width * nbands * depth;
break;
}
bufsize = width * nbands * depth;
buf1 = (unsigned char *)_TIFFmalloc(bufsize);
rowsperstrip = TIFFDefaultStripSize(out, rowsperstrip);
if (rowsperstrip > length) {
rowsperstrip = length;
}
TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, rowsperstrip );
_TIFF_lseek_f(fd, hdr_size, SEEK_SET); /* Skip the file header */
for (row = 0; row < length; row++) {
switch(interleaving) {
case BAND: /* band interleaved data */
for (band = 0; band < nbands; band++) {
if (_TIFF_lseek_f(fd,
hdr_size + (length*band+row)*linebytes,
SEEK_SET) == (_TIFF_off_t)-1) {
fprintf(stderr,
"%s: %s: scanline %lu: seek error.\n",
argv[0], argv[optind],
(unsigned long) row);
break;
}
if (read(fd, buf, linebytes) < 0) {
fprintf(stderr,
"%s: %s: scanline %lu: Read error.\n",
argv[0], argv[optind],
(unsigned long) row);
break;
}
if (swab) /* Swap bytes if needed */
swapBytesInScanline(buf, width, dtype);
for (col = 0; col < width; col++)
memcpy(buf1 + (col*nbands+band)*depth,
buf + col * depth, depth);
}
break;
case PIXEL: /* pixel interleaved data */
default:
if (read(fd, buf1, bufsize) < 0) {
fprintf(stderr,
"%s: %s: scanline %lu: Read error.\n",
argv[0], argv[optind],
(unsigned long) row);
break;
}
if (swab) /* Swap bytes if needed */
swapBytesInScanline(buf1, width, dtype);
break;
}
if (TIFFWriteScanline(out, buf1, row, 0) < 0) {
fprintf(stderr, "%s: %s: scanline %lu: Write error.\n",
argv[0], outfilename, (unsigned long) row);
break;
}
}
if (buf)
_TIFFfree(buf);
if (buf1)
_TIFFfree(buf1);
TIFFClose(out);
return (0);
}
示例4: main
//.........这里部分代码省略.........
"allocate space for scanline buffer");
goto bad3;
}
size = (size & ~31) / 8;
scanbuf = (char *) _TIFFmalloc(size);
if (!scanbuf) {
TIFFError(infilename,
"Can't allocate space for scanline buffer");
goto bad3;
}
for (row = 0; row < length; row++) {
if (info_hdr.iHeight > 0)
offset = file_hdr.iOffBits+(length-row-1)*size;
else
offset = file_hdr.iOffBits + row * size;
if (lseek(fd, offset, SEEK_SET) == (off_t)-1) {
TIFFError(infilename,
"scanline %lu: Seek error",
(unsigned long) row);
break;
}
if (read(fd, scanbuf, size) < 0) {
TIFFError(infilename,
"scanline %lu: Read error",
(unsigned long) row);
break;
}
rearrangePixels(scanbuf, width, info_hdr.iBitCount);
if (TIFFWriteScanline(out, scanbuf, row, 0)<0) {
TIFFError(infilename,
"scanline %lu: Write error",
(unsigned long) row);
break;
}
}
_TIFFfree(scanbuf);
/* -------------------------------------------------------------------- */
/* Read compressed image data. */
/* -------------------------------------------------------------------- */
} else if ( info_hdr.iCompression == BMPC_RLE8
|| info_hdr.iCompression == BMPC_RLE4 ) {
uint32 i, j, k, runlength;
uint32 compr_size, uncompr_size;
unsigned char *comprbuf;
unsigned char *uncomprbuf;
compr_size = file_hdr.iSize - file_hdr.iOffBits;
uncompr_size = width * length;
comprbuf = (unsigned char *) _TIFFmalloc( compr_size );
if (!comprbuf) {
TIFFError(infilename,
"Can't allocate space for compressed scanline buffer");
goto bad3;
}
uncomprbuf = (unsigned char *)_TIFFmalloc(uncompr_size);
if (!uncomprbuf) {
TIFFError(infilename,
"Can't allocate space for uncompressed scanline buffer");
示例5: write_image
//.........这里部分代码省略.........
TIFFSetField(tif, TIFFTAG_IMAGELENGTH, (uint32_t)d->height);
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, (uint16_t)PHOTOMETRIC_RGB);
TIFFSetField(tif, TIFFTAG_PLANARCONFIG, (uint16_t)PLANARCONFIG_CONTIG);
TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, (uint32_t)1);
TIFFSetField(tif, TIFFTAG_ORIENTATION, (uint16_t)ORIENTATION_TOPLEFT);
int resolution = dt_conf_get_int("metadata/resolution");
if(resolution > 0)
{
TIFFSetField(tif, TIFFTAG_XRESOLUTION, (float)resolution);
TIFFSetField(tif, TIFFTAG_YRESOLUTION, (float)resolution);
TIFFSetField(tif, TIFFTAG_RESOLUTIONUNIT, (uint16_t)RESUNIT_INCH);
}
const size_t rowsize = (d->width * 3) * d->bpp / 8;
if((rowdata = malloc(rowsize)) == NULL)
{
rc = 1;
goto exit;
}
if(d->bpp == 32)
{
for(int y = 0; y < d->height; y++)
{
float *in = (float *)in_void + (size_t)4 * y * d->width;
float *out = (float *)rowdata;
for(int x = 0; x < d->width; x++, in += 4, out += 3)
{
memcpy(out, in, 3 * sizeof(float));
}
if(TIFFWriteScanline(tif, rowdata, y, 0) == -1)
{
rc = 1;
goto exit;
}
}
}
else if(d->bpp == 16)
{
for(int y = 0; y < d->height; y++)
{
uint16_t *in = (uint16_t *)in_void + (size_t)4 * y * d->width;
uint16_t *out = (uint16_t *)rowdata;
for(int x = 0; x < d->width; x++, in += 4, out += 3)
{
memcpy(out, in, 3 * sizeof(uint16_t));
}
if(TIFFWriteScanline(tif, rowdata, y, 0) == -1)
{
rc = 1;
goto exit;
}
}
}
else
{
for(int y = 0; y < d->height; y++)
{
uint8_t *in = (uint8_t *)in_void + (size_t)4 * y * d->width;
uint8_t *out = (uint8_t *)rowdata;
示例6: fsdither
/*
* Floyd-Steinberg error propragation with threshold.
* This code is stolen from tiffmedian.
*/
static void
fsdither(TIFF* in, TIFF* out)
{
unsigned char *outline, *inputline, *inptr;
short *thisline, *nextline, *tmpptr;
register unsigned char *outptr;
register short *thisptr, *nextptr;
register uint32 i, j;
uint32 imax, jmax;
int lastline, lastpixel;
int bit;
tsize_t outlinesize;
imax = imagelength - 1;
jmax = imagewidth - 1;
inputline = (unsigned char *)_TIFFmalloc(TIFFScanlineSize(in));
thisline = (short *)_TIFFmalloc(imagewidth * sizeof (short));
nextline = (short *)_TIFFmalloc(imagewidth * sizeof (short));
outlinesize = TIFFScanlineSize(out);
outline = (unsigned char *) _TIFFmalloc(outlinesize);
/*
* Get first line
*/
if (TIFFReadScanline(in, inputline, 0, 0) <= 0)
return;
inptr = inputline;
nextptr = nextline;
for (j = 0; j < imagewidth; ++j)
*nextptr++ = *inptr++;
for (i = 1; i < imagelength; ++i) {
tmpptr = thisline;
thisline = nextline;
nextline = tmpptr;
lastline = (i == imax);
if (TIFFReadScanline(in, inputline, i, 0) <= 0)
break;
inptr = inputline;
nextptr = nextline;
for (j = 0; j < imagewidth; ++j)
*nextptr++ = *inptr++;
thisptr = thisline;
nextptr = nextline;
_TIFFmemset(outptr = outline, 0, outlinesize);
bit = 0x80;
for (j = 0; j < imagewidth; ++j) {
register int v;
lastpixel = (j == jmax);
v = *thisptr++;
if (v < 0)
v = 0;
else if (v > 255)
v = 255;
if (v > threshold) {
*outptr |= bit;
v -= 255;
}
bit >>= 1;
if (bit == 0) {
outptr++;
bit = 0x80;
}
if (!lastpixel)
thisptr[0] += v * 7 / 16;
if (!lastline) {
if (j != 0)
nextptr[-1] += v * 3 / 16;
*nextptr++ += v * 5 / 16;
if (!lastpixel)
nextptr[0] += v / 16;
}
}
if (TIFFWriteScanline(out, outline, i-1, 0) < 0)
break;
}
_TIFFfree(inputline);
_TIFFfree(thisline);
_TIFFfree(nextline);
_TIFFfree(outline);
}
示例7: switch
//.........这里部分代码省略.........
size_t fileStep = (width * channels * bitsPerChannel) / bitsPerByte;
int rowsPerStrip = (int)((1 << 13)/fileStep);
readParam(params, TIFFTAG_ROWSPERSTRIP, rowsPerStrip);
if( rowsPerStrip < 1 )
rowsPerStrip = 1;
if( rowsPerStrip > height )
rowsPerStrip = height;
// do NOT put "wb" as the mode, because the b means "big endian" mode, not "binary" mode.
// http://www.remotesensing.org/libtiff/man/TIFFOpen.3tiff.html
TIFF* pTiffHandle = TIFFOpen(m_filename.c_str(), "w");
if (!pTiffHandle)
{
return false;
}
// defaults for now, maybe base them on params in the future
int compression = COMPRESSION_LZW;
int predictor = PREDICTOR_HORIZONTAL;
readParam(params, TIFFTAG_COMPRESSION, compression);
readParam(params, TIFFTAG_PREDICTOR, predictor);
int colorspace = channels > 1 ? PHOTOMETRIC_RGB : PHOTOMETRIC_MINISBLACK;
if ( !TIFFSetField(pTiffHandle, TIFFTAG_IMAGEWIDTH, width)
|| !TIFFSetField(pTiffHandle, TIFFTAG_IMAGELENGTH, height)
|| !TIFFSetField(pTiffHandle, TIFFTAG_BITSPERSAMPLE, bitsPerChannel)
|| !TIFFSetField(pTiffHandle, TIFFTAG_COMPRESSION, compression)
|| !TIFFSetField(pTiffHandle, TIFFTAG_PHOTOMETRIC, colorspace)
|| !TIFFSetField(pTiffHandle, TIFFTAG_SAMPLESPERPIXEL, channels)
|| !TIFFSetField(pTiffHandle, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG)
|| !TIFFSetField(pTiffHandle, TIFFTAG_ROWSPERSTRIP, rowsPerStrip)
|| !TIFFSetField(pTiffHandle, TIFFTAG_PREDICTOR, predictor)
)
{
TIFFClose(pTiffHandle);
return false;
}
// row buffer, because TIFFWriteScanline modifies the original data!
size_t scanlineSize = TIFFScanlineSize(pTiffHandle);
AutoBuffer<uchar> _buffer(scanlineSize+32);
uchar* buffer = _buffer;
if (!buffer)
{
TIFFClose(pTiffHandle);
return false;
}
for (int y = 0; y < height; ++y)
{
switch(channels)
{
case 1:
{
memcpy(buffer, img.data + img.step * y, scanlineSize);
break;
}
case 3:
{
if (depth == CV_8U)
icvCvt_BGR2RGB_8u_C3R( img.data + img.step*y, 0, buffer, 0, cvSize(width,1) );
else
icvCvt_BGR2RGB_16u_C3R( (const ushort*)(img.data + img.step*y), 0, (ushort*)buffer, 0, cvSize(width,1) );
break;
}
case 4:
{
if (depth == CV_8U)
icvCvt_BGRA2RGBA_8u_C4R( img.data + img.step*y, 0, buffer, 0, cvSize(width,1) );
else
icvCvt_BGRA2RGBA_16u_C4R( (const ushort*)(img.data + img.step*y), 0, (ushort*)buffer, 0, cvSize(width,1) );
break;
}
default:
{
TIFFClose(pTiffHandle);
return false;
}
}
int writeResult = TIFFWriteScanline(pTiffHandle, buffer, y, 0);
if (writeResult != 1)
{
TIFFClose(pTiffHandle);
return false;
}
}
TIFFClose(pTiffHandle);
return true;
}
示例8: TIFFClientOpen
//.........这里部分代码省略.........
bytesperrow = 16 * asset->width;
break;
default:
components = 3;
color_model = BC_RGB888;
bits = 8;
type = TIFF_BYTE;
bytesperrow = 3 * asset->width;
break;
}
switch(asset->tiff_compression)
{
case FileTIFF::LZW:
compression = COMPRESSION_LZW;
break;
case FileTIFF::PACK_BITS:
compression = COMPRESSION_PACKBITS;
break;
case FileTIFF::DEFLATE:
compression = COMPRESSION_DEFLATE;
break;
case FileTIFF::JPEG:
compression = COMPRESSION_JPEG;
break;
default:
compression = COMPRESSION_NONE;
break;
}
TIFFSetField(stream, TIFFTAG_IMAGEWIDTH, asset->width);
TIFFSetField(stream, TIFFTAG_IMAGELENGTH, asset->height);
TIFFSetField(stream, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
TIFFSetField(stream, TIFFTAG_SAMPLESPERPIXEL, components);
TIFFSetField(stream, TIFFTAG_BITSPERSAMPLE, bits);
TIFFSetField(stream, TIFFTAG_SAMPLEFORMAT, sampleformat);
TIFFSetField(stream, TIFFTAG_COMPRESSION, compression);
TIFFSetField(stream, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(stream, TIFFTAG_ROWSPERSTRIP,
TIFFDefaultStripSize(stream, (uint32_t)-1));
// TIFFSetField(stream, TIFFTAG_ROWSPERSTRIP,
// (8 * 1024) / bytesperrow);
TIFFSetField(stream, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
if(frame->get_color_model() == color_model)
{
for(int i = 0; i < asset->height; i++)
{
TIFFWriteScanline(stream, frame->get_rows()[i], i, 0);
}
}
else
{
if(tiff_unit->temp &&
tiff_unit->temp->get_color_model() != color_model)
{
delete tiff_unit->temp;
tiff_unit->temp = 0;
}
if(!tiff_unit->temp)
{
tiff_unit->temp = new VFrame(0,
asset->width,
asset->height,
color_model);
}
cmodel_transfer(tiff_unit->temp->get_rows(),
frame->get_rows(),
tiff_unit->temp->get_y(),
tiff_unit->temp->get_u(),
tiff_unit->temp->get_v(),
frame->get_y(),
frame->get_u(),
frame->get_v(),
0,
0,
frame->get_w(),
frame->get_h(),
0,
0,
frame->get_w(),
frame->get_h(),
frame->get_color_model(),
color_model,
0,
frame->get_w(),
frame->get_w());
for(int i = 0; i < asset->height; i++)
{
TIFFWriteScanline(stream, tiff_unit->temp->get_rows()[i], i, 0);
}
}
TIFFClose(stream);
//printf("FileTIFF::write_frame 10\n");
return result;
}
示例9: TIFFwxOpen
//.........这里部分代码省略.........
(float)image->GetOptionInt(wxIMAGE_OPTION_RESOLUTIONX));
TIFFSetField(tif, TIFFTAG_YRESOLUTION,
(float)image->GetOptionInt(wxIMAGE_OPTION_RESOLUTIONY));
}
int spp = image->GetOptionInt(wxIMAGE_OPTION_SAMPLESPERPIXEL);
if ( !spp )
spp = 3;
int bpp = image->GetOptionInt(wxIMAGE_OPTION_BITSPERSAMPLE);
if ( !bpp )
bpp=8;
int compression = image->GetOptionInt(wxIMAGE_OPTION_COMPRESSION);
if ( !compression )
{
// we can't use COMPRESSION_LZW because current version of libtiff
// doesn't implement it ("no longer implemented due to Unisys patent
// enforcement") and other compression methods are lossy so we
// shouldn't use them by default -- and the only remaining one is none
compression = COMPRESSION_NONE;
}
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, spp);
TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, bpp);
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, spp*bpp == 1 ? PHOTOMETRIC_MINISBLACK
: PHOTOMETRIC_RGB);
TIFFSetField(tif, TIFFTAG_COMPRESSION, compression);
// scanlinesize if determined by spp and bpp
tsize_t linebytes = (tsize_t)image->GetWidth() * spp * bpp / 8;
if ( (image->GetWidth() % 8 > 0) && (spp * bpp < 8) )
linebytes+=1;
unsigned char *buf;
if (TIFFScanlineSize(tif) > linebytes || (spp * bpp < 24))
{
buf = (unsigned char *)_TIFFmalloc(TIFFScanlineSize(tif));
if (!buf)
{
if (verbose)
wxLogError( _("TIFF: Couldn't allocate memory.") );
TIFFClose( tif );
return false;
}
}
else
{
buf = NULL;
}
TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP,TIFFDefaultStripSize(tif, (uint32) -1));
unsigned char *ptr = image->GetData();
for ( int row = 0; row < image->GetHeight(); row++ )
{
if ( buf )
{
if ( spp * bpp > 1 )
{
// color image
memcpy(buf, ptr, image->GetWidth());
}
else // black and white image
{
for ( int column = 0; column < linebytes; column++ )
{
uint8 reverse = 0;
for ( int bp = 0; bp < 8; bp++ )
{
if ( ptr[column*24 + bp*3] > 0 )
{
// check only red as this is sufficient
reverse = (uint8)(reverse | 128 >> bp);
}
}
buf[column] = reverse;
}
}
}
if ( TIFFWriteScanline(tif, buf ? buf : ptr, (uint32)row, 0) < 0 )
{
if (verbose)
wxLogError( _("TIFF: Error writing image.") );
TIFFClose( tif );
if (buf)
_TIFFfree(buf);
return false;
}
ptr += image->GetWidth()*3;
}
示例10: main
int
main(int argc, char **argv)
{
TIFF *tif;
int i;
unsigned char buf[3] = { 0, 127, 255 };
char *value;
/* Test whether we can write tags. */
tif = TIFFOpen(filename, "w");
if (!tif) {
fprintf (stderr, "Can't create test TIFF file %s.\n", filename);
return 1;
}
if (!TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, 1)) {
fprintf (stderr, "Can't set ImageWidth tag.\n");
goto failure;
}
if (!TIFFSetField(tif, TIFFTAG_IMAGELENGTH, 1)) {
fprintf (stderr, "Can't set ImageLength tag.\n");
goto failure;
}
if (!TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8)) {
fprintf (stderr, "Can't set BitsPerSample tag.\n");
goto failure;
}
if (!TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 3)) {
fprintf (stderr, "Can't set SamplesPerPixel tag.\n");
goto failure;
}
if (!TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG)) {
fprintf (stderr, "Can't set PlanarConfiguration tag.\n");
goto failure;
}
if (!TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB)) {
fprintf (stderr, "Can't set PhotometricInterpretation tag.\n");
goto failure;
}
for (i = 0; i < NTAGS; i++) {
if (!TIFFSetField(tif, ascii_tags[i].tag,
ascii_tags[i].value)) {
fprintf(stderr, "Can't set tag %d.\n",
(int)ascii_tags[i].tag);
goto failure;
}
}
/* InkNames tag has special form, so we handle it separately. */
if (!TIFFSetField(tif, TIFFTAG_NUMBEROFINKS, 3)) {
fprintf (stderr, "Can't set tag %d.\n", TIFFTAG_NUMBEROFINKS);
goto failure;
}
if (!TIFFSetField(tif, TIFFTAG_INKNAMES, ink_names_size, ink_names)) {
fprintf (stderr, "Can't set tag %d.\n", TIFFTAG_INKNAMES);
goto failure;
}
/* Write dummy pixel data. */
if (!TIFFWriteScanline(tif, buf, 0, 0) < 0) {
fprintf (stderr, "Can't write image data.\n");
goto failure;
}
TIFFClose(tif);
/* Ok, now test whether we can read written values. */
tif = TIFFOpen(filename, "r");
if (!tif) {
fprintf (stderr, "Can't open test TIFF file %s.\n", filename);
return 1;
}
for (i = 0; i < NTAGS; i++) {
if (!TIFFGetField(tif, ascii_tags[i].tag, &value)
|| strcmp(value, ascii_tags[i].value)) {
fprintf(stderr, "Can't get tag %d.\n",
(int)ascii_tags[i].tag);
goto failure;
}
}
if (!TIFFGetField(tif, TIFFTAG_INKNAMES, &value)
|| memcmp(value, ink_names, ink_names_size)) {
fprintf (stderr, "Can't get tag %d.\n", TIFFTAG_INKNAMES);
goto failure;
}
TIFFClose(tif);
/* All tests passed; delete file and exit with success status. */
unlink(filename);
return 0;
failure:
/* Something goes wrong; close file and return unsuccessful status. */
TIFFClose(tif);
unlink(filename);
return 1;
//.........这里部分代码省略.........
示例11: main
int main(int argc, char *argv[])
{
int row;
uint8_t image_buffer[1024];
TIFF *tiff_file;
struct tm *tm;
time_t now;
char buf[133];
float x_resolution;
float y_resolution;
int i;
for (i = 0; sequence[i].name; i++)
{
if ((tiff_file = TIFFOpen(sequence[i].name, "w")) == NULL)
exit(2);
/* Prepare the directory entry fully before writing the image, or libtiff complains */
TIFFSetField(tiff_file, TIFFTAG_COMPRESSION, COMPRESSION_CCITT_T6);
TIFFSetField(tiff_file, TIFFTAG_IMAGEWIDTH, sequence[i].width);
TIFFSetField(tiff_file, TIFFTAG_BITSPERSAMPLE, 1);
TIFFSetField(tiff_file, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
TIFFSetField(tiff_file, TIFFTAG_SAMPLESPERPIXEL, 1);
TIFFSetField(tiff_file, TIFFTAG_ROWSPERSTRIP, -1L);
TIFFSetField(tiff_file, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(tiff_file, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE);
TIFFSetField(tiff_file, TIFFTAG_FILLORDER, FILLORDER_LSB2MSB);
x_resolution = sequence[i].x_res/100.0f;
y_resolution = sequence[i].y_res/100.0f;
TIFFSetField(tiff_file, TIFFTAG_XRESOLUTION, floorf(x_resolution*2.54f + 0.5f));
TIFFSetField(tiff_file, TIFFTAG_YRESOLUTION, floorf(y_resolution*2.54f + 0.5f));
TIFFSetField(tiff_file, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH);
TIFFSetField(tiff_file, TIFFTAG_SOFTWARE, "spandsp");
if (gethostname(buf, sizeof(buf)) == 0)
TIFFSetField(tiff_file, TIFFTAG_HOSTCOMPUTER, buf);
TIFFSetField(tiff_file, TIFFTAG_IMAGEDESCRIPTION, "Blank test image");
TIFFSetField(tiff_file, TIFFTAG_MAKE, "soft-switch.org");
TIFFSetField(tiff_file, TIFFTAG_MODEL, "test data");
time(&now);
tm = localtime(&now);
sprintf(buf,
"%4d/%02d/%02d %02d:%02d:%02d",
tm->tm_year + 1900,
tm->tm_mon + 1,
tm->tm_mday,
tm->tm_hour,
tm->tm_min,
tm->tm_sec);
TIFFSetField(tiff_file, TIFFTAG_DATETIME, buf);
TIFFSetField(tiff_file, TIFFTAG_IMAGELENGTH, sequence[i].length);
TIFFSetField(tiff_file, TIFFTAG_PAGENUMBER, 0, 1);
TIFFSetField(tiff_file, TIFFTAG_CLEANFAXDATA, CLEANFAXDATA_CLEAN);
TIFFSetField(tiff_file, TIFFTAG_IMAGEWIDTH, sequence[i].width);
/* Write the image first.... */
for (row = 0; row < sequence[i].length; row++)
{
memset(image_buffer, 0, sequence[i].width/8 + 1);
if (TIFFWriteScanline(tiff_file, image_buffer, row, 0) < 0)
{
printf("Write error at row %d.\n", row);
exit(2);
}
}
/* ....then the directory entry, and libtiff is happy. */
TIFFWriteDirectory(tiff_file);
TIFFClose(tiff_file);
}
return 0;
}
示例12: main
//.........这里部分代码省略.........
TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, WIDTH);
TIFFSetField(tif, TIFFTAG_IMAGELENGTH, HEIGHT);
TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8);
TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 3);
TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, 1);
TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(tif, TIFFTAG_RESOLUTIONUNIT, RESUNIT_NONE);
#ifdef notdef
TIFFSetField(tif, TIFFTAG_WHITEPOINT, whitex, whitey);
TIFFSetField(tif, TIFFTAG_PRIMARYCHROMATICITIES, primaries);
#endif
TIFFSetField(tif, TIFFTAG_REFERENCEBLACKWHITE, refblackwhite);
TIFFSetField(tif, TIFFTAG_TRANSFERFUNCTION, red, green, blue);
scan_line = (unsigned char *) malloc(WIDTH * 3);
for (i = 0; i < 255; i++) {
for (j = 0; j < 75; j++) {
scan_line[j * 3] = 255;
scan_line[(j * 3) + 1] = 255 - i;
scan_line[(j * 3) + 2] = 255 - i;
}
for (j = 75; j < 150; j++) {
scan_line[j * 3] = 255 - i;
scan_line[(j * 3) + 1] = 255;
scan_line[(j * 3) + 2] = 255 - i;
}
for (j = 150; j < 225; j++) {
scan_line[j * 3] = 255 - i;
scan_line[(j * 3) + 1] = 255 - i;
scan_line[(j * 3) + 2] = 255;
}
for (j = 225; j < 300; j++) {
scan_line[j * 3] = (i - 1) / 2;
scan_line[(j * 3) + 1] = (i - 1) / 2;
scan_line[(j * 3) + 2] = (i - 1) / 2;
}
for (j = 300; j < 375; j++) {
scan_line[j * 3] = 255 - i;
scan_line[(j * 3) + 1] = 255;
scan_line[(j * 3) + 2] = 255;
}
for (j = 375; j < 450; j++) {
scan_line[j * 3] = 255;
scan_line[(j * 3) + 1] = 255 - i;
scan_line[(j * 3) + 2] = 255;
}
for (j = 450; j < 525; j++) {
scan_line[j * 3] = 255;
scan_line[(j * 3) + 1] = 255;
scan_line[(j * 3) + 2] = 255 - i;
}
TIFFWriteScanline(tif, scan_line, i, 0);
}
for (i = 255; i < 512; i++) {
for (j = 0; j < 75; j++) {
scan_line[j * 3] = i;
scan_line[(j * 3) + 1] = 0;
scan_line[(j * 3) + 2] = 0;
}
for (j = 75; j < 150; j++) {
scan_line[j * 3] = 0;
scan_line[(j * 3) + 1] = i;
scan_line[(j * 3) + 2] = 0;
}
for (j = 150; j < 225; j++) {
scan_line[j * 3] = 0;
scan_line[(j * 3) + 1] = 0;
scan_line[(j * 3) + 2] = i;
}
for (j = 225; j < 300; j++) {
scan_line[j * 3] = (i - 1) / 2;
scan_line[(j * 3) + 1] = (i - 1) / 2;
scan_line[(j * 3) + 2] = (i - 1) / 2;
}
for (j = 300; j < 375; j++) {
scan_line[j * 3] = 0;
scan_line[(j * 3) + 1] = i;
scan_line[(j * 3) + 2] = i;
}
for (j = 375; j < 450; j++) {
scan_line[j * 3] = i;
scan_line[(j * 3) + 1] = 0;
scan_line[(j * 3) + 2] = i;
}
for (j = 450; j < 525; j++) {
scan_line[j * 3] = i;
scan_line[(j * 3) + 1] = i;
scan_line[(j * 3) + 2] = 0;
}
TIFFWriteScanline(tif, scan_line, i, 0);
}
free(scan_line);
TIFFClose(tif);
exit(0);
}
示例13: write_tiff_scanline
CAMLprim value write_tiff_scanline(value tiffh, value buf, value row) {
CAMLparam3(tiffh,buf,row);
TIFFWriteScanline((TIFF*)tiffh, String_val(buf), Int_val(row), 0);
CAMLreturn(Val_unit);
}
示例14: main
int main(int argc, char* argv[])
{
bool color;
int n1, i2, n2, nc, nbuf;
unsigned char *grey=NULL;
sf_file in=NULL;
TIFF *tiffout=NULL;
FILE *tiffin=NULL;
char *tiffname=NULL, buf[BUFSIZ];
sf_init(argc,argv);
in = sf_input("in");
fclose(sf_tempfile(&tiffname,"w"));
tiffout = TIFFOpen(tiffname,"wb");
if (tiffout == NULL) sf_error("can't open file %s\n", tiffname);
if (SF_UCHAR != sf_gettype(in)) sf_error("Need unsigned char in input");
if (!sf_histint(in,"n1",&n1)) sf_error("No n1= in input");
if (!sf_getbool("color",&color)) color=(bool)(3==n1);
if (color) {
nc = n1;
if (!sf_histint(in,"n2",&n1)) sf_error("No n2= in input");
if (!sf_histint(in,"n3",&n2)) sf_error("No n3= in input");
} else {
nc = 1;
if (!sf_histint(in,"n2",&n2)) sf_error("No n2= in input");
}
grey = sf_ucharalloc (n1*n2*nc);
sf_ucharread(grey,n1*n2*nc,in);
TIFFSetField(tiffout,TIFFTAG_IMAGEWIDTH,n1);
TIFFSetField(tiffout,TIFFTAG_IMAGELENGTH,n2);
TIFFSetField(tiffout,TIFFTAG_SAMPLESPERPIXEL,nc);
TIFFSetField(tiffout,TIFFTAG_BITSPERSAMPLE,8);
TIFFSetField(tiffout,TIFFTAG_ORIENTATION,ORIENTATION_TOPLEFT);
TIFFSetField(tiffout,TIFFTAG_PHOTOMETRIC,
(3==nc)? PHOTOMETRIC_RGB: PHOTOMETRIC_MINISBLACK);
TIFFSetField(tiffout,TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(tiffout, TIFFTAG_ROWSPERSTRIP, 1);
for (i2 = 0; i2 < n2; i2++) {
if (TIFFWriteScanline(tiffout, grey+i2*n1*nc, i2, 0) < 0)
sf_error("Trouble writing TIFF file");
}
TIFFClose(tiffout);
tiffin = fopen(tiffname,"rb");
while (1) {
nbuf = fread(buf,1,BUFSIZ,tiffin);
if (nbuf <= 0) break;
fwrite(buf,1,nbuf,stdout);
}
fclose(tiffin);
unlink(tiffname);
exit(0);
}
示例15: create_error_page
static int create_error_page(TIFF *tiff_file)
{
uint8_t image_buffer[1728/8 + 1];
int row;
int start_pixel;
int i;
/* ETSI ETS 300 242 B.5.4 Copy quality criteria - the ERROR page. */
for (row = 0; row < 68; row++)
{
clear_row(image_buffer, 1728);
if (TIFFWriteScanline(tiff_file, image_buffer, row, 0) < 0)
{
printf("Write error at row %d.\n", row);
exit(2);
}
}
clear_row(image_buffer, 1728);
set_pixel_range(image_buffer, 1, 0, 1727);
if (TIFFWriteScanline(tiff_file, image_buffer, row++, 0) < 0)
{
printf("Write error at row %d.\n", row);
exit(2);
}
clear_row(image_buffer, 1728);
if (TIFFWriteScanline(tiff_file, image_buffer, row++, 0) < 0)
{
printf("Write error at row %d.\n", row);
exit(2);
}
for (i = 0; i < 10; i++)
{
for (start_pixel = 16; start_pixel <= 1616; start_pixel += 64)
{
clear_row(image_buffer, 1728);
set_pixel_range(image_buffer, 1, start_pixel, start_pixel + 63);
if (TIFFWriteScanline(tiff_file, image_buffer, row, 0) < 0)
{
printf("Write error at row %d.\n", row);
exit(2);
}
row++;
}
}
clear_row(image_buffer, 1728);
if (TIFFWriteScanline(tiff_file, image_buffer, row++, 0) < 0)
{
printf("Write error at row %d.\n", row);
exit(2);
}
clear_row(image_buffer, 1728);
set_pixel_range(image_buffer, 1, 0, 1727);
if (TIFFWriteScanline(tiff_file, image_buffer, row++, 0) < 0)
{
printf("Write error at row %d.\n", row);
exit(2);
}
for (row = 332; row < 400; row++)
{
clear_row(image_buffer, 1728);
if (TIFFWriteScanline(tiff_file, image_buffer, row, 0) < 0)
{
printf("Write error at row %d.\n", row);
exit(2);
}
}
return 400;
}