1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
/*====================================================================*
- Copyright (C) 2001 Leptonica. All rights reserved.
- This software is distributed in the hope that it will be
- useful, but with NO WARRANTY OF ANY KIND.
- No author or distributor accepts responsibility to anyone for the
- consequences of using this software, or for whether it serves any
- particular purpose or works at all, unless he or she says so in
- writing. Everyone is granted permission to copy, modify and
- redistribute this source code, for commercial or non-commercial
- purposes, with the following restrictions: (1) the origin of this
- source code must not be misrepresented; (2) modified versions must
- be plainly marked as such; and (3) this notice may not be removed
- or altered from any source or modified source distribution.
*====================================================================*/
/*
* bilineartest.c
*/
#include <stdio.h>
#include <stdlib.h>
#include "allheaders.h"
#if 1 /* for test with large distortion */
#define X1 32
#define Y1 150
#define X2 520
#define Y2 150
#define X3 32
#define Y3 612
#define X4 520
#define Y4 612
#define X1P 32
#define Y1P 150
#define X2P 520
#define Y2P 44
#define X3P 32
#define Y3P 612
#define X4P 520
#define Y4P 694
#endif
main(int argc,
char **argv)
{
l_int32 d, h;
char *filein, *fileout;
l_float32 rat;
l_float32 *vc;
PIX *pix, *pixs, *pixx, *pixg, *pixgx, *pixgi;
PTA *ptas, *ptad;
static char mainName[] = "bilineartest";
if (argc != 3)
exit(ERROR_INT(" Syntax: bilineartest filein fileout", mainName, 1));
filein = argv[1];
fileout = argv[2];
#if 1 /* test with large distortion */
if ((pix = pixRead(filein)) == NULL)
exit(ERROR_INT("pixs not made", mainName, 1));
h = pixGetHeight(pix);
rat = 850. / h;
/* pixs = pixScale(pix, rat, rat); */
pixs = pixClone(pix);
ptas = ptaCreate(3);
ptaAddPt(ptas, X1, Y1);
ptaAddPt(ptas, X2, Y2);
ptaAddPt(ptas, X3, Y3);
ptaAddPt(ptas, X4, Y4);
ptad = ptaCreate(3);
ptaAddPt(ptad, X1P, Y1P);
ptaAddPt(ptad, X2P, Y2P);
ptaAddPt(ptad, X3P, Y3P);
ptaAddPt(ptad, X4P, Y4P);
startTimer();
pixx = pixBilinearSampled(pixs, ptas, ptad, L_BRING_IN_WHITE);
fprintf(stderr, " Time for pixBilinearSampled(): %6.2f sec\n", stopTimer());
pixDisplay(pixx, 0, 0);
d = pixGetDepth(pixs);
if (d == 1)
pixWrite("junkout1", pixx, IFF_PNG);
else
pixWrite("junkout1", pixx, IFF_JFIF_JPEG);
if (d == 1)
pixg = pixScaleToGray3(pixs);
else
pixg = pixClone(pixs);
startTimer();
pixgx = pixBilinearSampled(pixg, ptas, ptad, L_BRING_IN_WHITE);
fprintf(stderr, " Time for pixBilinearSampled(): %6.2f sec\n", stopTimer());
pixDisplay(pixgx, 300, 0);
pixWrite("junkout2", pixgx, IFF_PNG);
startTimer();
pixgi = pixBilinearInterpolated(pixg, ptas, ptad, L_BRING_IN_WHITE);
fprintf(stderr, " Time for pixBilinearInterpolated(): %6.2f sec\n",
stopTimer());
pixDisplay(pixgi, 600, 0);
pixWrite("junkout3", pixgi, IFF_PNG);
pixDestroy(&pix);
pixDestroy(&pixs);
pixDestroy(&pixx);
pixDestroy(&pixg);
pixDestroy(&pixgx);
pixDestroy(&pixgi);
ptaDestroy(&ptas);
ptaDestroy(&ptad);
#endif
exit(0);
}
|