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 * modifyhuesat.c 00018 * 00019 * modifyhuesat filein nhue dhue nsat dsat fileout 00020 * 00021 * where nhue and nsat are odd 00022 * 00023 * This gives a rectangle of nhue x nsat output images, 00024 * where the center image is not modified. 00025 * 00026 * Example: modifyhuesat test24.jpg 5 0.2 5 0.2 /tmp/junkout.jpg 00027 */ 00028 00029 #include "allheaders.h" 00030 00031 main(int argc, 00032 char **argv) 00033 { 00034 char *filein, *fileout; 00035 l_int32 i, j, w, d, nhue, nsat, tilewidth; 00036 l_float32 scale, dhue, dsat, delhue, delsat; 00037 PIX *pixs, *pixt1, *pixt2, *pixd; 00038 PIXA *pixa; 00039 static char mainName[] = "modifyhuesat"; 00040 00041 if (argc != 7) 00042 return ERROR_INT( 00043 " Syntax: modifyhuesat filein nhue dhue nsat dsat fileout", 00044 mainName, 1); 00045 00046 filein = argv[1]; 00047 nhue = atoi(argv[2]); 00048 dhue = atof(argv[3]); 00049 nsat = atoi(argv[4]); 00050 dsat = atof(argv[5]); 00051 fileout = argv[6]; 00052 00053 if (nhue % 2 == 0) { 00054 nhue++; 00055 fprintf(stderr, "nhue must be odd; raised to %d\n", nhue); 00056 } 00057 if (nsat % 2 == 0) { 00058 nsat++; 00059 fprintf(stderr, "nsat must be odd; raised to %d\n", nsat); 00060 } 00061 00062 if ((pixt1 = pixRead(filein)) == NULL) 00063 return ERROR_INT("pixt1 not read", mainName, 1); 00064 pixGetDimensions(pixt1, &w, NULL, NULL); 00065 scale = 250.0 / (l_float32)w; 00066 pixt2 = pixScale(pixt1, scale, scale); 00067 pixs = pixConvertTo32(pixt2); 00068 pixDestroy(&pixt1); 00069 pixDestroy(&pixt2); 00070 00071 pixGetDimensions(pixs, &w, NULL, &d); 00072 pixa = pixaCreate(nhue * nsat); 00073 for (i = 0; i < nsat; i++) { 00074 delsat = (i - nsat / 2) * dsat; 00075 pixt1 = pixModifySaturation(NULL, pixs, delsat); 00076 for (j = 0; j < nhue; j++) { 00077 delhue = (j - nhue / 2) * dhue; 00078 pixt2 = pixModifyHue(NULL, pixt1, delhue); 00079 pixaAddPix(pixa, pixt2, L_INSERT); 00080 } 00081 pixDestroy(&pixt1); 00082 } 00083 00084 tilewidth = L_MIN(w, 1500 / nsat); 00085 pixd = pixaDisplayTiledAndScaled(pixa, d, tilewidth, nsat, 0, 25, 3); 00086 pixWrite(fileout, pixd, IFF_JFIF_JPEG); 00087 00088 pixDestroy(&pixs); 00089 pixDestroy(&pixd); 00090 pixaDestroy(&pixa); 00091 return 0; 00092 } 00093