Leptonica 1.68
C Image Processing Library

blendtest1.c

Go to the documentation of this file.
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  * blendtest1.c
00018  *
00019  *     fract must be in interval [0.0, 1.0]
00020  */
00021 
00022 #include <stdio.h>
00023 #include <stdlib.h>
00024 #include "allheaders.h"
00025 
00026 #define   X     140 
00027 #define   Y     40 
00028 
00029 
00030 main(int    argc,
00031      char **argv)
00032 {
00033 char        *file1, *file2, *fileout;
00034 l_int32      d;
00035 l_float32    fract;
00036 PIX         *pixs1, *pixs2, *pixt1, *pixt2, *pixt3, *pixt4, *pixd;
00037 static char  mainName[] = "blendtest1";
00038 
00039     if (argc != 5)
00040         exit(ERROR_INT(" Syntax:  blendtest1 file1 file2 fract fileout",
00041             mainName, 1));
00042 
00043     file1 = argv[1];
00044     file2 = argv[2];
00045     fract = atof(argv[3]);
00046     fileout = argv[4];
00047 
00048     if ((pixs1 = pixRead(file1)) == NULL)
00049         exit(ERROR_INT("pixs1 not made", mainName, 1));
00050     if ((pixs2 = pixRead(file2)) == NULL)
00051         exit(ERROR_INT("pixs2 not made", mainName, 1));
00052 
00053 #if 0
00054     d = pixGetDepth(pixs2);
00055     if (d == 1) {
00056         pixt1 = pixBlend(pixs1, pixs2, X, Y, fract);
00057         pixt2 = pixBlend(pixt1, pixs2, X, Y + 60, fract);
00058         pixt3 = pixBlend(pixt2, pixs2, X, Y + 120, fract);
00059         pixt4 = pixBlend(pixt3, pixs2, X, Y + 180, fract);
00060         pixt5 = pixBlend(pixt4, pixs2, X, Y + 240, fract);
00061         pixd = pixBlend(pixt5, pixs2, X, Y + 300, fract);
00062         pixWrite(fileout, pixd, IFF_DEFAULT);
00063         pixDestroy(&pixt1);
00064         pixDestroy(&pixt2);
00065         pixDestroy(&pixt3);
00066         pixDestroy(&pixt4);
00067         pixDestroy(&pixt5);
00068     }
00069     else {
00070         pixt1 = pixBlend(pixs1, pixs2, X, Y, fract);
00071         pixt2 = pixBlend(pixt1, pixs2, X + 80, Y + 80, fract);
00072         pixt3 = pixBlend(pixt2, pixs2, X + 160, Y + 160, fract);
00073         pixt4 = pixBlend(pixt3, pixs2, X + 240, Y + 240, fract);
00074         pixt5 = pixBlend(pixt4, pixs2, X + 320, Y + 320, fract);
00075         pixd = pixBlend(pixt5, pixs2, X + 360, Y + 360, fract);
00076         pixWrite(fileout, pixd, IFF_DEFAULT);
00077         pixDestroy(&pixt1);
00078         pixDestroy(&pixt2);
00079         pixDestroy(&pixt3);
00080         pixDestroy(&pixt4);
00081         pixDestroy(&pixt5);
00082     }
00083     pixDestroy(&pixd);
00084 #endif
00085 
00086 #if 1  /* e.g., weasel8.png with fract = 0.3 */
00087     pixSnapColor(pixs2, pixs2, 0xff, 0xff, 50);
00088     pixBlendGray(pixs1, pixs1, pixs2, 200, 100, fract,
00089                  L_BLEND_GRAY, 1, 0xff);
00090     pixBlendGray(pixs1, pixs1, pixs2, 200, 200, fract,
00091                  L_BLEND_GRAY, 1, 0xff);
00092     pixBlendGray(pixs1, pixs1, pixs2, 200, 260, fract,
00093                  L_BLEND_GRAY, 1, 0xff);
00094     pixBlendGray(pixs1, pixs1, pixs2, 200, 340, fract,
00095                  L_BLEND_GRAY, 1, 0xff);
00096     pixWrite(fileout, pixs1, IFF_JFIF_JPEG);
00097     pixDisplay(pixs1, 200, 200);
00098 #endif
00099 
00100 #if 0  /* e.g., weasel8.png with fract = 0.5 */
00101     pixSnapColor(pixs2, pixs2, 0xff, 0xff, 50);
00102     pixBlendGray(pixs1, pixs1, pixs2, 200, 100, fract,
00103                  L_BLEND_GRAY_WITH_INVERSE, 1, 0xff);
00104     pixBlendGray(pixs1, pixs1, pixs2, 200, 200, fract,
00105                  L_BLEND_GRAY_WITH_INVERSE, 1, 0xff);
00106     pixBlendGray(pixs1, pixs1, pixs2, 200, 260, fract,
00107                  L_BLEND_GRAY_WITH_INVERSE, 1, 0xff);
00108     pixBlendGray(pixs1, pixs1, pixs2, 200, 340, fract,
00109                  L_BLEND_GRAY_WITH_INVERSE, 1, 0xff);
00110     pixWrite(fileout, pixs1, IFF_JFIF_JPEG);
00111     pixDisplay(pixs1, 200, 200);
00112 #endif
00113 
00114 #if 0  /* e.g., weasel32.png with fract = 0.2 */
00115     pixSnapColor(pixs2, pixs2, 0xffffff00, 0xffffff00, 50);
00116     pixBlendColor(pixs1, pixs1, pixs2, 200, 100, fract, 1, 0xffffff00);
00117     pixBlendColor(pixs1, pixs1, pixs2, 200, 200, fract, 1, 0xffffff00);
00118     pixBlendColor(pixs1, pixs1, pixs2, 200, 260, fract, 1, 0xffffff00);
00119     pixBlendColor(pixs1, pixs1, pixs2, 200, 340, fract, 1, 0xffffff00);
00120     pixWrite(fileout, pixs1, IFF_JFIF_JPEG);
00121     pixDisplay(pixs1, 200, 200);
00122 #endif
00123 
00124     pixDestroy(&pixs1);
00125     pixDestroy(&pixs2);
00126 
00127     exit(0);
00128 }
00129 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines