Leptonica 1.68
C Image Processing Library

arithtest.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  * arithtest.c
00018  *
00019  */
00020 #include <stdio.h>
00021 #include <stdlib.h>
00022 #include "allheaders.h"
00023 
00024 main(int    argc,
00025      char **argv)
00026 {
00027 char        *filein;
00028 l_int32      w, h, same;
00029 PIX         *pixs, *pix1, *pix2, *pix3, *pix4, *pix5;
00030 static char  mainName[] = "arithtest";
00031 
00032     if (argc != 2)
00033         exit(ERROR_INT(" Syntax:  arithtest filein", mainName, 1));
00034 
00035     filein = argv[1];
00036 
00037     if ((pixs = pixRead(filein)) == NULL)
00038         exit(ERROR_INT("pix not made", mainName, 1));
00039 
00040     w = pixGetWidth(pixs);
00041     h = pixGetHeight(pixs);
00042 
00043         /* input a grayscale image and convert it to 16 bpp */
00044     pix1 = pixInitAccumulate(w, h, 0);
00045     pixAccumulate(pix1, pixs, L_ARITH_ADD);
00046     pixMultConstAccumulate(pix1, 255., 0);
00047     pix2 = pixFinalAccumulate(pix1, 0, 16);
00048     l_pngSetStrip16To8(0);
00049     pixWrite("/tmp/junkpix1.png", pix2, IFF_PNG);
00050 
00051         /* convert it back to 8 bpp, linear mapped */
00052     pix3 = pixMaxDynamicRange(pix2, L_LINEAR_SCALE);
00053     pixWrite("/tmp/junkpix2.png", pix3, IFF_PNG);
00054 
00055         /* convert it back to 8 bpp using the MSB */
00056     pix4 = pixRead("/tmp/junkpix1.png");
00057     pix5 = pixConvert16To8(pix4, 1);
00058     pixWrite("/tmp/junkpix3.png", pix5, IFF_PNG);
00059     return 0;
00060 }
00061 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines