Пример #1
0
/*
 * Get an tile-organized image that has
 *     SamplesPerPixel > 1
 *     PlanarConfiguration separated
 * We assume that all such images are RGB.
 */    
boolean TIFFRasterImpl::gtTileSeparate(
    const RGBvalue* Map, u_long h, u_long w
) {
    u_long tilesize = TIFFTileSize(tif_);
    u_char* buf = new u_char[3*tilesize];
    if (buf == nil) {
	TIFFError(TIFFFileName(tif_), "No space for tile buffer");
	return false;
    }
    u_char* r = buf;
    u_char* g = r + tilesize;
    u_char* b = g + tilesize;
    tileSeparateRoutine put = pickTileSeparateCase(Map);
    u_long tw;
    TIFFGetField(tif_, TIFFTAG_TILEWIDTH, &tw);
    u_long th;
    TIFFGetField(tif_, TIFFTAG_TILELENGTH, &th);
    u_long y = setorientation(h);
    int toskew = (int)(orientation_ == ORIENTATION_TOPLEFT ? -tw+-w : -tw+w);
    for (u_long row = 0; row < h; row += th) {
	u_long nrow = (row + th > h ? h - row : th);
	for (u_long col = 0; col < w; col += tw) {
	    if (TIFFReadTile(tif_, r, col, row, 0, 0) < 0) {
		break;
	    }
	    if (TIFFReadTile(tif_, g, col, row, 0, 1) < 0) {
		break;
	    }
	    if (TIFFReadTile(tif_, b, col, row, 0, 2) < 0) {
		break;
	    }
	    if (col + tw > w) {
		/*
		 * Tile is clipped horizontally.  Calculate
		 * visible portion and skewing factors.
		 */
		u_long npix = w - col;
		int fromskew = (int)(tw - npix);
		(this->*put)(
		    raster_ + y*w + col, r, g, b, Map,
		    npix, nrow, fromskew, toskew + fromskew
		);
	    } else
		(this->*put)(
		    raster_ + y*w + col, r, g, b, Map,
		    tw, nrow, 0, toskew
		);
	}
	y += (orientation_ == ORIENTATION_TOPLEFT ? -nrow : nrow);
    }
    delete buf;
    return true;
}
Пример #2
0
/*
 * Get a strip-organized image with
 *     SamplesPerPixel > 1
 *     PlanarConfiguration separated
 * We assume that all such images are RGB.
 */
boolean TIFFRasterImpl::gtStripSeparate(
    const RGBvalue* Map, u_long h, u_long w
) {
    u_long stripsize = TIFFStripSize(tif_);
    u_char* buf = new u_char[3*stripsize];
    u_char* r = buf;
    u_char* g = r + stripsize;
    u_char* b = g + stripsize;
    tileSeparateRoutine put = pickTileSeparateCase(Map);
    u_long y = setorientation(h);
    int toskew = (int)(orientation_ == ORIENTATION_TOPLEFT ? -w + -w : -w + w);
    u_long rowsperstrip = (u_long) -1L;
    TIFFGetField(tif_, TIFFTAG_ROWSPERSTRIP, &rowsperstrip);
    u_long imagewidth;
    TIFFGetField(tif_, TIFFTAG_IMAGEWIDTH, &imagewidth);
    int scanline = TIFFScanlineSize(tif_);
    int fromskew = (int)(w < imagewidth ? imagewidth - w : 0);
    for (u_long row = 0; row < h; row += rowsperstrip) {
	u_int nrow = u_int(row + rowsperstrip > h ? h - row : rowsperstrip);
	if (TIFFReadEncodedStrip(
	    tif_, TIFFComputeStrip(tif_, row, 0), r, nrow*scanline) < 0
	) {
	    break;
	}
	if (TIFFReadEncodedStrip(
	    tif_, TIFFComputeStrip(tif_, row, 1), g, nrow*scanline) < 0
	) {
	    break;
	}
	if (TIFFReadEncodedStrip(
	    tif_, TIFFComputeStrip(tif_, row, 2), b, nrow*scanline) < 0
	) {
	    break;
	}
	(this->*put)(raster_ + y*w, r, g, b, Map, w, nrow, fromskew, toskew);
	y += (orientation_ == ORIENTATION_TOPLEFT ? -nrow : nrow);
    }
    delete buf;
    return true;
}
Пример #3
0
int
TIFFRGBAImageBegin(TIFFRGBAImage* img, TIFF* tif, int stop, char emsg[1024])
{
    uint16* sampleinfo;
    uint16 extrasamples;
    uint16 planarconfig;
    int colorchannels;

    img->tif = tif;
    img->stoponerr = stop;
    TIFFGetFieldDefaulted(tif, TIFFTAG_BITSPERSAMPLE, &img->bitspersample);
    switch (img->bitspersample) {
    case 1: case 2: case 4:
    case 8: case 16:
    break;
    default:
    sprintf(emsg, "Sorry, can not image with %d-bit samples",
    img->bitspersample);
    return (0);
    }
    img->alpha = 0;
    TIFFGetFieldDefaulted(tif, TIFFTAG_SAMPLESPERPIXEL, &img->samplesperpixel);
    TIFFGetFieldDefaulted(tif, TIFFTAG_EXTRASAMPLES,
    &extrasamples, &sampleinfo);
    if (extrasamples == 1)
    switch (sampleinfo[0]) {
    case EXTRASAMPLE_ASSOCALPHA:    /* data is pre-multiplied */
    case EXTRASAMPLE_UNASSALPHA:    /* data is not pre-multiplied */
    img->alpha = sampleinfo[0];
    break;
    }
    colorchannels = img->samplesperpixel - extrasamples;
    TIFFGetFieldDefaulted(tif, TIFFTAG_PLANARCONFIG, &planarconfig);
    if (!TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &img->photometric)) {
    switch (colorchannels) {
    case 1:
    if (isCCITTCompression(tif))
    img->photometric = PHOTOMETRIC_MINISWHITE;
    else
    img->photometric = PHOTOMETRIC_MINISBLACK;
    break;
    case 3:
    img->photometric = PHOTOMETRIC_RGB;
    break;
    default:
    sprintf(emsg, "Missing needed %s tag", photoTag);
    return (0);
    }
    }
    switch (img->photometric) {
    case PHOTOMETRIC_PALETTE:
    if (!TIFFGetField(tif, TIFFTAG_COLORMAP,
    &img->redcmap, &img->greencmap, &img->bluecmap)) {
    TIFFError(TIFFFileName(tif), "Missing required \"Colormap\" tag");
    return (0);
    }
    /* fall thru... */
    case PHOTOMETRIC_MINISWHITE:
    case PHOTOMETRIC_MINISBLACK:
    if (planarconfig == PLANARCONFIG_CONTIG && img->samplesperpixel != 1) {
    sprintf(emsg,
    "Sorry, can not handle contiguous data with %s=%d, and %s=%d",
    photoTag, img->photometric,
    "Samples/pixel", img->samplesperpixel);
    return (0);
    }
    break;
    case PHOTOMETRIC_YCBCR:
    if (planarconfig != PLANARCONFIG_CONTIG) {
    sprintf(emsg, "Sorry, can not handle YCbCr images with %s=%d",
    "Planarconfiguration", planarconfig);
    return (0);
    }
    /* It would probably be nice to have a reality check here. */
    { uint16 compress;
      TIFFGetField(tif, TIFFTAG_COMPRESSION, &compress);
      if (compress == COMPRESSION_JPEG && planarconfig == PLANARCONFIG_CONTIG) {
    /* can rely on libjpeg to convert to RGB */
    /* XXX should restore current state on exit */
    TIFFSetField(tif, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB);
    img->photometric = PHOTOMETRIC_RGB;
      }
    }
    break;
    case PHOTOMETRIC_RGB:
    if (colorchannels < 3) {
    sprintf(emsg, "Sorry, can not handle RGB image with %s=%d",
    "Color channels", colorchannels);
    return (0);
    }
    break;
    case PHOTOMETRIC_SEPARATED: {
    uint16 inkset;
    TIFFGetFieldDefaulted(tif, TIFFTAG_INKSET, &inkset);
    if (inkset != INKSET_CMYK) {
    sprintf(emsg, "Sorry, can not handle separated image with %s=%d",
    "InkSet", inkset);
    return (0);
    }
    if (img->samplesperpixel != 4) {
    sprintf(emsg, "Sorry, can not handle separated image with %s=%d",
    "Samples/pixel", img->samplesperpixel);
    return (0);
    }
    break;
    }
    default:
    sprintf(emsg, "Sorry, can not handle image with %s=%d",
    photoTag, img->photometric);
    return (0);
    }
    img->Map = NULL;
    img->BWmap = NULL;
    img->PALmap = NULL;
    img->ycbcr = NULL;
    TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &img->width);
    TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &img->height);
    TIFFGetFieldDefaulted(tif, TIFFTAG_ORIENTATION, &img->orientation);
    img->isContig =
    !(planarconfig == PLANARCONFIG_SEPARATE && colorchannels > 1);
    if (img->isContig) {
    img->get = TIFFIsTiled(tif) ? gtTileContig : gtStripContig;
    (void) pickTileContigCase(img);
    } else {
    img->get = TIFFIsTiled(tif) ? gtTileSeparate : gtStripSeparate;
    (void) pickTileSeparateCase(img);
    }
    return (1);
}