|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
Modified tif_getimage.c that takes uint64 as output pixel type
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/* $Id: tif_getimage.c,v 1.82 2012-06-06 00:17:49 fwarmerdam Exp $ */
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* Copyright (c) 1991-1997 Sam Leffler
|
|
Toshihiro Shimizu |
890ddd |
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
|
|
Toshihiro Shimizu |
890ddd |
*
|
|
Toshihiro Shimizu |
890ddd |
* Permission to use, copy, modify, distribute, and sell this software and
|
|
Toshihiro Shimizu |
890ddd |
* its documentation for any purpose is hereby granted without fee, provided
|
|
Toshihiro Shimizu |
890ddd |
* that (i) the above copyright notices and this permission notice appear in
|
|
Toshihiro Shimizu |
890ddd |
* all copies of the software and related documentation, and (ii) the names of
|
|
Toshihiro Shimizu |
890ddd |
* Sam Leffler and Silicon Graphics may not be used in any advertising or
|
|
Toshihiro Shimizu |
890ddd |
* publicity relating to the software without the specific, prior written
|
|
Toshihiro Shimizu |
890ddd |
* permission of Sam Leffler and Silicon Graphics.
|
|
Toshihiro Shimizu |
890ddd |
*
|
|
Toshihiro Shimizu |
890ddd |
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
|
Toshihiro Shimizu |
890ddd |
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
|
Toshihiro Shimizu |
890ddd |
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
|
Toshihiro Shimizu |
890ddd |
*
|
|
Toshihiro Shimizu |
890ddd |
* IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
|
|
Toshihiro Shimizu |
890ddd |
* ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
|
|
Toshihiro Shimizu |
890ddd |
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
|
Toshihiro Shimizu |
890ddd |
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
|
|
Toshihiro Shimizu |
890ddd |
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
|
Toshihiro Shimizu |
890ddd |
* OF THIS SOFTWARE.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* TIFF Library
|
|
Toshihiro Shimizu |
890ddd |
*
|
|
Toshihiro Shimizu |
890ddd |
* Read and return a packed RGBA image.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
#include "tiffiop.h"
|
|
Toshihiro Shimizu |
890ddd |
#include <stdio.h></stdio.h>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
typedef int (*gtFunc_32)(TIFFRGBAImage *, uint32 *, uint32, uint32);
|
|
Toshihiro Shimizu |
890ddd |
typedef int (*gtFunc_64)(TIFFRGBAImage *, uint64 *, uint32, uint32);
|
|
Toshihiro Shimizu |
890ddd |
typedef void (*tileContigRoutine_64)(TIFFRGBAImage *, uint64 *, uint32, uint32, uint32, uint32, int32, int32,
|
|
Toshihiro Shimizu |
890ddd |
unsigned char *);
|
|
Toshihiro Shimizu |
890ddd |
typedef void (*tileSeparateRoutine_64)(TIFFRGBAImage *, uint64 *, uint32, uint32, uint32, uint32, int32, int32,
|
|
Toshihiro Shimizu |
890ddd |
unsigned char *, unsigned char *, unsigned char *, unsigned char *);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
static int gtTileContig(TIFFRGBAImage *, uint64 *, uint32, uint32);
|
|
Toshihiro Shimizu |
890ddd |
static int gtTileSeparate(TIFFRGBAImage *, uint64 *, uint32, uint32);
|
|
Toshihiro Shimizu |
890ddd |
static int gtStripContig(TIFFRGBAImage *, uint64 *, uint32, uint32);
|
|
Toshihiro Shimizu |
890ddd |
static int gtStripSeparate(TIFFRGBAImage *, uint64 *, uint32, uint32);
|
|
Toshihiro Shimizu |
890ddd |
static int PickContigCase(TIFFRGBAImage *);
|
|
Toshihiro Shimizu |
890ddd |
static int PickSeparateCase(TIFFRGBAImage *);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
static int BuildMapUaToAa(TIFFRGBAImage *img);
|
|
Toshihiro Shimizu |
890ddd |
static int BuildMapBitdepth16To8(TIFFRGBAImage *img);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
static const char photoTag[] = "PhotometricInterpretation";
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* Helper constants used in Orientation tag handling
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
#define FLIP_VERTICALLY 0x01
|
|
Toshihiro Shimizu |
890ddd |
#define FLIP_HORIZONTALLY 0x02
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* Color conversion constants. We will define display types here.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
static const TIFFDisplay display_sRGB = {
|
|
Toshihiro Shimizu |
890ddd |
{/* XYZ -> luminance matrix */
|
|
Toshihiro Shimizu |
890ddd |
{3.2410F, -1.5374F, -0.4986F},
|
|
Toshihiro Shimizu |
890ddd |
{-0.9692F, 1.8760F, 0.0416F},
|
|
Toshihiro Shimizu |
890ddd |
{0.0556F, -0.2040F, 1.0570F}},
|
|
Toshihiro Shimizu |
890ddd |
100.0F,
|
|
Toshihiro Shimizu |
890ddd |
100.0F,
|
|
Toshihiro Shimizu |
890ddd |
100.0F, /* Light o/p for reference white */
|
|
Toshihiro Shimizu |
890ddd |
255,
|
|
Toshihiro Shimizu |
890ddd |
255,
|
|
Toshihiro Shimizu |
890ddd |
255, /* Pixel values for ref. white */
|
|
Toshihiro Shimizu |
890ddd |
1.0F,
|
|
Toshihiro Shimizu |
890ddd |
1.0F,
|
|
Toshihiro Shimizu |
890ddd |
1.0F, /* Residual light o/p for black pixel */
|
|
Toshihiro Shimizu |
890ddd |
2.4F,
|
|
Toshihiro Shimizu |
890ddd |
2.4F,
|
|
Toshihiro Shimizu |
890ddd |
2.4F, /* Gamma values for the three guns */
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
static int
|
|
Toshihiro Shimizu |
890ddd |
isCCITTCompression(TIFF *tif)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
uint16 compress;
|
|
Toshihiro Shimizu |
890ddd |
TIFFGetField(tif, TIFFTAG_COMPRESSION, &compress);
|
|
Toshihiro Shimizu |
890ddd |
return (compress == COMPRESSION_CCITTFAX3 ||
|
|
Toshihiro Shimizu |
890ddd |
compress == COMPRESSION_CCITTFAX4 ||
|
|
Toshihiro Shimizu |
890ddd |
compress == COMPRESSION_CCITTRLE ||
|
|
Toshihiro Shimizu |
890ddd |
compress == COMPRESSION_CCITTRLEW);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int TIFFRGBAImageBegin_64(TIFFRGBAImage *img, TIFF *tif, int stop, char emsg[1024])
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
uint16 *sampleinfo;
|
|
Toshihiro Shimizu |
890ddd |
uint16 extrasamples;
|
|
Toshihiro Shimizu |
890ddd |
uint16 planarconfig;
|
|
Toshihiro Shimizu |
890ddd |
uint16 compress;
|
|
Toshihiro Shimizu |
890ddd |
int colorchannels;
|
|
Toshihiro Shimizu |
890ddd |
uint16 *red_orig, *green_orig, *blue_orig;
|
|
Toshihiro Shimizu |
890ddd |
int n_color;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/* Initialize to normal values */
|
|
Toshihiro Shimizu |
890ddd |
img->row_offset = 0;
|
|
Toshihiro Shimizu |
890ddd |
img->col_offset = 0;
|
|
Toshihiro Shimizu |
890ddd |
img->redcmap = NULL;
|
|
Toshihiro Shimizu |
890ddd |
img->greencmap = NULL;
|
|
Toshihiro Shimizu |
890ddd |
img->bluecmap = NULL;
|
|
Toshihiro Shimizu |
890ddd |
img->req_orientation = ORIENTATION_BOTLEFT; /* It is the default */
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
img->tif = tif;
|
|
Toshihiro Shimizu |
890ddd |
img->stoponerr = stop;
|
|
Toshihiro Shimizu |
890ddd |
TIFFGetFieldDefaulted(tif, TIFFTAG_BITSPERSAMPLE, &img->bitspersample);
|
|
Toshihiro Shimizu |
890ddd |
switch (img->bitspersample) {
|
|
Toshihiro Shimizu |
890ddd |
case 1:
|
|
Toshihiro Shimizu |
890ddd |
case 2:
|
|
Toshihiro Shimizu |
890ddd |
case 4:
|
|
Toshihiro Shimizu |
890ddd |
case 8:
|
|
Toshihiro Shimizu |
890ddd |
case 16:
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
default:
|
|
Toshihiro Shimizu |
890ddd |
sprintf(emsg, "Sorry, can not handle images with %d-bit samples",
|
|
Toshihiro Shimizu |
890ddd |
img->bitspersample);
|
|
Toshihiro Shimizu |
890ddd |
goto fail_return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
img->alpha = 0;
|
|
Toshihiro Shimizu |
890ddd |
TIFFGetFieldDefaulted(tif, TIFFTAG_SAMPLESPERPIXEL, &img->samplesperpixel);
|
|
Toshihiro Shimizu |
890ddd |
TIFFGetFieldDefaulted(tif, TIFFTAG_EXTRASAMPLES,
|
|
Toshihiro Shimizu |
890ddd |
&extrasamples, &sampleinfo);
|
|
Toshihiro Shimizu |
890ddd |
if (extrasamples >= 1) {
|
|
Toshihiro Shimizu |
890ddd |
switch (sampleinfo[0]) {
|
|
Toshihiro Shimizu |
890ddd |
case EXTRASAMPLE_UNSPECIFIED: /* Workaround for some images without */
|
|
Toshihiro Shimizu |
890ddd |
if (img->samplesperpixel > 3) /* correct info about alpha channel */
|
|
Toshihiro Shimizu |
890ddd |
img->alpha = EXTRASAMPLE_ASSOCALPHA;
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
case EXTRASAMPLE_ASSOCALPHA: /* data is pre-multiplied */
|
|
Toshihiro Shimizu |
890ddd |
case EXTRASAMPLE_UNASSALPHA: /* data is not pre-multiplied */
|
|
Toshihiro Shimizu |
890ddd |
img->alpha = sampleinfo[0];
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef DEFAULT_EXTRASAMPLE_AS_ALPHA
|
|
Toshihiro Shimizu |
890ddd |
if (!TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &img->photometric))
|
|
Toshihiro Shimizu |
890ddd |
img->photometric = PHOTOMETRIC_MINISWHITE;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (extrasamples == 0 && img->samplesperpixel == 4 && img->photometric == PHOTOMETRIC_RGB) {
|
|
Toshihiro Shimizu |
890ddd |
img->alpha = EXTRASAMPLE_ASSOCALPHA;
|
|
Toshihiro Shimizu |
890ddd |
extrasamples = 1;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
colorchannels = img->samplesperpixel - extrasamples;
|
|
Toshihiro Shimizu |
890ddd |
TIFFGetFieldDefaulted(tif, TIFFTAG_COMPRESSION, &compress);
|
|
Toshihiro Shimizu |
890ddd |
TIFFGetFieldDefaulted(tif, TIFFTAG_PLANARCONFIG, &planarconfig);
|
|
Toshihiro Shimizu |
890ddd |
if (!TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &img->photometric)) {
|
|
Toshihiro Shimizu |
890ddd |
switch (colorchannels) {
|
|
Toshihiro Shimizu |
890ddd |
case 1:
|
|
Toshihiro Shimizu |
890ddd |
if (isCCITTCompression(tif))
|
|
Toshihiro Shimizu |
890ddd |
img->photometric = PHOTOMETRIC_MINISWHITE;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
img->photometric = PHOTOMETRIC_MINISBLACK;
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
case 3:
|
|
Toshihiro Shimizu |
890ddd |
img->photometric = PHOTOMETRIC_RGB;
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
default:
|
|
Toshihiro Shimizu |
890ddd |
sprintf(emsg, "Missing needed %s tag", photoTag);
|
|
Toshihiro Shimizu |
890ddd |
goto fail_return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
switch (img->photometric) {
|
|
Toshihiro Shimizu |
890ddd |
case PHOTOMETRIC_PALETTE:
|
|
Toshihiro Shimizu |
890ddd |
if (!TIFFGetField(tif, TIFFTAG_COLORMAP,
|
|
Toshihiro Shimizu |
890ddd |
&red_orig, &green_orig, &blue_orig)) {
|
|
Toshihiro Shimizu |
890ddd |
sprintf(emsg, "Missing required \"Colormap\" tag");
|
|
Toshihiro Shimizu |
890ddd |
goto fail_return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/* copy the colormaps so we can modify them */
|
|
Toshihiro Shimizu |
890ddd |
n_color = (1L << img->bitspersample);
|
|
Toshihiro Shimizu |
890ddd |
img->redcmap = (uint16 *)_TIFFmalloc(sizeof(uint16) * n_color);
|
|
Toshihiro Shimizu |
890ddd |
img->greencmap = (uint16 *)_TIFFmalloc(sizeof(uint16) * n_color);
|
|
Toshihiro Shimizu |
890ddd |
img->bluecmap = (uint16 *)_TIFFmalloc(sizeof(uint16) * n_color);
|
|
Toshihiro Shimizu |
890ddd |
if (!img->redcmap || !img->greencmap || !img->bluecmap) {
|
|
Toshihiro Shimizu |
890ddd |
sprintf(emsg, "Out of memory for colormap copy");
|
|
Toshihiro Shimizu |
890ddd |
goto fail_return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
_TIFFmemcpy(img->redcmap, red_orig, n_color * 2);
|
|
Toshihiro Shimizu |
890ddd |
_TIFFmemcpy(img->greencmap, green_orig, n_color * 2);
|
|
Toshihiro Shimizu |
890ddd |
_TIFFmemcpy(img->bluecmap, blue_orig, n_color * 2);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/* fall thru... */
|
|
Toshihiro Shimizu |
890ddd |
case PHOTOMETRIC_MINISWHITE:
|
|
Toshihiro Shimizu |
890ddd |
case PHOTOMETRIC_MINISBLACK:
|
|
Toshihiro Shimizu |
890ddd |
if (planarconfig == PLANARCONFIG_CONTIG && img->samplesperpixel != 1 && img->bitspersample < 8) {
|
|
Toshihiro Shimizu |
890ddd |
sprintf(emsg,
|
|
Toshihiro Shimizu |
890ddd |
"Sorry, can not handle contiguous data with %s=%d, "
|
|
Toshihiro Shimizu |
890ddd |
"and %s=%d and Bits/Sample=%d",
|
|
Toshihiro Shimizu |
890ddd |
photoTag, img->photometric,
|
|
Toshihiro Shimizu |
890ddd |
"Samples/pixel", img->samplesperpixel,
|
|
Toshihiro Shimizu |
890ddd |
img->bitspersample);
|
|
Toshihiro Shimizu |
890ddd |
goto fail_return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
case PHOTOMETRIC_YCBCR:
|
|
Toshihiro Shimizu |
890ddd |
/* It would probably be nice to have a reality check here. */
|
|
Toshihiro Shimizu |
890ddd |
if (planarconfig == PLANARCONFIG_CONTIG)
|
|
Toshihiro Shimizu |
890ddd |
/* can rely on libjpeg to convert to RGB */
|
|
Toshihiro Shimizu |
890ddd |
/* XXX should restore current state on exit */
|
|
Toshihiro Shimizu |
890ddd |
switch (compress) {
|
|
Toshihiro Shimizu |
890ddd |
case COMPRESSION_JPEG:
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* TODO: when complete tests verify complete desubsampling
|
|
Toshihiro Shimizu |
890ddd |
* and YCbCr handling, remove use of TIFFTAG_JPEGCOLORMODE in
|
|
Toshihiro Shimizu |
890ddd |
* favor of tif_getimage.c native handling
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
TIFFSetField(tif, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB);
|
|
Toshihiro Shimizu |
890ddd |
img->photometric = PHOTOMETRIC_RGB;
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
default:
|
|
Toshihiro Shimizu |
890ddd |
/* do nothing */;
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* TODO: if at all meaningful and useful, make more complete
|
|
Toshihiro Shimizu |
890ddd |
* support check here, or better still, refactor to let supporting
|
|
Toshihiro Shimizu |
890ddd |
* code decide whether there is support and what meaningfull
|
|
Toshihiro Shimizu |
890ddd |
* error to return
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
case PHOTOMETRIC_RGB:
|
|
Toshihiro Shimizu |
890ddd |
if (colorchannels < 3) {
|
|
Toshihiro Shimizu |
890ddd |
sprintf(emsg, "Sorry, can not handle RGB image with %s=%d",
|
|
Toshihiro Shimizu |
890ddd |
"Color channels", colorchannels);
|
|
Toshihiro Shimizu |
890ddd |
goto fail_return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
case PHOTOMETRIC_SEPARATED: {
|
|
Toshihiro Shimizu |
890ddd |
uint16 inkset;
|
|
Toshihiro Shimizu |
890ddd |
TIFFGetFieldDefaulted(tif, TIFFTAG_INKSET, &inkset);
|
|
Toshihiro Shimizu |
890ddd |
if (inkset != INKSET_CMYK) {
|
|
Toshihiro Shimizu |
890ddd |
sprintf(emsg, "Sorry, can not handle separated image with %s=%d",
|
|
Toshihiro Shimizu |
890ddd |
"InkSet", inkset);
|
|
Toshihiro Shimizu |
890ddd |
goto fail_return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (img->samplesperpixel < 4) {
|
|
Toshihiro Shimizu |
890ddd |
sprintf(emsg, "Sorry, can not handle separated image with %s=%d",
|
|
Toshihiro Shimizu |
890ddd |
"Samples/pixel", img->samplesperpixel);
|
|
Toshihiro Shimizu |
890ddd |
goto fail_return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
} break;
|
|
Toshihiro Shimizu |
890ddd |
case PHOTOMETRIC_LOGL:
|
|
Toshihiro Shimizu |
890ddd |
if (compress != COMPRESSION_SGILOG) {
|
|
Toshihiro Shimizu |
890ddd |
sprintf(emsg, "Sorry, LogL data must have %s=%d",
|
|
Toshihiro Shimizu |
890ddd |
"Compression", COMPRESSION_SGILOG);
|
|
Toshihiro Shimizu |
890ddd |
goto fail_return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
TIFFSetField(tif, TIFFTAG_SGILOGDATAFMT, SGILOGDATAFMT_8BIT);
|
|
Toshihiro Shimizu |
890ddd |
img->photometric = PHOTOMETRIC_MINISBLACK; /* little white lie */
|
|
Toshihiro Shimizu |
890ddd |
img->bitspersample = 8;
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
case PHOTOMETRIC_LOGLUV:
|
|
Toshihiro Shimizu |
890ddd |
if (compress != COMPRESSION_SGILOG && compress != COMPRESSION_SGILOG24) {
|
|
Toshihiro Shimizu |
890ddd |
sprintf(emsg, "Sorry, LogLuv data must have %s=%d or %d",
|
|
Toshihiro Shimizu |
890ddd |
"Compression", COMPRESSION_SGILOG, COMPRESSION_SGILOG24);
|
|
Toshihiro Shimizu |
890ddd |
goto fail_return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (planarconfig != PLANARCONFIG_CONTIG) {
|
|
Toshihiro Shimizu |
890ddd |
sprintf(emsg, "Sorry, can not handle LogLuv images with %s=%d",
|
|
Toshihiro Shimizu |
890ddd |
"Planarconfiguration", planarconfig);
|
|
Toshihiro Shimizu |
890ddd |
return (0);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
TIFFSetField(tif, TIFFTAG_SGILOGDATAFMT, SGILOGDATAFMT_8BIT);
|
|
Toshihiro Shimizu |
890ddd |
img->photometric = PHOTOMETRIC_RGB; /* little white lie */
|
|
Toshihiro Shimizu |
890ddd |
img->bitspersample = 8;
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
case PHOTOMETRIC_CIELAB:
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
default:
|
|
Toshihiro Shimizu |
890ddd |
sprintf(emsg, "Sorry, can not handle image with %s=%d",
|
|
Toshihiro Shimizu |
890ddd |
photoTag, img->photometric);
|
|
Toshihiro Shimizu |
890ddd |
goto fail_return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
img->Map = NULL;
|
|
Toshihiro Shimizu |
890ddd |
img->BWmap = NULL;
|
|
Toshihiro Shimizu |
890ddd |
img->PALmap = NULL;
|
|
Toshihiro Shimizu |
890ddd |
img->ycbcr = NULL;
|
|
Toshihiro Shimizu |
890ddd |
img->cielab = NULL;
|
|
Toshihiro Shimizu |
890ddd |
img->UaToAa = NULL;
|
|
Toshihiro Shimizu |
890ddd |
img->Bitdepth16To8 = NULL;
|
|
Toshihiro Shimizu |
890ddd |
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &img->width);
|
|
Toshihiro Shimizu |
890ddd |
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &img->height);
|
|
Toshihiro Shimizu |
890ddd |
TIFFGetFieldDefaulted(tif, TIFFTAG_ORIENTATION, &img->orientation);
|
|
Toshihiro Shimizu |
890ddd |
img->isContig =
|
|
Toshihiro Shimizu |
890ddd |
!(planarconfig == PLANARCONFIG_SEPARATE && img->samplesperpixel > 1);
|
|
Toshihiro Shimizu |
890ddd |
if (img->isContig) {
|
|
Toshihiro Shimizu |
890ddd |
if (!PickContigCase(img)) {
|
|
Toshihiro Shimizu |
890ddd |
sprintf(emsg, "Sorry, can not handle image");
|
|
Toshihiro Shimizu |
890ddd |
goto fail_return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
if (!PickSeparateCase(img)) {
|
|
Toshihiro Shimizu |
890ddd |
sprintf(emsg, "Sorry, can not handle image");
|
|
Toshihiro Shimizu |
890ddd |
goto fail_return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return 1;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
fail_return:
|
|
Toshihiro Shimizu |
890ddd |
_TIFFfree(img->redcmap);
|
|
Toshihiro Shimizu |
890ddd |
_TIFFfree(img->greencmap);
|
|
Toshihiro Shimizu |
890ddd |
_TIFFfree(img->bluecmap);
|
|
Toshihiro Shimizu |
890ddd |
img->redcmap = img->greencmap = img->bluecmap = NULL;
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int TIFFRGBAImageGet_64(TIFFRGBAImage *img, uint64 *raster, uint32 w, uint32 h)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
gtFunc_64 get = (gtFunc_64)img->get;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (img->get == NULL) {
|
|
Toshihiro Shimizu |
890ddd |
TIFFErrorExt(img->tif->tif_clientdata, TIFFFileName(img->tif), "No \"get\" routine setup");
|
|
Toshihiro Shimizu |
890ddd |
return (0);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (img->put.any == NULL) {
|
|
Toshihiro Shimizu |
890ddd |
TIFFErrorExt(img->tif->tif_clientdata, TIFFFileName(img->tif),
|
|
Toshihiro Shimizu |
890ddd |
"No \"put\" routine setupl; probably can not handle image format");
|
|
Toshihiro Shimizu |
890ddd |
return (0);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Casting between 2 function pointers is allowed in and C++ and works as expected
|
|
Toshihiro Shimizu |
890ddd |
// if re-casted back.
|
|
Toshihiro Shimizu |
890ddd |
// See C 6.3.2.3 (8) and 5.2.10 (6)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return (*get)(img, raster, w, h);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
static int
|
|
Toshihiro Shimizu |
890ddd |
setorientation(TIFFRGBAImage *img)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
switch (img->orientation) {
|
|
Toshihiro Shimizu |
890ddd |
case ORIENTATION_TOPLEFT:
|
|
Toshihiro Shimizu |
890ddd |
case ORIENTATION_LEFTTOP:
|
|
Toshihiro Shimizu |
890ddd |
if (img->req_orientation == ORIENTATION_TOPRIGHT ||
|
|
Toshihiro Shimizu |
890ddd |
img->req_orientation == ORIENTATION_RIGHTTOP)
|
|
Toshihiro Shimizu |
890ddd |
return FLIP_HORIZONTALLY;
|
|
Toshihiro Shimizu |
890ddd |
else if (img->req_orientation == ORIENTATION_BOTRIGHT ||
|
|
Toshihiro Shimizu |
890ddd |
img->req_orientation == ORIENTATION_RIGHTBOT)
|
|
Toshihiro Shimizu |
890ddd |
return FLIP_HORIZONTALLY | FLIP_VERTICALLY;
|
|
Toshihiro Shimizu |
890ddd |
else if (img->req_orientation == ORIENTATION_BOTLEFT ||
|
|
Toshihiro Shimizu |
890ddd |
img->req_orientation == ORIENTATION_LEFTBOT)
|
|
Toshihiro Shimizu |
890ddd |
return FLIP_VERTICALLY;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
case ORIENTATION_TOPRIGHT:
|
|
Toshihiro Shimizu |
890ddd |
case ORIENTATION_RIGHTTOP:
|
|
Toshihiro Shimizu |
890ddd |
if (img->req_orientation == ORIENTATION_TOPLEFT ||
|
|
Toshihiro Shimizu |
890ddd |
img->req_orientation == ORIENTATION_LEFTTOP)
|
|
Toshihiro Shimizu |
890ddd |
return FLIP_HORIZONTALLY;
|
|
Toshihiro Shimizu |
890ddd |
else if (img->req_orientation == ORIENTATION_BOTRIGHT ||
|
|
Toshihiro Shimizu |
890ddd |
img->req_orientation == ORIENTATION_RIGHTBOT)
|
|
Toshihiro Shimizu |
890ddd |
return FLIP_VERTICALLY;
|
|
Toshihiro Shimizu |
890ddd |
else if (img->req_orientation == ORIENTATION_BOTLEFT ||
|
|
Toshihiro Shimizu |
890ddd |
img->req_orientation == ORIENTATION_LEFTBOT)
|
|
Toshihiro Shimizu |
890ddd |
return FLIP_HORIZONTALLY | FLIP_VERTICALLY;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
case ORIENTATION_BOTRIGHT:
|
|
Toshihiro Shimizu |
890ddd |
case ORIENTATION_RIGHTBOT:
|
|
Toshihiro Shimizu |
890ddd |
if (img->req_orientation == ORIENTATION_TOPLEFT ||
|
|
Toshihiro Shimizu |
890ddd |
img->req_orientation == ORIENTATION_LEFTTOP)
|
|
Toshihiro Shimizu |
890ddd |
return FLIP_HORIZONTALLY | FLIP_VERTICALLY;
|
|
Toshihiro Shimizu |
890ddd |
else if (img->req_orientation == ORIENTATION_TOPRIGHT ||
|
|
Toshihiro Shimizu |
890ddd |
img->req_orientation == ORIENTATION_RIGHTTOP)
|
|
Toshihiro Shimizu |
890ddd |
return FLIP_VERTICALLY;
|
|
Toshihiro Shimizu |
890ddd |
else if (img->req_orientation == ORIENTATION_BOTLEFT ||
|
|
Toshihiro Shimizu |
890ddd |
img->req_orientation == ORIENTATION_LEFTBOT)
|
|
Toshihiro Shimizu |
890ddd |
return FLIP_HORIZONTALLY;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
case ORIENTATION_BOTLEFT:
|
|
Toshihiro Shimizu |
890ddd |
case ORIENTATION_LEFTBOT:
|
|
Toshihiro Shimizu |
890ddd |
if (img->req_orientation == ORIENTATION_TOPLEFT ||
|
|
Toshihiro Shimizu |
890ddd |
img->req_orientation == ORIENTATION_LEFTTOP)
|
|
Toshihiro Shimizu |
890ddd |
return FLIP_VERTICALLY;
|
|
Toshihiro Shimizu |
890ddd |
else if (img->req_orientation == ORIENTATION_TOPRIGHT ||
|
|
Toshihiro Shimizu |
890ddd |
img->req_orientation == ORIENTATION_RIGHTTOP)
|
|
Toshihiro Shimizu |
890ddd |
return FLIP_HORIZONTALLY | FLIP_VERTICALLY;
|
|
Toshihiro Shimizu |
890ddd |
else if (img->req_orientation == ORIENTATION_BOTRIGHT ||
|
|
Toshihiro Shimizu |
890ddd |
img->req_orientation == ORIENTATION_RIGHTBOT)
|
|
Toshihiro Shimizu |
890ddd |
return FLIP_HORIZONTALLY;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
default: /* NOTREACHED */
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* Get an tile-organized image that has
|
|
Toshihiro Shimizu |
890ddd |
* PlanarConfiguration contiguous if SamplesPerPixel > 1
|
|
Toshihiro Shimizu |
890ddd |
* or
|
|
Toshihiro Shimizu |
890ddd |
* SamplesPerPixel == 1
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
static int
|
|
Toshihiro Shimizu |
890ddd |
gtTileContig(TIFFRGBAImage *img, uint64 *raster, uint32 w, uint32 h)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TIFF *tif = img->tif;
|
|
Toshihiro Shimizu |
890ddd |
tileContigRoutine_64 put = (tileContigRoutine_64)img->put.contig;
|
|
Toshihiro Shimizu |
890ddd |
uint32 col, row, y, rowstoread;
|
|
Toshihiro Shimizu |
890ddd |
tmsize_t pos;
|
|
Toshihiro Shimizu |
890ddd |
uint32 tw, th;
|
|
Toshihiro Shimizu |
890ddd |
unsigned char *buf;
|
|
Toshihiro Shimizu |
890ddd |
int32 fromskew, toskew;
|
|
Toshihiro Shimizu |
890ddd |
uint32 nrow;
|
|
Toshihiro Shimizu |
890ddd |
int ret = 1, flip;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
buf = (unsigned char *)_TIFFmalloc(TIFFTileSize(tif));
|
|
Toshihiro Shimizu |
890ddd |
if (buf == 0) {
|
|
Toshihiro Shimizu |
890ddd |
TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", "No space for tile buffer");
|
|
Toshihiro Shimizu |
890ddd |
return (0);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
_TIFFmemset(buf, 0, TIFFTileSize(tif));
|
|
Toshihiro Shimizu |
890ddd |
TIFFGetField(tif, TIFFTAG_TILEWIDTH, &tw);
|
|
Toshihiro Shimizu |
890ddd |
TIFFGetField(tif, TIFFTAG_TILELENGTH, &th);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
flip = setorientation(img);
|
|
Toshihiro Shimizu |
890ddd |
if (flip & FLIP_VERTICALLY) {
|
|
Toshihiro Shimizu |
890ddd |
y = h - 1;
|
|
Toshihiro Shimizu |
890ddd |
toskew = -(int32)(tw + w);
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
y = 0;
|
|
Toshihiro Shimizu |
890ddd |
toskew = -(int32)(tw - w);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (row = 0; row < h; row += nrow) {
|
|
Toshihiro Shimizu |
890ddd |
rowstoread = th - (row + img->row_offset) % th;
|
|
Toshihiro Shimizu |
890ddd |
nrow = (row + rowstoread > h ? h - row : rowstoread);
|
|
Toshihiro Shimizu |
890ddd |
for (col = 0; col < w; col += tw) {
|
|
Toshihiro Shimizu |
890ddd |
if (TIFFReadTile(tif, buf, col + img->col_offset,
|
|
Toshihiro Shimizu |
890ddd |
row + img->row_offset, 0, 0) == (tmsize_t)(-1) &&
|
|
Toshihiro Shimizu |
890ddd |
img->stoponerr) {
|
|
Toshihiro Shimizu |
890ddd |
ret = 0;
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
pos = ((row + img->row_offset) % th) * TIFFTileRowSize(tif);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (col + tw > w) {
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* Tile is clipped horizontally. Calculate
|
|
Toshihiro Shimizu |
890ddd |
* visible portion and skewing factors.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
uint32 npix = w - col;
|
|
Toshihiro Shimizu |
890ddd |
fromskew = tw - npix;
|
|
Toshihiro Shimizu |
890ddd |
(*put)(img, raster + y * w + col, col, y,
|
|
Toshihiro Shimizu |
890ddd |
npix, nrow, fromskew, toskew + fromskew, buf + pos);
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
(*put)(img, raster + y * w + col, col, y, tw, nrow, 0, toskew, buf + pos);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
y += (flip & FLIP_VERTICALLY ? -(int32)nrow : (int32)nrow);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
_TIFFfree(buf);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (flip & FLIP_HORIZONTALLY) {
|
|
Toshihiro Shimizu |
890ddd |
uint32 line;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (line = 0; line < h; line++) {
|
|
Toshihiro Shimizu |
890ddd |
uint64 *left = raster + (line * w);
|
|
Toshihiro Shimizu |
890ddd |
uint64 *right = left + w - 1;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
while (left < right) {
|
|
Toshihiro Shimizu |
890ddd |
uint64 temp = *left;
|
|
Toshihiro Shimizu |
890ddd |
*left = *right;
|
|
Toshihiro Shimizu |
890ddd |
*right = temp;
|
|
Toshihiro Shimizu |
890ddd |
left++, right--;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return (ret);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* Get an tile-organized image that has
|
|
Toshihiro Shimizu |
890ddd |
* SamplesPerPixel > 1
|
|
Toshihiro Shimizu |
890ddd |
* PlanarConfiguration separated
|
|
Toshihiro Shimizu |
890ddd |
* We assume that all such images are RGB.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
static int
|
|
Toshihiro Shimizu |
890ddd |
gtTileSeparate(TIFFRGBAImage *img, uint64 *raster, uint32 w, uint32 h)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TIFF *tif = img->tif;
|
|
Toshihiro Shimizu |
890ddd |
tileSeparateRoutine_64 put = (tileSeparateRoutine_64)img->put.separate;
|
|
Toshihiro Shimizu |
890ddd |
uint32 col, row, y, rowstoread;
|
|
Toshihiro Shimizu |
890ddd |
tmsize_t pos;
|
|
Toshihiro Shimizu |
890ddd |
uint32 tw, th;
|
|
Toshihiro Shimizu |
890ddd |
unsigned char *buf;
|
|
Toshihiro Shimizu |
890ddd |
unsigned char *p0;
|
|
Toshihiro Shimizu |
890ddd |
unsigned char *p1;
|
|
Toshihiro Shimizu |
890ddd |
unsigned char *p2;
|
|
Toshihiro Shimizu |
890ddd |
unsigned char *pa;
|
|
Toshihiro Shimizu |
890ddd |
tmsize_t tilesize;
|
|
Toshihiro Shimizu |
890ddd |
tmsize_t bufsize;
|
|
Toshihiro Shimizu |
890ddd |
int32 fromskew, toskew;
|
|
Toshihiro Shimizu |
890ddd |
int alpha = img->alpha;
|
|
Toshihiro Shimizu |
890ddd |
uint32 nrow;
|
|
Toshihiro Shimizu |
890ddd |
int ret = 1, flip;
|
|
Toshihiro Shimizu |
890ddd |
int colorchannels;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
tilesize = TIFFTileSize(tif);
|
|
Toshihiro Shimizu |
890ddd |
bufsize = TIFFSafeMultiply(tmsize_t, alpha ? 4 : 3, tilesize);
|
|
Toshihiro Shimizu |
890ddd |
if (bufsize == 0) {
|
|
Toshihiro Shimizu |
890ddd |
TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "Integer overflow in %s", "gtTileSeparate");
|
|
Toshihiro Shimizu |
890ddd |
return (0);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
buf = (unsigned char *)_TIFFmalloc(bufsize);
|
|
Toshihiro Shimizu |
890ddd |
if (buf == 0) {
|
|
Toshihiro Shimizu |
890ddd |
TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", "No space for tile buffer");
|
|
Toshihiro Shimizu |
890ddd |
return (0);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
_TIFFmemset(buf, 0, bufsize);
|
|
Toshihiro Shimizu |
890ddd |
p0 = buf;
|
|
Toshihiro Shimizu |
890ddd |
p1 = p0 + tilesize;
|
|
Toshihiro Shimizu |
890ddd |
p2 = p1 + tilesize;
|
|
Toshihiro Shimizu |
890ddd |
pa = (alpha ? (p2 + tilesize) : NULL);
|
|
Toshihiro Shimizu |
890ddd |
TIFFGetField(tif, TIFFTAG_TILEWIDTH, &tw);
|
|
Toshihiro Shimizu |
890ddd |
TIFFGetField(tif, TIFFTAG_TILELENGTH, &th);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
flip = setorientation(img);
|
|
Toshihiro Shimizu |
890ddd |
if (flip & FLIP_VERTICALLY) {
|
|
Toshihiro Shimizu |
890ddd |
y = h - 1;
|
|
Toshihiro Shimizu |
890ddd |
toskew = -(int32)(tw + w);
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
y = 0;
|
|
Toshihiro Shimizu |
890ddd |
toskew = -(int32)(tw - w);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
switch (img->photometric) {
|
|
Toshihiro Shimizu |
890ddd |
case PHOTOMETRIC_MINISWHITE:
|
|
Toshihiro Shimizu |
890ddd |
case PHOTOMETRIC_MINISBLACK:
|
|
Toshihiro Shimizu |
890ddd |
case PHOTOMETRIC_PALETTE:
|
|
Toshihiro Shimizu |
890ddd |
colorchannels = 1;
|
|
Toshihiro Shimizu |
890ddd |
p2 = p1 = p0;
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
default:
|
|
Toshihiro Shimizu |
890ddd |
colorchannels = 3;
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (row = 0; row < h; row += nrow) {
|
|
Toshihiro Shimizu |
890ddd |
rowstoread = th - (row + img->row_offset) % th;
|
|
Toshihiro Shimizu |
890ddd |
nrow = (row + rowstoread > h ? h - row : rowstoread);
|
|
Toshihiro Shimizu |
890ddd |
for (col = 0; col < w; col += tw) {
|
|
Toshihiro Shimizu |
890ddd |
if (TIFFReadTile(tif, p0, col + img->col_offset,
|
|
Toshihiro Shimizu |
890ddd |
row + img->row_offset, 0, 0) == (tmsize_t)(-1) &&
|
|
Toshihiro Shimizu |
890ddd |
img->stoponerr) {
|
|
Toshihiro Shimizu |
890ddd |
ret = 0;
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (colorchannels > 1 && TIFFReadTile(tif, p1, col + img->col_offset, row + img->row_offset, 0, 1) == (tmsize_t)(-1) && img->stoponerr) {
|
|
Toshihiro Shimizu |
890ddd |
ret = 0;
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (colorchannels > 1 && TIFFReadTile(tif, p2, col + img->col_offset, row + img->row_offset, 0, 2) == (tmsize_t)(-1) && img->stoponerr) {
|
|
Toshihiro Shimizu |
890ddd |
ret = 0;
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (alpha && TIFFReadTile(tif, pa, col + img->col_offset, row + img->row_offset, 0, colorchannels) == (tmsize_t)(-1) && img->stoponerr) {
|
|
Toshihiro Shimizu |
890ddd |
ret = 0;
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
pos = ((row + img->row_offset) % th) * TIFFTileRowSize(tif);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (col + tw > w) {
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* Tile is clipped horizontally. Calculate
|
|
Toshihiro Shimizu |
890ddd |
* visible portion and skewing factors.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
uint32 npix = w - col;
|
|
Toshihiro Shimizu |
890ddd |
fromskew = tw - npix;
|
|
Toshihiro Shimizu |
890ddd |
(*put)(img, raster + y * w + col, col, y,
|
|
Toshihiro Shimizu |
890ddd |
npix, nrow, fromskew, toskew + fromskew,
|
|
Toshihiro Shimizu |
890ddd |
p0 + pos, p1 + pos, p2 + pos, (alpha ? (pa + pos) : NULL));
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
(*put)(img, raster + y * w + col, col, y,
|
|
Toshihiro Shimizu |
890ddd |
tw, nrow, 0, toskew, p0 + pos, p1 + pos, p2 + pos, (alpha ? (pa + pos) : NULL));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
y += (flip & FLIP_VERTICALLY ? -(int32)nrow : (int32)nrow);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (flip & FLIP_HORIZONTALLY) {
|
|
Toshihiro Shimizu |
890ddd |
uint32 line;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (line = 0; line < h; line++) {
|
|
Toshihiro Shimizu |
890ddd |
uint64 *left = raster + (line * w);
|
|
Toshihiro Shimizu |
890ddd |
uint64 *right = left + w - 1;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
while (left < right) {
|
|
Toshihiro Shimizu |
890ddd |
uint64 temp = *left;
|
|
Toshihiro Shimizu |
890ddd |
*left = *right;
|
|
Toshihiro Shimizu |
890ddd |
*right = temp;
|
|
Toshihiro Shimizu |
890ddd |
left++, right--;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
_TIFFfree(buf);
|
|
Toshihiro Shimizu |
890ddd |
return (ret);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* Get a strip-organized image that has
|
|
Toshihiro Shimizu |
890ddd |
* PlanarConfiguration contiguous if SamplesPerPixel > 1
|
|
Toshihiro Shimizu |
890ddd |
* or
|
|
Toshihiro Shimizu |
890ddd |
* SamplesPerPixel == 1
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
static int
|
|
Toshihiro Shimizu |
890ddd |
gtStripContig(TIFFRGBAImage *img, uint64 *raster, uint32 w, uint32 h)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TIFF *tif = img->tif;
|
|
Toshihiro Shimizu |
890ddd |
tileContigRoutine_64 put = (tileContigRoutine_64)img->put.contig;
|
|
Toshihiro Shimizu |
890ddd |
uint32 row, y, nrow, nrowsub, rowstoread;
|
|
Toshihiro Shimizu |
890ddd |
tmsize_t pos;
|
|
Toshihiro Shimizu |
890ddd |
unsigned char *buf;
|
|
Toshihiro Shimizu |
890ddd |
uint32 rowsperstrip;
|
|
Toshihiro Shimizu |
890ddd |
uint16 subsamplinghor, subsamplingver;
|
|
Toshihiro Shimizu |
890ddd |
uint32 imagewidth = img->width;
|
|
Toshihiro Shimizu |
890ddd |
tmsize_t scanline;
|
|
Toshihiro Shimizu |
890ddd |
int32 fromskew, toskew;
|
|
Toshihiro Shimizu |
890ddd |
int ret = 1, flip;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
buf = (unsigned char *)_TIFFmalloc(TIFFStripSize(tif));
|
|
Toshihiro Shimizu |
890ddd |
if (buf == 0) {
|
|
Toshihiro Shimizu |
890ddd |
TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "No space for strip buffer");
|
|
Toshihiro Shimizu |
890ddd |
return (0);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
_TIFFmemset(buf, 0, TIFFStripSize(tif));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
flip = setorientation(img);
|
|
Toshihiro Shimizu |
890ddd |
if (flip & FLIP_VERTICALLY) {
|
|
Toshihiro Shimizu |
890ddd |
y = h - 1;
|
|
Toshihiro Shimizu |
890ddd |
toskew = -(int32)(w + w);
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
y = 0;
|
|
Toshihiro Shimizu |
890ddd |
toskew = -(int32)(w - w);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TIFFGetFieldDefaulted(tif, TIFFTAG_ROWSPERSTRIP, &rowsperstrip);
|
|
Toshihiro Shimizu |
890ddd |
TIFFGetFieldDefaulted(tif, TIFFTAG_YCBCRSUBSAMPLING, &subsamplinghor, &subsamplingver);
|
|
Toshihiro Shimizu |
890ddd |
scanline = TIFFScanlineSize(tif);
|
|
Toshihiro Shimizu |
890ddd |
fromskew = (w < imagewidth ? imagewidth - w : 0);
|
|
Toshihiro Shimizu |
890ddd |
for (row = 0; row < h; row += nrow) {
|
|
Toshihiro Shimizu |
890ddd |
rowstoread = rowsperstrip - (row + img->row_offset) % rowsperstrip;
|
|
Toshihiro Shimizu |
890ddd |
nrow = (row + rowstoread > h ? h - row : rowstoread);
|
|
Toshihiro Shimizu |
890ddd |
nrowsub = nrow;
|
|
Toshihiro Shimizu |
890ddd |
if ((nrowsub % subsamplingver) != 0)
|
|
Toshihiro Shimizu |
890ddd |
nrowsub += subsamplingver - nrowsub % subsamplingver;
|
|
Toshihiro Shimizu |
890ddd |
if (TIFFReadEncodedStrip(tif,
|
|
Toshihiro Shimizu |
890ddd |
TIFFComputeStrip(tif, row + img->row_offset, 0),
|
|
Toshihiro Shimizu |
890ddd |
buf,
|
|
Toshihiro Shimizu |
890ddd |
((row + img->row_offset) % rowsperstrip + nrowsub) * scanline) == (tmsize_t)(-1) &&
|
|
Toshihiro Shimizu |
890ddd |
img->stoponerr) {
|
|
Toshihiro Shimizu |
890ddd |
ret = 0;
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
pos = ((row + img->row_offset) % rowsperstrip) * scanline;
|
|
Toshihiro Shimizu |
890ddd |
(*put)(img, raster + y * w, 0, y, w, nrow, fromskew, toskew, buf + pos);
|
|
Toshihiro Shimizu |
890ddd |
y += (flip & FLIP_VERTICALLY ? -(int32)nrow : (int32)nrow);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (flip & FLIP_HORIZONTALLY) {
|
|
Toshihiro Shimizu |
890ddd |
uint32 line;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (line = 0; line < h; line++) {
|
|
Toshihiro Shimizu |
890ddd |
uint64 *left = raster + (line * w);
|
|
Toshihiro Shimizu |
890ddd |
uint64 *right = left + w - 1;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
while (left < right) {
|
|
Toshihiro Shimizu |
890ddd |
uint64 temp = *left;
|
|
Toshihiro Shimizu |
890ddd |
*left = *right;
|
|
Toshihiro Shimizu |
890ddd |
*right = temp;
|
|
Toshihiro Shimizu |
890ddd |
left++, right--;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
_TIFFfree(buf);
|
|
Toshihiro Shimizu |
890ddd |
return (ret);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* Get a strip-organized image with
|
|
Toshihiro Shimizu |
890ddd |
* SamplesPerPixel > 1
|
|
Toshihiro Shimizu |
890ddd |
* PlanarConfiguration separated
|
|
Toshihiro Shimizu |
890ddd |
* We assume that all such images are RGB.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
static int
|
|
Toshihiro Shimizu |
890ddd |
gtStripSeparate(TIFFRGBAImage *img, uint64 *raster, uint32 w, uint32 h)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TIFF *tif = img->tif;
|
|
Toshihiro Shimizu |
890ddd |
tileSeparateRoutine_64 put = (tileSeparateRoutine_64)img->put.separate;
|
|
Toshihiro Shimizu |
890ddd |
unsigned char *buf;
|
|
Toshihiro Shimizu |
890ddd |
unsigned char *p0, *p1, *p2, *pa;
|
|
Toshihiro Shimizu |
890ddd |
uint32 row, y, nrow, rowstoread;
|
|
Toshihiro Shimizu |
890ddd |
tmsize_t pos;
|
|
Toshihiro Shimizu |
890ddd |
tmsize_t scanline;
|
|
Toshihiro Shimizu |
890ddd |
uint32 rowsperstrip, offset_row;
|
|
Toshihiro Shimizu |
890ddd |
uint32 imagewidth = img->width;
|
|
Toshihiro Shimizu |
890ddd |
tmsize_t stripsize;
|
|
Toshihiro Shimizu |
890ddd |
tmsize_t bufsize;
|
|
Toshihiro Shimizu |
890ddd |
int32 fromskew, toskew;
|
|
Toshihiro Shimizu |
890ddd |
int alpha = img->alpha;
|
|
Toshihiro Shimizu |
890ddd |
int ret = 1, flip, colorchannels;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
stripsize = TIFFStripSize(tif);
|
|
Toshihiro Shimizu |
890ddd |
bufsize = TIFFSafeMultiply(tmsize_t, alpha ? 4 : 3, stripsize);
|
|
Toshihiro Shimizu |
890ddd |
if (bufsize == 0) {
|
|
Toshihiro Shimizu |
890ddd |
TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "Integer overflow in %s", "gtStripSeparate");
|
|
Toshihiro Shimizu |
890ddd |
return (0);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
p0 = buf = (unsigned char *)_TIFFmalloc(bufsize);
|
|
Toshihiro Shimizu |
890ddd |
if (buf == 0) {
|
|
Toshihiro Shimizu |
890ddd |
TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "No space for tile buffer");
|
|
Toshihiro Shimizu |
890ddd |
return (0);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
_TIFFmemset(buf, 0, bufsize);
|
|
Toshihiro Shimizu |
890ddd |
p1 = p0 + stripsize;
|
|
Toshihiro Shimizu |
890ddd |
p2 = p1 + stripsize;
|
|
Toshihiro Shimizu |
890ddd |
pa = (alpha ? (p2 + stripsize) : NULL);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
flip = setorientation(img);
|
|
Toshihiro Shimizu |
890ddd |
if (flip & FLIP_VERTICALLY) {
|
|
Toshihiro Shimizu |
890ddd |
y = h - 1;
|
|
Toshihiro Shimizu |
890ddd |
toskew = -(int32)(w + w);
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
y = 0;
|
|
Toshihiro Shimizu |
890ddd |
toskew = -(int32)(w - w);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
switch (img->photometric) {
|
|
Toshihiro Shimizu |
890ddd |
case PHOTOMETRIC_MINISWHITE:
|
|
Toshihiro Shimizu |
890ddd |
case PHOTOMETRIC_MINISBLACK:
|
|
Toshihiro Shimizu |
890ddd |
case PHOTOMETRIC_PALETTE:
|
|
Toshihiro Shimizu |
890ddd |
colorchannels = 1;
|
|
Toshihiro Shimizu |
890ddd |
p2 = p1 = p0;
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
default:
|
|
Toshihiro Shimizu |
890ddd |
colorchannels = 3;
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TIFFGetFieldDefaulted(tif, TIFFTAG_ROWSPERSTRIP, &rowsperstrip);
|
|
Toshihiro Shimizu |
890ddd |
scanline = TIFFScanlineSize(tif);
|
|
Toshihiro Shimizu |
890ddd |
fromskew = (w < imagewidth ? imagewidth - w : 0);
|
|
Toshihiro Shimizu |
890ddd |
for (row = 0; row < h; row += nrow) {
|
|
Toshihiro Shimizu |
890ddd |
rowstoread = rowsperstrip - (row + img->row_offset) % rowsperstrip;
|
|
Toshihiro Shimizu |
890ddd |
nrow = (row + rowstoread > h ? h - row : rowstoread);
|
|
Toshihiro Shimizu |
890ddd |
offset_row = row + img->row_offset;
|
|
Toshihiro Shimizu |
890ddd |
if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, 0),
|
|
Toshihiro Shimizu |
890ddd |
p0, ((row + img->row_offset) % rowsperstrip + nrow) * scanline) == (tmsize_t)(-1) &&
|
|
Toshihiro Shimizu |
890ddd |
img->stoponerr) {
|
|
Toshihiro Shimizu |
890ddd |
ret = 0;
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (colorchannels > 1 && TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, 1), p1, ((row + img->row_offset) % rowsperstrip + nrow) * scanline) == (tmsize_t)(-1) && img->stoponerr) {
|
|
Toshihiro Shimizu |
890ddd |
ret = 0;
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (colorchannels > 1 && TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, 2), p2, ((row + img->row_offset) % rowsperstrip + nrow) * scanline) == (tmsize_t)(-1) && img->stoponerr) {
|
|
Toshihiro Shimizu |
890ddd |
ret = 0;
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (alpha) {
|
|
Toshihiro Shimizu |
890ddd |
if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, colorchannels),
|
|
Toshihiro Shimizu |
890ddd |
pa, ((row + img->row_offset) % rowsperstrip + nrow) * scanline) == (tmsize_t)(-1) &&
|
|
Toshihiro Shimizu |
890ddd |
img->stoponerr) {
|
|
Toshihiro Shimizu |
890ddd |
ret = 0;
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
pos = ((row + img->row_offset) % rowsperstrip) * scanline;
|
|
Toshihiro Shimizu |
890ddd |
(*put)(img, raster + y * w, 0, y, w, nrow, fromskew, toskew, p0 + pos, p1 + pos,
|
|
Toshihiro Shimizu |
890ddd |
p2 + pos, (alpha ? (pa + pos) : NULL));
|
|
Toshihiro Shimizu |
890ddd |
y += (flip & FLIP_VERTICALLY ? -(int32)nrow : (int32)nrow);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (flip & FLIP_HORIZONTALLY) {
|
|
Toshihiro Shimizu |
890ddd |
uint32 line;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (line = 0; line < h; line++) {
|
|
Toshihiro Shimizu |
890ddd |
uint64 *left = raster + (line * w);
|
|
Toshihiro Shimizu |
890ddd |
uint64 *right = left + w - 1;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
while (left < right) {
|
|
Toshihiro Shimizu |
890ddd |
uint64 temp = *left;
|
|
Toshihiro Shimizu |
890ddd |
*left = *right;
|
|
Toshihiro Shimizu |
890ddd |
*right = temp;
|
|
Toshihiro Shimizu |
890ddd |
left++, right--;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
_TIFFfree(buf);
|
|
Toshihiro Shimizu |
890ddd |
return (ret);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* The following routines move decoded data returned
|
|
Toshihiro Shimizu |
890ddd |
* from the TIFF library into rasters filled with packed
|
|
Toshihiro Shimizu |
890ddd |
* ABGR pixels (i.e. suitable for passing to lrecwrite.)
|
|
Toshihiro Shimizu |
890ddd |
*
|
|
Toshihiro Shimizu |
890ddd |
* The routines have been created according to the most
|
|
Toshihiro Shimizu |
890ddd |
* important cases and optimized. PickContigCase and
|
|
Toshihiro Shimizu |
890ddd |
* PickSeparateCase analyze the parameters and select
|
|
Toshihiro Shimizu |
890ddd |
* the appropriate "get" and "put" routine to use.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
#define REPEAT8(op) \
|
|
Toshihiro Shimizu |
890ddd |
REPEAT4(op); \
|
|
Toshihiro Shimizu |
890ddd |
REPEAT4(op)
|
|
Toshihiro Shimizu |
890ddd |
#define REPEAT4(op) \
|
|
Toshihiro Shimizu |
890ddd |
REPEAT2(op); \
|
|
Toshihiro Shimizu |
890ddd |
REPEAT2(op)
|
|
Toshihiro Shimizu |
890ddd |
#define REPEAT2(op) \
|
|
Toshihiro Shimizu |
890ddd |
op; \
|
|
Toshihiro Shimizu |
890ddd |
op
|
|
Toshihiro Shimizu |
890ddd |
#define CASE8(x, op) \
|
|
Toshihiro Shimizu |
890ddd |
switch (x) { \
|
|
Toshihiro Shimizu |
890ddd |
case 7: \
|
|
Toshihiro Shimizu |
890ddd |
op; \
|
|
Toshihiro Shimizu |
890ddd |
case 6: \
|
|
Toshihiro Shimizu |
890ddd |
op; \
|
|
Toshihiro Shimizu |
890ddd |
case 5: \
|
|
Toshihiro Shimizu |
890ddd |
op; \
|
|
Toshihiro Shimizu |
890ddd |
case 4: \
|
|
Toshihiro Shimizu |
890ddd |
op; \
|
|
Toshihiro Shimizu |
890ddd |
case 3: \
|
|
Toshihiro Shimizu |
890ddd |
op; \
|
|
Toshihiro Shimizu |
890ddd |
case 2: \
|
|
Toshihiro Shimizu |
890ddd |
op; \
|
|
Toshihiro Shimizu |
890ddd |
case 1: \
|
|
Toshihiro Shimizu |
890ddd |
op; \
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#define CASE4(x, op) \
|
|
Toshihiro Shimizu |
890ddd |
switch (x) { \
|
|
Toshihiro Shimizu |
890ddd |
case 3: \
|
|
Toshihiro Shimizu |
890ddd |
op; \
|
|
Toshihiro Shimizu |
890ddd |
case 2: \
|
|
Toshihiro Shimizu |
890ddd |
op; \
|
|
Toshihiro Shimizu |
890ddd |
case 1: \
|
|
Toshihiro Shimizu |
890ddd |
op; \
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#define NOP
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define UNROLL8(w, op1, op2) \
|
|
Toshihiro Shimizu |
890ddd |
{ \
|
|
Toshihiro Shimizu |
890ddd |
uint32 _x; \
|
|
Toshihiro Shimizu |
890ddd |
for (_x = w; _x >= 8; _x -= 8) { \
|
|
Toshihiro Shimizu |
890ddd |
op1; \
|
|
Toshihiro Shimizu |
890ddd |
REPEAT8(op2); \
|
|
Toshihiro Shimizu |
890ddd |
} \
|
|
Toshihiro Shimizu |
890ddd |
if (_x > 0) { \
|
|
Toshihiro Shimizu |
890ddd |
op1; \
|
|
Toshihiro Shimizu |
890ddd |
CASE8(_x, op2); \
|
|
Toshihiro Shimizu |
890ddd |
} \
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#define UNROLL4(w, op1, op2) \
|
|
Toshihiro Shimizu |
890ddd |
{ \
|
|
Toshihiro Shimizu |
890ddd |
uint64 _x; \
|
|
Toshihiro Shimizu |
890ddd |
for (_x = w; _x >= 4; _x -= 4) { \
|
|
Toshihiro Shimizu |
890ddd |
op1; \
|
|
Toshihiro Shimizu |
890ddd |
REPEAT4(op2); \
|
|
Toshihiro Shimizu |
890ddd |
} \
|
|
Toshihiro Shimizu |
890ddd |
if (_x > 0) { \
|
|
Toshihiro Shimizu |
890ddd |
op1; \
|
|
Toshihiro Shimizu |
890ddd |
CASE4(_x, op2); \
|
|
Toshihiro Shimizu |
890ddd |
} \
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#define UNROLL2(w, op1, op2) \
|
|
Toshihiro Shimizu |
890ddd |
{ \
|
|
Toshihiro Shimizu |
890ddd |
uint64 _x; \
|
|
Toshihiro Shimizu |
890ddd |
for (_x = w; _x >= 2; _x -= 2) { \
|
|
Toshihiro Shimizu |
890ddd |
op1; \
|
|
Toshihiro Shimizu |
890ddd |
REPEAT2(op2); \
|
|
Toshihiro Shimizu |
890ddd |
} \
|
|
Toshihiro Shimizu |
890ddd |
if (_x) { \
|
|
Toshihiro Shimizu |
890ddd |
op1; \
|
|
Toshihiro Shimizu |
890ddd |
op2; \
|
|
Toshihiro Shimizu |
890ddd |
} \
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define SKEW(r, g, b, skew) \
|
|
Toshihiro Shimizu |
890ddd |
{ \
|
|
Toshihiro Shimizu |
890ddd |
r += skew; \
|
|
Toshihiro Shimizu |
890ddd |
g += skew; \
|
|
Toshihiro Shimizu |
890ddd |
b += skew; \
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#define SKEW4(r, g, b, a, skew) \
|
|
Toshihiro Shimizu |
890ddd |
{ \
|
|
Toshihiro Shimizu |
890ddd |
r += skew; \
|
|
Toshihiro Shimizu |
890ddd |
g += skew; \
|
|
Toshihiro Shimizu |
890ddd |
b += skew; \
|
|
Toshihiro Shimizu |
890ddd |
a += skew; \
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define A1 (((uint64)0xffffL) << 48)
|
|
Toshihiro Shimizu |
890ddd |
#define PACK_32(r, g, b) \
|
|
Toshihiro Shimizu |
890ddd |
((uint32)(r) | ((uint32)(g) << 8) | ((uint32)(b) << 16) | (0xff << 24))
|
|
Toshihiro Shimizu |
890ddd |
#define PACK(r, g, b) \
|
|
Toshihiro Shimizu |
890ddd |
((uint64)(r) | ((uint64)(g) << 16) | ((uint64)(b) << 32) | A1)
|
|
Toshihiro Shimizu |
890ddd |
#define PACK4(r, g, b, a) \
|
|
Toshihiro Shimizu |
890ddd |
((uint64)(r) | ((uint64)(g) << 16) | ((uint64)(b) << 32) | ((uint64)(a) << 48))
|
|
Toshihiro Shimizu |
890ddd |
#define W2B(v) (((v) >> 16) & 0xffff)
|
|
Toshihiro Shimizu |
890ddd |
/* TODO: PACKW should have be made redundant in favor of Bitdepth16To8 LUT */
|
|
Toshihiro Shimizu |
890ddd |
#define PACKW(r, g, b) \
|
|
Toshihiro Shimizu |
890ddd |
((uint64)W2B(r) | ((uint64)W2B(g) << 16) | ((uint64)W2B(b) << 32) | A1)
|
|
Toshihiro Shimizu |
890ddd |
#define PACKW4(r, g, b, a) \
|
|
Toshihiro Shimizu |
890ddd |
((uint64)W2B(r) | ((uint64)W2B(g) << 16) | ((uint64)W2B(b) << 32) | ((uint64)W2B(a) << 48))
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define DECLAREContigPutFunc(name) \
|
|
Toshihiro Shimizu |
890ddd |
static void name( \
|
|
Toshihiro Shimizu |
890ddd |
TIFFRGBAImage *img, \
|
|
Toshihiro Shimizu |
890ddd |
uint64 *cp, \
|
|
Toshihiro Shimizu |
890ddd |
uint32 x, uint32 y, \
|
|
Toshihiro Shimizu |
890ddd |
uint32 w, uint32 h, \
|
|
Toshihiro Shimizu |
890ddd |
int32 fromskew, int32 toskew, \
|
|
Toshihiro Shimizu |
890ddd |
unsigned char *pp)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* 8-bit greyscale => colormap/RGB
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
DECLAREContigPutFunc(putgreytile)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int samplesperpixel = img->samplesperpixel;
|
|
Toshihiro Shimizu |
890ddd |
uint64 **BWmap = (uint64 **)img->BWmap;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
(void)y;
|
|
Toshihiro Shimizu |
890ddd |
while (h-- > 0) {
|
|
Toshihiro Shimizu |
890ddd |
for (x = w; x-- > 0;) {
|
|
Toshihiro Shimizu |
890ddd |
*cp++ = BWmap[*pp][0];
|
|
Toshihiro Shimizu |
890ddd |
pp += samplesperpixel;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
cp += toskew;
|
|
Toshihiro Shimizu |
890ddd |
pp += fromskew;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* 8-bit greyscale with associated alpha => colormap/RGBA
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
DECLAREContigPutFunc(putagreytile)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int samplesperpixel = img->samplesperpixel;
|
|
Toshihiro Shimizu |
890ddd |
uint64 **BWmap = (uint64 **)img->BWmap;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
(void)y;
|
|
Toshihiro Shimizu |
890ddd |
while (h-- > 0) {
|
|
Toshihiro Shimizu |
890ddd |
for (x = w; x-- > 0;) {
|
|
Toshihiro Shimizu |
890ddd |
*cp++ = BWmap[*pp][0] & ((uint64) * (pp + 1) << 48 | ~A1);
|
|
Toshihiro Shimizu |
890ddd |
pp += samplesperpixel;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
cp += toskew;
|
|
Toshihiro Shimizu |
890ddd |
pp += fromskew;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* 16-bit greyscale => colormap/RGB
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
DECLAREContigPutFunc(put16bitbwtile)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int samplesperpixel = img->samplesperpixel;
|
|
Toshihiro Shimizu |
890ddd |
uint64 **BWmap = (uint64 **)img->BWmap;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
(void)y;
|
|
Toshihiro Shimizu |
890ddd |
while (h-- > 0) {
|
|
Toshihiro Shimizu |
890ddd |
uint16 *wp = (uint16 *)pp;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (x = w; x-- > 0;) {
|
|
Toshihiro Shimizu |
890ddd |
/* use high order byte of 16bit value */
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
*cp++ = BWmap[*wp >> 8][0];
|
|
Toshihiro Shimizu |
890ddd |
pp += 2 * samplesperpixel;
|
|
Toshihiro Shimizu |
890ddd |
wp += samplesperpixel;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
cp += toskew;
|
|
Toshihiro Shimizu |
890ddd |
pp += fromskew;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* 1-bit bilevel => colormap/RGB
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
DECLAREContigPutFunc(put1bitbwtile)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
uint64 **BWmap = (uint64 **)img->BWmap;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
(void)x;
|
|
Toshihiro Shimizu |
890ddd |
(void)y;
|
|
Toshihiro Shimizu |
890ddd |
fromskew /= 8;
|
|
Toshihiro Shimizu |
890ddd |
while (h-- > 0) {
|
|
Toshihiro Shimizu |
890ddd |
uint64 *bw;
|
|
Toshihiro Shimizu |
890ddd |
UNROLL8(w, bw = BWmap[*pp++], *cp++ = *bw++);
|
|
Toshihiro Shimizu |
890ddd |
cp += toskew;
|
|
Toshihiro Shimizu |
890ddd |
pp += fromskew;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* 2-bit greyscale => colormap/RGB
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
DECLAREContigPutFunc(put2bitbwtile)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
uint64 **BWmap = (uint64 **)img->BWmap;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
(void)x;
|
|
Toshihiro Shimizu |
890ddd |
(void)y;
|
|
Toshihiro Shimizu |
890ddd |
fromskew /= 4;
|
|
Toshihiro Shimizu |
890ddd |
while (h-- > 0) {
|
|
Toshihiro Shimizu |
890ddd |
uint64 *bw;
|
|
Toshihiro Shimizu |
890ddd |
UNROLL4(w, bw = BWmap[*pp++], *cp++ = *bw++);
|
|
Toshihiro Shimizu |
890ddd |
cp += toskew;
|
|
Toshihiro Shimizu |
890ddd |
pp += fromskew;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* 4-bit greyscale => colormap/RGB
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
DECLAREContigPutFunc(put4bitbwtile)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
uint64 **BWmap = (uint64 **)img->BWmap;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
(void)x;
|
|
Toshihiro Shimizu |
890ddd |
(void)y;
|
|
Toshihiro Shimizu |
890ddd |
fromskew /= 2;
|
|
Toshihiro Shimizu |
890ddd |
while (h-- > 0) {
|
|
Toshihiro Shimizu |
890ddd |
uint64 *bw;
|
|
Toshihiro Shimizu |
890ddd |
UNROLL2(w, bw = BWmap[*pp++], *cp++ = *bw++);
|
|
Toshihiro Shimizu |
890ddd |
cp += toskew;
|
|
Toshihiro Shimizu |
890ddd |
pp += fromskew;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* 8-bit packed samples, no Map => RGB
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
DECLAREContigPutFunc(putRGBcontig8bittile)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int samplesperpixel = img->samplesperpixel;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
(void)x;
|
|
Toshihiro Shimizu |
890ddd |
(void)y;
|
|
Toshihiro Shimizu |
890ddd |
fromskew *= samplesperpixel;
|
|
Toshihiro Shimizu |
890ddd |
while (h-- > 0) {
|
|
Toshihiro Shimizu |
890ddd |
UNROLL8(w, NOP,
|
|
Toshihiro Shimizu |
890ddd |
*cp++ = PACK(pp[0] << 8, pp[1] << 8, pp[2] << 8);
|
|
Toshihiro Shimizu |
890ddd |
pp += samplesperpixel);
|
|
Toshihiro Shimizu |
890ddd |
cp += toskew;
|
|
Toshihiro Shimizu |
890ddd |
pp += fromskew;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* 8-bit packed samples => RGBA
|
|
Toshihiro Shimizu |
890ddd |
* (known to have Map == NULL)
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
DECLAREContigPutFunc(putRGBAAcontig8bittile)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int samplesperpixel = img->samplesperpixel;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
(void)x;
|
|
Toshihiro Shimizu |
890ddd |
(void)y;
|
|
Toshihiro Shimizu |
890ddd |
fromskew *= samplesperpixel;
|
|
Toshihiro Shimizu |
890ddd |
while (h-- > 0) {
|
|
Toshihiro Shimizu |
890ddd |
UNROLL8(w, NOP,
|
|
Toshihiro Shimizu |
890ddd |
*cp++ = PACK4(pp[0] << 8, pp[1] << 8, pp[2] << 8, pp[3] << 8);
|
|
Toshihiro Shimizu |
890ddd |
pp += samplesperpixel);
|
|
Toshihiro Shimizu |
890ddd |
cp += toskew;
|
|
Toshihiro Shimizu |
890ddd |
pp += fromskew;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* 16-bit packed samples => RGB
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
DECLAREContigPutFunc(putRGBcontig16bittile)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int samplesperpixel = img->samplesperpixel;
|
|
Toshihiro Shimizu |
890ddd |
uint16 *wp = (uint16 *)pp;
|
|
Toshihiro Shimizu |
890ddd |
(void)y;
|
|
Toshihiro Shimizu |
890ddd |
fromskew *= samplesperpixel;
|
|
Toshihiro Shimizu |
890ddd |
while (h-- > 0) {
|
|
Toshihiro Shimizu |
890ddd |
for (x = w; x-- > 0;) {
|
|
Toshihiro Shimizu |
890ddd |
*cp++ = PACK(wp[0], wp[1], wp[2]);
|
|
Toshihiro Shimizu |
890ddd |
wp += samplesperpixel;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
cp += toskew;
|
|
Toshihiro Shimizu |
890ddd |
wp += fromskew;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* 16-bit packed samples => RGBA w/ associated alpha
|
|
Toshihiro Shimizu |
890ddd |
* (known to have Map == NULL)
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
DECLAREContigPutFunc(putRGBAAcontig16bittile)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int samplesperpixel = img->samplesperpixel;
|
|
Toshihiro Shimizu |
890ddd |
uint16 *wp = (uint16 *)pp;
|
|
Toshihiro Shimizu |
890ddd |
(void)y;
|
|
Toshihiro Shimizu |
890ddd |
fromskew *= samplesperpixel;
|
|
Toshihiro Shimizu |
890ddd |
while (h-- > 0) {
|
|
Toshihiro Shimizu |
890ddd |
for (x = w; x-- > 0;) {
|
|
Toshihiro Shimizu |
890ddd |
*cp++ = PACK4(wp[0], wp[1], wp[2], wp[3]);
|
|
Toshihiro Shimizu |
890ddd |
wp += samplesperpixel;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
cp += toskew;
|
|
Toshihiro Shimizu |
890ddd |
wp += fromskew;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* 8-bit packed CMYK samples w/o Map => RGB
|
|
Toshihiro Shimizu |
890ddd |
*
|
|
Toshihiro Shimizu |
890ddd |
* NB: The conversion of CMYK->RGB is *very* crude.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
DECLAREContigPutFunc(putRGBcontig8bitCMYKtile)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int samplesperpixel = img->samplesperpixel;
|
|
Toshihiro Shimizu |
890ddd |
uint16 r, g, b, k;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
(void)x;
|
|
Toshihiro Shimizu |
890ddd |
(void)y;
|
|
Toshihiro Shimizu |
890ddd |
fromskew *= samplesperpixel;
|
|
Toshihiro Shimizu |
890ddd |
while (h-- > 0) {
|
|
Toshihiro Shimizu |
890ddd |
UNROLL8(w, NOP,
|
|
Toshihiro Shimizu |
890ddd |
k = 255 - pp[3];
|
|
Toshihiro Shimizu |
890ddd |
r = (k * (255 - pp[0]));
|
|
Toshihiro Shimizu |
890ddd |
g = (k * (255 - pp[1]));
|
|
Toshihiro Shimizu |
890ddd |
b = (k * (255 - pp[2]));
|
|
Toshihiro Shimizu |
890ddd |
*cp++ = PACK(r, g, b);
|
|
Toshihiro Shimizu |
890ddd |
pp += samplesperpixel);
|
|
Toshihiro Shimizu |
890ddd |
cp += toskew;
|
|
Toshihiro Shimizu |
890ddd |
pp += fromskew;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* 8-bit packed CMYK samples w/Map => RGB
|
|
Toshihiro Shimizu |
890ddd |
*
|
|
Toshihiro Shimizu |
890ddd |
* NB: The conversion of CMYK->RGB is *very* crude.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
DECLAREContigPutFunc(putRGBcontig8bitCMYKMaptile)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int samplesperpixel = img->samplesperpixel;
|
|
Toshihiro Shimizu |
890ddd |
TIFFRGBValue *Map = img->Map;
|
|
Toshihiro Shimizu |
890ddd |
uint16 r, g, b, k;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
(void)y;
|
|
Toshihiro Shimizu |
890ddd |
fromskew *= samplesperpixel;
|
|
Toshihiro Shimizu |
890ddd |
while (h-- > 0) {
|
|
Toshihiro Shimizu |
890ddd |
for (x = w; x-- > 0;) {
|
|
Toshihiro Shimizu |
890ddd |
k = 255 - pp[3];
|
|
Toshihiro Shimizu |
890ddd |
r = (k * (255 - pp[0])) / 255;
|
|
Toshihiro Shimizu |
890ddd |
g = (k * (255 - pp[1])) / 255;
|
|
Toshihiro Shimizu |
890ddd |
b = (k * (255 - pp[2])) / 255;
|
|
Toshihiro Shimizu |
890ddd |
*cp++ = PACK(Map[r] << 8, Map[g] << 8, Map[b] << 8);
|
|
Toshihiro Shimizu |
890ddd |
pp += samplesperpixel;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
pp += fromskew;
|
|
Toshihiro Shimizu |
890ddd |
cp += toskew;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define DECLARESepPutFunc(name) \
|
|
Toshihiro Shimizu |
890ddd |
static void name( \
|
|
Toshihiro Shimizu |
890ddd |
TIFFRGBAImage *img, \
|
|
Toshihiro Shimizu |
890ddd |
uint64 *cp, \
|
|
Toshihiro Shimizu |
890ddd |
uint32 x, uint32 y, \
|
|
Toshihiro Shimizu |
890ddd |
uint32 w, uint32 h, \
|
|
Toshihiro Shimizu |
890ddd |
int32 fromskew, int32 toskew, \
|
|
Toshihiro Shimizu |
890ddd |
unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* 8-bit unpacked samples => RGB
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
DECLARESepPutFunc(putRGBseparate8bittile)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
(void)img;
|
|
Toshihiro Shimizu |
890ddd |
(void)x;
|
|
Toshihiro Shimizu |
890ddd |
(void)y;
|
|
Toshihiro Shimizu |
890ddd |
(void)a;
|
|
Toshihiro Shimizu |
890ddd |
while (h-- > 0) {
|
|
Toshihiro Shimizu |
890ddd |
UNROLL8(w, NOP, *cp++ = PACK(*r++ << 8, *g++ << 8, *b++ << 8));
|
|
Toshihiro Shimizu |
890ddd |
SKEW(r, g, b, fromskew);
|
|
Toshihiro Shimizu |
890ddd |
cp += toskew;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* 8-bit unpacked samples => RGBA w/ associated alpha
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
DECLARESepPutFunc(putRGBAAseparate8bittile)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
(void)img;
|
|
Toshihiro Shimizu |
890ddd |
(void)x;
|
|
Toshihiro Shimizu |
890ddd |
(void)y;
|
|
Toshihiro Shimizu |
890ddd |
while (h-- > 0) {
|
|
Toshihiro Shimizu |
890ddd |
UNROLL8(w, NOP, *cp++ = PACK4(*r++ << 8, *g++ << 8, *b++ << 8, *a++ << 8));
|
|
Toshihiro Shimizu |
890ddd |
SKEW4(r, g, b, a, fromskew);
|
|
Toshihiro Shimizu |
890ddd |
cp += toskew;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* 8-bit unpacked CMYK samples => RGBA
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
DECLARESepPutFunc(putCMYKseparate8bittile)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
(void)img;
|
|
Toshihiro Shimizu |
890ddd |
(void)y;
|
|
Toshihiro Shimizu |
890ddd |
while (h-- > 0) {
|
|
Toshihiro Shimizu |
890ddd |
uint32 rv, gv, bv, kv;
|
|
Toshihiro Shimizu |
890ddd |
for (x = w; x-- > 0;) {
|
|
Toshihiro Shimizu |
890ddd |
kv = 255 - *a++;
|
|
Toshihiro Shimizu |
890ddd |
rv = (kv * (255 - *r++));
|
|
Toshihiro Shimizu |
890ddd |
gv = (kv * (255 - *g++));
|
|
Toshihiro Shimizu |
890ddd |
bv = (kv * (255 - *b++));
|
|
Toshihiro Shimizu |
890ddd |
*cp++ = PACK4(rv, gv, bv, 65535);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
SKEW4(r, g, b, a, fromskew);
|
|
Toshihiro Shimizu |
890ddd |
cp += toskew;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* 16-bit unpacked samples => RGB
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
DECLARESepPutFunc(putRGBseparate16bittile)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
uint16 *wr = (uint16 *)r;
|
|
Toshihiro Shimizu |
890ddd |
uint16 *wg = (uint16 *)g;
|
|
Toshihiro Shimizu |
890ddd |
uint16 *wb = (uint16 *)b;
|
|
Toshihiro Shimizu |
890ddd |
(void)img;
|
|
Toshihiro Shimizu |
890ddd |
(void)y;
|
|
Toshihiro Shimizu |
890ddd |
(void)a;
|
|
Toshihiro Shimizu |
890ddd |
while (h-- > 0) {
|
|
Toshihiro Shimizu |
890ddd |
for (x = 0; x < w; x++)
|
|
Toshihiro Shimizu |
890ddd |
*cp++ = PACK(*wr++, *wg++, *wb++);
|
|
Toshihiro Shimizu |
890ddd |
SKEW(wr, wg, wb, fromskew);
|
|
Toshihiro Shimizu |
890ddd |
cp += toskew;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* 16-bit unpacked samples => RGBA w/ associated alpha
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
DECLARESepPutFunc(putRGBAAseparate16bittile)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
uint16 *wr = (uint16 *)r;
|
|
Toshihiro Shimizu |
890ddd |
uint16 *wg = (uint16 *)g;
|
|
Toshihiro Shimizu |
890ddd |
uint16 *wb = (uint16 *)b;
|
|
Toshihiro Shimizu |
890ddd |
uint16 *wa = (uint16 *)a;
|
|
Toshihiro Shimizu |
890ddd |
(void)img;
|
|
Toshihiro Shimizu |
890ddd |
(void)y;
|
|
Toshihiro Shimizu |
890ddd |
while (h-- > 0) {
|
|
Toshihiro Shimizu |
890ddd |
for (x = 0; x < w; x++)
|
|
Toshihiro Shimizu |
890ddd |
*cp++ = PACK4(*wr++, *wg++, *wb++, *wa++);
|
|
Toshihiro Shimizu |
890ddd |
SKEW4(wr, wg, wb, wa, fromskew);
|
|
Toshihiro Shimizu |
890ddd |
cp += toskew;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* 8-bit packed CIE L*a*b 1976 samples => RGB
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
DECLAREContigPutFunc(putcontig8bitCIELab)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
float X, Y, Z;
|
|
Toshihiro Shimizu |
890ddd |
uint32 r, g, b;
|
|
Toshihiro Shimizu |
890ddd |
(void)y;
|
|
Toshihiro Shimizu |
890ddd |
fromskew *= 3;
|
|
Toshihiro Shimizu |
890ddd |
while (h-- > 0) {
|
|
Toshihiro Shimizu |
890ddd |
for (x = w; x-- > 0;) {
|
|
Toshihiro Shimizu |
890ddd |
TIFFCIELabToXYZ(img->cielab,
|
|
Toshihiro Shimizu |
890ddd |
(unsigned char)pp[0],
|
|
Toshihiro Shimizu |
890ddd |
(signed char)pp[1],
|
|
Toshihiro Shimizu |
890ddd |
(signed char)pp[2],
|
|
Toshihiro Shimizu |
890ddd |
&X, &Y, &Z);
|
|
Toshihiro Shimizu |
890ddd |
TIFFXYZToRGB(img->cielab, X, Y, Z, &r, &g, &b);
|
|
Toshihiro Shimizu |
890ddd |
*cp++ = PACK(r << 8, g << 8, b << 8);
|
|
Toshihiro Shimizu |
890ddd |
pp += 3;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
cp += toskew;
|
|
Toshihiro Shimizu |
890ddd |
pp += fromskew;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* YCbCr -> RGB conversion and packing routines.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define YCbCrtoRGB(dst, Y) \
|
|
Toshihiro Shimizu |
890ddd |
{ \
|
|
Toshihiro Shimizu |
890ddd |
uint32 r, g, b; \
|
|
Toshihiro Shimizu |
890ddd |
TIFFYCbCrtoRGB(img->ycbcr, (Y), Cb, Cr, &r, &g, &b); \
|
|
Toshihiro Shimizu |
890ddd |
dst = PACK(((uint64)r) << 8, ((uint64)g) << 8, ((uint64)b) << 8); \
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* 8-bit packed YCbCr samples w/ 4,4 subsampling => RGB
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
DECLAREContigPutFunc(putcontig8bitYCbCr44tile)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
uint64 *cp1 = cp + w + toskew;
|
|
Toshihiro Shimizu |
890ddd |
uint64 *cp2 = cp1 + w + toskew;
|
|
Toshihiro Shimizu |
890ddd |
uint64 *cp3 = cp2 + w + toskew;
|
|
Toshihiro Shimizu |
890ddd |
int32 incr = 3 * w + 4 * toskew;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
(void)y;
|
|
Toshihiro Shimizu |
890ddd |
/* adjust fromskew */
|
|
Toshihiro Shimizu |
890ddd |
fromskew = (fromskew * 18) / 4;
|
|
Toshihiro Shimizu |
890ddd |
if ((h & 3) == 0 && (w & 3) == 0) {
|
|
Toshihiro Shimizu |
890ddd |
for (; h >= 4; h -= 4) {
|
|
Toshihiro Shimizu |
890ddd |
x = w >> 2;
|
|
Toshihiro Shimizu |
890ddd |
do {
|
|
Toshihiro Shimizu |
890ddd |
int32 Cb = pp[16];
|
|
Toshihiro Shimizu |
890ddd |
int32 Cr = pp[17];
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp[0], pp[0]);
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp[1], pp[1]);
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp[2], pp[2]);
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp[3], pp[3]);
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp1[0], pp[4]);
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp1[1], pp[5]);
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp1[2], pp[6]);
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp1[3], pp[7]);
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp2[0], pp[8]);
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp2[1], pp[9]);
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp2[2], pp[10]);
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp2[3], pp[11]);
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp3[0], pp[12]);
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp3[1], pp[13]);
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp3[2], pp[14]);
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp3[3], pp[15]);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
cp += 4, cp1 += 4, cp2 += 4, cp3 += 4;
|
|
Toshihiro Shimizu |
890ddd |
pp += 18;
|
|
Toshihiro Shimizu |
890ddd |
} while (--x);
|
|
Toshihiro Shimizu |
890ddd |
cp += incr, cp1 += incr, cp2 += incr, cp3 += incr;
|
|
Toshihiro Shimizu |
890ddd |
pp += fromskew;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
while (h > 0) {
|
|
Toshihiro Shimizu |
890ddd |
for (x = w; x > 0;) {
|
|
Toshihiro Shimizu |
890ddd |
int32 Cb = pp[16];
|
|
Toshihiro Shimizu |
890ddd |
int32 Cr = pp[17];
|
|
Toshihiro Shimizu |
890ddd |
switch (x) {
|
|
Toshihiro Shimizu |
890ddd |
default:
|
|
Toshihiro Shimizu |
890ddd |
switch (h) {
|
|
Toshihiro Shimizu |
890ddd |
default:
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp3[3], pp[15]); /* FALLTHROUGH */
|
|
Toshihiro Shimizu |
890ddd |
case 3:
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp2[3], pp[11]); /* FALLTHROUGH */
|
|
Toshihiro Shimizu |
890ddd |
case 2:
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp1[3], pp[7]); /* FALLTHROUGH */
|
|
Toshihiro Shimizu |
890ddd |
case 1:
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp[3], pp[3]); /* FALLTHROUGH */
|
|
Toshihiro Shimizu |
890ddd |
} /* FALLTHROUGH */
|
|
Toshihiro Shimizu |
890ddd |
case 3:
|
|
Toshihiro Shimizu |
890ddd |
switch (h) {
|
|
Toshihiro Shimizu |
890ddd |
default:
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp3[2], pp[14]); /* FALLTHROUGH */
|
|
Toshihiro Shimizu |
890ddd |
case 3:
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp2[2], pp[10]); /* FALLTHROUGH */
|
|
Toshihiro Shimizu |
890ddd |
case 2:
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp1[2], pp[6]); /* FALLTHROUGH */
|
|
Toshihiro Shimizu |
890ddd |
case 1:
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp[2], pp[2]); /* FALLTHROUGH */
|
|
Toshihiro Shimizu |
890ddd |
} /* FALLTHROUGH */
|
|
Toshihiro Shimizu |
890ddd |
case 2:
|
|
Toshihiro Shimizu |
890ddd |
switch (h) {
|
|
Toshihiro Shimizu |
890ddd |
default:
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp3[1], pp[13]); /* FALLTHROUGH */
|
|
Toshihiro Shimizu |
890ddd |
case 3:
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp2[1], pp[9]); /* FALLTHROUGH */
|
|
Toshihiro Shimizu |
890ddd |
case 2:
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp1[1], pp[5]); /* FALLTHROUGH */
|
|
Toshihiro Shimizu |
890ddd |
case 1:
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp[1], pp[1]); /* FALLTHROUGH */
|
|
Toshihiro Shimizu |
890ddd |
} /* FALLTHROUGH */
|
|
Toshihiro Shimizu |
890ddd |
case 1:
|
|
Toshihiro Shimizu |
890ddd |
switch (h) {
|
|
Toshihiro Shimizu |
890ddd |
default:
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp3[0], pp[12]); /* FALLTHROUGH */
|
|
Toshihiro Shimizu |
890ddd |
case 3:
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp2[0], pp[8]); /* FALLTHROUGH */
|
|
Toshihiro Shimizu |
890ddd |
case 2:
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp1[0], pp[4]); /* FALLTHROUGH */
|
|
Toshihiro Shimizu |
890ddd |
case 1:
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp[0], pp[0]); /* FALLTHROUGH */
|
|
Toshihiro Shimizu |
890ddd |
} /* FALLTHROUGH */
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (x < 4) {
|
|
Toshihiro Shimizu |
890ddd |
cp += x;
|
|
Toshihiro Shimizu |
890ddd |
cp1 += x;
|
|
Toshihiro Shimizu |
890ddd |
cp2 += x;
|
|
Toshihiro Shimizu |
890ddd |
cp3 += x;
|
|
Toshihiro Shimizu |
890ddd |
x = 0;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
cp += 4;
|
|
Toshihiro Shimizu |
890ddd |
cp1 += 4;
|
|
Toshihiro Shimizu |
890ddd |
cp2 += 4;
|
|
Toshihiro Shimizu |
890ddd |
cp3 += 4;
|
|
Toshihiro Shimizu |
890ddd |
x -= 4;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
pp += 18;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (h <= 4)
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
h -= 4;
|
|
Toshihiro Shimizu |
890ddd |
cp += incr, cp1 += incr, cp2 += incr, cp3 += incr;
|
|
Toshihiro Shimizu |
890ddd |
pp += fromskew;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* 8-bit packed YCbCr samples w/ 4,2 subsampling => RGB
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
DECLAREContigPutFunc(putcontig8bitYCbCr42tile)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
uint64 *cp1 = cp + w + toskew;
|
|
Toshihiro Shimizu |
890ddd |
int32 incr = 2 * toskew + w;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
(void)y;
|
|
Toshihiro Shimizu |
890ddd |
fromskew = (fromskew * 10) / 4;
|
|
Toshihiro Shimizu |
890ddd |
if ((h & 3) == 0 && (w & 1) == 0) {
|
|
Toshihiro Shimizu |
890ddd |
for (; h >= 2; h -= 2) {
|
|
Toshihiro Shimizu |
890ddd |
x = w >> 2;
|
|
Toshihiro Shimizu |
890ddd |
do {
|
|
Toshihiro Shimizu |
890ddd |
int32 Cb = pp[8];
|
|
Toshihiro Shimizu |
890ddd |
int32 Cr = pp[9];
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp[0], pp[0]);
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp[1], pp[1]);
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp[2], pp[2]);
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp[3], pp[3]);
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp1[0], pp[4]);
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp1[1], pp[5]);
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp1[2], pp[6]);
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp1[3], pp[7]);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
cp += 4, cp1 += 4;
|
|
Toshihiro Shimizu |
890ddd |
pp += 10;
|
|
Toshihiro Shimizu |
890ddd |
} while (--x);
|
|
Toshihiro Shimizu |
890ddd |
cp += incr, cp1 += incr;
|
|
Toshihiro Shimizu |
890ddd |
pp += fromskew;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
while (h > 0) {
|
|
Toshihiro Shimizu |
890ddd |
for (x = w; x > 0;) {
|
|
Toshihiro Shimizu |
890ddd |
int32 Cb = pp[8];
|
|
Toshihiro Shimizu |
890ddd |
int32 Cr = pp[9];
|
|
Toshihiro Shimizu |
890ddd |
switch (x) {
|
|
Toshihiro Shimizu |
890ddd |
default:
|
|
Toshihiro Shimizu |
890ddd |
switch (h) {
|
|
Toshihiro Shimizu |
890ddd |
default:
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp1[3], pp[7]); /* FALLTHROUGH */
|
|
Toshihiro Shimizu |
890ddd |
case 1:
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp[3], pp[3]); /* FALLTHROUGH */
|
|
Toshihiro Shimizu |
890ddd |
} /* FALLTHROUGH */
|
|
Toshihiro Shimizu |
890ddd |
case 3:
|
|
Toshihiro Shimizu |
890ddd |
switch (h) {
|
|
Toshihiro Shimizu |
890ddd |
default:
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp1[2], pp[6]); /* FALLTHROUGH */
|
|
Toshihiro Shimizu |
890ddd |
case 1:
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp[2], pp[2]); /* FALLTHROUGH */
|
|
Toshihiro Shimizu |
890ddd |
} /* FALLTHROUGH */
|
|
Toshihiro Shimizu |
890ddd |
case 2:
|
|
Toshihiro Shimizu |
890ddd |
switch (h) {
|
|
Toshihiro Shimizu |
890ddd |
default:
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp1[1], pp[5]); /* FALLTHROUGH */
|
|
Toshihiro Shimizu |
890ddd |
case 1:
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp[1], pp[1]); /* FALLTHROUGH */
|
|
Toshihiro Shimizu |
890ddd |
} /* FALLTHROUGH */
|
|
Toshihiro Shimizu |
890ddd |
case 1:
|
|
Toshihiro Shimizu |
890ddd |
switch (h) {
|
|
Toshihiro Shimizu |
890ddd |
default:
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp1[0], pp[4]); /* FALLTHROUGH */
|
|
Toshihiro Shimizu |
890ddd |
case 1:
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp[0], pp[0]); /* FALLTHROUGH */
|
|
Toshihiro Shimizu |
890ddd |
} /* FALLTHROUGH */
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (x < 4) {
|
|
Toshihiro Shimizu |
890ddd |
cp += x;
|
|
Toshihiro Shimizu |
890ddd |
cp1 += x;
|
|
Toshihiro Shimizu |
890ddd |
x = 0;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
cp += 4;
|
|
Toshihiro Shimizu |
890ddd |
cp1 += 4;
|
|
Toshihiro Shimizu |
890ddd |
x -= 4;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
pp += 10;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (h <= 2)
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
h -= 2;
|
|
Toshihiro Shimizu |
890ddd |
cp += incr, cp1 += incr;
|
|
Toshihiro Shimizu |
890ddd |
pp += fromskew;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* 8-bit packed YCbCr samples w/ 4,1 subsampling => RGB
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
DECLAREContigPutFunc(putcontig8bitYCbCr41tile)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
(void)y;
|
|
Toshihiro Shimizu |
890ddd |
/* XXX adjust fromskew */
|
|
Toshihiro Shimizu |
890ddd |
do {
|
|
Toshihiro Shimizu |
890ddd |
x = w >> 2;
|
|
Toshihiro Shimizu |
890ddd |
do {
|
|
Toshihiro Shimizu |
890ddd |
int32 Cb = pp[4];
|
|
Toshihiro Shimizu |
890ddd |
int32 Cr = pp[5];
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp[0], pp[0]);
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp[1], pp[1]);
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp[2], pp[2]);
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp[3], pp[3]);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
cp += 4;
|
|
Toshihiro Shimizu |
890ddd |
pp += 6;
|
|
Toshihiro Shimizu |
890ddd |
} while (--x);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if ((w & 3) != 0) {
|
|
Toshihiro Shimizu |
890ddd |
int32 Cb = pp[4];
|
|
Toshihiro Shimizu |
890ddd |
int32 Cr = pp[5];
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
switch ((w & 3)) {
|
|
Toshihiro Shimizu |
890ddd |
case 3:
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp[2], pp[2]);
|
|
Toshihiro Shimizu |
890ddd |
case 2:
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp[1], pp[1]);
|
|
Toshihiro Shimizu |
890ddd |
case 1:
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp[0], pp[0]);
|
|
Toshihiro Shimizu |
890ddd |
case 0:
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
cp += (w & 3);
|
|
Toshihiro Shimizu |
890ddd |
pp += 6;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
cp += toskew;
|
|
Toshihiro Shimizu |
890ddd |
pp += fromskew;
|
|
Toshihiro Shimizu |
890ddd |
} while (--h);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* 8-bit packed YCbCr samples w/ 2,2 subsampling => RGB
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
DECLAREContigPutFunc(putcontig8bitYCbCr22tile)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
uint64 *cp2;
|
|
Toshihiro Shimizu |
890ddd |
int32 incr = 2 * toskew + w;
|
|
Toshihiro Shimizu |
890ddd |
(void)y;
|
|
Toshihiro Shimizu |
890ddd |
fromskew = (fromskew / 2) * 6;
|
|
Toshihiro Shimizu |
890ddd |
cp2 = cp + w + toskew;
|
|
Toshihiro Shimizu |
890ddd |
while (h >= 2) {
|
|
Toshihiro Shimizu |
890ddd |
x = w;
|
|
Toshihiro Shimizu |
890ddd |
while (x >= 2) {
|
|
Toshihiro Shimizu |
890ddd |
uint32 Cb = pp[4];
|
|
Toshihiro Shimizu |
890ddd |
uint32 Cr = pp[5];
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp[0], pp[0]);
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp[1], pp[1]);
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp2[0], pp[2]);
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp2[1], pp[3]);
|
|
Toshihiro Shimizu |
890ddd |
cp += 2;
|
|
Toshihiro Shimizu |
890ddd |
cp2 += 2;
|
|
Toshihiro Shimizu |
890ddd |
pp += 6;
|
|
Toshihiro Shimizu |
890ddd |
x -= 2;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (x == 1) {
|
|
Toshihiro Shimizu |
890ddd |
uint32 Cb = pp[4];
|
|
Toshihiro Shimizu |
890ddd |
uint32 Cr = pp[5];
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp[0], pp[0]);
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp2[0], pp[2]);
|
|
Toshihiro Shimizu |
890ddd |
cp++;
|
|
Toshihiro Shimizu |
890ddd |
cp2++;
|
|
Toshihiro Shimizu |
890ddd |
pp += 6;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
cp += incr;
|
|
Toshihiro Shimizu |
890ddd |
cp2 += incr;
|
|
Toshihiro Shimizu |
890ddd |
pp += fromskew;
|
|
Toshihiro Shimizu |
890ddd |
h -= 2;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (h == 1) {
|
|
Toshihiro Shimizu |
890ddd |
x = w;
|
|
Toshihiro Shimizu |
890ddd |
while (x >= 2) {
|
|
Toshihiro Shimizu |
890ddd |
uint32 Cb = pp[4];
|
|
Toshihiro Shimizu |
890ddd |
uint32 Cr = pp[5];
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp[0], pp[0]);
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp[1], pp[1]);
|
|
Toshihiro Shimizu |
890ddd |
cp += 2;
|
|
Toshihiro Shimizu |
890ddd |
cp2 += 2;
|
|
Toshihiro Shimizu |
890ddd |
pp += 6;
|
|
Toshihiro Shimizu |
890ddd |
x -= 2;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (x == 1) {
|
|
Toshihiro Shimizu |
890ddd |
uint32 Cb = pp[4];
|
|
Toshihiro Shimizu |
890ddd |
uint32 Cr = pp[5];
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp[0], pp[0]);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* 8-bit packed YCbCr samples w/ 2,1 subsampling => RGB
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
DECLAREContigPutFunc(putcontig8bitYCbCr21tile)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
(void)y;
|
|
Toshihiro Shimizu |
890ddd |
fromskew = (fromskew * 4) / 2;
|
|
Toshihiro Shimizu |
890ddd |
do {
|
|
Toshihiro Shimizu |
890ddd |
x = w >> 1;
|
|
Toshihiro Shimizu |
890ddd |
do {
|
|
Toshihiro Shimizu |
890ddd |
int32 Cb = pp[2];
|
|
Toshihiro Shimizu |
890ddd |
int32 Cr = pp[3];
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp[0], pp[0]);
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp[1], pp[1]);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
cp += 2;
|
|
Toshihiro Shimizu |
890ddd |
pp += 4;
|
|
Toshihiro Shimizu |
890ddd |
} while (--x);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if ((w & 1) != 0) {
|
|
Toshihiro Shimizu |
890ddd |
int32 Cb = pp[2];
|
|
Toshihiro Shimizu |
890ddd |
int32 Cr = pp[3];
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp[0], pp[0]);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
cp += 1;
|
|
Toshihiro Shimizu |
890ddd |
pp += 4;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
cp += toskew;
|
|
Toshihiro Shimizu |
890ddd |
pp += fromskew;
|
|
Toshihiro Shimizu |
890ddd |
} while (--h);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* 8-bit packed YCbCr samples w/ 1,2 subsampling => RGB
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
DECLAREContigPutFunc(putcontig8bitYCbCr12tile)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
uint64 *cp2;
|
|
Toshihiro Shimizu |
890ddd |
int32 incr = 2 * toskew + w;
|
|
Toshihiro Shimizu |
890ddd |
(void)y;
|
|
Toshihiro Shimizu |
890ddd |
fromskew = (fromskew / 2) * 4;
|
|
Toshihiro Shimizu |
890ddd |
cp2 = cp + w + toskew;
|
|
Toshihiro Shimizu |
890ddd |
while (h >= 2) {
|
|
Toshihiro Shimizu |
890ddd |
x = w;
|
|
Toshihiro Shimizu |
890ddd |
do {
|
|
Toshihiro Shimizu |
890ddd |
uint32 Cb = pp[2];
|
|
Toshihiro Shimizu |
890ddd |
uint32 Cr = pp[3];
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp[0], pp[0]);
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp2[0], pp[1]);
|
|
Toshihiro Shimizu |
890ddd |
cp++;
|
|
Toshihiro Shimizu |
890ddd |
cp2++;
|
|
Toshihiro Shimizu |
890ddd |
pp += 4;
|
|
Toshihiro Shimizu |
890ddd |
} while (--x);
|
|
Toshihiro Shimizu |
890ddd |
cp += incr;
|
|
Toshihiro Shimizu |
890ddd |
cp2 += incr;
|
|
Toshihiro Shimizu |
890ddd |
pp += fromskew;
|
|
Toshihiro Shimizu |
890ddd |
h -= 2;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (h == 1) {
|
|
Toshihiro Shimizu |
890ddd |
x = w;
|
|
Toshihiro Shimizu |
890ddd |
do {
|
|
Toshihiro Shimizu |
890ddd |
uint32 Cb = pp[2];
|
|
Toshihiro Shimizu |
890ddd |
uint32 Cr = pp[3];
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(cp[0], pp[0]);
|
|
Toshihiro Shimizu |
890ddd |
cp++;
|
|
Toshihiro Shimizu |
890ddd |
pp += 4;
|
|
Toshihiro Shimizu |
890ddd |
} while (--x);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* 8-bit packed YCbCr samples w/ no subsampling => RGB
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
DECLAREContigPutFunc(putcontig8bitYCbCr11tile)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
(void)y;
|
|
Toshihiro Shimizu |
890ddd |
fromskew *= 3;
|
|
Toshihiro Shimizu |
890ddd |
do {
|
|
Toshihiro Shimizu |
890ddd |
x = w; /* was x = w>>1; patched 2000/09/25 warmerda@home.com */
|
|
Toshihiro Shimizu |
890ddd |
do {
|
|
Toshihiro Shimizu |
890ddd |
int32 Cb = pp[1];
|
|
Toshihiro Shimizu |
890ddd |
int32 Cr = pp[2];
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
YCbCrtoRGB(*cp++, pp[0]);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
pp += 3;
|
|
Toshihiro Shimizu |
890ddd |
} while (--x);
|
|
Toshihiro Shimizu |
890ddd |
cp += toskew;
|
|
Toshihiro Shimizu |
890ddd |
pp += fromskew;
|
|
Toshihiro Shimizu |
890ddd |
} while (--h);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* 8-bit packed YCbCr samples w/ no subsampling => RGB
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
DECLARESepPutFunc(putseparate8bitYCbCr11tile)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
(void)y;
|
|
Toshihiro Shimizu |
890ddd |
(void)a;
|
|
Toshihiro Shimizu |
890ddd |
/* TODO: naming of input vars is still off, change obfuscating declaration inside define, or resolve obfuscation */
|
|
Toshihiro Shimizu |
890ddd |
while (h-- > 0) {
|
|
Toshihiro Shimizu |
890ddd |
x = w;
|
|
Toshihiro Shimizu |
890ddd |
do {
|
|
Toshihiro Shimizu |
890ddd |
uint32 dr, dg, db;
|
|
Toshihiro Shimizu |
890ddd |
TIFFYCbCrtoRGB(img->ycbcr, *r++, *g++, *b++, &dr, &dg, &db);
|
|
Toshihiro Shimizu |
890ddd |
*cp++ = PACK(dr, dg, db);
|
|
Toshihiro Shimizu |
890ddd |
} while (--x);
|
|
Toshihiro Shimizu |
890ddd |
SKEW(r, g, b, fromskew);
|
|
Toshihiro Shimizu |
890ddd |
cp += toskew;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#undef YCbCrtoRGB
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
static int
|
|
Toshihiro Shimizu |
890ddd |
initYCbCrConversion(TIFFRGBAImage *img)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
static const char module[] = "initYCbCrConversion";
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
float *luma, *refBlackWhite;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (img->ycbcr == NULL) {
|
|
Toshihiro Shimizu |
890ddd |
img->ycbcr = (TIFFYCbCrToRGB *)_TIFFmalloc(
|
|
Toshihiro Shimizu |
890ddd |
TIFFroundup_32(sizeof(TIFFYCbCrToRGB), sizeof(long)) + 4 * 256 * sizeof(TIFFRGBValue) + 2 * 256 * sizeof(int) + 3 * 256 * sizeof(int32));
|
|
Toshihiro Shimizu |
890ddd |
if (img->ycbcr == NULL) {
|
|
Toshihiro Shimizu |
890ddd |
TIFFErrorExt(img->tif->tif_clientdata, module,
|
|
Toshihiro Shimizu |
890ddd |
"No space for YCbCr->RGB conversion state");
|
|
Toshihiro Shimizu |
890ddd |
return (0);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TIFFGetFieldDefaulted(img->tif, TIFFTAG_YCBCRCOEFFICIENTS, &luma);
|
|
Toshihiro Shimizu |
890ddd |
TIFFGetFieldDefaulted(img->tif, TIFFTAG_REFERENCEBLACKWHITE,
|
|
Toshihiro Shimizu |
890ddd |
&refBlackWhite);
|
|
Toshihiro Shimizu |
890ddd |
if (TIFFYCbCrToRGBInit(img->ycbcr, luma, refBlackWhite) < 0)
|
|
Toshihiro Shimizu |
890ddd |
return (0);
|
|
Toshihiro Shimizu |
890ddd |
return (1);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
static tileContigRoutine_64
|
|
Toshihiro Shimizu |
890ddd |
initCIELabConversion(TIFFRGBAImage *img)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
static const char module[] = "initCIELabConversion";
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
float *whitePoint;
|
|
Toshihiro Shimizu |
890ddd |
float refWhite[3];
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!img->cielab) {
|
|
Toshihiro Shimizu |
890ddd |
img->cielab = (TIFFCIELabToRGB *)
|
|
Toshihiro Shimizu |
890ddd |
_TIFFmalloc(sizeof(TIFFCIELabToRGB));
|
|
Toshihiro Shimizu |
890ddd |
if (!img->cielab) {
|
|
Toshihiro Shimizu |
890ddd |
TIFFErrorExt(img->tif->tif_clientdata, module,
|
|
Toshihiro Shimizu |
890ddd |
"No space for CIE L*a*b*->RGB conversion state.");
|
|
Toshihiro Shimizu |
890ddd |
return NULL;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TIFFGetFieldDefaulted(img->tif, TIFFTAG_WHITEPOINT, &whitePoint);
|
|
Toshihiro Shimizu |
890ddd |
refWhite[1] = 100.0F;
|
|
Toshihiro Shimizu |
890ddd |
refWhite[0] = whitePoint[0] / whitePoint[1] * refWhite[1];
|
|
Toshihiro Shimizu |
890ddd |
refWhite[2] = (1.0F - whitePoint[0] - whitePoint[1]) / whitePoint[1] * refWhite[1];
|
|
Toshihiro Shimizu |
890ddd |
if (TIFFCIELabToRGBInit(img->cielab, &display_sRGB, refWhite) < 0) {
|
|
Toshihiro Shimizu |
890ddd |
TIFFErrorExt(img->tif->tif_clientdata, module,
|
|
Toshihiro Shimizu |
890ddd |
"Failed to initialize CIE L*a*b*->RGB conversion state.");
|
|
Toshihiro Shimizu |
890ddd |
_TIFFfree(img->cielab);
|
|
Toshihiro Shimizu |
890ddd |
return NULL;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return putcontig8bitCIELab;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* Greyscale images with less than 8 bits/sample are handled
|
|
Toshihiro Shimizu |
890ddd |
* with a table to avoid lots of shifts and masks. The table
|
|
Toshihiro Shimizu |
890ddd |
* is setup so that put*bwtile (below) can retrieve 8/bitspersample
|
|
Toshihiro Shimizu |
890ddd |
* pixel values simply by indexing into the table with one
|
|
Toshihiro Shimizu |
890ddd |
* number.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
static int
|
|
Toshihiro Shimizu |
890ddd |
makebwmap(TIFFRGBAImage *img)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TIFFRGBValue *Map = img->Map;
|
|
Toshihiro Shimizu |
890ddd |
int bitspersample = img->bitspersample;
|
|
Toshihiro Shimizu |
890ddd |
int nsamples = 8 / bitspersample;
|
|
Toshihiro Shimizu |
890ddd |
int i;
|
|
Toshihiro Shimizu |
890ddd |
uint64 *p;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (nsamples == 0)
|
|
Toshihiro Shimizu |
890ddd |
nsamples = 1;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
img->BWmap = (uint32 **)_TIFFmalloc(
|
|
Toshihiro Shimizu |
890ddd |
256 * sizeof(uint32 *) + (256 * nsamples * sizeof(uint64)));
|
|
Toshihiro Shimizu |
890ddd |
if (img->BWmap == NULL) {
|
|
Toshihiro Shimizu |
890ddd |
TIFFErrorExt(img->tif->tif_clientdata, TIFFFileName(img->tif), "No space for B&W mapping table");
|
|
Toshihiro Shimizu |
890ddd |
return (0);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
p = (uint64 *)(img->BWmap + 256);
|
|
Toshihiro Shimizu |
890ddd |
for (i = 0; i < 256; i++) {
|
|
Toshihiro Shimizu |
890ddd |
TIFFRGBValue c;
|
|
Toshihiro Shimizu |
890ddd |
img->BWmap[i] = (uint32 *)p;
|
|
Toshihiro Shimizu |
890ddd |
switch (bitspersample) {
|
|
Toshihiro Shimizu |
890ddd |
#define GREY(x) \
|
|
Toshihiro Shimizu |
890ddd |
c = Map[x]; \
|
|
Toshihiro Shimizu |
890ddd |
*p++ = PACK(c << 8, c << 8, c << 8);
|
|
Toshihiro Shimizu |
890ddd |
case 1:
|
|
Toshihiro Shimizu |
890ddd |
GREY(i >> 7);
|
|
Toshihiro Shimizu |
890ddd |
GREY((i >> 6) & 1);
|
|
Toshihiro Shimizu |
890ddd |
GREY((i >> 5) & 1);
|
|
Toshihiro Shimizu |
890ddd |
GREY((i >> 4) & 1);
|
|
Toshihiro Shimizu |
890ddd |
GREY((i >> 3) & 1);
|
|
Toshihiro Shimizu |
890ddd |
GREY((i >> 2) & 1);
|
|
Toshihiro Shimizu |
890ddd |
GREY((i >> 1) & 1);
|
|
Toshihiro Shimizu |
890ddd |
GREY(i & 1);
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
case 2:
|
|
Toshihiro Shimizu |
890ddd |
GREY(i >> 6);
|
|
Toshihiro Shimizu |
890ddd |
GREY((i >> 4) & 3);
|
|
Toshihiro Shimizu |
890ddd |
GREY((i >> 2) & 3);
|
|
Toshihiro Shimizu |
890ddd |
GREY(i & 3);
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
case 4:
|
|
Toshihiro Shimizu |
890ddd |
GREY(i >> 4);
|
|
Toshihiro Shimizu |
890ddd |
GREY(i & 0xf);
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
case 8:
|
|
Toshihiro Shimizu |
890ddd |
case 16:
|
|
Toshihiro Shimizu |
890ddd |
GREY(i);
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#undef GREY
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return (1);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* Construct a mapping table to convert from the range
|
|
Toshihiro Shimizu |
890ddd |
* of the data samples to [0,255] --for display. This
|
|
Toshihiro Shimizu |
890ddd |
* process also handles inverting B&W images when needed.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
static int
|
|
Toshihiro Shimizu |
890ddd |
setupMap(TIFFRGBAImage *img)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int32 x, range;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
range = (int32)((1L << img->bitspersample) - 1);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/* treat 16 bit the same as eight bit */
|
|
Toshihiro Shimizu |
890ddd |
if (img->bitspersample == 16)
|
|
Toshihiro Shimizu |
890ddd |
range = (int32)255;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
img->Map = (TIFFRGBValue *)_TIFFmalloc((range + 1) * sizeof(TIFFRGBValue));
|
|
Toshihiro Shimizu |
890ddd |
if (img->Map == NULL) {
|
|
Toshihiro Shimizu |
890ddd |
TIFFErrorExt(img->tif->tif_clientdata, TIFFFileName(img->tif),
|
|
Toshihiro Shimizu |
890ddd |
"No space for photometric conversion table");
|
|
Toshihiro Shimizu |
890ddd |
return (0);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (img->photometric == PHOTOMETRIC_MINISWHITE) {
|
|
Toshihiro Shimizu |
890ddd |
for (x = 0; x <= range; x++)
|
|
Toshihiro Shimizu |
890ddd |
img->Map[x] = (TIFFRGBValue)(((range - x) * 255) / range);
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
for (x = 0; x <= range; x++)
|
|
Toshihiro Shimizu |
890ddd |
img->Map[x] = (TIFFRGBValue)((x * 255) / range);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (img->bitspersample <= 16 &&
|
|
Toshihiro Shimizu |
890ddd |
(img->photometric == PHOTOMETRIC_MINISBLACK ||
|
|
Toshihiro Shimizu |
890ddd |
img->photometric == PHOTOMETRIC_MINISWHITE)) {
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* Use photometric mapping table to construct
|
|
Toshihiro Shimizu |
890ddd |
* unpacking tables for samples <= 8 bits.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
if (!makebwmap(img))
|
|
Toshihiro Shimizu |
890ddd |
return (0);
|
|
Toshihiro Shimizu |
890ddd |
/* no longer need Map, free it */
|
|
Toshihiro Shimizu |
890ddd |
_TIFFfree(img->Map), img->Map = NULL;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return (1);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
static int
|
|
Toshihiro Shimizu |
890ddd |
checkcmap(TIFFRGBAImage *img)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
uint16 *r = img->redcmap;
|
|
Toshihiro Shimizu |
890ddd |
uint16 *g = img->greencmap;
|
|
Toshihiro Shimizu |
890ddd |
uint16 *b = img->bluecmap;
|
|
Toshihiro Shimizu |
890ddd |
long n = 1L << img->bitspersample;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
while (n-- > 0)
|
|
Toshihiro Shimizu |
890ddd |
if (*r++ >= 256 || *g++ >= 256 || *b++ >= 256)
|
|
Toshihiro Shimizu |
890ddd |
return (16);
|
|
Toshihiro Shimizu |
890ddd |
return (8);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
static void
|
|
Toshihiro Shimizu |
890ddd |
cvtcmap(TIFFRGBAImage *img)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
uint16 *r = img->redcmap;
|
|
Toshihiro Shimizu |
890ddd |
uint16 *g = img->greencmap;
|
|
Toshihiro Shimizu |
890ddd |
uint16 *b = img->bluecmap;
|
|
Toshihiro Shimizu |
890ddd |
long i;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (i = (1L << img->bitspersample) - 1; i >= 0; i--) {
|
|
Toshihiro Shimizu |
890ddd |
#define CVT(x) ((uint16)((x) >> 8))
|
|
Toshihiro Shimizu |
890ddd |
r[i] = CVT(r[i]);
|
|
Toshihiro Shimizu |
890ddd |
g[i] = CVT(g[i]);
|
|
Toshihiro Shimizu |
890ddd |
b[i] = CVT(b[i]);
|
|
Toshihiro Shimizu |
890ddd |
#undef CVT
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* Palette images with <= 8 bits/sample are handled
|
|
Toshihiro Shimizu |
890ddd |
* with a table to avoid lots of shifts and masks. The table
|
|
Toshihiro Shimizu |
890ddd |
* is setup so that put*cmaptile (below) can retrieve 8/bitspersample
|
|
Toshihiro Shimizu |
890ddd |
* pixel values simply by indexing into the table with one
|
|
Toshihiro Shimizu |
890ddd |
* number.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
static int
|
|
Toshihiro Shimizu |
890ddd |
makecmap(TIFFRGBAImage *img)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int bitspersample = img->bitspersample;
|
|
Toshihiro Shimizu |
890ddd |
int nsamples = 8 / bitspersample;
|
|
Toshihiro Shimizu |
890ddd |
uint16 *r = img->redcmap;
|
|
Toshihiro Shimizu |
890ddd |
uint16 *g = img->greencmap;
|
|
Toshihiro Shimizu |
890ddd |
uint16 *b = img->bluecmap;
|
|
Toshihiro Shimizu |
890ddd |
uint32 *p;
|
|
Toshihiro Shimizu |
890ddd |
int i;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
img->PALmap = (uint32 **)_TIFFmalloc(
|
|
Toshihiro Shimizu |
890ddd |
256 * sizeof(uint32 *) + (256 * nsamples * sizeof(uint32)));
|
|
Toshihiro Shimizu |
890ddd |
if (img->PALmap == NULL) {
|
|
Toshihiro Shimizu |
890ddd |
TIFFErrorExt(img->tif->tif_clientdata, TIFFFileName(img->tif), "No space for Palette mapping table");
|
|
Toshihiro Shimizu |
890ddd |
return (0);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
p = (uint32 *)(img->PALmap + 256);
|
|
Toshihiro Shimizu |
890ddd |
for (i = 0; i < 256; i++) {
|
|
Toshihiro Shimizu |
890ddd |
TIFFRGBValue c;
|
|
Toshihiro Shimizu |
890ddd |
img->PALmap[i] = p;
|
|
Toshihiro Shimizu |
890ddd |
#define CMAP(x) \
|
|
Toshihiro Shimizu |
890ddd |
c = (TIFFRGBValue)x; \
|
|
Toshihiro Shimizu |
890ddd |
*p++ = PACK_32(r[c] & 0xff, g[c] & 0xff, b[c] & 0xff);
|
|
Toshihiro Shimizu |
890ddd |
switch (bitspersample) {
|
|
Toshihiro Shimizu |
890ddd |
case 1:
|
|
Toshihiro Shimizu |
890ddd |
CMAP(i >> 7);
|
|
Toshihiro Shimizu |
890ddd |
CMAP((i >> 6) & 1);
|
|
Toshihiro Shimizu |
890ddd |
CMAP((i >> 5) & 1);
|
|
Toshihiro Shimizu |
890ddd |
CMAP((i >> 4) & 1);
|
|
Toshihiro Shimizu |
890ddd |
CMAP((i >> 3) & 1);
|
|
Toshihiro Shimizu |
890ddd |
CMAP((i >> 2) & 1);
|
|
Toshihiro Shimizu |
890ddd |
CMAP((i >> 1) & 1);
|
|
Toshihiro Shimizu |
890ddd |
CMAP(i & 1);
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
case 2:
|
|
Toshihiro Shimizu |
890ddd |
CMAP(i >> 6);
|
|
Toshihiro Shimizu |
890ddd |
CMAP((i >> 4) & 3);
|
|
Toshihiro Shimizu |
890ddd |
CMAP((i >> 2) & 3);
|
|
Toshihiro Shimizu |
890ddd |
CMAP(i & 3);
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
case 4:
|
|
Toshihiro Shimizu |
890ddd |
CMAP(i >> 4);
|
|
Toshihiro Shimizu |
890ddd |
CMAP(i & 0xf);
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
case 8:
|
|
Toshihiro Shimizu |
890ddd |
CMAP(i);
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#undef CMAP
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return (1);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* Construct any mapping table used
|
|
Toshihiro Shimizu |
890ddd |
* by the associated put routine.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
static int
|
|
Toshihiro Shimizu |
890ddd |
buildMap(TIFFRGBAImage *img)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
switch (img->photometric) {
|
|
Toshihiro Shimizu |
890ddd |
case PHOTOMETRIC_RGB:
|
|
Toshihiro Shimizu |
890ddd |
case PHOTOMETRIC_YCBCR:
|
|
Toshihiro Shimizu |
890ddd |
case PHOTOMETRIC_SEPARATED:
|
|
Toshihiro Shimizu |
890ddd |
if (img->bitspersample == 8)
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
/* fall thru... */
|
|
Toshihiro Shimizu |
890ddd |
case PHOTOMETRIC_MINISBLACK:
|
|
Toshihiro Shimizu |
890ddd |
case PHOTOMETRIC_MINISWHITE:
|
|
Toshihiro Shimizu |
890ddd |
if (!setupMap(img))
|
|
Toshihiro Shimizu |
890ddd |
return (0);
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
case PHOTOMETRIC_PALETTE:
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* Convert 16-bit colormap to 8-bit (unless it looks
|
|
Toshihiro Shimizu |
890ddd |
* like an old-style 8-bit colormap).
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
if (checkcmap(img) == 16)
|
|
Toshihiro Shimizu |
890ddd |
cvtcmap(img);
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
TIFFWarningExt(img->tif->tif_clientdata, TIFFFileName(img->tif), "Assuming 8-bit colormap");
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* Use mapping table and colormap to construct
|
|
Toshihiro Shimizu |
890ddd |
* unpacking tables for samples < 8 bits.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
if (img->bitspersample <= 8 && !makecmap(img))
|
|
Toshihiro Shimizu |
890ddd |
return (0);
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return (1);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* Select the appropriate conversion routine for packed data.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
static int
|
|
Toshihiro Shimizu |
890ddd |
PickContigCase(TIFFRGBAImage *img)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
img->get = (gtFunc_32)(TIFFIsTiled(img->tif) ? gtTileContig : gtStripContig);
|
|
Toshihiro Shimizu |
890ddd |
img->put.contig = NULL;
|
|
Toshihiro Shimizu |
890ddd |
switch (img->photometric) {
|
|
Toshihiro Shimizu |
890ddd |
case PHOTOMETRIC_RGB:
|
|
Toshihiro Shimizu |
890ddd |
switch (img->bitspersample) {
|
|
Toshihiro Shimizu |
890ddd |
case 8:
|
|
Toshihiro Shimizu |
890ddd |
if (img->alpha != EXTRASAMPLE_UNSPECIFIED)
|
|
Toshihiro Shimizu |
890ddd |
img->put.contig = (tileContigRoutine)putRGBAAcontig8bittile;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
img->put.contig = (tileContigRoutine)putRGBcontig8bittile;
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
case 16:
|
|
Toshihiro Shimizu |
890ddd |
if (img->alpha != EXTRASAMPLE_UNSPECIFIED)
|
|
Toshihiro Shimizu |
890ddd |
img->put.contig = (tileContigRoutine)putRGBAAcontig16bittile;
|
|
Toshihiro Shimizu |
890ddd |
else {
|
|
Toshihiro Shimizu |
890ddd |
if (BuildMapBitdepth16To8(img))
|
|
Toshihiro Shimizu |
890ddd |
img->put.contig = (tileContigRoutine)putRGBcontig16bittile;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
case PHOTOMETRIC_SEPARATED:
|
|
Toshihiro Shimizu |
890ddd |
if (buildMap(img)) {
|
|
Toshihiro Shimizu |
890ddd |
if (img->bitspersample == 8) {
|
|
Toshihiro Shimizu |
890ddd |
if (!img->Map)
|
|
Toshihiro Shimizu |
890ddd |
img->put.contig = (tileContigRoutine)putRGBcontig8bitCMYKtile;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
img->put.contig = (tileContigRoutine)putRGBcontig8bitCMYKMaptile;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
case PHOTOMETRIC_PALETTE:
|
|
Toshihiro Shimizu |
890ddd |
case PHOTOMETRIC_MINISWHITE:
|
|
Toshihiro Shimizu |
890ddd |
case PHOTOMETRIC_MINISBLACK:
|
|
Toshihiro Shimizu |
890ddd |
if (buildMap(img)) {
|
|
Toshihiro Shimizu |
890ddd |
switch (img->bitspersample) {
|
|
Toshihiro Shimizu |
890ddd |
case 16:
|
|
Toshihiro Shimizu |
890ddd |
img->put.contig = (tileContigRoutine)put16bitbwtile;
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
case 8:
|
|
Toshihiro Shimizu |
890ddd |
if (img->alpha && img->samplesperpixel == 2)
|
|
Toshihiro Shimizu |
890ddd |
img->put.contig = (tileContigRoutine)putagreytile;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
img->put.contig = (tileContigRoutine)putgreytile;
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
case 4:
|
|
Toshihiro Shimizu |
890ddd |
img->put.contig = (tileContigRoutine)put4bitbwtile;
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
case 2:
|
|
Toshihiro Shimizu |
890ddd |
img->put.contig = (tileContigRoutine)put2bitbwtile;
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
case 1:
|
|
Toshihiro Shimizu |
890ddd |
img->put.contig = (tileContigRoutine)put1bitbwtile;
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
case PHOTOMETRIC_YCBCR:
|
|
Toshihiro Shimizu |
890ddd |
if ((img->bitspersample == 8) && (img->samplesperpixel == 3)) {
|
|
Toshihiro Shimizu |
890ddd |
if (initYCbCrConversion(img) != 0) {
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* The 6.0 spec says that subsampling must be
|
|
Toshihiro Shimizu |
890ddd |
* one of 1, 2, or 4, and that vertical subsampling
|
|
Toshihiro Shimizu |
890ddd |
* must always be <= horizontal subsampling; so
|
|
Toshihiro Shimizu |
890ddd |
* there are only a few possibilities and we just
|
|
Toshihiro Shimizu |
890ddd |
* enumerate the cases.
|
|
Toshihiro Shimizu |
890ddd |
* Joris: added support for the [1,2] case, nonetheless, to accomodate
|
|
Toshihiro Shimizu |
890ddd |
* some OJPEG files
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
uint16 SubsamplingHor;
|
|
Toshihiro Shimizu |
890ddd |
uint16 SubsamplingVer;
|
|
Toshihiro Shimizu |
890ddd |
TIFFGetFieldDefaulted(img->tif, TIFFTAG_YCBCRSUBSAMPLING, &SubsamplingHor, &SubsamplingVer);
|
|
Toshihiro Shimizu |
890ddd |
switch ((SubsamplingHor << 4) | SubsamplingVer) {
|
|
Toshihiro Shimizu |
890ddd |
case 0x44:
|
|
Toshihiro Shimizu |
890ddd |
img->put.contig = (tileContigRoutine)putcontig8bitYCbCr44tile;
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
case 0x42:
|
|
Toshihiro Shimizu |
890ddd |
img->put.contig = (tileContigRoutine)putcontig8bitYCbCr42tile;
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
case 0x41:
|
|
Toshihiro Shimizu |
890ddd |
img->put.contig = (tileContigRoutine)putcontig8bitYCbCr41tile;
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
case 0x22:
|
|
Toshihiro Shimizu |
890ddd |
img->put.contig = (tileContigRoutine)putcontig8bitYCbCr22tile;
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
case 0x21:
|
|
Toshihiro Shimizu |
890ddd |
img->put.contig = (tileContigRoutine)putcontig8bitYCbCr21tile;
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
case 0x12:
|
|
Toshihiro Shimizu |
890ddd |
img->put.contig = (tileContigRoutine)putcontig8bitYCbCr12tile;
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
case 0x11:
|
|
Toshihiro Shimizu |
890ddd |
img->put.contig = (tileContigRoutine)putcontig8bitYCbCr11tile;
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
case PHOTOMETRIC_CIELAB:
|
|
Toshihiro Shimizu |
890ddd |
if (buildMap(img)) {
|
|
Toshihiro Shimizu |
890ddd |
if (img->bitspersample == 8)
|
|
Toshihiro Shimizu |
890ddd |
img->put.contig = (tileContigRoutine)initCIELabConversion(img);
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return ((img->get != NULL) && (img->put.contig != NULL));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* Select the appropriate conversion routine for unpacked data.
|
|
Toshihiro Shimizu |
890ddd |
*
|
|
Toshihiro Shimizu |
890ddd |
* NB: we assume that unpacked single channel data is directed
|
|
Toshihiro Shimizu |
890ddd |
* to the "packed routines.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
static int
|
|
Toshihiro Shimizu |
890ddd |
PickSeparateCase(TIFFRGBAImage *img)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
img->get = (gtFunc_32)(TIFFIsTiled(img->tif) ? gtTileSeparate : gtStripSeparate);
|
|
Toshihiro Shimizu |
890ddd |
img->put.separate = NULL;
|
|
Toshihiro Shimizu |
890ddd |
switch (img->photometric) {
|
|
Toshihiro Shimizu |
890ddd |
case PHOTOMETRIC_MINISWHITE:
|
|
Toshihiro Shimizu |
890ddd |
case PHOTOMETRIC_MINISBLACK:
|
|
Toshihiro Shimizu |
890ddd |
/* greyscale images processed pretty much as RGB by gtTileSeparate */
|
|
Toshihiro Shimizu |
890ddd |
case PHOTOMETRIC_RGB:
|
|
Toshihiro Shimizu |
890ddd |
switch (img->bitspersample) {
|
|
Toshihiro Shimizu |
890ddd |
case 8:
|
|
Toshihiro Shimizu |
890ddd |
if (img->alpha != EXTRASAMPLE_UNSPECIFIED)
|
|
Toshihiro Shimizu |
890ddd |
img->put.separate = (tileSeparateRoutine)putRGBAAseparate8bittile;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
img->put.separate = (tileSeparateRoutine)putRGBseparate8bittile;
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
case 16:
|
|
Toshihiro Shimizu |
890ddd |
if (img->alpha != EXTRASAMPLE_UNSPECIFIED) {
|
|
Toshihiro Shimizu |
890ddd |
if (BuildMapBitdepth16To8(img))
|
|
Toshihiro Shimizu |
890ddd |
img->put.separate = (tileSeparateRoutine)putRGBAAseparate16bittile;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
if (BuildMapBitdepth16To8(img))
|
|
Toshihiro Shimizu |
890ddd |
img->put.separate = (tileSeparateRoutine)putRGBseparate16bittile;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
case PHOTOMETRIC_SEPARATED:
|
|
Toshihiro Shimizu |
890ddd |
if (img->bitspersample == 8 && img->samplesperpixel == 4) {
|
|
Toshihiro Shimizu |
890ddd |
img->alpha = 1; // Not alpha, but seems like the only way to get 4th band
|
|
Toshihiro Shimizu |
890ddd |
img->put.separate = (tileSeparateRoutine)putCMYKseparate8bittile;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
case PHOTOMETRIC_YCBCR:
|
|
Toshihiro Shimizu |
890ddd |
if ((img->bitspersample == 8) && (img->samplesperpixel == 3)) {
|
|
Toshihiro Shimizu |
890ddd |
if (initYCbCrConversion(img) != 0) {
|
|
Toshihiro Shimizu |
890ddd |
uint16 hs, vs;
|
|
Toshihiro Shimizu |
890ddd |
TIFFGetFieldDefaulted(img->tif, TIFFTAG_YCBCRSUBSAMPLING, &hs, &vs);
|
|
Toshihiro Shimizu |
890ddd |
switch ((hs << 4) | vs) {
|
|
Toshihiro Shimizu |
890ddd |
case 0x11:
|
|
Toshihiro Shimizu |
890ddd |
img->put.separate = (tileSeparateRoutine)putseparate8bitYCbCr11tile;
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
/* TODO: add other cases here */
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return ((img->get != NULL) && (img->put.separate != NULL));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
static int
|
|
Toshihiro Shimizu |
890ddd |
BuildMapBitdepth16To8(TIFFRGBAImage *img)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
static const char module[] = "BuildMapBitdepth16To8";
|
|
Toshihiro Shimizu |
890ddd |
uint8 *m;
|
|
Toshihiro Shimizu |
890ddd |
uint32 n;
|
|
Toshihiro Shimizu |
890ddd |
assert(img->Bitdepth16To8 == NULL);
|
|
Toshihiro Shimizu |
890ddd |
img->Bitdepth16To8 = _TIFFmalloc(65536);
|
|
Toshihiro Shimizu |
890ddd |
if (img->Bitdepth16To8 == NULL) {
|
|
Toshihiro Shimizu |
890ddd |
TIFFErrorExt(img->tif->tif_clientdata, module, "Out of memory");
|
|
Toshihiro Shimizu |
890ddd |
return (0);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
m = img->Bitdepth16To8;
|
|
Toshihiro Shimizu |
890ddd |
for (n = 0; n < 65536; n++)
|
|
Toshihiro Shimizu |
890ddd |
*m++ = (n + 128) / 257;
|
|
Toshihiro Shimizu |
890ddd |
return (1);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* Read a whole strip off data from the file, and convert to RGBA form.
|
|
Toshihiro Shimizu |
890ddd |
* If this is the last strip, then it will only contain the portion of
|
|
Toshihiro Shimizu |
890ddd |
* the strip that is actually within the image space. The result is
|
|
Toshihiro Shimizu |
890ddd |
* organized in bottom to top form.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int TIFFReadRGBAStrip_64(TIFF *tif, uint32 row, uint64 *raster)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
char emsg[1024] = "";
|
|
Toshihiro Shimizu |
890ddd |
TIFFRGBAImage img;
|
|
Toshihiro Shimizu |
890ddd |
int ok;
|
|
Toshihiro Shimizu |
890ddd |
uint32 rowsperstrip, rows_to_read;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (TIFFIsTiled(tif)) {
|
|
Toshihiro Shimizu |
890ddd |
TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif),
|
|
Toshihiro Shimizu |
890ddd |
"Can't use TIFFReadRGBAStrip() with tiled file.");
|
|
Toshihiro Shimizu |
890ddd |
return (0);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TIFFGetFieldDefaulted(tif, TIFFTAG_ROWSPERSTRIP, &rowsperstrip);
|
|
Toshihiro Shimizu |
890ddd |
if ((row % rowsperstrip) != 0) {
|
|
Toshihiro Shimizu |
890ddd |
TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif),
|
|
Toshihiro Shimizu |
890ddd |
"Row passed to TIFFReadRGBAStrip() must be first in a strip.");
|
|
Toshihiro Shimizu |
890ddd |
return (0);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (TIFFRGBAImageOK(tif, emsg) && TIFFRGBAImageBegin_64(&img, tif, 0, emsg)) {
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
img.row_offset = row;
|
|
Toshihiro Shimizu |
890ddd |
img.col_offset = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (row + rowsperstrip > img.height)
|
|
Toshihiro Shimizu |
890ddd |
rows_to_read = img.height - row;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
rows_to_read = rowsperstrip;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
ok = TIFFRGBAImageGet_64(&img, raster, img.width, rows_to_read);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TIFFRGBAImageEnd(&img);
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", emsg);
|
|
Toshihiro Shimizu |
890ddd |
ok = 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return (ok);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* Read a whole tile off data from the file, and convert to RGBA form.
|
|
Toshihiro Shimizu |
890ddd |
* The returned RGBA data is organized from bottom to top of tile,
|
|
Toshihiro Shimizu |
890ddd |
* and may include zeroed areas if the tile extends off the image.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int TIFFReadRGBATile_64(TIFF *tif, uint32 col, uint32 row, uint64 *raster)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
char emsg[1024] = "";
|
|
Toshihiro Shimizu |
890ddd |
TIFFRGBAImage img;
|
|
Toshihiro Shimizu |
890ddd |
int ok;
|
|
Toshihiro Shimizu |
890ddd |
uint32 tile_xsize, tile_ysize;
|
|
Toshihiro Shimizu |
890ddd |
uint32 read_xsize, read_ysize;
|
|
Toshihiro Shimizu |
890ddd |
uint32 i_row;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* Verify that our request is legal - on a tile file, and on a
|
|
Toshihiro Shimizu |
890ddd |
* tile boundary.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!TIFFIsTiled(tif)) {
|
|
Toshihiro Shimizu |
890ddd |
TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif),
|
|
Toshihiro Shimizu |
890ddd |
"Can't use TIFFReadRGBATile() with stripped file.");
|
|
Toshihiro Shimizu |
890ddd |
return (0);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TIFFGetFieldDefaulted(tif, TIFFTAG_TILEWIDTH, &tile_xsize);
|
|
Toshihiro Shimizu |
890ddd |
TIFFGetFieldDefaulted(tif, TIFFTAG_TILELENGTH, &tile_ysize);
|
|
Toshihiro Shimizu |
890ddd |
if ((col % tile_xsize) != 0 || (row % tile_ysize) != 0) {
|
|
Toshihiro Shimizu |
890ddd |
TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif),
|
|
Toshihiro Shimizu |
890ddd |
"Row/col passed to TIFFReadRGBATile() must be top"
|
|
Toshihiro Shimizu |
890ddd |
"left corner of a tile.");
|
|
Toshihiro Shimizu |
890ddd |
return (0);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* Setup the RGBA reader.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!TIFFRGBAImageOK(tif, emsg) || !TIFFRGBAImageBegin_64(&img, tif, 0, emsg)) {
|
|
Toshihiro Shimizu |
890ddd |
TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", emsg);
|
|
Toshihiro Shimizu |
890ddd |
return (0);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* The TIFFRGBAImageGet() function doesn't allow us to get off the
|
|
Toshihiro Shimizu |
890ddd |
* edge of the image, even to fill an otherwise valid tile. So we
|
|
Toshihiro Shimizu |
890ddd |
* figure out how much we can read, and fix up the tile buffer to
|
|
Toshihiro Shimizu |
890ddd |
* a full tile configuration afterwards.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (row + tile_ysize > img.height)
|
|
Toshihiro Shimizu |
890ddd |
read_ysize = img.height - row;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
read_ysize = tile_ysize;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (col + tile_xsize > img.width)
|
|
Toshihiro Shimizu |
890ddd |
read_xsize = img.width - col;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
read_xsize = tile_xsize;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* Read the chunk of imagery.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
img.row_offset = row;
|
|
Toshihiro Shimizu |
890ddd |
img.col_offset = col;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
ok = TIFFRGBAImageGet_64(&img, raster, read_xsize, read_ysize);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TIFFRGBAImageEnd(&img);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* If our read was incomplete we will need to fix up the tile by
|
|
Toshihiro Shimizu |
890ddd |
* shifting the data around as if a full tile of data is being returned.
|
|
Toshihiro Shimizu |
890ddd |
*
|
|
Toshihiro Shimizu |
890ddd |
* This is all the more complicated because the image is organized in
|
|
Toshihiro Shimizu |
890ddd |
* bottom to top format.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (read_xsize == tile_xsize && read_ysize == tile_ysize)
|
|
Toshihiro Shimizu |
890ddd |
return (ok);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (i_row = 0; i_row < read_ysize; i_row++) {
|
|
Toshihiro Shimizu |
890ddd |
memmove(raster + (tile_ysize - i_row - 1) * tile_xsize,
|
|
Toshihiro Shimizu |
890ddd |
raster + (read_ysize - i_row - 1) * read_xsize,
|
|
Toshihiro Shimizu |
890ddd |
read_xsize * sizeof(uint64));
|
|
Toshihiro Shimizu |
890ddd |
_TIFFmemset(raster + (tile_ysize - i_row - 1) * tile_xsize + read_xsize,
|
|
Toshihiro Shimizu |
890ddd |
0, sizeof(uint64) * (tile_xsize - read_xsize));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (i_row = read_ysize; i_row < tile_ysize; i_row++) {
|
|
Toshihiro Shimizu |
890ddd |
_TIFFmemset(raster + (tile_ysize - i_row - 1) * tile_xsize,
|
|
Toshihiro Shimizu |
890ddd |
0, sizeof(uint64) * tile_xsize);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return (ok);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/* vim: set ts=8 sts=8 sw=8 noet: */
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* Local Variables:
|
|
Toshihiro Shimizu |
890ddd |
* mode: c
|
|
Toshihiro Shimizu |
890ddd |
* c-basic-offset: 8
|
|
Toshihiro Shimizu |
890ddd |
* fill-column: 78
|
|
Toshihiro Shimizu |
890ddd |
* End:
|
|
Toshihiro Shimizu |
890ddd |
*/
|