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 * byteatest.c 00018 * 00019 */ 00020 00021 #include <string.h> 00022 #include "allheaders.h" 00023 00024 main(int argc, 00025 char **argv) 00026 { 00027 char *str; 00028 l_uint8 *data1, *data2; 00029 l_int32 i, n, start, end, same1, same2; 00030 size_t size1, size2; 00031 FILE *fp; 00032 NUMA *na; 00033 SARRAY *sa; 00034 L_BYTEA *lba1, *lba2, *lba3, *lba4, *lba5; 00035 static char mainName[] = "byteatest"; 00036 00037 if (argc != 1) 00038 exit(ERROR_INT("syntax: whatever11", mainName, 1)); 00039 00040 /* Test basic init, join and split */ 00041 lba1 = l_byteaInitFromFile("feyn.tif"); 00042 lba2 = l_byteaInitFromFile("test24.jpg"); 00043 size1 = l_byteaGetSize(lba1); 00044 size2 = l_byteaGetSize(lba2); 00045 l_byteaJoin(lba1, &lba2); 00046 lba3 = l_byteaInitFromMem(lba1->data, size1); 00047 lba4 = l_byteaInitFromMem(lba1->data + size1, size2); 00048 00049 /* Split by hand */ 00050 l_binaryWrite("junk1", "w", lba3->data, lba3->size); 00051 l_binaryWrite("junk2", "w", lba4->data, lba4->size); 00052 filesAreIdentical("feyn.tif", "junk1", &same1); 00053 filesAreIdentical("test24.jpg", "junk2", &same2); 00054 if (same1 && same2) 00055 fprintf(stderr, "OK for join file\n"); 00056 else 00057 fprintf(stderr, "Error: files are different!\n"); 00058 00059 /* Split by function */ 00060 l_byteaSplit(lba1, size1, &lba5); 00061 l_binaryWrite("junk3", "w", lba1->data, lba1->size); 00062 l_binaryWrite("junk4", "w", lba5->data, lba5->size); 00063 filesAreIdentical("feyn.tif", "junk3", &same1); 00064 filesAreIdentical("test24.jpg", "junk4", &same2); 00065 if (same1 && same2) 00066 fprintf(stderr, "OK for split file\n"); 00067 else 00068 fprintf(stderr, "Error: files are different!\n"); 00069 l_byteaDestroy(&lba1); 00070 l_byteaDestroy(&lba2); 00071 l_byteaDestroy(&lba3); 00072 l_byteaDestroy(&lba4); 00073 l_byteaDestroy(&lba5); 00074 00075 /* Test appending */ 00076 data1 = l_binaryRead("whatever10.c", &size1); 00077 sa = sarrayCreateLinesFromString((char *)data1, 1); 00078 lba1 = l_byteaCreate(0); 00079 n = sarrayGetCount(sa); 00080 for (i = 0; i < n; i++) { 00081 str = sarrayGetString(sa, i, L_NOCOPY); 00082 l_byteaAppendString(lba1, str); 00083 l_byteaAppendString(lba1, (char *)"\n"); 00084 } 00085 data2 = l_byteaGetData(lba1, &size2); 00086 l_binaryWrite("junk1.txt", "w", data2, size2); 00087 filesAreIdentical("whatever10.c", "junk1.txt", &same1); 00088 if (same1) 00089 fprintf(stderr, "OK for appended file\n"); 00090 else 00091 fprintf(stderr, "Error: appended file is different!\n"); 00092 lept_free(data1); 00093 sarrayDestroy(&sa); 00094 l_byteaDestroy(&lba1); 00095 00096 /* Test search */ 00097 convertToPdf("test24.jpg", L_JPEG_ENCODE, 0, "junk3.pdf", 00098 0, 0, 100, NULL, 0, NULL); 00099 lba1 = l_byteaInitFromFile("junk3.pdf"); 00100 l_byteaFindEachSequence(lba1, (l_uint8 *)" 0 obj\n", 7, &na); 00101 numaWriteStream(stderr, na); 00102 l_byteaDestroy(&lba1); 00103 numaDestroy(&na); 00104 00105 /* Test write to file */ 00106 lba1 = l_byteaInitFromFile("feyn.tif"); 00107 fp = lept_fopen("junk5", "wb"); 00108 size1 = l_byteaGetSize(lba1); 00109 for (start = 0; start < size1; start += 1000) { 00110 end = L_MIN(start + 1000 - 1, size1 - 1); 00111 l_byteaWriteStream(fp, lba1, start, end); 00112 } 00113 lept_fclose(fp); 00114 l_byteaDestroy(&lba1); 00115 00116 return 0; 00117 } 00118 00119