Leptonica 1.68
C Image Processing Library

buffertest.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  * buffertest.c
00018  *
00019  *   Tests the bbuffer operations
00020  */
00021 
00022 #include "allheaders.h"
00023 
00024 #define   NBLOCKS     11
00025 
00026 main(int    argc,
00027      char **argv)
00028 {
00029 char        *filein, *fileout;
00030 l_uint8     *array1, *array2, *dataout, *dataout2;
00031 l_int32      i, blocksize;
00032 size_t       nbytes, nout, nout2;
00033 BBUFFER     *bb, *bb2;
00034 FILE        *fp;
00035 static char  mainName[] = "buffertest";
00036 
00037     if (argc != 3)
00038         exit(ERROR_INT(" Syntax:  buffertest filein fileout", mainName, 1));
00039 
00040     filein = argv[1];
00041     fileout = argv[2];
00042 
00043     if ((array1 = l_binaryRead(filein, &nbytes)) == NULL)
00044         exit(ERROR_INT("array not made", mainName, 1));
00045     fprintf(stderr, " Bytes read from file: %ld\n", nbytes);
00046 
00047         /* Application of byte buffer ops: compress/decompress in memory */
00048 #if 1
00049     dataout = zlibCompress(array1, nbytes, &nout);
00050     l_binaryWrite(fileout, "w", dataout, nout);
00051 
00052     dataout2 = zlibUncompress(dataout, nout, &nout2);
00053     l_binaryWrite("/tmp/junktest", "w", dataout2, nout2);
00054 
00055     fprintf(stderr,
00056             "nbytes in = %ld, nbytes comp = %ld, nbytes uncomp = %ld\n",
00057             nbytes, nout, nout2);
00058     lept_free(dataout);
00059     lept_free(dataout2);
00060 #endif
00061 
00062         /* Low-level byte buffer read/write test */
00063 #if 0
00064     bb = bbufferCreate(array1, nbytes);
00065     bbufferRead(bb, array1, nbytes);
00066 
00067     array2 = (l_uint8 *)lept_calloc(2 * nbytes, sizeof(l_uint8));
00068 
00069     fprintf(stderr, " Bytes initially in buffer: %d\n", bb->n);
00070 
00071     blocksize = (2 * nbytes) / NBLOCKS;
00072     for (i = 0; i <= NBLOCKS; i++) {
00073         bbufferWrite(bb, array2, blocksize, &nout);
00074         fprintf(stderr, " block %d: wrote %d bytes\n", i + 1, nout); 
00075     }
00076 
00077     fprintf(stderr, " Bytes left in buffer: %d\n", bb->n);
00078 
00079     bb2 = bbufferCreate(NULL, 0);
00080     bbufferRead(bb2, array1, nbytes);
00081     fp = lept_fopen(fileout, "wb");
00082     bbufferWriteStream(bb2, fp, nbytes, &nout);
00083     fprintf(stderr, " bytes written out to fileout: %d\n", nout);
00084             
00085     bbufferDestroy(&bb);
00086     bbufferDestroy(&bb2);
00087     lept_free(array2);
00088 #endif
00089 
00090     lept_free(array1);
00091     return 0;
00092 }
00093 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines