Leptonica 1.68
C Image Processing Library
|
00001 /*====================================================================* 00002 - Copyright (C) 2001 Leptonica. All rights reserved. 00003 - This software is distributed in the hope that it will be 00004 - useful, but with NO WARRANTY OF ANY KIND. 00005 - No author or distributor accepts responsibility to anyone for the 00006 - consequences of using this software, or for whether it serves any 00007 - particular purpose or works at all, unless he or she says so in 00008 - writing. Everyone is granted permission to copy, modify and 00009 - redistribute this source code, for commercial or non-commercial 00010 - purposes, with the following restrictions: (1) the origin of this 00011 - source code must not be misrepresented; (2) modified versions must 00012 - be plainly marked as such; and (3) this notice may not be removed 00013 - or altered from any source or modified source distribution. 00014 *====================================================================*/ 00015 00016 /* 00017 * hardlight_reg.c 00018 * 00019 */ 00020 00021 #include "allheaders.h" 00022 00023 static PIXA *TestHardlight(const char *file1, const char *file2, 00024 L_REGPARAMS *rp); 00025 00026 main(int argc, 00027 char **argv) 00028 { 00029 char fname[256]; 00030 PIX *pix; 00031 PIXA *pixa; 00032 L_REGPARAMS *rp; 00033 00034 if (regTestSetup(argc, argv, &rp)) 00035 return 1; 00036 00037 pixa = TestHardlight("hardlight1_1.jpg", "hardlight1_2.jpg", rp); 00038 pix = pixaDisplay(pixa, 0, 0); 00039 regTestWritePixAndCheck(rp, pix, IFF_PNG); 00040 pixDisplayWithTitle(pix, 0, 0, NULL, rp->display); 00041 pixaDestroy(&pixa); 00042 pixDestroy(&pix); 00043 00044 pixa = TestHardlight("hardlight2_1.jpg", "hardlight2_2.jpg", rp); 00045 pix = pixaDisplay(pixa, 0, 500); 00046 regTestWritePixAndCheck(rp, pix, IFF_PNG); 00047 pixDisplayWithTitle(pix, 0, 0, NULL, rp->display); 00048 pixaDestroy(&pixa); 00049 pixDestroy(&pix); 00050 00051 regTestCleanup(rp); 00052 return 0; 00053 } 00054 00055 static PIXA * 00056 TestHardlight(const char *file1, 00057 const char *file2, 00058 L_REGPARAMS *rp) 00059 { 00060 PIX *pixs1, *pixs2, *pixr, *pixt1, *pixt2, *pixd; 00061 PIXA *pixa; 00062 00063 PROCNAME("TestHardlight"); 00064 00065 /* Read in images */ 00066 pixs1 = pixRead(file1); 00067 pixs2 = pixRead(file2); 00068 if (!pixs1) 00069 return (PIXA *)ERROR_PTR("pixs1 not read", procName, NULL); 00070 if (!pixs2) 00071 return (PIXA *)ERROR_PTR("pixs2 not read", procName, NULL); 00072 00073 pixa = pixaCreate(0); 00074 00075 /* ---------- Test not-in-place; no colormaps ----------- */ 00076 pixSaveTiled(pixs1, pixa, 1, 1, 20, 32); 00077 pixSaveTiled(pixs2, pixa, 1, 0, 20, 0); 00078 pixd = pixBlendHardLight(NULL, pixs1, pixs2, 0, 0, 1.0); 00079 regTestWritePixAndCheck(rp, pixd, IFF_PNG); 00080 pixSaveTiled(pixd, pixa, 1, 1, 20, 0); 00081 pixDestroy(&pixd); 00082 00083 pixt2 = pixConvertTo32(pixs2); 00084 pixd = pixBlendHardLight(NULL, pixs1, pixt2, 0, 0, 1.0); 00085 regTestWritePixAndCheck(rp, pixd, IFF_PNG); 00086 pixSaveTiled(pixd, pixa, 1, 0, 20, 0); 00087 pixDestroy(&pixt2); 00088 pixDestroy(&pixd); 00089 00090 pixd = pixBlendHardLight(NULL, pixs2, pixs1, 0, 0, 1.0); 00091 pixSaveTiled(pixd, pixa, 1, 0, 20, 0); 00092 pixDestroy(&pixd); 00093 00094 /* ---------- Test not-in-place; colormaps ----------- */ 00095 pixt1 = pixMedianCutQuant(pixs1, 0); 00096 if (pixGetDepth(pixs2) == 8) 00097 pixt2 = pixConvertGrayToColormap8(pixs2, 8); 00098 else 00099 /* pixt2 = pixConvertTo8(pixs2, 1); */ 00100 pixt2 = pixMedianCutQuant(pixs2, 0); 00101 pixSaveTiled(pixt1, pixa, 1, 1, 20, 0); 00102 pixSaveTiled(pixt2, pixa, 1, 0, 20, 0); 00103 00104 pixd = pixBlendHardLight(NULL, pixt1, pixs2, 0, 0, 1.0); 00105 regTestWritePixAndCheck(rp, pixd, IFF_PNG); 00106 pixSaveTiled(pixd, pixa, 1, 1, 20, 0); 00107 pixDestroy(&pixd); 00108 00109 pixd = pixBlendHardLight(NULL, pixt1, pixt2, 0, 0, 1.0); 00110 regTestWritePixAndCheck(rp, pixd, IFF_PNG); 00111 pixSaveTiled(pixd, pixa, 1, 0, 20, 0); 00112 pixDestroy(&pixd); 00113 00114 pixd = pixBlendHardLight(NULL, pixt2, pixt1, 0, 0, 1.0); 00115 regTestWritePixAndCheck(rp, pixd, IFF_PNG); 00116 pixSaveTiled(pixd, pixa, 1, 0, 20, 0); 00117 pixDestroy(&pixt1); 00118 pixDestroy(&pixt2); 00119 pixDestroy(&pixd); 00120 00121 /* ---------- Test in-place; no colormaps ----------- */ 00122 pixBlendHardLight(pixs1, pixs1, pixs2, 0, 0, 1.0); 00123 regTestWritePixAndCheck(rp, pixs1, IFF_PNG); 00124 pixSaveTiled(pixs1, pixa, 1, 1, 20, 0); 00125 pixDestroy(&pixs1); 00126 00127 pixs1 = pixRead(file1); 00128 pixt2 = pixConvertTo32(pixs2); 00129 pixBlendHardLight(pixs1, pixs1, pixt2, 0, 0, 1.0); 00130 regTestWritePixAndCheck(rp, pixs1, IFF_PNG); 00131 pixSaveTiled(pixs1, pixa, 1, 0, 20, 0); 00132 pixDestroy(&pixt2); 00133 pixDestroy(&pixs1); 00134 00135 pixs1 = pixRead(file1); 00136 pixBlendHardLight(pixs2, pixs2, pixs1, 0, 0, 1.0); 00137 regTestWritePixAndCheck(rp, pixs2, IFF_PNG); 00138 pixSaveTiled(pixs2, pixa, 1, 0, 20, 0); 00139 pixDestroy(&pixs2); 00140 00141 pixDestroy(&pixs1); 00142 pixDestroy(&pixs2); 00143 return pixa; 00144 } 00145 00146