static int
PredictorSetupEncode(TIFF* tif)
{
	TIFFPredictorState* sp = PredictorState(tif);
	TIFFDirectory* td = &tif->tif_dir;

	if (!(*sp->setupencode)(tif) || !PredictorSetup(tif))
		return (0);
	if (sp->predictor == 2) {
		switch (td->td_bitspersample) {
		case 8:  sp->pfunc = horDiff8; break;
		case 16: sp->pfunc = horDiff16; break;
		}
		/*
		 * Override default encoding method with
		 * one that does the predictor stuff.
		 */
		sp->coderow = tif->tif_encoderow;
		tif->tif_encoderow = PredictorEncodeRow;
		sp->codestrip = tif->tif_encodestrip;
		tif->tif_encodestrip = PredictorEncodeTile;
		sp->codetile = tif->tif_encodetile;
		tif->tif_encodetile = PredictorEncodeTile;
	}
	return (1);
}
Example #2
0
static int
PredictorSetupDecode(TIFF* tif) {
    TIFFPredictorState* sp = PredictorState(tif);
    TIFFDirectory* td = &tif->tif_dir;

    if (!(*sp->setupdecode)(tif) || !PredictorSetup(tif)) {
        return (0);
    }
    if (sp->predictor == 2) {
        switch (td->td_bitspersample) {
        case 8:
            sp->pfunc = horAcc8;
            break;
        case 16:
            sp->pfunc = horAcc16;
            break;
        }
        /*
         * Override default decoding method with
         * one that does the predictor stuff.
         */
        sp->coderow = tif->tif_decoderow;
        tif->tif_decoderow = PredictorDecodeRow;
        sp->codestrip = tif->tif_decodestrip;
        tif->tif_decodestrip = PredictorDecodeTile;
        sp->codetile = tif->tif_decodetile;
        tif->tif_decodetile = PredictorDecodeTile;
        /*
         * If the data is horizontally differenced
         * 16-bit data that requires byte-swapping,
         * then it must be byte swapped before the
         * accumulation step.  We do this with a
         * special-purpose routine and override the
         * normal post decoding logic that the library
         * setup when the directory was read.
         */
        if (tif->tif_flags & TIFF_SWAB) {
            if (sp->pfunc == horAcc16) {
                sp->pfunc = swabHorAcc16;
                tif->tif_postdecode = _TIFFNoPostDecode;
            } /* else handle 32-bit case... */
        }
    }
    return (1);
}
Example #3
0
static int
PredictorSetupDecode(TIFF* tif)
{
	TIFFPredictorState* sp = PredictorState(tif);
	TIFFDirectory* td = &tif->tif_dir;

	if (!(*sp->setupdecode)(tif) || !PredictorSetup(tif))
		return 0;

	if (sp->predictor == 2) {
		switch (td->td_bitspersample) {
			case 8:  sp->pfunc = horAcc8; break;
			case 16: sp->pfunc = horAcc16; break;
		}
		/*
		 * Override default decoding method with one that does the
		 * predictor stuff.
		 */
		sp->coderow = tif->tif_decoderow;
		tif->tif_decoderow = PredictorDecodeRow;
		sp->codestrip = tif->tif_decodestrip;
		tif->tif_decodestrip = PredictorDecodeTile;
		sp->codetile = tif->tif_decodetile;
		tif->tif_decodetile = PredictorDecodeTile;
		/*
		 * If the data is horizontally differenced 16-bit data that
		 * requires byte-swapping, then it must be byte swapped before
		 * the accumulation step.  We do this with a special-purpose
		 * routine and override the normal post decoding logic that
		 * the library setup when the directory was read.
		 */
		if (tif->tif_flags & TIFF_SWAB) {
			if (sp->pfunc == horAcc16) {
				sp->pfunc = swabHorAcc16;
				tif->tif_postdecode = _TIFFNoPostDecode;
			} /* else handle 32-bit case... */
		}
	}

	else if (sp->predictor == 3) {
		sp->pfunc = fpAcc;
		/*
		 * Override default decoding method with one that does the
		 * predictor stuff.
		 */
		sp->coderow = tif->tif_decoderow;
		tif->tif_decoderow = PredictorDecodeRow;
		sp->codestrip = tif->tif_decodestrip;
		tif->tif_decodestrip = PredictorDecodeTile;
		sp->codetile = tif->tif_decodetile;
		tif->tif_decodetile = PredictorDecodeTile;
		/*
		 * The data should not be swapped outside of the floating
		 * point predictor, the accumulation routine should return
		 * byres in the native order.
		 */
		if (tif->tif_flags & TIFF_SWAB) {
			tif->tif_postdecode = _TIFFNoPostDecode;
		}
		/*
		 * Allocate buffer to keep the decoded bytes before
		 * rearranging in the ight order
		 */
	}

	return 1;
}
Example #4
0
static int
PredictorSetupEncode(TIFF* tif)
{
	TIFFPredictorState* sp = PredictorState(tif);
	TIFFDirectory* td = &tif->tif_dir;

	if (!(*sp->setupencode)(tif) || !PredictorSetup(tif))
		return 0;

	if (sp->predictor == 2) {
		switch (td->td_bitspersample) {
			case 8:  sp->encodepfunc = horDiff8; break;
			case 16: sp->encodepfunc = horDiff16; break;
			case 32: sp->encodepfunc = horDiff32; break;
		}
		/*
		 * Override default encoding method with one that does the
		 * predictor stuff.
		 */
                if( tif->tif_encoderow != PredictorEncodeRow )
                {
                    sp->encoderow = tif->tif_encoderow;
                    tif->tif_encoderow = PredictorEncodeRow;
                    sp->encodestrip = tif->tif_encodestrip;
                    tif->tif_encodestrip = PredictorEncodeTile;
                    sp->encodetile = tif->tif_encodetile;
                    tif->tif_encodetile = PredictorEncodeTile;
                }

                /*
                 * If the data is horizontally differenced 16-bit data that
                 * requires byte-swapping, then it must be byte swapped after
                 * the differentiation step.  We do this with a special-purpose
                 * routine and override the normal post decoding logic that
                 * the library setup when the directory was read.
                 */
                if (tif->tif_flags & TIFF_SWAB) {
                    if (sp->encodepfunc == horDiff16) {
                            sp->encodepfunc = swabHorDiff16;
                            tif->tif_postdecode = _TIFFNoPostDecode;
                    } else if (sp->encodepfunc == horDiff32) {
                            sp->encodepfunc = swabHorDiff32;
                            tif->tif_postdecode = _TIFFNoPostDecode;
                    }
                }
        }

	else if (sp->predictor == 3) {
		sp->encodepfunc = fpDiff;
		/*
		 * Override default encoding method with one that does the
		 * predictor stuff.
		 */
                if( tif->tif_encoderow != PredictorEncodeRow )
                {
                    sp->encoderow = tif->tif_encoderow;
                    tif->tif_encoderow = PredictorEncodeRow;
                    sp->encodestrip = tif->tif_encodestrip;
                    tif->tif_encodestrip = PredictorEncodeTile;
                    sp->encodetile = tif->tif_encodetile;
                    tif->tif_encodetile = PredictorEncodeTile;
                }
	}

	return 1;
}