├── .gitignore ├── LICENSE ├── Makefile ├── README ├── fet ├── allocfet.c ├── delfet.c ├── extrfet.c ├── freefet.c ├── lkupfet.c ├── nistcom.c ├── printfet.c ├── readfet.c ├── strfet.c ├── updatfet.c └── writefet.c ├── include ├── computil.h ├── dataio.h ├── defs.h ├── fet.h ├── ihead.h ├── ioutil.h ├── jpegl.h ├── jpeglsd4.h ├── nistcom.h ├── swap.h ├── usebsd.h ├── util.h └── wsq.h ├── ioutil ├── dataio.c └── filesize.c ├── jpegl ├── decoder.c ├── encoder.c ├── huff.c ├── huftable.c ├── imgdat.c ├── ppi.c ├── sd4util.c ├── tableio.c └── util.c ├── png2wsq.c ├── util ├── computil.c ├── fatalerr.c └── syserr.c ├── wsq ├── cropcoeff.c ├── decoder.c ├── encoder.c ├── globals.c ├── huff.c ├── ppi.c ├── sd14util.c ├── tableio.c ├── tree.c └── util.c └── wsq2png.c /.gitignore: -------------------------------------------------------------------------------- 1 | .* 2 | .gitconfig 3 | ~* 4 | *.pro.user* 5 | *.o 6 | *.so 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015, Paweł Moll 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # libwsq imported from NBIS rel 4.2.0 2 | 3 | OBJS := wsq/cropcoeff.o wsq/decoder.o wsq/encoder.o wsq/globals.o wsq/huff.o wsq/ppi.o wsq/sd14util.o wsq/tableio.o wsq/tree.o wsq/util.o 4 | OBJS += jpegl/decoder.o jpegl/encoder.o jpegl/huff.o jpegl/huftable.o jpegl/imgdat.o jpegl/ppi.o jpegl/sd4util.o jpegl/tableio.o jpegl/util.o 5 | OBJS += fet/allocfet.o fet/extrfet.o fet/lkupfet.o fet/printfet.o fet/strfet.o fet/writefet.o fet/delfet.o fet/freefet.o fet/nistcom.o fet/readfet.o fet/updatfet.o 6 | OBJS += util/computil.o util/syserr.o util/fatalerr.o 7 | OBJS += ioutil/dataio.o ioutil/filesize.o 8 | 9 | CPPFLAGS := -Iinclude 10 | CFLAGS := -Wall -g -D__NBISLE__ 11 | LDFLAGS := -lm 12 | 13 | all: png2wsq wsq2png 14 | 15 | clean: 16 | rm -f $(OBJS) 17 | rm -f png2wsq png2wsq.o 18 | rm -f wsq2png wsq2png.o 19 | 20 | png2wsq: png2wsq.o $(OBJS) 21 | $(CC) $^ -o $@ -lpng $(LDFLAGS) 22 | 23 | png2wsq.o: png2wsq.c 24 | 25 | wsq2png: wsq2png.o $(OBJS) 26 | $(CC) $^ -o $@ -lpng $(LDFLAGS) 27 | 28 | wsq2png.o: wsq2png.c 29 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | This is a simple tool allowing conversion between Wavelet Scalar 2 | Quantization (WSQ) image format and standard PNG. 3 | 4 | WSQ is mainly used for fingerprint images, see more details here: 5 | 6 | http://www.nist.gov/itl/iad/ig/wsq.cfm 7 | 8 | This implementation is taken from NBIS rel 4.2.0 released into 9 | Public Domain. See more details here: 10 | 11 | http://www.nist.gov/itl/iad/ig/nbis.cfm 12 | -------------------------------------------------------------------------------- /fet/allocfet.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | License: 4 | This software and/or related materials was developed at the National Institute 5 | of Standards and Technology (NIST) by employees of the Federal Government 6 | in the course of their official duties. Pursuant to title 17 Section 105 7 | of the United States Code, this software is not subject to copyright 8 | protection and is in the public domain. 9 | 10 | This software and/or related materials have been determined to be not subject 11 | to the EAR (see Part 734.3 of the EAR for exact details) because it is 12 | a publicly available technology and software, and is freely distributed 13 | to any interested party with no licensing requirements. Therefore, it is 14 | permissible to distribute this software as a free download from the internet. 15 | 16 | Disclaimer: 17 | This software and/or related materials was developed to promote biometric 18 | standards and biometric technology testing for the Federal Government 19 | in accordance with the USA PATRIOT Act and the Enhanced Border Security 20 | and Visa Entry Reform Act. Specific hardware and software products identified 21 | in this software were used in order to perform the software development. 22 | In no case does such identification imply recommendation or endorsement 23 | by the National Institute of Standards and Technology, nor does it imply that 24 | the products and equipment identified are necessarily the best available 25 | for the purpose. 26 | 27 | This software and/or related materials are provided "AS-IS" without warranty 28 | of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, 29 | NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY 30 | or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the 31 | licensed product, however used. In no event shall NIST be liable for any 32 | damages and/or costs, including but not limited to incidental or consequential 33 | damages of any kind, including economic damage or injury to property and lost 34 | profits, regardless of whether NIST shall be advised, have reason to know, 35 | or in fact shall know of the possibility. 36 | 37 | By using this software, you agree to bear all risk relating to quality, 38 | use and performance of the software and/or related materials. You agree 39 | to hold the Government harmless from any claim arising from your use 40 | of the software. 41 | 42 | *******************************************************************************/ 43 | 44 | 45 | /*********************************************************************** 46 | LIBRARY: FET - Feature File/List Utilities 47 | 48 | FILE: ALLOCFET.C 49 | AUTHOR: Michael Garris 50 | DATE: 01/11/2001 51 | UPDATED: 03/10/2005 by MDG 52 | 53 | Contains routines responsibile allocating data structures 54 | used to hold attribute-value paired lists. 55 | 56 | ROUTINES: 57 | #cat: allocfet - allocates and initialized an empty fet structure. 58 | #cat: Exits on error. 59 | #cat: allocfet_ret - allocates and initialized an empty fet structure. 60 | #cat: Returns on error. 61 | #cat: reallocfet - reallocates an fet structure of a 62 | #cat: specified length. Exits on error. 63 | #cat: reallocfet_ret - reallocates an fet structure of a 64 | #cat: specified length. Returns on error. 65 | 66 | ***********************************************************************/ 67 | 68 | #include 69 | #include 70 | #include 71 | 72 | /********************************************************************/ 73 | FET *allocfet(int numfeatures) 74 | { 75 | FET *fet; 76 | 77 | fet = (FET *)malloc(sizeof(FET)); 78 | if (fet == (FET *)NULL) 79 | syserr("allocfet","malloc","fet"); 80 | /* calloc here is required */ 81 | fet->names = (char **)calloc(numfeatures, sizeof(char *)); 82 | if (fet->names == (char **)NULL) 83 | syserr("allocfet","calloc","fet->names"); 84 | fet->values = (char **)calloc(numfeatures, sizeof(char *)); 85 | if (fet->values == (char **)NULL) 86 | syserr("allocfet","calloc","fet->values"); 87 | fet->alloc = numfeatures; 88 | fet->num = 0; 89 | return(fet); 90 | } 91 | 92 | /********************************************************************/ 93 | int allocfet_ret(FET **ofet, int numfeatures) 94 | { 95 | FET *fet; 96 | 97 | fet = (FET *)malloc(sizeof(FET)); 98 | if (fet == (FET *)NULL){ 99 | fprintf(stderr, "ERROR : allocfet_ret : malloc : fet\n"); 100 | return(-2); 101 | } 102 | /* calloc here is required */ 103 | fet->names = (char **)calloc(numfeatures, sizeof(char *)); 104 | if (fet->names == (char **)NULL){ 105 | fprintf(stderr, "ERROR : allocfet_ret : calloc : fet->names\n"); 106 | free(fet); 107 | return(-3); 108 | } 109 | fet->values = (char **)calloc(numfeatures, sizeof(char *)); 110 | if (fet->values == (char **)NULL){ 111 | fprintf(stderr, "ERROR : allocfet_ret : calloc : fet->values\n"); 112 | free(fet->names); 113 | free(fet); 114 | return(-4); 115 | } 116 | fet->alloc = numfeatures; 117 | fet->num = 0; 118 | 119 | *ofet = fet; 120 | 121 | return(0); 122 | } 123 | 124 | /********************************************************************/ 125 | FET *reallocfet(FET *fet, int newlen) 126 | { 127 | if (fet == (FET *)NULL || fet->alloc == 0) 128 | return(allocfet(newlen)); 129 | 130 | fet->names = (char **)realloc(fet->names, newlen * sizeof(char *)); 131 | if (fet->names == (char **)NULL) 132 | fatalerr("reallocfet", "realloc", "space for increased fet->names"); 133 | fet->values = (char **)realloc(fet->values, newlen * sizeof(char *)); 134 | if (fet->values == (char **)NULL) 135 | fatalerr("reallocfet", "realloc", "space for increased fet->values"); 136 | fet->alloc = newlen; 137 | 138 | return(fet); 139 | } 140 | 141 | /********************************************************************/ 142 | int reallocfet_ret(FET **ofet, int newlen) 143 | { 144 | int ret; 145 | FET *fet; 146 | 147 | fet = *ofet; 148 | 149 | /* If fet not allocated ... */ 150 | if ((fet == (FET *)NULL || fet->alloc == 0)){ 151 | /* Allocate the fet. */ 152 | if((ret = allocfet_ret(ofet, newlen))) 153 | /* Return error code. */ 154 | return(ret); 155 | /* Otherwise allocation was successful. */ 156 | return(0); 157 | } 158 | 159 | /* Oherwise, reallocate fet. */ 160 | fet->names = (char **)realloc(fet->names, newlen * sizeof(char *)); 161 | if (fet->names == (char **)NULL){ 162 | fprintf(stderr, "ERROR : reallocfet_ret : realloc : fet->names\n"); 163 | return(-2); 164 | } 165 | fet->values = (char **)realloc(fet->values, newlen * sizeof(char *)); 166 | if (fet->values == (char **)NULL){ 167 | fprintf(stderr, "ERROR : reallocfet_ret : realloc : fet->values"); 168 | return(-3); 169 | } 170 | fet->alloc = newlen; 171 | 172 | return(0); 173 | } 174 | -------------------------------------------------------------------------------- /fet/delfet.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | License: 4 | This software and/or related materials was developed at the National Institute 5 | of Standards and Technology (NIST) by employees of the Federal Government 6 | in the course of their official duties. Pursuant to title 17 Section 105 7 | of the United States Code, this software is not subject to copyright 8 | protection and is in the public domain. 9 | 10 | This software and/or related materials have been determined to be not subject 11 | to the EAR (see Part 734.3 of the EAR for exact details) because it is 12 | a publicly available technology and software, and is freely distributed 13 | to any interested party with no licensing requirements. Therefore, it is 14 | permissible to distribute this software as a free download from the internet. 15 | 16 | Disclaimer: 17 | This software and/or related materials was developed to promote biometric 18 | standards and biometric technology testing for the Federal Government 19 | in accordance with the USA PATRIOT Act and the Enhanced Border Security 20 | and Visa Entry Reform Act. Specific hardware and software products identified 21 | in this software were used in order to perform the software development. 22 | In no case does such identification imply recommendation or endorsement 23 | by the National Institute of Standards and Technology, nor does it imply that 24 | the products and equipment identified are necessarily the best available 25 | for the purpose. 26 | 27 | This software and/or related materials are provided "AS-IS" without warranty 28 | of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, 29 | NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY 30 | or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the 31 | licensed product, however used. In no event shall NIST be liable for any 32 | damages and/or costs, including but not limited to incidental or consequential 33 | damages of any kind, including economic damage or injury to property and lost 34 | profits, regardless of whether NIST shall be advised, have reason to know, 35 | or in fact shall know of the possibility. 36 | 37 | By using this software, you agree to bear all risk relating to quality, 38 | use and performance of the software and/or related materials. You agree 39 | to hold the Government harmless from any claim arising from your use 40 | of the software. 41 | 42 | *******************************************************************************/ 43 | 44 | 45 | /*********************************************************************** 46 | LIBRARY: FET - Feature File/List Utilities 47 | 48 | FILE: DELFET.C 49 | AUTHOR: Michael Garris 50 | DATE: 01/11/2001 51 | UPDATED: 03/10/2005 by MDG 52 | 53 | Contains routines responsible for removing an entry from an 54 | attribute-value paired list. 55 | 56 | ROUTINES: 57 | #cat: deletefet - removes the specified feature entry from an fet structure. 58 | #cat: Exits on error. 59 | #cat: deletefet_ret - removes the specified feature entry from an fet 60 | #cat: structure. Returns on error. 61 | 62 | ***********************************************************************/ 63 | 64 | #include 65 | #include 66 | #include 67 | #include 68 | 69 | /*********************************************************************/ 70 | void deletefet(char *feature, FET *fet) 71 | { 72 | int item; 73 | 74 | for (item = 0; 75 | (item < fet->num) && (strcmp(fet->names[item],feature) != 0); 76 | item++); 77 | if(item >= fet->num) 78 | fatalerr("deletefet",feature,"Feature not found"); 79 | free(fet->names[item]); 80 | if(fet->values[item] != (char *)NULL) 81 | free(fet->values[item]); 82 | for (++item;itemnum;item++){ 83 | fet->names[item-1] = fet->names[item]; 84 | fet->values[item-1] = fet->values[item]; 85 | } 86 | fet->names[fet->num-1] = '\0'; 87 | fet->values[fet->num-1] = '\0'; 88 | (fet->num)--; 89 | } 90 | 91 | /*********************************************************************/ 92 | int deletefet_ret(char *feature, FET *fet) 93 | { 94 | int item; 95 | 96 | for (item = 0; 97 | (item < fet->num) && (strcmp(fet->names[item],feature) != 0); 98 | item++); 99 | if(item >= fet->num){ 100 | fprintf(stderr, "ERROR : deletefet_ret : feature %s not found\n", 101 | feature); 102 | return(-2); 103 | } 104 | free(fet->names[item]); 105 | if(fet->values[item] != (char *)NULL) 106 | free(fet->values[item]); 107 | for (++item;itemnum;item++){ 108 | fet->names[item-1] = fet->names[item]; 109 | fet->values[item-1] = fet->values[item]; 110 | } 111 | fet->names[fet->num-1] = '\0'; 112 | fet->values[fet->num-1] = '\0'; 113 | (fet->num)--; 114 | 115 | return(0); 116 | } 117 | -------------------------------------------------------------------------------- /fet/extrfet.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | License: 4 | This software and/or related materials was developed at the National Institute 5 | of Standards and Technology (NIST) by employees of the Federal Government 6 | in the course of their official duties. Pursuant to title 17 Section 105 7 | of the United States Code, this software is not subject to copyright 8 | protection and is in the public domain. 9 | 10 | This software and/or related materials have been determined to be not subject 11 | to the EAR (see Part 734.3 of the EAR for exact details) because it is 12 | a publicly available technology and software, and is freely distributed 13 | to any interested party with no licensing requirements. Therefore, it is 14 | permissible to distribute this software as a free download from the internet. 15 | 16 | Disclaimer: 17 | This software and/or related materials was developed to promote biometric 18 | standards and biometric technology testing for the Federal Government 19 | in accordance with the USA PATRIOT Act and the Enhanced Border Security 20 | and Visa Entry Reform Act. Specific hardware and software products identified 21 | in this software were used in order to perform the software development. 22 | In no case does such identification imply recommendation or endorsement 23 | by the National Institute of Standards and Technology, nor does it imply that 24 | the products and equipment identified are necessarily the best available 25 | for the purpose. 26 | 27 | This software and/or related materials are provided "AS-IS" without warranty 28 | of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, 29 | NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY 30 | or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the 31 | licensed product, however used. In no event shall NIST be liable for any 32 | damages and/or costs, including but not limited to incidental or consequential 33 | damages of any kind, including economic damage or injury to property and lost 34 | profits, regardless of whether NIST shall be advised, have reason to know, 35 | or in fact shall know of the possibility. 36 | 37 | By using this software, you agree to bear all risk relating to quality, 38 | use and performance of the software and/or related materials. You agree 39 | to hold the Government harmless from any claim arising from your use 40 | of the software. 41 | 42 | *******************************************************************************/ 43 | 44 | 45 | /*********************************************************************** 46 | LIBRARY: FET - Feature File/List Utilities 47 | 48 | FILE: EXTRFET.C 49 | AUTHOR: Michael Garris 50 | DATE: 01/11/2001 51 | UPDATED: 03/10/2005 by MDG 52 | 02/28/2007 by Kenneth KO 53 | 54 | Contains routines responsible for locating and returning the 55 | value stored with a specified attribute in an attribute-value 56 | paired list. 57 | 58 | ROUTINES: 59 | #cat: extractfet - returns the specified feature entry from an fet structure. 60 | #cat: Exits on error. 61 | #cat: extractfet_ret - returns the specified feature entry from an fet 62 | #cat: structure. Returns on error. 63 | 64 | ***********************************************************************/ 65 | 66 | #include 67 | #include 68 | #include 69 | #include 70 | #include 71 | 72 | 73 | /*******************************************************************/ 74 | char *extractfet(char *feature, FET *fet) 75 | { 76 | int item; 77 | char *value; 78 | 79 | for (item = 0; 80 | (item < fet->num) && (strcmp(fet->names[item],feature) != 0); 81 | item++); 82 | if (item>=fet->num) 83 | fatalerr("extractfet",feature,"not found"); 84 | if(fet->values[item] != (char *)NULL){ 85 | value = strdup(fet->values[item]); 86 | if (value == (char *)NULL) 87 | syserr("extractfet","strdup","value"); 88 | } 89 | else 90 | value = (char *)NULL; 91 | return(value); 92 | } 93 | 94 | /*******************************************************************/ 95 | int extractfet_ret(char **ovalue, char *feature, FET *fet) 96 | { 97 | int item; 98 | char *value; 99 | 100 | for (item = 0; 101 | (item < fet->num) && (strcmp(fet->names[item],feature) != 0); 102 | item++); 103 | if (item>=fet->num){ 104 | fprintf(stderr, "ERROR : extractfet_ret : feature %s not found\n", 105 | feature); 106 | return(-2); 107 | } 108 | if(fet->values[item] != (char *)NULL){ 109 | value = (char *)strdup(fet->values[item]); 110 | if (value == (char *)NULL){ 111 | fprintf(stderr, "ERROR : extractfet_ret : strdup : value\n"); 112 | return(-3); 113 | } 114 | } 115 | else 116 | value = (char *)NULL; 117 | 118 | *ovalue = value; 119 | 120 | return(0); 121 | } 122 | -------------------------------------------------------------------------------- /fet/freefet.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | License: 4 | This software and/or related materials was developed at the National Institute 5 | of Standards and Technology (NIST) by employees of the Federal Government 6 | in the course of their official duties. Pursuant to title 17 Section 105 7 | of the United States Code, this software is not subject to copyright 8 | protection and is in the public domain. 9 | 10 | This software and/or related materials have been determined to be not subject 11 | to the EAR (see Part 734.3 of the EAR for exact details) because it is 12 | a publicly available technology and software, and is freely distributed 13 | to any interested party with no licensing requirements. Therefore, it is 14 | permissible to distribute this software as a free download from the internet. 15 | 16 | Disclaimer: 17 | This software and/or related materials was developed to promote biometric 18 | standards and biometric technology testing for the Federal Government 19 | in accordance with the USA PATRIOT Act and the Enhanced Border Security 20 | and Visa Entry Reform Act. Specific hardware and software products identified 21 | in this software were used in order to perform the software development. 22 | In no case does such identification imply recommendation or endorsement 23 | by the National Institute of Standards and Technology, nor does it imply that 24 | the products and equipment identified are necessarily the best available 25 | for the purpose. 26 | 27 | This software and/or related materials are provided "AS-IS" without warranty 28 | of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, 29 | NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY 30 | or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the 31 | licensed product, however used. In no event shall NIST be liable for any 32 | damages and/or costs, including but not limited to incidental or consequential 33 | damages of any kind, including economic damage or injury to property and lost 34 | profits, regardless of whether NIST shall be advised, have reason to know, 35 | or in fact shall know of the possibility. 36 | 37 | By using this software, you agree to bear all risk relating to quality, 38 | use and performance of the software and/or related materials. You agree 39 | to hold the Government harmless from any claim arising from your use 40 | of the software. 41 | 42 | *******************************************************************************/ 43 | 44 | 45 | /*********************************************************************** 46 | LIBRARY: FET - Feature File/List Utilities 47 | 48 | FILE: FREEFET.C 49 | AUTHOR: Michael Garris 50 | DATE: 01/11/2001 51 | 52 | Contains routines responsible for the deallocation of a data 53 | structure used to hold an attribute-value paired list. 54 | 55 | ROUTINES: 56 | #cat: freefet - deallocates the memory for an fet structure. 57 | #cat: 58 | 59 | ***********************************************************************/ 60 | 61 | #include 62 | 63 | void freefet(FET *fet) 64 | { 65 | int item; 66 | for (item=0;itemnum;item++){ 67 | free (fet->names[item]); 68 | free (fet->values[item]); 69 | } 70 | free((char *)fet->names); 71 | free((char *)fet->values); 72 | free(fet); 73 | } 74 | -------------------------------------------------------------------------------- /fet/lkupfet.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | License: 4 | This software and/or related materials was developed at the National Institute 5 | of Standards and Technology (NIST) by employees of the Federal Government 6 | in the course of their official duties. Pursuant to title 17 Section 105 7 | of the United States Code, this software is not subject to copyright 8 | protection and is in the public domain. 9 | 10 | This software and/or related materials have been determined to be not subject 11 | to the EAR (see Part 734.3 of the EAR for exact details) because it is 12 | a publicly available technology and software, and is freely distributed 13 | to any interested party with no licensing requirements. Therefore, it is 14 | permissible to distribute this software as a free download from the internet. 15 | 16 | Disclaimer: 17 | This software and/or related materials was developed to promote biometric 18 | standards and biometric technology testing for the Federal Government 19 | in accordance with the USA PATRIOT Act and the Enhanced Border Security 20 | and Visa Entry Reform Act. Specific hardware and software products identified 21 | in this software were used in order to perform the software development. 22 | In no case does such identification imply recommendation or endorsement 23 | by the National Institute of Standards and Technology, nor does it imply that 24 | the products and equipment identified are necessarily the best available 25 | for the purpose. 26 | 27 | This software and/or related materials are provided "AS-IS" without warranty 28 | of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, 29 | NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY 30 | or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the 31 | licensed product, however used. In no event shall NIST be liable for any 32 | damages and/or costs, including but not limited to incidental or consequential 33 | damages of any kind, including economic damage or injury to property and lost 34 | profits, regardless of whether NIST shall be advised, have reason to know, 35 | or in fact shall know of the possibility. 36 | 37 | By using this software, you agree to bear all risk relating to quality, 38 | use and performance of the software and/or related materials. You agree 39 | to hold the Government harmless from any claim arising from your use 40 | of the software. 41 | 42 | *******************************************************************************/ 43 | 44 | 45 | /*********************************************************************** 46 | LIBRARY: FET - Feature File/List Utilities 47 | 48 | FILE: LKUPFET.C 49 | AUTHOR: Michael Garris 50 | DATE: 01/11/2001 51 | UPDATED: 02/28/2007 52 | 53 | Contains routines responsible for looking up the value of 54 | a specified attribute in and attribute-value paired list. 55 | 56 | ROUTINES: 57 | #cat: lookupfet - returns the specified feature entry from an fet 58 | #cat: structure. Returns TRUE if found, FALSE if not. 59 | 60 | ***********************************************************************/ 61 | 62 | #include 63 | #include 64 | #include 65 | #include 66 | #include 67 | 68 | /*******************************************************************/ 69 | int lookupfet(char **ovalue, char *feature, FET *fet) 70 | { 71 | int item; 72 | char *value; 73 | 74 | for (item = 0; 75 | (item < fet->num) && (strcmp(fet->names[item],feature) != 0); 76 | item++); 77 | if (item>=fet->num){ 78 | return(FALSE); 79 | } 80 | if(fet->values[item] != (char *)NULL){ 81 | value = strdup(fet->values[item]); 82 | if (value == (char *)NULL){ 83 | fprintf(stderr, "ERROR : lookupfet : strdup : value\n"); 84 | return(-2); 85 | } 86 | } 87 | else 88 | value = (char *)NULL; 89 | 90 | *ovalue = value; 91 | 92 | return(TRUE); 93 | } 94 | -------------------------------------------------------------------------------- /fet/printfet.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | License: 4 | This software and/or related materials was developed at the National Institute 5 | of Standards and Technology (NIST) by employees of the Federal Government 6 | in the course of their official duties. Pursuant to title 17 Section 105 7 | of the United States Code, this software is not subject to copyright 8 | protection and is in the public domain. 9 | 10 | This software and/or related materials have been determined to be not subject 11 | to the EAR (see Part 734.3 of the EAR for exact details) because it is 12 | a publicly available technology and software, and is freely distributed 13 | to any interested party with no licensing requirements. Therefore, it is 14 | permissible to distribute this software as a free download from the internet. 15 | 16 | Disclaimer: 17 | This software and/or related materials was developed to promote biometric 18 | standards and biometric technology testing for the Federal Government 19 | in accordance with the USA PATRIOT Act and the Enhanced Border Security 20 | and Visa Entry Reform Act. Specific hardware and software products identified 21 | in this software were used in order to perform the software development. 22 | In no case does such identification imply recommendation or endorsement 23 | by the National Institute of Standards and Technology, nor does it imply that 24 | the products and equipment identified are necessarily the best available 25 | for the purpose. 26 | 27 | This software and/or related materials are provided "AS-IS" without warranty 28 | of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, 29 | NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY 30 | or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the 31 | licensed product, however used. In no event shall NIST be liable for any 32 | damages and/or costs, including but not limited to incidental or consequential 33 | damages of any kind, including economic damage or injury to property and lost 34 | profits, regardless of whether NIST shall be advised, have reason to know, 35 | or in fact shall know of the possibility. 36 | 37 | By using this software, you agree to bear all risk relating to quality, 38 | use and performance of the software and/or related materials. You agree 39 | to hold the Government harmless from any claim arising from your use 40 | of the software. 41 | 42 | *******************************************************************************/ 43 | 44 | 45 | /*********************************************************************** 46 | LIBRARY: FET - Feature File/List Utilities 47 | 48 | FILE: PRINTFET.C 49 | AUTHOR: Michael Garris 50 | DATE: 01/11/2001 51 | 52 | Contains routines responsible for printing the contents of 53 | a data structure holding an attribute-value paired list. 54 | 55 | ROUTINES: 56 | #cat: printfet - dumps the contents of an fet structure to the specified 57 | #cat: open file pointer. 58 | 59 | ***********************************************************************/ 60 | 61 | #include 62 | #include 63 | 64 | void printfet(FILE *fp, FET *fet) 65 | { 66 | int item; 67 | 68 | for (item = 0; itemnum; item++){ 69 | if(fet->values[item] == (char *)NULL) 70 | fprintf(fp,"%s\n",fet->names[item]); 71 | else 72 | fprintf(fp,"%s %s\n",fet->names[item],fet->values[item]); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /fet/readfet.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | License: 4 | This software and/or related materials was developed at the National Institute 5 | of Standards and Technology (NIST) by employees of the Federal Government 6 | in the course of their official duties. Pursuant to title 17 Section 105 7 | of the United States Code, this software is not subject to copyright 8 | protection and is in the public domain. 9 | 10 | This software and/or related materials have been determined to be not subject 11 | to the EAR (see Part 734.3 of the EAR for exact details) because it is 12 | a publicly available technology and software, and is freely distributed 13 | to any interested party with no licensing requirements. Therefore, it is 14 | permissible to distribute this software as a free download from the internet. 15 | 16 | Disclaimer: 17 | This software and/or related materials was developed to promote biometric 18 | standards and biometric technology testing for the Federal Government 19 | in accordance with the USA PATRIOT Act and the Enhanced Border Security 20 | and Visa Entry Reform Act. Specific hardware and software products identified 21 | in this software were used in order to perform the software development. 22 | In no case does such identification imply recommendation or endorsement 23 | by the National Institute of Standards and Technology, nor does it imply that 24 | the products and equipment identified are necessarily the best available 25 | for the purpose. 26 | 27 | This software and/or related materials are provided "AS-IS" without warranty 28 | of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, 29 | NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY 30 | or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the 31 | licensed product, however used. In no event shall NIST be liable for any 32 | damages and/or costs, including but not limited to incidental or consequential 33 | damages of any kind, including economic damage or injury to property and lost 34 | profits, regardless of whether NIST shall be advised, have reason to know, 35 | or in fact shall know of the possibility. 36 | 37 | By using this software, you agree to bear all risk relating to quality, 38 | use and performance of the software and/or related materials. You agree 39 | to hold the Government harmless from any claim arising from your use 40 | of the software. 41 | 42 | *******************************************************************************/ 43 | 44 | 45 | /*********************************************************************** 46 | LIBRARY: FET - Feature File/List Utilities 47 | 48 | FILE: READFET.C 49 | AUTHOR: Michael Garris 50 | DATE: 01/11/2001 51 | UPDATED: 03/10/2005 by MDG 52 | 02/28/2007 by Kenneth Ko 53 | 54 | Contains routines responsible for reading the contents of 55 | a file into a data structure holding an attribute-value 56 | paired list. 57 | 58 | ROUTINES: 59 | #cat: readfetfile - opens an fet file and reads its contents into an 60 | #cat: fet structure. Exits on error. 61 | #cat: readfetfile_ret - opens an fet file and reads its contents into an 62 | #cat: fet structure. Returns on error. 63 | 64 | ***********************************************************************/ 65 | 66 | #include 67 | #include 68 | #include 69 | #include 70 | #include 71 | 72 | /*****************************************************************/ 73 | FET *readfetfile(char *file) 74 | { 75 | FILE *fp; 76 | FET *fet; 77 | char c,buf[MAXFETLENGTH]; 78 | 79 | if ((fp = fopen(file,"rb")) == (FILE *)NULL) 80 | syserr("readfetfile","fopen",file); 81 | 82 | fet = allocfet(MAXFETS); 83 | while (fscanf(fp,"%s",buf) != EOF){ 84 | while(((c = getc(fp)) == ' ') || (c == '\t')); 85 | ungetc(c, fp); 86 | if (fet->num >= fet->alloc) 87 | reallocfet(fet, fet->alloc + MAXFETS); 88 | fet->names[fet->num] = strdup(buf); 89 | if(fet->names[fet->num] == (char *)NULL) 90 | syserr("readfetfile","strdup","fet->names[]"); 91 | fgets(buf,MAXFETLENGTH-1,fp); 92 | buf[strlen(buf)-1] = '\0'; 93 | fet->values[fet->num] = (char *)strdup(buf); 94 | if(fet->values[fet->num] == (char *)NULL) 95 | syserr("readfetfile","strdup","fet->values[]"); 96 | (fet->num)++; 97 | } 98 | fclose(fp); 99 | return(fet); 100 | } 101 | 102 | /*****************************************************************/ 103 | int readfetfile_ret(FET **ofet, char *file) 104 | { 105 | int ret; 106 | FILE *fp; 107 | FET *fet; 108 | char c,buf[MAXFETLENGTH]; 109 | 110 | if ((fp = fopen(file,"rb")) == (FILE *)NULL){ 111 | fprintf(stderr, "ERROR : readfetfile_ret : fopen : %s\n", file); 112 | return(-2); 113 | } 114 | 115 | if((ret = allocfet_ret(&fet, MAXFETS))){ 116 | fclose(fp); 117 | return(ret); 118 | } 119 | 120 | while (fscanf(fp,"%s",buf) != EOF){ 121 | while(((c = getc(fp)) == ' ') || (c == '\t')); 122 | ungetc(c, fp); 123 | if (fet->num >= fet->alloc){ 124 | if((ret = reallocfet_ret(&fet, fet->alloc + MAXFETS))){ 125 | fclose(fp); 126 | freefet(fet); 127 | return(ret); 128 | } 129 | } 130 | fet->names[fet->num] = (char *)strdup(buf); 131 | if(fet->names[fet->num] == (char *)NULL){ 132 | fprintf(stderr, "ERROR : readfetfile_ret : strdup : fet->names[]\n"); 133 | fclose(fp); 134 | freefet(fet); 135 | return(-3); 136 | } 137 | fgets(buf,MAXFETLENGTH-1,fp); 138 | buf[strlen(buf)-1] = '\0'; 139 | fet->values[fet->num] = (char *)strdup(buf); 140 | if(fet->values[fet->num] == (char *)NULL){ 141 | fprintf(stderr, "ERROR : readfetfile_ret : strdup : fet->values[]\n"); 142 | fclose(fp); 143 | freefet(fet); 144 | return(-4); 145 | } 146 | (fet->num)++; 147 | } 148 | fclose(fp); 149 | *ofet = fet; 150 | 151 | return(0); 152 | } 153 | -------------------------------------------------------------------------------- /fet/strfet.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | License: 4 | This software and/or related materials was developed at the National Institute 5 | of Standards and Technology (NIST) by employees of the Federal Government 6 | in the course of their official duties. Pursuant to title 17 Section 105 7 | of the United States Code, this software is not subject to copyright 8 | protection and is in the public domain. 9 | 10 | This software and/or related materials have been determined to be not subject 11 | to the EAR (see Part 734.3 of the EAR for exact details) because it is 12 | a publicly available technology and software, and is freely distributed 13 | to any interested party with no licensing requirements. Therefore, it is 14 | permissible to distribute this software as a free download from the internet. 15 | 16 | Disclaimer: 17 | This software and/or related materials was developed to promote biometric 18 | standards and biometric technology testing for the Federal Government 19 | in accordance with the USA PATRIOT Act and the Enhanced Border Security 20 | and Visa Entry Reform Act. Specific hardware and software products identified 21 | in this software were used in order to perform the software development. 22 | In no case does such identification imply recommendation or endorsement 23 | by the National Institute of Standards and Technology, nor does it imply that 24 | the products and equipment identified are necessarily the best available 25 | for the purpose. 26 | 27 | This software and/or related materials are provided "AS-IS" without warranty 28 | of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, 29 | NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY 30 | or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the 31 | licensed product, however used. In no event shall NIST be liable for any 32 | damages and/or costs, including but not limited to incidental or consequential 33 | damages of any kind, including economic damage or injury to property and lost 34 | profits, regardless of whether NIST shall be advised, have reason to know, 35 | or in fact shall know of the possibility. 36 | 37 | By using this software, you agree to bear all risk relating to quality, 38 | use and performance of the software and/or related materials. You agree 39 | to hold the Government harmless from any claim arising from your use 40 | of the software. 41 | 42 | *******************************************************************************/ 43 | 44 | 45 | /*********************************************************************** 46 | LIBRARY: FET - Feature File/List Utilities 47 | 48 | FILE: STRFET.C 49 | AUTHOR: Michael Garris 50 | DATE: 01/11/2001 51 | UPDATED: 03/10/2005 by MDG 52 | 53 | Contains routines responsible for converting an attribute-value 54 | paired list to and from a null-terminated string. 55 | 56 | ROUTINES: 57 | #cat: fet2string - takes an FET structure and concatenates (name,value) 58 | #cat: pairs into a single null-terminated string with each 59 | #cat: (name,value) pair delimited by a new-line. 60 | #cat: string2fet - parses a null-terminated string representing a 61 | #cat: list of (name,value) pairs into an FET structure. 62 | 63 | ***********************************************************************/ 64 | 65 | #include 66 | #include 67 | #include 68 | 69 | /*****************************************************************/ 70 | int fet2string(char **ostr, FET *fet) 71 | { 72 | int i, size; 73 | char *str; 74 | 75 | /* Calculate size of string. */ 76 | size = 0; 77 | for(i = 0; i < fet->num; i++){ 78 | size += strlen(fet->names[i]); 79 | size += strlen(fet->values[i]); 80 | size += 2; 81 | } 82 | /* Make room for NULL for final strlen() below. */ 83 | size++; 84 | 85 | if((str = (char *)calloc(size, sizeof(char))) == (char *)NULL){ 86 | fprintf(stderr, "ERROR : fet2string : malloc : str\n"); 87 | return(-2); 88 | } 89 | 90 | for(i = 0; i < fet->num; i++){ 91 | strcat(str, fet->names[i]); 92 | strcat(str, " "); 93 | strcat(str, fet->values[i]); 94 | strcat(str, "\n"); 95 | } 96 | 97 | str[strlen(str)-1] = '\0'; 98 | 99 | *ostr = str; 100 | return(0); 101 | } 102 | 103 | /*****************************************************************/ 104 | int string2fet(FET **ofet, char *istr) 105 | { 106 | int ret; 107 | char *iptr, *optr; 108 | char name[MAXFETLENGTH], value[MAXFETLENGTH], *vptr; 109 | FET *fet; 110 | 111 | if((ret = allocfet_ret(&fet, MAXFETS))) 112 | return(ret); 113 | 114 | iptr = istr; 115 | while(*iptr != '\0'){ 116 | /* Get next name */ 117 | optr = name; 118 | while((*iptr != '\0')&&(*iptr != ' ')&&(*iptr != '\t')) 119 | *optr++ = *iptr++; 120 | *optr = '\0'; 121 | 122 | /* Skip white space */ 123 | while((*iptr != '\0')&& 124 | ((*iptr == ' ')||(*iptr == '\t'))) 125 | iptr++; 126 | 127 | /* Get next value */ 128 | optr = value; 129 | while((*iptr != '\0')&&(*iptr != '\n')) 130 | *optr++ = *iptr++; 131 | *optr = '\0'; 132 | 133 | /* Skip white space */ 134 | while((*iptr != '\0')&& 135 | ((*iptr == ' ')||(*iptr == '\t')||(*iptr == '\n'))) 136 | iptr++; 137 | 138 | /* Test (name,value) pair */ 139 | if(strlen(name) == 0){ 140 | fprintf(stderr, "ERROR : string2fet : empty name string found\n"); 141 | return(-2); 142 | } 143 | if(strlen(value) == 0) 144 | vptr = (char *)NULL; 145 | else 146 | vptr = value; 147 | 148 | /* Store name and value pair into FET. */ 149 | if((ret = updatefet_ret(name, vptr, fet))){ 150 | freefet(fet); 151 | return(ret); 152 | } 153 | } 154 | 155 | *ofet = fet; 156 | return(0); 157 | } 158 | -------------------------------------------------------------------------------- /fet/updatfet.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | License: 4 | This software and/or related materials was developed at the National Institute 5 | of Standards and Technology (NIST) by employees of the Federal Government 6 | in the course of their official duties. Pursuant to title 17 Section 105 7 | of the United States Code, this software is not subject to copyright 8 | protection and is in the public domain. 9 | 10 | This software and/or related materials have been determined to be not subject 11 | to the EAR (see Part 734.3 of the EAR for exact details) because it is 12 | a publicly available technology and software, and is freely distributed 13 | to any interested party with no licensing requirements. Therefore, it is 14 | permissible to distribute this software as a free download from the internet. 15 | 16 | Disclaimer: 17 | This software and/or related materials was developed to promote biometric 18 | standards and biometric technology testing for the Federal Government 19 | in accordance with the USA PATRIOT Act and the Enhanced Border Security 20 | and Visa Entry Reform Act. Specific hardware and software products identified 21 | in this software were used in order to perform the software development. 22 | In no case does such identification imply recommendation or endorsement 23 | by the National Institute of Standards and Technology, nor does it imply that 24 | the products and equipment identified are necessarily the best available 25 | for the purpose. 26 | 27 | This software and/or related materials are provided "AS-IS" without warranty 28 | of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, 29 | NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY 30 | or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the 31 | licensed product, however used. In no event shall NIST be liable for any 32 | damages and/or costs, including but not limited to incidental or consequential 33 | damages of any kind, including economic damage or injury to property and lost 34 | profits, regardless of whether NIST shall be advised, have reason to know, 35 | or in fact shall know of the possibility. 36 | 37 | By using this software, you agree to bear all risk relating to quality, 38 | use and performance of the software and/or related materials. You agree 39 | to hold the Government harmless from any claim arising from your use 40 | of the software. 41 | 42 | *******************************************************************************/ 43 | 44 | 45 | /*********************************************************************** 46 | LIBRARY: FET - Feature File/List Utilities 47 | 48 | FILE: UPDATFET.C 49 | AUTHOR: Michael Garris 50 | DATE: 01/11/2001 51 | UPDATED: 03/10/2005 by MDG 52 | 02/28/2007 by Kenneth Ko 53 | 54 | Contains routines responsible for replacing the value of 55 | a specified attribute in an attribute-value paird list. 56 | 57 | ROUTINES: 58 | #cat: updatefet - replaces a feature entry in an fet structure, or creates 59 | #cat: a new entry if the feature does not already exist. 60 | #cat: Exits on error. 61 | #cat: updatefet_ret - replaces a feature entry in an fet structure, or 62 | #cat: creates a new entry if the feature does not already exist. 63 | #cat: Returns on error. 64 | 65 | ***********************************************************************/ 66 | 67 | #include 68 | #include 69 | #include 70 | #include 71 | #include 72 | #include 73 | 74 | /***********************************************************************/ 75 | void updatefet(char *feature, char *value, FET *fet) 76 | { 77 | int item; 78 | int increased, incr; 79 | 80 | for (item = 0; 81 | (item < fet->num) && (strcmp(fet->names[item],feature) != 0); 82 | item++); 83 | if (item < fet->num){ 84 | if(fet->values[item] != (char *)NULL){ 85 | free(fet->values[item]); 86 | fet->values[item] = (char *)NULL; 87 | } 88 | if(value != (char *)NULL){ 89 | fet->values[item] = strdup(value); 90 | if(fet->values[item] == (char *)NULL) 91 | syserr("updatefet","strdup","fet->values[]"); 92 | } 93 | } 94 | else{ 95 | if(fet->num >= fet->alloc){ 96 | incr = fet->alloc / 10; /* add 10% or 10 which- */ 97 | increased = fet->alloc + max(10, incr); /* ever is larger */ 98 | reallocfet(fet, increased); 99 | } 100 | fet->names[fet->num] = (char *)strdup(feature); 101 | if(fet->names[fet->num] == (char *)NULL) 102 | syserr("updatefet","strdup","fet->names[]"); 103 | if(value != (char *)NULL){ 104 | fet->values[fet->num] = (char *)strdup(value); 105 | if(fet->values[fet->num] == (char *)NULL) 106 | syserr("updatefet","strdup","fet->values[]"); 107 | } 108 | (fet->num)++; 109 | } 110 | } 111 | 112 | /***********************************************************************/ 113 | int updatefet_ret(char *feature, char *value, FET *fet) 114 | { 115 | int ret, item; 116 | int increased, incr; 117 | 118 | for (item = 0; 119 | (item < fet->num) && (strcmp(fet->names[item],feature) != 0); 120 | item++); 121 | if (item < fet->num){ 122 | if(fet->values[item] != (char *)NULL){ 123 | free(fet->values[item]); 124 | fet->values[item] = (char *)NULL; 125 | } 126 | if(value != (char *)NULL){ 127 | fet->values[item] = (char *)strdup(value); 128 | if(fet->values[item] == (char *)NULL){ 129 | fprintf(stderr, "ERROR : updatefet_ret : strdup : fet->values[]\n"); 130 | return(-2); 131 | } 132 | } 133 | } 134 | else{ 135 | if(fet->num >= fet->alloc){ 136 | incr = fet->alloc / 10; /* add 10% or 10 which- */ 137 | increased = fet->alloc + max(10, incr); /* ever is larger */ 138 | if((ret = reallocfet_ret(&fet, increased))) 139 | return(ret); 140 | } 141 | fet->names[fet->num] = (char *)strdup(feature); 142 | if(fet->names[fet->num] == (char *)NULL){ 143 | fprintf(stderr, "ERROR : updatefet_ret : strdup : fet->names[]\n"); 144 | return(-3); 145 | } 146 | if(value != (char *)NULL){ 147 | fet->values[fet->num] = (char *)strdup(value); 148 | if(fet->values[fet->num] == (char *)NULL){ 149 | fprintf(stderr, "ERROR : updatefet_ret : strdup : fet->values[]\n"); 150 | return(-4); 151 | } 152 | } 153 | (fet->num)++; 154 | } 155 | 156 | return(0); 157 | } 158 | -------------------------------------------------------------------------------- /fet/writefet.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | License: 4 | This software and/or related materials was developed at the National Institute 5 | of Standards and Technology (NIST) by employees of the Federal Government 6 | in the course of their official duties. Pursuant to title 17 Section 105 7 | of the United States Code, this software is not subject to copyright 8 | protection and is in the public domain. 9 | 10 | This software and/or related materials have been determined to be not subject 11 | to the EAR (see Part 734.3 of the EAR for exact details) because it is 12 | a publicly available technology and software, and is freely distributed 13 | to any interested party with no licensing requirements. Therefore, it is 14 | permissible to distribute this software as a free download from the internet. 15 | 16 | Disclaimer: 17 | This software and/or related materials was developed to promote biometric 18 | standards and biometric technology testing for the Federal Government 19 | in accordance with the USA PATRIOT Act and the Enhanced Border Security 20 | and Visa Entry Reform Act. Specific hardware and software products identified 21 | in this software were used in order to perform the software development. 22 | In no case does such identification imply recommendation or endorsement 23 | by the National Institute of Standards and Technology, nor does it imply that 24 | the products and equipment identified are necessarily the best available 25 | for the purpose. 26 | 27 | This software and/or related materials are provided "AS-IS" without warranty 28 | of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, 29 | NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY 30 | or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the 31 | licensed product, however used. In no event shall NIST be liable for any 32 | damages and/or costs, including but not limited to incidental or consequential 33 | damages of any kind, including economic damage or injury to property and lost 34 | profits, regardless of whether NIST shall be advised, have reason to know, 35 | or in fact shall know of the possibility. 36 | 37 | By using this software, you agree to bear all risk relating to quality, 38 | use and performance of the software and/or related materials. You agree 39 | to hold the Government harmless from any claim arising from your use 40 | of the software. 41 | 42 | *******************************************************************************/ 43 | 44 | 45 | /*********************************************************************** 46 | LIBRARY: FET - Feature File/List Utilities 47 | 48 | FILE: WRITEFET.C 49 | AUTHOR: Michael Garris 50 | DATE: 01/11/2001 51 | UPDATED: 03/10/2005 by MDG 52 | 53 | Contains routines responsible for writing the contents of 54 | an attribute-value paired list to a file. 55 | 56 | ROUTINES: 57 | #cat: writefetfile - write the contents of an fet structure to the 58 | #cat: specified file. Exits on error. 59 | #cat: writefetfile_ret - write the contents of an fet structure to the 60 | #cat: specified file. Returns on error. 61 | 62 | ***********************************************************************/ 63 | 64 | #include 65 | #include 66 | #include 67 | 68 | /*****************************************************************/ 69 | void writefetfile(char *file, FET *fet) 70 | { 71 | FILE *fp = (FILE *)NULL; 72 | int item; 73 | 74 | if ((fp = fopen(file,"wb")) == (FILE *)NULL) 75 | syserr("writefetfile","fopen",file); 76 | for (item = 0; itemnum; item++){ 77 | if(fet->values[item] == (char *)NULL) 78 | fprintf(fp,"%s\n",fet->names[item]); 79 | else 80 | fprintf(fp,"%s %s\n",fet->names[item],fet->values[item]); 81 | } 82 | fclose(fp); 83 | } 84 | 85 | /*****************************************************************/ 86 | int writefetfile_ret(char *file, FET *fet) 87 | { 88 | FILE *fp = (FILE *)NULL; 89 | int item; 90 | 91 | if ((fp = fopen(file,"wb")) == (FILE *)NULL){ 92 | fprintf(stderr, "ERROR : writefetfile_ret : fopen : %s\n",file); 93 | return(-2); 94 | } 95 | 96 | for (item = 0; itemnum; item++){ 97 | if(fet->values[item] == (char *)NULL) 98 | fprintf(fp,"%s\n",fet->names[item]); 99 | else 100 | fprintf(fp,"%s %s\n",fet->names[item],fet->values[item]); 101 | } 102 | fclose(fp); 103 | 104 | return(0); 105 | } 106 | -------------------------------------------------------------------------------- /include/computil.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | License: 4 | This software and/or related materials was developed at the National Institute 5 | of Standards and Technology (NIST) by employees of the Federal Government 6 | in the course of their official duties. Pursuant to title 17 Section 105 7 | of the United States Code, this software is not subject to copyright 8 | protection and is in the public domain. 9 | 10 | This software and/or related materials have been determined to be not subject 11 | to the EAR (see Part 734.3 of the EAR for exact details) because it is 12 | a publicly available technology and software, and is freely distributed 13 | to any interested party with no licensing requirements. Therefore, it is 14 | permissible to distribute this software as a free download from the internet. 15 | 16 | Disclaimer: 17 | This software and/or related materials was developed to promote biometric 18 | standards and biometric technology testing for the Federal Government 19 | in accordance with the USA PATRIOT Act and the Enhanced Border Security 20 | and Visa Entry Reform Act. Specific hardware and software products identified 21 | in this software were used in order to perform the software development. 22 | In no case does such identification imply recommendation or endorsement 23 | by the National Institute of Standards and Technology, nor does it imply that 24 | the products and equipment identified are necessarily the best available 25 | for the purpose. 26 | 27 | This software and/or related materials are provided "AS-IS" without warranty 28 | of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, 29 | NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY 30 | or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the 31 | licensed product, however used. In no event shall NIST be liable for any 32 | damages and/or costs, including but not limited to incidental or consequential 33 | damages of any kind, including economic damage or injury to property and lost 34 | profits, regardless of whether NIST shall be advised, have reason to know, 35 | or in fact shall know of the possibility. 36 | 37 | By using this software, you agree to bear all risk relating to quality, 38 | use and performance of the software and/or related materials. You agree 39 | to hold the Government harmless from any claim arising from your use 40 | of the software. 41 | 42 | *******************************************************************************/ 43 | 44 | 45 | #ifndef _COMPUTIL_H 46 | #define _COMPUTIL_H 47 | 48 | extern int read_skip_marker_segment(const unsigned short, FILE *); 49 | extern int getc_skip_marker_segment(const unsigned short, 50 | unsigned char **, unsigned char *); 51 | 52 | #endif /* !_COMPUTIL_H */ 53 | 54 | -------------------------------------------------------------------------------- /include/dataio.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | License: 4 | This software and/or related materials was developed at the National Institute 5 | of Standards and Technology (NIST) by employees of the Federal Government 6 | in the course of their official duties. Pursuant to title 17 Section 105 7 | of the United States Code, this software is not subject to copyright 8 | protection and is in the public domain. 9 | 10 | This software and/or related materials have been determined to be not subject 11 | to the EAR (see Part 734.3 of the EAR for exact details) because it is 12 | a publicly available technology and software, and is freely distributed 13 | to any interested party with no licensing requirements. Therefore, it is 14 | permissible to distribute this software as a free download from the internet. 15 | 16 | Disclaimer: 17 | This software and/or related materials was developed to promote biometric 18 | standards and biometric technology testing for the Federal Government 19 | in accordance with the USA PATRIOT Act and the Enhanced Border Security 20 | and Visa Entry Reform Act. Specific hardware and software products identified 21 | in this software were used in order to perform the software development. 22 | In no case does such identification imply recommendation or endorsement 23 | by the National Institute of Standards and Technology, nor does it imply that 24 | the products and equipment identified are necessarily the best available 25 | for the purpose. 26 | 27 | This software and/or related materials are provided "AS-IS" without warranty 28 | of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, 29 | NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY 30 | or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the 31 | licensed product, however used. In no event shall NIST be liable for any 32 | damages and/or costs, including but not limited to incidental or consequential 33 | damages of any kind, including economic damage or injury to property and lost 34 | profits, regardless of whether NIST shall be advised, have reason to know, 35 | or in fact shall know of the possibility. 36 | 37 | By using this software, you agree to bear all risk relating to quality, 38 | use and performance of the software and/or related materials. You agree 39 | to hold the Government harmless from any claim arising from your use 40 | of the software. 41 | 42 | *******************************************************************************/ 43 | 44 | 45 | #ifndef _DATA_IO_H 46 | #define _DATA_IO_H 47 | 48 | /* dataio.c */ 49 | extern int read_byte(unsigned char *, FILE *); 50 | extern int getc_byte(unsigned char *, unsigned char **, unsigned char *); 51 | extern int getc_bytes(unsigned char **, const int, unsigned char **, 52 | unsigned char *); 53 | extern int write_byte(const unsigned char, FILE *); 54 | extern int putc_byte(const unsigned char, unsigned char *, const int, int *); 55 | extern int putc_bytes(unsigned char *, const int, unsigned char *, 56 | const int, int *); 57 | extern int read_ushort(unsigned short *, FILE *); 58 | extern int getc_ushort(unsigned short *, unsigned char **, unsigned char *); 59 | extern int write_ushort(unsigned short, FILE *); 60 | extern int putc_ushort(unsigned short, unsigned char *, const int, int *); 61 | extern int read_uint(unsigned int *, FILE *); 62 | extern int getc_uint(unsigned int *, unsigned char **, unsigned char *); 63 | extern int write_uint(unsigned int, FILE *); 64 | extern int putc_uint(unsigned int, unsigned char *, const int, int *); 65 | extern void write_bits(unsigned char **, const unsigned short, const short, 66 | int *, unsigned char *, int *); 67 | extern void flush_bits(unsigned char **, int *, unsigned char *, int *); 68 | extern int read_ascii_file(char *, char **); 69 | 70 | #endif /* !_DATA_IO_H */ 71 | -------------------------------------------------------------------------------- /include/defs.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | License: 4 | This software and/or related materials was developed at the National Institute 5 | of Standards and Technology (NIST) by employees of the Federal Government 6 | in the course of their official duties. Pursuant to title 17 Section 105 7 | of the United States Code, this software is not subject to copyright 8 | protection and is in the public domain. 9 | 10 | This software and/or related materials have been determined to be not subject 11 | to the EAR (see Part 734.3 of the EAR for exact details) because it is 12 | a publicly available technology and software, and is freely distributed 13 | to any interested party with no licensing requirements. Therefore, it is 14 | permissible to distribute this software as a free download from the internet. 15 | 16 | Disclaimer: 17 | This software and/or related materials was developed to promote biometric 18 | standards and biometric technology testing for the Federal Government 19 | in accordance with the USA PATRIOT Act and the Enhanced Border Security 20 | and Visa Entry Reform Act. Specific hardware and software products identified 21 | in this software were used in order to perform the software development. 22 | In no case does such identification imply recommendation or endorsement 23 | by the National Institute of Standards and Technology, nor does it imply that 24 | the products and equipment identified are necessarily the best available 25 | for the purpose. 26 | 27 | This software and/or related materials are provided "AS-IS" without warranty 28 | of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, 29 | NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY 30 | or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the 31 | licensed product, however used. In no event shall NIST be liable for any 32 | damages and/or costs, including but not limited to incidental or consequential 33 | damages of any kind, including economic damage or injury to property and lost 34 | profits, regardless of whether NIST shall be advised, have reason to know, 35 | or in fact shall know of the possibility. 36 | 37 | By using this software, you agree to bear all risk relating to quality, 38 | use and performance of the software and/or related materials. You agree 39 | to hold the Government harmless from any claim arising from your use 40 | of the software. 41 | 42 | *******************************************************************************/ 43 | 44 | #ifndef _DEFS_H 45 | #define _DEFS_H 46 | 47 | /*********************************************************************/ 48 | /* General Purpose Defines */ 49 | /*********************************************************************/ 50 | #ifndef True 51 | #define True 1 52 | #define False 0 53 | #endif 54 | #ifndef TRUE 55 | #define TRUE True 56 | #define FALSE False 57 | #endif 58 | #define Yes True 59 | #define No False 60 | #define Empty NULL 61 | #ifndef None 62 | #define None -1 63 | #endif 64 | #ifndef FOUND 65 | #define FOUND 1 66 | #endif 67 | #define NOT_FOUND_NEG -1 68 | #define EOL EOF 69 | #ifndef DEG2RAD 70 | #define DEG2RAD (double)(57.29578) 71 | #endif 72 | #define max(a, b) ((a) > (b) ? (a) : (b)) 73 | #define min(a, b) ((a) < (b) ? (a) : (b)) 74 | #define sround(x) ((int) (((x)<0) ? (x)-0.5 : (x)+0.5)) 75 | #define sround_uint(x) ((unsigned int) (((x)<0) ? (x)-0.5 : (x)+0.5)) 76 | #define align_to_16(_v_) ((((_v_)+15)>>4)<<4) 77 | #define align_to_32(_v_) ((((_v_)+31)>>5)<<5) 78 | #ifndef CHUNKS 79 | #define CHUNKS 100 80 | #endif 81 | 82 | #endif /* !_DEFS_H */ 83 | -------------------------------------------------------------------------------- /include/fet.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | License: 4 | This software and/or related materials was developed at the National Institute 5 | of Standards and Technology (NIST) by employees of the Federal Government 6 | in the course of their official duties. Pursuant to title 17 Section 105 7 | of the United States Code, this software is not subject to copyright 8 | protection and is in the public domain. 9 | 10 | This software and/or related materials have been determined to be not subject 11 | to the EAR (see Part 734.3 of the EAR for exact details) because it is 12 | a publicly available technology and software, and is freely distributed 13 | to any interested party with no licensing requirements. Therefore, it is 14 | permissible to distribute this software as a free download from the internet. 15 | 16 | Disclaimer: 17 | This software and/or related materials was developed to promote biometric 18 | standards and biometric technology testing for the Federal Government 19 | in accordance with the USA PATRIOT Act and the Enhanced Border Security 20 | and Visa Entry Reform Act. Specific hardware and software products identified 21 | in this software were used in order to perform the software development. 22 | In no case does such identification imply recommendation or endorsement 23 | by the National Institute of Standards and Technology, nor does it imply that 24 | the products and equipment identified are necessarily the best available 25 | for the purpose. 26 | 27 | This software and/or related materials are provided "AS-IS" without warranty 28 | of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, 29 | NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY 30 | or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the 31 | licensed product, however used. In no event shall NIST be liable for any 32 | damages and/or costs, including but not limited to incidental or consequential 33 | damages of any kind, including economic damage or injury to property and lost 34 | profits, regardless of whether NIST shall be advised, have reason to know, 35 | or in fact shall know of the possibility. 36 | 37 | By using this software, you agree to bear all risk relating to quality, 38 | use and performance of the software and/or related materials. You agree 39 | to hold the Government harmless from any claim arising from your use 40 | of the software. 41 | 42 | *******************************************************************************/ 43 | 44 | 45 | #ifndef _FET_H 46 | #define _FET_H 47 | 48 | #include 49 | #include /* Added by MDG on 03-10-05 */ 50 | 51 | #ifndef True 52 | #define True 1 53 | #define False 0 54 | #endif 55 | #define FET_EXT "fet" 56 | #define MAXFETS 100 57 | #define MAXFETLENGTH 512 58 | 59 | typedef struct fetstruct{ 60 | int alloc; 61 | int num; 62 | char **names; 63 | char **values; 64 | } FET; 65 | 66 | /* allocfet.c */ 67 | extern FET *allocfet(int); 68 | extern int allocfet_ret(FET **, int); 69 | extern FET *reallocfet(FET *, int); 70 | extern int reallocfet_ret(FET **, int); 71 | /* delfet.c */ 72 | extern void deletefet(char *, FET *); 73 | extern int deletefet_ret(char *, FET *); 74 | /* extfet.c */ 75 | extern char *extractfet(char *, FET *); 76 | extern int extractfet_ret(char **, char *, FET *); 77 | /* freefet.c */ 78 | extern void freefet(FET *); 79 | /* lkupfet.c */ 80 | extern int lookupfet(char **, char *, FET *); 81 | /* printfet.c */ 82 | extern void printfet(FILE *, FET *); 83 | /* readfet.c */ 84 | extern FET *readfetfile(char *); 85 | extern int readfetfile_ret(FET **, char *); 86 | /* strfet.c */ 87 | extern int fet2string(char **, FET *); 88 | extern int string2fet(FET **, char *); 89 | /* updatfet.c */ 90 | extern void updatefet(char *, char *, FET *); 91 | extern int updatefet_ret(char *, char *, FET *); 92 | /* writefet.c */ 93 | extern void writefetfile(char *, FET *); 94 | extern int writefetfile_ret(char *, FET *); 95 | 96 | #endif /* !_FET_H */ 97 | -------------------------------------------------------------------------------- /include/ihead.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | License: 4 | This software and/or related materials was developed at the National Institute 5 | of Standards and Technology (NIST) by employees of the Federal Government 6 | in the course of their official duties. Pursuant to title 17 Section 105 7 | of the United States Code, this software is not subject to copyright 8 | protection and is in the public domain. 9 | 10 | This software and/or related materials have been determined to be not subject 11 | to the EAR (see Part 734.3 of the EAR for exact details) because it is 12 | a publicly available technology and software, and is freely distributed 13 | to any interested party with no licensing requirements. Therefore, it is 14 | permissible to distribute this software as a free download from the internet. 15 | 16 | Disclaimer: 17 | This software and/or related materials was developed to promote biometric 18 | standards and biometric technology testing for the Federal Government 19 | in accordance with the USA PATRIOT Act and the Enhanced Border Security 20 | and Visa Entry Reform Act. Specific hardware and software products identified 21 | in this software were used in order to perform the software development. 22 | In no case does such identification imply recommendation or endorsement 23 | by the National Institute of Standards and Technology, nor does it imply that 24 | the products and equipment identified are necessarily the best available 25 | for the purpose. 26 | 27 | This software and/or related materials are provided "AS-IS" without warranty 28 | of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, 29 | NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY 30 | or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the 31 | licensed product, however used. In no event shall NIST be liable for any 32 | damages and/or costs, including but not limited to incidental or consequential 33 | damages of any kind, including economic damage or injury to property and lost 34 | profits, regardless of whether NIST shall be advised, have reason to know, 35 | or in fact shall know of the possibility. 36 | 37 | By using this software, you agree to bear all risk relating to quality, 38 | use and performance of the software and/or related materials. You agree 39 | to hold the Government harmless from any claim arising from your use 40 | of the software. 41 | 42 | *******************************************************************************/ 43 | 44 | 45 | #ifndef _IHEAD_H 46 | #define _IHEAD_H 47 | 48 | /************************************************************/ 49 | /* File Name: IHead.h */ 50 | /* Package: NIST Internal Image Header */ 51 | /* Author: Michael D. Garris */ 52 | /* Date: 2/08/90 */ 53 | /* Updated: 3/14/05 by MDG */ 54 | /************************************************************/ 55 | 56 | #include /* Added by MDG in 03-14-05 */ 57 | #include /* Added by MDG in 03-14-05 */ 58 | 59 | /* Defines used by the ihead structure */ 60 | #define IHDR_SIZE 288 /* len of hdr record (always even bytes) */ 61 | #define SHORT_CHARS 8 /* # of ASCII chars to represent a short */ 62 | #define BUFSIZE 80 /* default buffer size */ 63 | #define DATELEN 26 /* character length of date string */ 64 | 65 | typedef struct ihead{ 66 | char id[BUFSIZE]; /* identification/comment field */ 67 | char created[DATELEN]; /* date created */ 68 | char width[SHORT_CHARS]; /* pixel width of image */ 69 | char height[SHORT_CHARS]; /* pixel height of image */ 70 | char depth[SHORT_CHARS]; /* bits per pixel */ 71 | char density[SHORT_CHARS]; /* pixels per inch */ 72 | char compress[SHORT_CHARS]; /* compression code */ 73 | char complen[SHORT_CHARS]; /* compressed data length */ 74 | char align[SHORT_CHARS]; /* scanline multiple: 8|16|32 */ 75 | char unitsize[SHORT_CHARS]; /* bit size of image memory units */ 76 | char sigbit; /* 0->sigbit first | 1->sigbit last */ 77 | char byte_order; /* 0->highlow | 1->lowhigh*/ 78 | char pix_offset[SHORT_CHARS]; /* pixel column offset */ 79 | char whitepix[SHORT_CHARS]; /* intensity of white pixel */ 80 | char issigned; /* 0->unsigned data | 1->signed data */ 81 | char rm_cm; /* 0->row maj | 1->column maj */ 82 | char tb_bt; /* 0->top2bottom | 1->bottom2top */ 83 | char lr_rl; /* 0->left2right | 1->right2left */ 84 | char parent[BUFSIZE]; /* parent image file */ 85 | char par_x[SHORT_CHARS]; /* from x pixel in parent */ 86 | char par_y[SHORT_CHARS]; /* from y pixel in parent */ 87 | }IHEAD; 88 | 89 | /* General Defines */ 90 | #define UNCOMP 0 91 | #define CCITT_G3 1 92 | #define CCITT_G4 2 93 | #define RL 5 94 | #define JPEG_SD 6 95 | #define WSQ_SD14 7 96 | #define MSBF '0' 97 | #define LSBF '1' 98 | #define HILOW '0' 99 | #define LOWHI '1' 100 | #define UNSIGNED '0' 101 | #define SIGNED '1' 102 | #define ROW_MAJ '0' 103 | #define COL_MAJ '1' 104 | #define TOP2BOT '0' 105 | #define BOT2TOP '1' 106 | #define LEFT2RIGHT '0' 107 | #define RIGHT2LEFT '1' 108 | 109 | #define BYTE_SIZE 8.0 110 | 111 | /* getcomp.c */ 112 | extern int getcomptype(char *); 113 | /* getnset.c */ 114 | extern char *get_id(IHEAD *); 115 | extern int set_id(IHEAD *, char *); 116 | extern char *get_created(IHEAD *); 117 | extern int set_created(IHEAD *); 118 | extern int get_width(IHEAD *); 119 | extern int set_width(IHEAD *, int); 120 | extern int get_height(IHEAD *); 121 | extern int set_height(IHEAD *, int); 122 | extern int get_depth(IHEAD *); 123 | extern int set_depth(IHEAD *, int); 124 | extern int get_density(IHEAD *); 125 | extern int set_density(IHEAD *, int); 126 | extern int get_compression(IHEAD *); 127 | extern int set_compression(IHEAD *, int); 128 | extern int get_complen(IHEAD *); 129 | extern int set_complen(IHEAD *, int); 130 | extern int get_align(IHEAD *); 131 | extern int set_align(IHEAD *, int); 132 | extern int get_unitsize(IHEAD *); 133 | extern int set_unitsize(IHEAD *, int); 134 | extern int get_sigbit(IHEAD *); 135 | extern int set_sigbit(IHEAD *, int); 136 | extern int get_byte_order(IHEAD *); 137 | extern int set_byte_order(IHEAD *, int); 138 | extern int get_pix_offset(IHEAD *); 139 | extern int set_pix_offset(IHEAD *, int); 140 | extern int get_whitepix(IHEAD *); 141 | extern int set_whitepix(IHEAD *, int); 142 | extern int get_issigned(IHEAD *); 143 | extern int set_issigned(IHEAD *, int); 144 | extern int get_rm_cm(IHEAD *); 145 | extern int set_rm_cm(IHEAD *, int); 146 | extern int get_tb_bt(IHEAD *); 147 | extern int set_tb_bt(IHEAD *, int); 148 | extern int get_lr_rl(IHEAD *); 149 | extern int set_lr_rl(IHEAD *, int); 150 | extern char *get_parent(IHEAD *); 151 | extern int set_parent(IHEAD *, char *); 152 | extern int get_par_x(IHEAD *); 153 | extern int set_par_x(IHEAD *, int); 154 | extern int get_par_y(IHEAD *); 155 | extern int set_par_y(IHEAD *, int); 156 | /* nullihdr.c */ 157 | extern void nullihdr(IHEAD *); 158 | /* parsihdr.c */ 159 | extern void parseihdrid(char *, char *, char *); 160 | /* prntihdr.c */ 161 | extern void printihdr(IHEAD *, FILE *); 162 | /* readihdr.c */ 163 | extern IHEAD *readihdr(register FILE *); 164 | /* valdcomp.c */ 165 | extern int valid_compression(int); 166 | /* writihdr.c */ 167 | extern void writeihdr(FILE *, IHEAD *); 168 | 169 | #endif /* !_IHEAD_H */ 170 | -------------------------------------------------------------------------------- /include/ioutil.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | License: 4 | This software and/or related materials was developed at the National Institute 5 | of Standards and Technology (NIST) by employees of the Federal Government 6 | in the course of their official duties. Pursuant to title 17 Section 105 7 | of the United States Code, this software is not subject to copyright 8 | protection and is in the public domain. 9 | 10 | This software and/or related materials have been determined to be not subject 11 | to the EAR (see Part 734.3 of the EAR for exact details) because it is 12 | a publicly available technology and software, and is freely distributed 13 | to any interested party with no licensing requirements. Therefore, it is 14 | permissible to distribute this software as a free download from the internet. 15 | 16 | Disclaimer: 17 | This software and/or related materials was developed to promote biometric 18 | standards and biometric technology testing for the Federal Government 19 | in accordance with the USA PATRIOT Act and the Enhanced Border Security 20 | and Visa Entry Reform Act. Specific hardware and software products identified 21 | in this software were used in order to perform the software development. 22 | In no case does such identification imply recommendation or endorsement 23 | by the National Institute of Standards and Technology, nor does it imply that 24 | the products and equipment identified are necessarily the best available 25 | for the purpose. 26 | 27 | This software and/or related materials are provided "AS-IS" without warranty 28 | of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, 29 | NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY 30 | or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the 31 | licensed product, however used. In no event shall NIST be liable for any 32 | damages and/or costs, including but not limited to incidental or consequential 33 | damages of any kind, including economic damage or injury to property and lost 34 | profits, regardless of whether NIST shall be advised, have reason to know, 35 | or in fact shall know of the possibility. 36 | 37 | By using this software, you agree to bear all risk relating to quality, 38 | use and performance of the software and/or related materials. You agree 39 | to hold the Government harmless from any claim arising from your use 40 | of the software. 41 | 42 | *******************************************************************************/ 43 | 44 | 45 | #ifndef _IOUTIL_H 46 | #define _IOUTIL_H 47 | 48 | #ifndef True 49 | #define True 1 50 | #define False 0 51 | #endif 52 | 53 | #define MaxLineLength 512 54 | #define EOL EOF 55 | 56 | /* fileexst.c */ 57 | extern int file_exists(char *); 58 | /* filehead.c */ 59 | extern void filehead(char *); 60 | /* fileroot.c */ 61 | extern void fileroot(char *); 62 | /* filesize.c */ 63 | extern int filesize(char *); 64 | /* filetail.c */ 65 | extern void filetail(char *); 66 | /* findfile.c */ 67 | extern int find_file(char *, char *); 68 | /* newext.c */ 69 | extern void newext(char *, const int, char *); 70 | extern int newext_ret(char *, int, char *); 71 | extern void newextlong(char **, char *); 72 | /* readutil.c */ 73 | extern int read_strstr_file(char *, char ***, char ***, int *, const int); 74 | extern int read_fltflt_file(char *, float **, float **, int *, const int); 75 | 76 | #endif /* !_IOUTIL_H */ 77 | -------------------------------------------------------------------------------- /include/jpegl.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | License: 4 | This software and/or related materials was developed at the National Institute 5 | of Standards and Technology (NIST) by employees of the Federal Government 6 | in the course of their official duties. Pursuant to title 17 Section 105 7 | of the United States Code, this software is not subject to copyright 8 | protection and is in the public domain. 9 | 10 | This software and/or related materials have been determined to be not subject 11 | to the EAR (see Part 734.3 of the EAR for exact details) because it is 12 | a publicly available technology and software, and is freely distributed 13 | to any interested party with no licensing requirements. Therefore, it is 14 | permissible to distribute this software as a free download from the internet. 15 | 16 | Disclaimer: 17 | This software and/or related materials was developed to promote biometric 18 | standards and biometric technology testing for the Federal Government 19 | in accordance with the USA PATRIOT Act and the Enhanced Border Security 20 | and Visa Entry Reform Act. Specific hardware and software products identified 21 | in this software were used in order to perform the software development. 22 | In no case does such identification imply recommendation or endorsement 23 | by the National Institute of Standards and Technology, nor does it imply that 24 | the products and equipment identified are necessarily the best available 25 | for the purpose. 26 | 27 | This software and/or related materials are provided "AS-IS" without warranty 28 | of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, 29 | NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY 30 | or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the 31 | licensed product, however used. In no event shall NIST be liable for any 32 | damages and/or costs, including but not limited to incidental or consequential 33 | damages of any kind, including economic damage or injury to property and lost 34 | profits, regardless of whether NIST shall be advised, have reason to know, 35 | or in fact shall know of the possibility. 36 | 37 | By using this software, you agree to bear all risk relating to quality, 38 | use and performance of the software and/or related materials. You agree 39 | to hold the Government harmless from any claim arising from your use 40 | of the software. 41 | 42 | *******************************************************************************/ 43 | 44 | 45 | /****************************************************************/ 46 | /* */ 47 | /* This header was created for use with */ 48 | /* lossless jpeg compression and decompression */ 49 | /* designed for 8 bit input precision */ 50 | /* */ 51 | /* developed by: Craig Watson */ 52 | /* date: 6 Nov 91 */ 53 | /* updated: 22 DEC 97 */ 54 | /* updated: 03/11/2005 by MDG */ 55 | /* */ 56 | /****************************************************************/ 57 | #ifndef _JPEGL_H 58 | #define _JPEGL_H 59 | 60 | #ifndef _NISTCOM_H 61 | #include 62 | #endif 63 | 64 | /* JPEGL Marker Definitions */ 65 | #define SOF3 0xffc3 66 | #define DHT 0xffc4 67 | #define RST0 0xffd0 68 | #define RST1 0xffd1 69 | #define RST2 0xffd2 70 | #define RST3 0xffd3 71 | #define RST4 0xffd4 72 | #define RST5 0xffd5 73 | #define RST6 0xffd6 74 | #define RST7 0xffd7 75 | #define SOI 0xffd8 76 | #define EOI 0xffd9 77 | #define SOS 0xffda 78 | #define DNL 0xffdc 79 | #define DRI 0xffdd 80 | #define COM 0xfffe 81 | #define APP0 0xffe0 82 | /* Case for getting ANY marker. */ 83 | #define ANY 0xffff 84 | /* Cases for getting a table from a set of possible ones. */ 85 | #define TBLS_N_SOF 2 86 | #define TBLS_N_SOS (TBLS_N_SOF + 1) 87 | 88 | /* Predictor Definitions */ 89 | /* c b */ 90 | /* a x */ 91 | #define PRED1 1 /* Px = Ra */ 92 | #define PRED2 2 /* Px = Rb */ 93 | #define PRED3 3 /* Px = Rc */ 94 | #define PRED4 4 /* Px = Ra+Rb-Rc */ 95 | #define PRED5 5 /* Px = Ra+((Rb-Rc)/2) */ 96 | #define PRED6 6 /* Px = Rb+((Ra-Rc)/2) */ 97 | #define PRED7 7 /* Px = (Ra+Rb)/2 */ 98 | #define BITSET 0x01 99 | #define LSBITMASK 0x0001 100 | #define CATMASK 0x8000 101 | 102 | #define NO_INTRLV 0 103 | #define MAX_CMPNTS 4 104 | #define FREE_IMAGE 1 105 | #define NO_FREE_IMAGE 0 106 | #define BUF_SIZE 50000 /* Compressed image buffer size */ 107 | 108 | #define MIN_HUFFTABLE_ID 16 /* Set according to JPEGL spec */ 109 | #define MAX_HUFFBITS 16 /* DO NOT CHANGE THIS CONSTANT!! */ 110 | #define MAX_HUFFCOUNTS_JPEGL 16 /* Length of code table: change as */ 111 | /* needed but DO NOT EXCEED 256 */ 112 | #define MAX_CATEGORY 10 /* Largest difference category for uchar data */ 113 | #define LARGESTDIFF 511 /* Largest difference value */ 114 | 115 | #define READ_TABLE_LEN 1 116 | #define NO_READ_TABLE_LEN 0 117 | 118 | #define FIRSTBIT 7 119 | #ifndef BITSPERBYTE 120 | #define BITSPERBYTE 8 121 | #endif 122 | 123 | /* JFIF SCAN UNIT DESIGNATORS */ 124 | #define UNKNOWN_UNITS 0 125 | #define PPI_UNITS 1 /* pixels per inch */ 126 | #define PPCM_UNITS 2 /* pixels per centimeter */ 127 | 128 | 129 | typedef struct hcode { 130 | short size; 131 | unsigned int code; 132 | } HUFFCODE; 133 | 134 | #define JFIF_IDENT "JFIF" 135 | #define JFIF_IDENT_LEN 5 136 | #define JFIF_VERSION 0x0102 137 | #define JFIF_HEADER_LEN 16 138 | 139 | typedef struct jheader { 140 | unsigned short ver; 141 | char ident[JFIF_IDENT_LEN]; 142 | unsigned char units; 143 | unsigned short dx, dy; 144 | unsigned char tx, ty; 145 | } JFIF_HEADER; 146 | 147 | typedef struct image { 148 | int max_width, max_height, pix_depth, ppi; 149 | int intrlv; /* 0 = no, 1 = yes */ 150 | int n_cmpnts; 151 | int cmpnt_depth; 152 | int hor_sampfctr[MAX_CMPNTS]; 153 | int vrt_sampfctr[MAX_CMPNTS]; 154 | int samp_width[MAX_CMPNTS]; 155 | int samp_height[MAX_CMPNTS]; 156 | unsigned char point_trans[MAX_CMPNTS]; 157 | unsigned char predict[MAX_CMPNTS]; 158 | unsigned char *image[MAX_CMPNTS]; 159 | short *diff[MAX_CMPNTS]; /* was short ** */ 160 | } IMG_DAT; 161 | 162 | typedef struct htable { 163 | unsigned char def; 164 | unsigned char table_id; 165 | unsigned char *bits; 166 | unsigned char *values; 167 | int last_size; 168 | int *codesize; 169 | int *freq; 170 | int *maxcode; 171 | int *mincode; 172 | int *valptr; 173 | HUFFCODE *huffcode_table; 174 | } HUF_TABLE; 175 | 176 | typedef struct fheader { 177 | unsigned char prec; 178 | unsigned short x; 179 | unsigned short y; 180 | unsigned char Nf; 181 | unsigned char C[MAX_CMPNTS]; 182 | unsigned char HV[MAX_CMPNTS]; 183 | unsigned char Tq[MAX_CMPNTS]; 184 | } FRM_HEADER_JPEGL; 185 | 186 | typedef struct sheader { 187 | unsigned char Ns; 188 | unsigned char Cs[MAX_CMPNTS]; 189 | unsigned char Tda[MAX_CMPNTS]; 190 | unsigned char Ss; 191 | unsigned char Se; 192 | unsigned char Ahl; 193 | } SCN_HEADER; 194 | 195 | /* GLOBAL VARIABLES */ 196 | extern int debug; 197 | 198 | /* encoder.c */ 199 | extern int jpegl_encode_mem(unsigned char **, int *, IMG_DAT *, char *); 200 | extern int gen_diff_freqs(IMG_DAT *, HUF_TABLE **); 201 | extern int compress_image_intrlv(IMG_DAT *, HUF_TABLE **, 202 | unsigned char *, const int, int *); 203 | extern int compress_image_non_intrlv(IMG_DAT *, HUF_TABLE **, 204 | unsigned char *, const int, int *); 205 | extern int code_diff(HUFFCODE *, HUFFCODE *, int *, unsigned int *, short *); 206 | 207 | /* decoder.c */ 208 | extern int jpegl_decode_mem(IMG_DAT **, int *, unsigned char *, const int); 209 | extern void build_huff_decode_table(int [MAX_CATEGORY][LARGESTDIFF+1]); 210 | extern int decode_data(int *, int *, int *, int *, unsigned char *, 211 | unsigned char **, unsigned char *, int *); 212 | extern int nextbits_jpegl(unsigned short *, FILE *, int *, const int); 213 | extern int getc_nextbits_jpegl(unsigned short *, unsigned char **, 214 | unsigned char *, int *, const int); 215 | 216 | /* huff.c */ 217 | extern int read_huffman_table(unsigned char *, unsigned char **, 218 | unsigned char **, const int, FILE *, const int, int *); 219 | extern int getc_huffman_table(unsigned char *, unsigned char **, 220 | unsigned char **, const int, unsigned char **, 221 | unsigned char *, const int, int *); 222 | extern int write_huffman_table(const unsigned short, const unsigned char, 223 | unsigned char *, unsigned char *, FILE *); 224 | extern int putc_huffman_table(const unsigned short, const unsigned char, 225 | unsigned char *, unsigned char *, unsigned char *, 226 | const int, int *); 227 | extern int find_huff_sizes(int **, int *, const int); 228 | extern void find_least_freq(int *, int *, int *, const int); 229 | extern int find_num_huff_sizes(unsigned char **, int *, int *, const int); 230 | extern int sort_huffbits(unsigned char *); 231 | extern int sort_code_sizes(unsigned char **, int *, const int); 232 | extern int build_huffcode_table(HUFFCODE **, HUFFCODE *, const int, 233 | unsigned char *, const int); 234 | extern int build_huffsizes(HUFFCODE **, int *, unsigned char *, const int); 235 | extern void build_huffcodes(HUFFCODE *); 236 | extern void gen_decode_table(HUFFCODE *, int *, int *, int *, unsigned char *); 237 | 238 | /* huftable.c */ 239 | extern int gen_huff_tables(HUF_TABLE **, const int); 240 | extern int read_huffman_table_jpegl(HUF_TABLE **, FILE *); 241 | extern int getc_huffman_table_jpegl(HUF_TABLE **, unsigned char **, 242 | unsigned char *); 243 | extern void free_HUFF_TABLES(HUF_TABLE **, const int); 244 | extern void free_HUFF_TABLE(HUF_TABLE *); 245 | 246 | /* imgdat.c */ 247 | int get_IMG_DAT_image(unsigned char **, int *, int *, int *, int *, int *, 248 | IMG_DAT *); 249 | extern int setup_IMG_DAT_nonintrlv_encode(IMG_DAT **, unsigned char *, 250 | const int, const int, const int, const int, int *, int *, 251 | const int, const unsigned char, const unsigned char); 252 | extern int setup_IMG_DAT_decode(IMG_DAT **, const int, FRM_HEADER_JPEGL *); 253 | extern int update_IMG_DAT_decode(IMG_DAT *, SCN_HEADER *, HUF_TABLE **); 254 | extern void free_IMG_DAT(IMG_DAT *, const int); 255 | 256 | /* ppi.c */ 257 | extern int get_ppi_jpegl(int *, JFIF_HEADER *); 258 | 259 | /* tableio.c */ 260 | extern int read_marker_jpegl(unsigned short *, const int, FILE *); 261 | extern int getc_marker_jpegl(unsigned short *, const int, unsigned char **, 262 | unsigned char *); 263 | extern int setup_jfif_header(JFIF_HEADER **, const unsigned char, 264 | const int, const int); 265 | extern int read_jfif_header(JFIF_HEADER **, FILE *); 266 | extern int getc_jfif_header(JFIF_HEADER **, unsigned char **, unsigned char *); 267 | extern int write_jfif_header(JFIF_HEADER *, FILE *); 268 | extern int putc_jfif_header(JFIF_HEADER *, unsigned char *, const int, int *); 269 | extern int read_table_jpegl(const unsigned short, HUF_TABLE **, FILE *); 270 | extern int getc_table_jpegl(const unsigned short, HUF_TABLE **, 271 | unsigned char **, unsigned char *); 272 | extern int setup_frame_header_jpegl(FRM_HEADER_JPEGL **, IMG_DAT *); 273 | extern int read_frame_header_jpegl(FRM_HEADER_JPEGL **, FILE *); 274 | extern int getc_frame_header_jpegl(FRM_HEADER_JPEGL **, unsigned char **, 275 | unsigned char *); 276 | extern int write_frame_header_jpegl(FRM_HEADER_JPEGL *, FILE *); 277 | extern int putc_frame_header_jpegl(FRM_HEADER_JPEGL *, unsigned char *, 278 | const int, int *); 279 | extern int setup_scan_header(SCN_HEADER **, IMG_DAT *, const int); 280 | extern int read_scan_header(SCN_HEADER **, FILE *); 281 | extern int getc_scan_header(SCN_HEADER **, unsigned char **, unsigned char *); 282 | extern int write_scan_header(SCN_HEADER *, FILE *); 283 | extern int putc_scan_header(SCN_HEADER *, unsigned char *, const int, int *); 284 | extern int read_comment(unsigned char **, FILE *); 285 | extern int getc_comment(unsigned char **, unsigned char **, unsigned char *); 286 | extern int write_comment(const unsigned short, unsigned char *, const int, 287 | FILE *); 288 | extern int putc_comment(const unsigned short, unsigned char *, const int, 289 | unsigned char *, const int, int *); 290 | extern int add_comment_jpegl(unsigned char **, int *, unsigned char *, 291 | const int, unsigned char *); 292 | extern int getc_nistcom_jpegl(NISTCOM **, unsigned char *, const int); 293 | extern int putc_nistcom_jpegl(char *, const int, const int, const int, 294 | const int, const int, const int, int *, int *, 295 | const int, unsigned char *, const int, int *); 296 | 297 | 298 | /* util.c */ 299 | extern int predict(short *, unsigned char *, const int, const int, const int, 300 | const int, const int); 301 | extern short categorize(const short); 302 | 303 | #endif /* !_JPEGL_H */ 304 | -------------------------------------------------------------------------------- /include/jpeglsd4.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | License: 4 | This software and/or related materials was developed at the National Institute 5 | of Standards and Technology (NIST) by employees of the Federal Government 6 | in the course of their official duties. Pursuant to title 17 Section 105 7 | of the United States Code, this software is not subject to copyright 8 | protection and is in the public domain. 9 | 10 | This software and/or related materials have been determined to be not subject 11 | to the EAR (see Part 734.3 of the EAR for exact details) because it is 12 | a publicly available technology and software, and is freely distributed 13 | to any interested party with no licensing requirements. Therefore, it is 14 | permissible to distribute this software as a free download from the internet. 15 | 16 | Disclaimer: 17 | This software and/or related materials was developed to promote biometric 18 | standards and biometric technology testing for the Federal Government 19 | in accordance with the USA PATRIOT Act and the Enhanced Border Security 20 | and Visa Entry Reform Act. Specific hardware and software products identified 21 | in this software were used in order to perform the software development. 22 | In no case does such identification imply recommendation or endorsement 23 | by the National Institute of Standards and Technology, nor does it imply that 24 | the products and equipment identified are necessarily the best available 25 | for the purpose. 26 | 27 | This software and/or related materials are provided "AS-IS" without warranty 28 | of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, 29 | NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY 30 | or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the 31 | licensed product, however used. In no event shall NIST be liable for any 32 | damages and/or costs, including but not limited to incidental or consequential 33 | damages of any kind, including economic damage or injury to property and lost 34 | profits, regardless of whether NIST shall be advised, have reason to know, 35 | or in fact shall know of the possibility. 36 | 37 | By using this software, you agree to bear all risk relating to quality, 38 | use and performance of the software and/or related materials. You agree 39 | to hold the Government harmless from any claim arising from your use 40 | of the software. 41 | 42 | *******************************************************************************/ 43 | 44 | 45 | #ifndef _JPEGLSD4_H 46 | #define _JPEGLSD4_H 47 | 48 | #include 49 | 50 | #define MAX_HUFFBITS_JPEGL_SD4 10 51 | 52 | extern int jpegl_sd4_decode_mem(unsigned char *, const int, const int, 53 | const int, const int, unsigned char *); 54 | 55 | #endif /* !_JPEGLSD4_H */ 56 | -------------------------------------------------------------------------------- /include/nistcom.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | License: 4 | This software and/or related materials was developed at the National Institute 5 | of Standards and Technology (NIST) by employees of the Federal Government 6 | in the course of their official duties. Pursuant to title 17 Section 105 7 | of the United States Code, this software is not subject to copyright 8 | protection and is in the public domain. 9 | 10 | This software and/or related materials have been determined to be not subject 11 | to the EAR (see Part 734.3 of the EAR for exact details) because it is 12 | a publicly available technology and software, and is freely distributed 13 | to any interested party with no licensing requirements. Therefore, it is 14 | permissible to distribute this software as a free download from the internet. 15 | 16 | Disclaimer: 17 | This software and/or related materials was developed to promote biometric 18 | standards and biometric technology testing for the Federal Government 19 | in accordance with the USA PATRIOT Act and the Enhanced Border Security 20 | and Visa Entry Reform Act. Specific hardware and software products identified 21 | in this software were used in order to perform the software development. 22 | In no case does such identification imply recommendation or endorsement 23 | by the National Institute of Standards and Technology, nor does it imply that 24 | the products and equipment identified are necessarily the best available 25 | for the purpose. 26 | 27 | This software and/or related materials are provided "AS-IS" without warranty 28 | of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, 29 | NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY 30 | or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the 31 | licensed product, however used. In no event shall NIST be liable for any 32 | damages and/or costs, including but not limited to incidental or consequential 33 | damages of any kind, including economic damage or injury to property and lost 34 | profits, regardless of whether NIST shall be advised, have reason to know, 35 | or in fact shall know of the possibility. 36 | 37 | By using this software, you agree to bear all risk relating to quality, 38 | use and performance of the software and/or related materials. You agree 39 | to hold the Government harmless from any claim arising from your use 40 | of the software. 41 | 42 | *******************************************************************************/ 43 | 44 | 45 | #ifndef _NISTCOM_H 46 | #define _NISTCOM_H 47 | 48 | #ifndef _IHEAD_H 49 | #include 50 | #endif 51 | 52 | #ifndef _FET_H 53 | #include 54 | typedef FET NISTCOM; 55 | #endif 56 | 57 | #define NCM_EXT "ncm" 58 | #define NCM_HEADER "NIST_COM" /* manditory */ 59 | #define NCM_PIX_WIDTH "PIX_WIDTH" /* manditory */ 60 | #define NCM_PIX_HEIGHT "PIX_HEIGHT" /* manditory */ 61 | #define NCM_PIX_DEPTH "PIX_DEPTH" /* 1,8,24 (manditory)*/ 62 | #define NCM_PPI "PPI" /* -1 if unknown (manditory)*/ 63 | #define NCM_COLORSPACE "COLORSPACE" /* RGB,YCbCr,GRAY */ 64 | #define NCM_N_CMPNTS "NUM_COMPONENTS" /* [1..4] (manditory w/hv_factors)*/ 65 | #define NCM_HV_FCTRS "HV_FACTORS" /* H0,V0:H1,V1:...*/ 66 | #define NCM_INTRLV "INTERLEAVE" /* 0,1 (manditory w/depth=24) */ 67 | #define NCM_COMPRESSION "COMPRESSION" /* NONE,JPEGB,JPEGL,WSQ */ 68 | #define NCM_JPEGB_QUAL "JPEGB_QUALITY" /* [20..95] */ 69 | #define NCM_JPEGL_PREDICT "JPEGL_PREDICT" /* [1..7] */ 70 | #define NCM_WSQ_RATE "WSQ_BITRATE" /* ex. .75,2.25 (-1.0 if unknown)*/ 71 | #define NCM_LOSSY "LOSSY" /* 0,1 */ 72 | 73 | #define NCM_HISTORY "HISTORY" /* ex. SD historical data */ 74 | #define NCM_FING_CLASS "FING_CLASS" /* ex. A,L,R,S,T,W */ 75 | #define NCM_SEX "SEX" /* m,f */ 76 | #define NCM_SCAN_TYPE "SCAN_TYPE" /* l,i */ 77 | #define NCM_FACE_POS "FACE_POS" /* f,p */ 78 | #define NCM_AGE "AGE" 79 | #define NCM_SD_ID "SD_ID" /* 4,9,10,14,18 */ 80 | 81 | 82 | /* nistcom.c */ 83 | extern int combine_nistcom(NISTCOM **, const int, const int, 84 | const int, const int, const int); 85 | extern int combine_jpegl_nistcom(NISTCOM **, const int, const int, 86 | const int, const int, const int, const int, 87 | int *, int *, const int, const int); 88 | extern int combine_wsq_nistcom(NISTCOM **, const int, const int, 89 | const int, const int, const int, const float); 90 | extern int combine_jpegb_nistcom(NISTCOM **, const int, const int, 91 | const int, const int, const int, 92 | char *, const int, const int, const int); 93 | extern int del_jpegl_nistcom(NISTCOM *); 94 | extern int del_wsq_nistcom(NISTCOM *); 95 | extern int del_jpegb_nistcom(NISTCOM *); 96 | extern int add_jpegb_nistcom(NISTCOM *, const int); 97 | extern int add_jpegl_nistcom(NISTCOM *, const int, int *, int *, 98 | const int, const int); 99 | extern int add_wsq_nistcom(NISTCOM *); 100 | extern int sd_ihead_to_nistcom(NISTCOM **, IHEAD *, int); 101 | extern int sd4_ihead_to_nistcom(NISTCOM **, IHEAD *); 102 | extern int sd9_10_14_ihead_to_nistcom(NISTCOM **, IHEAD *, const int); 103 | extern int sd18_ihead_to_nistcom(NISTCOM **, IHEAD *); 104 | extern int get_sd_class(char *, const int, char *); 105 | extern int get_class_from_ncic_class_string(char *, const int, char *); 106 | 107 | 108 | #endif /* !_NISTCOM_H */ 109 | -------------------------------------------------------------------------------- /include/swap.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | License: 4 | This software and/or related materials was developed at the National Institute 5 | of Standards and Technology (NIST) by employees of the Federal Government 6 | in the course of their official duties. Pursuant to title 17 Section 105 7 | of the United States Code, this software is not subject to copyright 8 | protection and is in the public domain. 9 | 10 | This software and/or related materials have been determined to be not subject 11 | to the EAR (see Part 734.3 of the EAR for exact details) because it is 12 | a publicly available technology and software, and is freely distributed 13 | to any interested party with no licensing requirements. Therefore, it is 14 | permissible to distribute this software as a free download from the internet. 15 | 16 | Disclaimer: 17 | This software and/or related materials was developed to promote biometric 18 | standards and biometric technology testing for the Federal Government 19 | in accordance with the USA PATRIOT Act and the Enhanced Border Security 20 | and Visa Entry Reform Act. Specific hardware and software products identified 21 | in this software were used in order to perform the software development. 22 | In no case does such identification imply recommendation or endorsement 23 | by the National Institute of Standards and Technology, nor does it imply that 24 | the products and equipment identified are necessarily the best available 25 | for the purpose. 26 | 27 | This software and/or related materials are provided "AS-IS" without warranty 28 | of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, 29 | NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY 30 | or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the 31 | licensed product, however used. In no event shall NIST be liable for any 32 | damages and/or costs, including but not limited to incidental or consequential 33 | damages of any kind, including economic damage or injury to property and lost 34 | profits, regardless of whether NIST shall be advised, have reason to know, 35 | or in fact shall know of the possibility. 36 | 37 | By using this software, you agree to bear all risk relating to quality, 38 | use and performance of the software and/or related materials. You agree 39 | to hold the Government harmless from any claim arising from your use 40 | of the software. 41 | 42 | *******************************************************************************/ 43 | 44 | 45 | #ifndef _SWAP_H 46 | #define _SWAP_H 47 | 48 | #define swap_uint_bytes(_ui_) \ 49 | { \ 50 | unsigned int _b_ = _ui_; \ 51 | unsigned char *_f_ = (unsigned char *)&(_b_); \ 52 | unsigned char *_t_ = (unsigned char *)&(_ui_); \ 53 | _t_[3] = _f_[0]; \ 54 | _t_[2] = _f_[1]; \ 55 | _t_[1] = _f_[2]; \ 56 | _t_[0] = _f_[3]; \ 57 | } 58 | 59 | #define swap_int_bytes(_ui_) \ 60 | { \ 61 | int _b_ = _ui_; \ 62 | unsigned char *_f_ = (unsigned char *)&(_b_); \ 63 | unsigned char *_t_ = (unsigned char *)&(_ui_); \ 64 | _t_[3] = _f_[0]; \ 65 | _t_[2] = _f_[1]; \ 66 | _t_[1] = _f_[2]; \ 67 | _t_[0] = _f_[3]; \ 68 | } 69 | 70 | #define swap_ushort_bytes(_us_) \ 71 | { \ 72 | unsigned short _b_ = _us_; \ 73 | unsigned char *_f_ = (unsigned char *)&(_b_); \ 74 | unsigned char *_t_ = (unsigned char *)&(_us_); \ 75 | _t_[1] = _f_[0]; \ 76 | _t_[0] = _f_[1]; \ 77 | } 78 | 79 | #define swap_short_bytes(_a_) \ 80 | { \ 81 | short _b_ = _a_; \ 82 | char *_f_ = (char *) &_b_; \ 83 | char *_t_ = (char *) &_a_; \ 84 | _t_[1] = _f_[0]; \ 85 | _t_[0] = _f_[1]; \ 86 | } 87 | 88 | #define swap_float_bytes(_flt_) \ 89 | { \ 90 | float _b_ = _flt_; \ 91 | unsigned char *_f_ = (unsigned char *)&(_b_); \ 92 | unsigned char *_t_ = (unsigned char *)&(_flt_); \ 93 | _t_[3] = _f_[0]; \ 94 | _t_[2] = _f_[1]; \ 95 | _t_[1] = _f_[2]; \ 96 | _t_[0] = _f_[3]; \ 97 | } 98 | 99 | #define swap_short(_a_) \ 100 | { \ 101 | short _b_ = _a_; \ 102 | char *_f_ = (char *) &_b_; \ 103 | char *_t_ = (char *) &_a_; \ 104 | _t_[1] = _f_[0]; \ 105 | _t_[0] = _f_[1]; \ 106 | } 107 | 108 | #define swap_image_shorts(_data,_swidth,_sheight) \ 109 | { \ 110 | unsigned short *_sdata = (unsigned short *)_data; \ 111 | int _i,_wdlen=16; \ 112 | for (_i = 0;_i<(int)((_swidth/_wdlen)*_sheight);_i++) \ 113 | swap_short(_sdata[_i]);\ 114 | } 115 | 116 | #define swap_int(_a_, _b_) \ 117 | { \ 118 | int _t_ = _a_; \ 119 | _a_ = _b_; \ 120 | _b_ = _t_; \ 121 | } 122 | 123 | #define swap_float(_a_, _b_) \ 124 | { \ 125 | float _t_ = _a_; \ 126 | _a_ = _b_; \ 127 | _b_ = _t_; \ 128 | } 129 | 130 | #define swap_string(_a_, _b_) \ 131 | { \ 132 | char *_t_ = _a_; \ 133 | _a_ = _b_; \ 134 | _b_ = _t_; \ 135 | } 136 | 137 | #endif /* !_SWAP_H */ 138 | -------------------------------------------------------------------------------- /include/usebsd.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | License: 4 | This software and/or related materials was developed at the National Institute 5 | of Standards and Technology (NIST) by employees of the Federal Government 6 | in the course of their official duties. Pursuant to title 17 Section 105 7 | of the United States Code, this software is not subject to copyright 8 | protection and is in the public domain. 9 | 10 | This software and/or related materials have been determined to be not subject 11 | to the EAR (see Part 734.3 of the EAR for exact details) because it is 12 | a publicly available technology and software, and is freely distributed 13 | to any interested party with no licensing requirements. Therefore, it is 14 | permissible to distribute this software as a free download from the internet. 15 | 16 | Disclaimer: 17 | This software and/or related materials was developed to promote biometric 18 | standards and biometric technology testing for the Federal Government 19 | in accordance with the USA PATRIOT Act and the Enhanced Border Security 20 | and Visa Entry Reform Act. Specific hardware and software products identified 21 | in this software were used in order to perform the software development. 22 | In no case does such identification imply recommendation or endorsement 23 | by the National Institute of Standards and Technology, nor does it imply that 24 | the products and equipment identified are necessarily the best available 25 | for the purpose. 26 | 27 | This software and/or related materials are provided "AS-IS" without warranty 28 | of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, 29 | NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY 30 | or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the 31 | licensed product, however used. In no event shall NIST be liable for any 32 | damages and/or costs, including but not limited to incidental or consequential 33 | damages of any kind, including economic damage or injury to property and lost 34 | profits, regardless of whether NIST shall be advised, have reason to know, 35 | or in fact shall know of the possibility. 36 | 37 | By using this software, you agree to bear all risk relating to quality, 38 | use and performance of the software and/or related materials. You agree 39 | to hold the Government harmless from any claim arising from your use 40 | of the software. 41 | 42 | *******************************************************************************/ 43 | 44 | 45 | /*********************************************************************** 46 | FILE: USEBSD.H 47 | AUTHOR: Michael Garris 48 | DATE: 06/09/2005 49 | 50 | Controls definitions to facilitate the portable use of 51 | BSD-based library routines on both Linux and Cygwin platforms. 52 | This file must be included when code is calling for example: 53 | 54 | strdup() 55 | rindex() 56 | setlinebuf() 57 | 58 | and the strict ANSI flag "-ansi" is used. The including of 59 | this file is intended to have no effect when the "-ansi" 60 | compiler flag is not in use. 61 | 62 | ***********************************************************************/ 63 | #ifndef _USEBSD_H 64 | #define _USEBSD_H 65 | 66 | #if defined(__linux__) && !defined(_BSD_SOURCE) 67 | #define _BSD_SOURCE 68 | #elif defined(__CYGWIN__) && defined(__STRICT_ANSI__) 69 | #undef __STRICT_ANSI__ 70 | #endif 71 | 72 | /* The setting of _BSD_SOURCE under Linux sets up subsequent */ 73 | /* definitions in . Therefore this file should be */ 74 | /* included first, so to help ensure this, is */ 75 | /* included here at the end of this file */ 76 | #include 77 | 78 | #endif /* !_USEBSD_H */ 79 | -------------------------------------------------------------------------------- /include/util.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | License: 4 | This software and/or related materials was developed at the National Institute 5 | of Standards and Technology (NIST) by employees of the Federal Government 6 | in the course of their official duties. Pursuant to title 17 Section 105 7 | of the United States Code, this software is not subject to copyright 8 | protection and is in the public domain. 9 | 10 | This software and/or related materials have been determined to be not subject 11 | to the EAR (see Part 734.3 of the EAR for exact details) because it is 12 | a publicly available technology and software, and is freely distributed 13 | to any interested party with no licensing requirements. Therefore, it is 14 | permissible to distribute this software as a free download from the internet. 15 | 16 | Disclaimer: 17 | This software and/or related materials was developed to promote biometric 18 | standards and biometric technology testing for the Federal Government 19 | in accordance with the USA PATRIOT Act and the Enhanced Border Security 20 | and Visa Entry Reform Act. Specific hardware and software products identified 21 | in this software were used in order to perform the software development. 22 | In no case does such identification imply recommendation or endorsement 23 | by the National Institute of Standards and Technology, nor does it imply that 24 | the products and equipment identified are necessarily the best available 25 | for the purpose. 26 | 27 | This software and/or related materials are provided "AS-IS" without warranty 28 | of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, 29 | NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY 30 | or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the 31 | licensed product, however used. In no event shall NIST be liable for any 32 | damages and/or costs, including but not limited to incidental or consequential 33 | damages of any kind, including economic damage or injury to property and lost 34 | profits, regardless of whether NIST shall be advised, have reason to know, 35 | or in fact shall know of the possibility. 36 | 37 | By using this software, you agree to bear all risk relating to quality, 38 | use and performance of the software and/or related materials. You agree 39 | to hold the Government harmless from any claim arising from your use 40 | of the software. 41 | 42 | *******************************************************************************/ 43 | 44 | 45 | #ifndef _UTIL_H 46 | #define _UTIL_H 47 | 48 | /* UPDATED: 03/15/2005 by MDG */ 49 | #ifdef __MSYS__ 50 | #include 51 | #else 52 | #include 53 | #endif 54 | 55 | #ifndef True 56 | #define True 1 57 | #define False 0 58 | #endif 59 | 60 | /* bres.c */ 61 | extern int bres_line_alloc(const int, const int, const int, const int, int **, 62 | int **, int *, int *); 63 | 64 | /* bubble.c */ 65 | extern void bubble_sort_int(int *, const int); 66 | 67 | /* fatalerr.c */ 68 | extern void fatalerr(char *, char *, char *); 69 | 70 | /* invbytes.h */ 71 | extern void inv_bytes(unsigned char *, int); 72 | 73 | /* ssxstats.c */ 74 | extern double ssx_stddev(const double, const double, const int); 75 | extern double ssx_variance(const double, const double, const int); 76 | extern double ssx(const double, const double, const int); 77 | 78 | /* syserr.c */ 79 | extern void syserr(char *, char *, char *); 80 | 81 | /* ticks.c */ 82 | extern clock_t ticks(void); 83 | extern int ticksPerSec(void); 84 | 85 | /* time.c */ 86 | extern char *current_time(void); 87 | 88 | /* fixup.c */ 89 | /* 90 | #ifdef __MSYS__ 91 | extern void __assert(const char *, int, const char *); 92 | 93 | extern char *index(const char *, int); 94 | 95 | extern void sleep (const int); 96 | #endif 97 | */ 98 | #endif /* !_UTIL_H */ 99 | -------------------------------------------------------------------------------- /include/wsq.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | License: 4 | This software and/or related materials was developed at the National Institute 5 | of Standards and Technology (NIST) by employees of the Federal Government 6 | in the course of their official duties. Pursuant to title 17 Section 105 7 | of the United States Code, this software is not subject to copyright 8 | protection and is in the public domain. 9 | 10 | This software and/or related materials have been determined to be not subject 11 | to the EAR (see Part 734.3 of the EAR for exact details) because it is 12 | a publicly available technology and software, and is freely distributed 13 | to any interested party with no licensing requirements. Therefore, it is 14 | permissible to distribute this software as a free download from the internet. 15 | 16 | Disclaimer: 17 | This software and/or related materials was developed to promote biometric 18 | standards and biometric technology testing for the Federal Government 19 | in accordance with the USA PATRIOT Act and the Enhanced Border Security 20 | and Visa Entry Reform Act. Specific hardware and software products identified 21 | in this software were used in order to perform the software development. 22 | In no case does such identification imply recommendation or endorsement 23 | by the National Institute of Standards and Technology, nor does it imply that 24 | the products and equipment identified are necessarily the best available 25 | for the purpose. 26 | 27 | This software and/or related materials are provided "AS-IS" without warranty 28 | of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, 29 | NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY 30 | or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the 31 | licensed product, however used. In no event shall NIST be liable for any 32 | damages and/or costs, including but not limited to incidental or consequential 33 | damages of any kind, including economic damage or injury to property and lost 34 | profits, regardless of whether NIST shall be advised, have reason to know, 35 | or in fact shall know of the possibility. 36 | 37 | By using this software, you agree to bear all risk relating to quality, 38 | use and performance of the software and/or related materials. You agree 39 | to hold the Government harmless from any claim arising from your use 40 | of the software. 41 | 42 | *******************************************************************************/ 43 | 44 | 45 | #ifndef _WSQ_H 46 | #define _WSQ_H 47 | 48 | #ifndef _STDIO_H 49 | #include 50 | #endif 51 | 52 | #ifndef _IHEAD_H 53 | #include 54 | #endif 55 | 56 | #ifndef _JPEGL_H 57 | #include 58 | #endif 59 | 60 | #ifndef TRUE 61 | #define TRUE 1 62 | #define FALSE 0 63 | #endif 64 | 65 | /* WSQ Marker Definitions */ 66 | #define SOI_WSQ 0xffa0 67 | #define EOI_WSQ 0xffa1 68 | #define SOF_WSQ 0xffa2 69 | #define SOB_WSQ 0xffa3 70 | #define DTT_WSQ 0xffa4 71 | #define DQT_WSQ 0xffa5 72 | #define DHT_WSQ 0xffa6 73 | #define DRT_WSQ 0xffa7 74 | #define COM_WSQ 0xffa8 75 | /* Case for getting ANY marker. */ 76 | #define ANY_WSQ 0xffff 77 | #define TBLS_N_SOB (TBLS_N_SOF + 2) 78 | 79 | /* Filter Bank Definitions */ 80 | #ifdef FILTBANK_EVEN_8X8_1 81 | #define MAX_HIFILT 8 82 | #define MAX_LOFILT 8 83 | #else 84 | #define MAX_HIFILT 7 85 | #define MAX_LOFILT 9 86 | #endif 87 | 88 | /* Subband Definitions */ 89 | #define STRT_SUBBAND_2 19 90 | #define STRT_SUBBAND_3 52 91 | #define MAX_SUBBANDS 64 92 | #define NUM_SUBBANDS 60 93 | #define STRT_SUBBAND_DEL (NUM_SUBBANDS) 94 | #define STRT_SIZE_REGION_2 4 95 | #define STRT_SIZE_REGION_3 51 96 | 97 | #define MIN_IMG_DIM 256 98 | 99 | #define WHITE 255 100 | #define BLACK 0 101 | 102 | #define COEFF_CODE 0 103 | #define RUN_CODE 1 104 | 105 | #define RAW_IMAGE 1 106 | #define IHEAD_IMAGE 0 107 | 108 | #define VARIANCE_THRESH 1.01 109 | 110 | typedef struct quantization { 111 | float q; /* quantization level */ 112 | float cr; /* compression ratio */ 113 | float r; /* compression bitrate */ 114 | float qbss_t[MAX_SUBBANDS]; 115 | float qbss[MAX_SUBBANDS]; 116 | float qzbs[MAX_SUBBANDS]; 117 | float var[MAX_SUBBANDS]; 118 | } QUANT_VALS; 119 | 120 | typedef struct wavlet_tree { 121 | int x; 122 | int y; 123 | int lenx; 124 | int leny; 125 | int inv_rw; 126 | int inv_cl; 127 | } W_TREE; 128 | #define W_TREELEN 20 129 | 130 | typedef struct quant_tree { 131 | short x; /* UL corner of block */ 132 | short y; 133 | short lenx; /* block size */ 134 | short leny; /* block size */ 135 | } Q_TREE; 136 | #define Q_TREELEN 64 137 | 138 | /* Defined in jpegl.h 139 | typedef struct hcode { 140 | short size; 141 | unsigned short code; 142 | } HUFFCODE; 143 | */ 144 | 145 | typedef struct table_dtt { 146 | float *lofilt; 147 | float *hifilt; 148 | unsigned char losz; 149 | unsigned char hisz; 150 | char lodef; 151 | char hidef; 152 | } DTT_TABLE; 153 | 154 | typedef struct table_dqt { 155 | float bin_center; 156 | float q_bin[MAX_SUBBANDS]; 157 | float z_bin[MAX_SUBBANDS]; 158 | char dqt_def; 159 | } DQT_TABLE; 160 | 161 | #define MAX_DHT_TABLES 8 162 | 163 | /* Defined in jpegl.h */ 164 | /* #define MAX_HUFFBITS 16 DO NOT CHANGE THIS CONSTANT!! */ 165 | #define MAX_HUFFCOUNTS_WSQ 256 /* Length of code table: change as needed */ 166 | /* but DO NOT EXCEED 256 */ 167 | #define MAX_HUFFCOEFF 74 /* -73 .. +74 */ 168 | #define MAX_HUFFZRUN 100 169 | 170 | typedef struct table_dht { 171 | unsigned char tabdef; 172 | unsigned char huffbits[MAX_HUFFBITS]; 173 | unsigned char huffvalues[MAX_HUFFCOUNTS_WSQ+1]; 174 | } DHT_TABLE; 175 | 176 | typedef struct header_frm { 177 | unsigned char black; 178 | unsigned char white; 179 | unsigned short width; 180 | unsigned short height; 181 | float m_shift; 182 | float r_scale; 183 | unsigned char wsq_encoder; 184 | unsigned short software; 185 | } FRM_HEADER_WSQ; 186 | 187 | /* External global variables. */ 188 | extern int debug; 189 | extern QUANT_VALS quant_vals; 190 | extern W_TREE w_tree[]; 191 | extern Q_TREE q_tree[]; 192 | extern DTT_TABLE dtt_table; 193 | extern DQT_TABLE dqt_table; 194 | extern DHT_TABLE dht_table[]; 195 | extern FRM_HEADER_WSQ frm_header_wsq; 196 | extern float hifilt[]; 197 | extern float lofilt[]; 198 | 199 | 200 | /* External function definitions. */ 201 | /* cropcoeff.c */ 202 | extern void quant_block_sizes2(int *, int *, int *, const DQT_TABLE *, 203 | W_TREE *, const int, Q_TREE *, const int); 204 | extern int wsq_crop_qdata(const DQT_TABLE *, Q_TREE *, Q_TREE *, Q_TREE *, 205 | short *, int, int, int, int, short *); 206 | extern int wsq_cropcoeff_mem(unsigned char **, int *, int *, int *, int, int, 207 | int, int, int *, int *, unsigned char *, const int, short **, 208 | int *, int *); 209 | extern int wsq_huffcode_mem(unsigned char *, int *, short *, int, int, 210 | unsigned char *, const int, const int, const int); 211 | extern int wsq_dehuff_mem(short **, int *, int *, double *, double *, 212 | int *, int *, unsigned char *, const int ilen); 213 | extern int read_wsq_frame_header(unsigned char *, const int, int *, int *, 214 | double *, double *); 215 | 216 | /* decoder.c */ 217 | extern int wsq_decode_mem(unsigned char **, int *, int *, int *, int *, int *, 218 | unsigned char *, const int); 219 | extern int wsq_decode_file(unsigned char **, int *, int *, int *, int *, 220 | int *, FILE *); 221 | extern int huffman_decode_data_mem(short *, DTT_TABLE *, DQT_TABLE *, 222 | DHT_TABLE *, unsigned char **, unsigned char *); 223 | extern int huffman_decode_data_file(short *, DTT_TABLE *, DQT_TABLE *, 224 | DHT_TABLE *, FILE *); 225 | extern int decode_data_mem(int *, int *, int *, int *, unsigned char *, 226 | unsigned char **, unsigned char *, int *, unsigned short *); 227 | extern int decode_data_file(int *, int *, int *, int *, unsigned char *, FILE *, 228 | int *, unsigned short *); 229 | extern int nextbits_wsq(unsigned short *, unsigned short *, FILE *, int *, 230 | const int); 231 | extern int getc_nextbits_wsq(unsigned short *, unsigned short *, 232 | unsigned char **, unsigned char *, int *, const int); 233 | 234 | /* encoder.c */ 235 | extern int wsq_encode_mem(unsigned char **, int *, const float, unsigned char *, 236 | const int, const int, const int, const int, char *); 237 | extern int gen_hufftable_wsq(HUFFCODE **, unsigned char **, unsigned char **, 238 | short *, const int *, const int); 239 | extern int compress_block(unsigned char *, int *, short *, 240 | const int, const int, const int, HUFFCODE *); 241 | extern int count_block(int **, const int, short *, 242 | const int, const int, const int); 243 | 244 | /* huff.c */ 245 | extern int check_huffcodes_wsq(HUFFCODE *, int); 246 | 247 | /* ppi.c */ 248 | extern int read_ppi_wsq(int *, FILE *); 249 | extern int getc_ppi_wsq(int *, unsigned char *, const int); 250 | 251 | /* tableio.c */ 252 | extern int read_marker_wsq(unsigned short *, const int, FILE *); 253 | extern int getc_marker_wsq(unsigned short *, const int, unsigned char **, 254 | unsigned char *); 255 | extern int read_table_wsq(unsigned short, DTT_TABLE *, DQT_TABLE *, DHT_TABLE *, 256 | FILE *); 257 | extern int getc_table_wsq(unsigned short, DTT_TABLE *, DQT_TABLE *, DHT_TABLE *, 258 | unsigned char **, unsigned char *); 259 | extern int read_transform_table(DTT_TABLE *, FILE *); 260 | extern int getc_transform_table(DTT_TABLE *, unsigned char **, unsigned char *); 261 | extern int write_transform_table(float *, const int, float *, const int, 262 | FILE *); 263 | extern int putc_transform_table(float *, const int, float *, const int, 264 | unsigned char *, const int, int *); 265 | extern int read_quantization_table(DQT_TABLE *, FILE *); 266 | extern int getc_quantization_table(DQT_TABLE *, unsigned char **, 267 | unsigned char *); 268 | extern int write_quantization_table(QUANT_VALS *, FILE *); 269 | extern int putc_quantization_table(QUANT_VALS *, unsigned char *, const int, 270 | int *); 271 | extern int read_huffman_table_wsq(DHT_TABLE *, FILE *); 272 | extern int getc_huffman_table_wsq(DHT_TABLE *, unsigned char **, 273 | unsigned char *); 274 | extern int read_frame_header_wsq(FRM_HEADER_WSQ *, FILE *); 275 | extern int getc_frame_header_wsq(FRM_HEADER_WSQ *, unsigned char **, 276 | unsigned char *); 277 | extern int write_frame_header_wsq(const int, const int, const float, 278 | const float, FILE *); 279 | extern int putc_frame_header_wsq(const int, const int, const float, 280 | const float, unsigned char *, const int, int *); 281 | extern int read_block_header(unsigned char *, FILE *); 282 | extern int getc_block_header(unsigned char *, unsigned char **, 283 | unsigned char *); 284 | extern int write_block_header(const int, FILE *); 285 | extern int putc_block_header(const int, unsigned char *, const int, int *); 286 | extern int add_comment_wsq(unsigned char **, int *, unsigned char *, 287 | const int, unsigned char *); 288 | extern int putc_nistcom_wsq(char *, const int, const int, const int, 289 | const int, const int, const float, unsigned char *, 290 | const int, int *); 291 | extern int read_nistcom_wsq(NISTCOM **, FILE *); 292 | extern int getc_nistcom_wsq(NISTCOM **, unsigned char *, const int); 293 | extern int print_comments_wsq(FILE *, unsigned char *, const int); 294 | 295 | /* tree.c */ 296 | extern void build_wsq_trees(W_TREE w_tree[], const int, 297 | Q_TREE q_tree[], const int, const int, const int); 298 | extern void build_w_tree(W_TREE w_tree[], const int, const int); 299 | extern void w_tree4(W_TREE w_tree[], const int, const int, 300 | const int, const int, const int, const int, const int); 301 | extern void build_q_tree(W_TREE w_tree[], Q_TREE q_tree[]); 302 | extern void q_tree16(Q_TREE q_tree[], const int, const int, const int, 303 | const int, const int, const int, const int); 304 | extern void q_tree4(Q_TREE q_tree[], const int, const int, const int, 305 | const int, const int); 306 | 307 | /* util.c */ 308 | extern int conv_img_2_flt_ret(float *, float *, float *, unsigned char *, 309 | const int); 310 | extern void conv_img_2_flt(float *, float *, float *, unsigned char *, 311 | const int); 312 | extern void conv_img_2_uchar(unsigned char *, float *, const int, const int, 313 | const float, const float); 314 | extern void variance( QUANT_VALS *quant_vals, Q_TREE q_tree[], const int, 315 | float *, const int, const int); 316 | extern int quantize(short **, int *, QUANT_VALS *, Q_TREE qtree[], const int, 317 | float *, const int, const int); 318 | extern void quant_block_sizes(int *, int *, int *, 319 | QUANT_VALS *, W_TREE w_tree[], const int, 320 | Q_TREE q_tree[], const int); 321 | extern int unquantize(float **, const DQT_TABLE *, 322 | Q_TREE q_tree[], const int, short *, const int, const int); 323 | extern int wsq_decompose(float *, const int, const int, 324 | W_TREE w_tree[], const int, float *, const int, 325 | float *, const int); 326 | extern void get_lets(float *, float *, const int, const int, const int, 327 | const int, float *, const int, float *, const int, const int); 328 | extern int wsq_reconstruct(float *, const int, const int, 329 | W_TREE w_tree[], const int, const DTT_TABLE *); 330 | extern void join_lets(float *, float *, const int, const int, 331 | const int, const int, float *, const int, 332 | float *, const int, const int); 333 | extern int int_sign(const int); 334 | extern int image_size(const int, short *, short *); 335 | extern void init_wsq_decoder_resources(void); 336 | extern void free_wsq_decoder_resources(void); 337 | 338 | extern int delete_comments_wsq(unsigned char **, int *, unsigned char *, int); 339 | 340 | #endif /* !_WSQ_H */ 341 | -------------------------------------------------------------------------------- /ioutil/filesize.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | License: 4 | This software and/or related materials was developed at the National Institute 5 | of Standards and Technology (NIST) by employees of the Federal Government 6 | in the course of their official duties. Pursuant to title 17 Section 105 7 | of the United States Code, this software is not subject to copyright 8 | protection and is in the public domain. 9 | 10 | This software and/or related materials have been determined to be not subject 11 | to the EAR (see Part 734.3 of the EAR for exact details) because it is 12 | a publicly available technology and software, and is freely distributed 13 | to any interested party with no licensing requirements. Therefore, it is 14 | permissible to distribute this software as a free download from the internet. 15 | 16 | Disclaimer: 17 | This software and/or related materials was developed to promote biometric 18 | standards and biometric technology testing for the Federal Government 19 | in accordance with the USA PATRIOT Act and the Enhanced Border Security 20 | and Visa Entry Reform Act. Specific hardware and software products identified 21 | in this software were used in order to perform the software development. 22 | In no case does such identification imply recommendation or endorsement 23 | by the National Institute of Standards and Technology, nor does it imply that 24 | the products and equipment identified are necessarily the best available 25 | for the purpose. 26 | 27 | This software and/or related materials are provided "AS-IS" without warranty 28 | of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, 29 | NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY 30 | or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the 31 | licensed product, however used. In no event shall NIST be liable for any 32 | damages and/or costs, including but not limited to incidental or consequential 33 | damages of any kind, including economic damage or injury to property and lost 34 | profits, regardless of whether NIST shall be advised, have reason to know, 35 | or in fact shall know of the possibility. 36 | 37 | By using this software, you agree to bear all risk relating to quality, 38 | use and performance of the software and/or related materials. You agree 39 | to hold the Government harmless from any claim arising from your use 40 | of the software. 41 | 42 | *******************************************************************************/ 43 | 44 | 45 | /*********************************************************************** 46 | LIBRARY: IOUTIL - INPUT/OUTPUT Utilities 47 | 48 | FILE: FILESIZE.C 49 | AUTHOR: Michael Garris 50 | DATE: 12/05/2001 51 | 52 | Contains routines responsible for determining the size of 53 | a file in bytes given its path name. 54 | 55 | ROUTINES: 56 | #cat: filesize - opens the specified pathname and determines the size of 57 | #cat: of the file in bytes. 58 | 59 | ***********************************************************************/ 60 | 61 | #include 62 | #include 63 | 64 | /**********************************************************************/ 65 | int filesize(char *ifile) 66 | { 67 | FILE *fp; 68 | int ret; 69 | 70 | /* Open file. */ 71 | if((fp = fopen(ifile, "rb")) == (FILE *)NULL){ 72 | fprintf(stderr, "ERROR : filesize : file %s could not be opened\n", 73 | ifile); 74 | return(-2); 75 | } 76 | 77 | /* Move file pointer to end of file. */ 78 | if(fseek(fp, 0, SEEK_END)){ 79 | fprintf(stderr, "ERROR : filesize : seeking to EOF of file %s failed\n", 80 | ifile); 81 | return(-3); 82 | } 83 | 84 | /* Get byte offest to end of file. */ 85 | if((ret = ftell(fp)) < 0){ 86 | fprintf(stderr, "ERROR : filesize : ftell at EOF of file %s failed\n", 87 | ifile); 88 | return(-4); 89 | } 90 | 91 | /* Close file. */ 92 | fclose(fp); 93 | 94 | /* Return size of file in bytes. */ 95 | return(ret); 96 | } 97 | -------------------------------------------------------------------------------- /jpegl/huftable.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | License: 4 | This software and/or related materials was developed at the National Institute 5 | of Standards and Technology (NIST) by employees of the Federal Government 6 | in the course of their official duties. Pursuant to title 17 Section 105 7 | of the United States Code, this software is not subject to copyright 8 | protection and is in the public domain. 9 | 10 | This software and/or related materials have been determined to be not subject 11 | to the EAR (see Part 734.3 of the EAR for exact details) because it is 12 | a publicly available technology and software, and is freely distributed 13 | to any interested party with no licensing requirements. Therefore, it is 14 | permissible to distribute this software as a free download from the internet. 15 | 16 | Disclaimer: 17 | This software and/or related materials was developed to promote biometric 18 | standards and biometric technology testing for the Federal Government 19 | in accordance with the USA PATRIOT Act and the Enhanced Border Security 20 | and Visa Entry Reform Act. Specific hardware and software products identified 21 | in this software were used in order to perform the software development. 22 | In no case does such identification imply recommendation or endorsement 23 | by the National Institute of Standards and Technology, nor does it imply that 24 | the products and equipment identified are necessarily the best available 25 | for the purpose. 26 | 27 | This software and/or related materials are provided "AS-IS" without warranty 28 | of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, 29 | NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY 30 | or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the 31 | licensed product, however used. In no event shall NIST be liable for any 32 | damages and/or costs, including but not limited to incidental or consequential 33 | damages of any kind, including economic damage or injury to property and lost 34 | profits, regardless of whether NIST shall be advised, have reason to know, 35 | or in fact shall know of the possibility. 36 | 37 | By using this software, you agree to bear all risk relating to quality, 38 | use and performance of the software and/or related materials. You agree 39 | to hold the Government harmless from any claim arising from your use 40 | of the software. 41 | 42 | *******************************************************************************/ 43 | 44 | 45 | /*********************************************************************** 46 | LIBRARY: JPEGL - Lossless JPEG Image Compression 47 | 48 | FILE: HUFTABLE.C 49 | AUTHORS: Craig Watson 50 | Michael Garris 51 | DATE: 12/01/2000 52 | UPDATED: 03/16/2005 by MDG 53 | 54 | Contains routines responsible for processing huffman tables 55 | used for JPEGL (lossless) image compression. 56 | 57 | ROUTINES: 58 | #cat: gen_huff_tables - Given frequency of difference categories, generates 59 | #cat: huffman tables for use with JPEGL compression. 60 | #cat: read_huffman_table_jpegl - Reads the next huffman table from an 61 | #cat: open JPEGL compressed file. 62 | #cat: getc_huffman_table_jpegl - Reads the next huffman table from a 63 | #cat: JPEGL compressed memory buffer. 64 | #cat: free_HUFF_TABLES - deallocates a list of huffman tables. 65 | #cat: 66 | #cat: free_HUFF_TABLE - deallocates a huffman table structure. 67 | #cat: 68 | 69 | ***********************************************************************/ 70 | 71 | #include 72 | #include 73 | #include 74 | 75 | /*****************************************************/ 76 | /* for encoder */ 77 | int gen_huff_tables(HUF_TABLE **huf_table, const int N) 78 | { 79 | int i, ret, adjust; 80 | HUFFCODE *thuffcode_table; 81 | 82 | for(i = 0; i < N; i++) { 83 | 84 | huf_table[i]->table_id = MIN_HUFFTABLE_ID + i; 85 | 86 | if((ret = find_huff_sizes(&(huf_table[i]->codesize), 87 | huf_table[i]->freq, MAX_HUFFCOUNTS_JPEGL))){ 88 | return(ret); 89 | } 90 | 91 | if((ret = find_num_huff_sizes(&(huf_table[i]->bits), &adjust, 92 | huf_table[i]->codesize, MAX_HUFFCOUNTS_JPEGL))){ 93 | return(ret); 94 | } 95 | 96 | if(adjust){ 97 | if((ret = sort_huffbits(huf_table[i]->bits))){ 98 | return(ret); 99 | } 100 | } 101 | 102 | if((ret = sort_code_sizes(&(huf_table[i]->values), 103 | huf_table[i]->codesize, MAX_HUFFCOUNTS_JPEGL))){ 104 | return(ret); 105 | } 106 | 107 | if((ret = build_huffsizes(&thuffcode_table, &(huf_table[i]->last_size), 108 | huf_table[i]->bits, MAX_HUFFCOUNTS_JPEGL))){ 109 | return(ret); 110 | } 111 | 112 | build_huffcodes(thuffcode_table); 113 | 114 | if((ret = build_huffcode_table(&(huf_table[i]->huffcode_table), 115 | thuffcode_table, huf_table[i]->last_size, 116 | huf_table[i]->values, MAX_HUFFCOUNTS_JPEGL))){ 117 | free(thuffcode_table); 118 | return(ret); 119 | } 120 | 121 | free(thuffcode_table); 122 | } 123 | 124 | return(0); 125 | } 126 | 127 | 128 | /***************************************************/ 129 | /* for decoder */ 130 | int read_huffman_table_jpegl(HUF_TABLE **huf_table, FILE *infp) 131 | { 132 | int ret, i, bytes_left; 133 | unsigned char table_id; 134 | HUF_TABLE *thuf_table; 135 | 136 | thuf_table = (HUF_TABLE *)calloc(1, sizeof(HUF_TABLE)); 137 | if(thuf_table == (HUF_TABLE *)NULL){ 138 | fprintf(stderr, "ERROR : read_huffman_table_jpegl : "); 139 | fprintf(stderr, "calloc : thuf_table\n"); 140 | return(-2); 141 | } 142 | 143 | if((ret = read_huffman_table(&table_id, &(thuf_table->bits), 144 | &(thuf_table->values), MAX_HUFFCOUNTS_JPEGL, 145 | infp, READ_TABLE_LEN, &bytes_left))){ 146 | free_HUFF_TABLE(thuf_table); 147 | return(ret); 148 | } 149 | 150 | /* There should only be one table in each DHT record in a */ 151 | /* JPEGL file. If extra bytes remain, then ERROR. */ 152 | if(bytes_left){ 153 | fprintf(stderr, "ERROR : read_huffman_table_jpegl : "); 154 | fprintf(stderr, "extra bytes after huffman table ID = %d\n", table_id); 155 | free_HUFF_TABLE(thuf_table); 156 | return(-3); 157 | } 158 | 159 | if((table_id < MIN_HUFFTABLE_ID) || 160 | (table_id >= (MIN_HUFFTABLE_ID + MAX_CMPNTS))){ 161 | 162 | if(table_id <= 3){ 163 | fprintf(stderr, "WARNING : read_huffman_table_jpegl : "); 164 | fprintf(stderr, "huffman table index %d not in range %d - %d\n", 165 | table_id, MIN_HUFFTABLE_ID, 166 | MAX_CMPNTS+MIN_HUFFTABLE_ID-1); 167 | fprintf(stderr, "Attempting to decode with given table index."); 168 | fprintf(stderr, " Assuming index values 0-3 are being used.\n"); 169 | table_id += MIN_HUFFTABLE_ID; 170 | } 171 | else{ 172 | fprintf(stderr, "ERROR : read_huffman_table_jpegl : "); 173 | fprintf(stderr, "huffman table index %d not in range %d - %d\n", 174 | table_id, MIN_HUFFTABLE_ID, 175 | MAX_CMPNTS+MIN_HUFFTABLE_ID-1); 176 | free_HUFF_TABLE(thuf_table); 177 | return(-4); 178 | } 179 | } 180 | 181 | thuf_table->table_id = table_id; 182 | thuf_table->def = 1; 183 | 184 | /* Add new huffman table to list. */ 185 | 186 | i = thuf_table->table_id - MIN_HUFFTABLE_ID; 187 | if((huf_table[i] != (HUF_TABLE *)NULL) && 188 | (huf_table[i]->def == 1)){ 189 | 190 | fprintf(stderr, 191 | "ERROR : jpegl_decode_mem : huffman table %d illegally redefined\n", 192 | thuf_table->table_id); 193 | free_HUFF_TABLE(thuf_table); 194 | return(-5); 195 | } 196 | 197 | huf_table[i] = thuf_table; 198 | 199 | /* Build rest of table. */ 200 | 201 | thuf_table->maxcode = (int *)calloc(MAX_HUFFCOUNTS_JPEGL+1, 202 | sizeof(int)); 203 | if(thuf_table->maxcode == (int *)NULL){ 204 | fprintf(stderr, "ERROR : read_huffman_table_jpegl : "); 205 | fprintf(stderr, "calloc : maxcode\n"); 206 | free_HUFF_TABLE(thuf_table); 207 | return(-6); 208 | } 209 | 210 | thuf_table->mincode = (int *)calloc(MAX_HUFFCOUNTS_JPEGL+1, 211 | sizeof(int)); 212 | if(thuf_table->mincode == (int *)NULL){ 213 | fprintf(stderr, "ERROR : read_huffman_table_jpegl : "); 214 | fprintf(stderr, "calloc : mincode\n"); 215 | free_HUFF_TABLE(thuf_table); 216 | return(-7); 217 | } 218 | 219 | thuf_table->valptr = (int *)calloc(MAX_HUFFCOUNTS_JPEGL+1, sizeof(int)); 220 | if(thuf_table->valptr == (int *)NULL){ 221 | fprintf(stderr, "ERROR : read_huffman_table_jpegl : "); 222 | fprintf(stderr, "calloc : valptr\n"); 223 | free_HUFF_TABLE(thuf_table); 224 | return(-8); 225 | } 226 | 227 | /*the next two routines reconstruct the huffman tables that were used 228 | in the Jpeg lossless compression*/ 229 | if((ret = build_huffsizes(&(thuf_table->huffcode_table), 230 | &(thuf_table->last_size), thuf_table->bits, 231 | MAX_HUFFCOUNTS_JPEGL))){ 232 | free_HUFF_TABLE(thuf_table); 233 | return(ret); 234 | } 235 | 236 | build_huffcodes(thuf_table->huffcode_table); 237 | 238 | /*this routine builds a set of three tables used in decoding the compressed 239 | data*/ 240 | gen_decode_table(thuf_table->huffcode_table, 241 | thuf_table->maxcode, thuf_table->mincode, 242 | thuf_table->valptr, thuf_table->bits); 243 | 244 | free(thuf_table->huffcode_table); 245 | thuf_table->huffcode_table = (HUFFCODE *)NULL; 246 | 247 | return(0); 248 | } 249 | 250 | /***************************************************/ 251 | /* for decoder */ 252 | int getc_huffman_table_jpegl(HUF_TABLE **huf_table, 253 | unsigned char **cbufptr, unsigned char *ebufptr) 254 | { 255 | int ret, i, bytes_left; 256 | unsigned char table_id; 257 | HUF_TABLE *thuf_table; 258 | 259 | thuf_table = (HUF_TABLE *)calloc(1, sizeof(HUF_TABLE)); 260 | if(thuf_table == (HUF_TABLE *)NULL){ 261 | fprintf(stderr, "ERROR : getc_huffman_table_jpegl : "); 262 | fprintf(stderr, "calloc : thuf_table\n"); 263 | return(-2); 264 | } 265 | 266 | if((ret = getc_huffman_table(&table_id, &(thuf_table->bits), 267 | &(thuf_table->values), MAX_HUFFCOUNTS_JPEGL, 268 | cbufptr, ebufptr, READ_TABLE_LEN, &bytes_left))){ 269 | free_HUFF_TABLE(thuf_table); 270 | return(ret); 271 | } 272 | 273 | /* There should only be one table in each DHT record in a */ 274 | /* JPEGL file. If extra bytes remain, then ERROR. */ 275 | if(bytes_left){ 276 | fprintf(stderr, "ERROR : getc_huffman_table_jpegl : "); 277 | fprintf(stderr, "extra bytes after huffman table ID = %d\n", table_id); 278 | free_HUFF_TABLE(thuf_table); 279 | return(-3); 280 | } 281 | 282 | if((table_id < MIN_HUFFTABLE_ID) || 283 | (table_id >= (MIN_HUFFTABLE_ID + MAX_CMPNTS))){ 284 | 285 | if(table_id <= 3){ 286 | fprintf(stderr, "WARNING : getc_huffman_table_jpegl : "); 287 | fprintf(stderr, "huffman table index %d not in range %d - %d\n", 288 | table_id, MIN_HUFFTABLE_ID, 289 | MAX_CMPNTS+MIN_HUFFTABLE_ID-1); 290 | fprintf(stderr, "Attempting to decode with given table index."); 291 | fprintf(stderr, " Assuming index values 0-3 are being used.\n"); 292 | table_id += MIN_HUFFTABLE_ID; 293 | } 294 | else{ 295 | fprintf(stderr, "ERROR : getc_huffman_table_jpegl : "); 296 | fprintf(stderr, "huffman table index %d not in range %d - %d\n", 297 | table_id, MIN_HUFFTABLE_ID, 298 | MAX_CMPNTS+MIN_HUFFTABLE_ID-1); 299 | free_HUFF_TABLE(thuf_table); 300 | return(-4); 301 | } 302 | } 303 | 304 | thuf_table->table_id = table_id; 305 | thuf_table->def = 1; 306 | 307 | /* Add new huffman table to list. */ 308 | 309 | i = thuf_table->table_id - MIN_HUFFTABLE_ID; 310 | if((huf_table[i] != (HUF_TABLE *)NULL) && 311 | (huf_table[i]->def == 1)){ 312 | 313 | fprintf(stderr, 314 | "ERROR : jpegl_decode_mem : huffman table %d illegally redefined\n", 315 | thuf_table->table_id); 316 | free_HUFF_TABLE(thuf_table); 317 | return(-5); 318 | } 319 | 320 | huf_table[i] = thuf_table; 321 | 322 | /* Build rest of table. */ 323 | 324 | thuf_table->maxcode = (int *)calloc(MAX_HUFFCOUNTS_JPEGL+1, 325 | sizeof(int)); 326 | if(thuf_table->maxcode == (int *)NULL){ 327 | fprintf(stderr, "ERROR : getc_huffman_table_jpegl : "); 328 | fprintf(stderr, "calloc : maxcode\n"); 329 | free_HUFF_TABLE(thuf_table); 330 | return(-6); 331 | } 332 | 333 | thuf_table->mincode = (int *)calloc(MAX_HUFFCOUNTS_JPEGL+1, 334 | sizeof(int)); 335 | if(thuf_table->mincode == (int *)NULL){ 336 | fprintf(stderr, "ERROR : getc_huffman_table_jpegl : "); 337 | fprintf(stderr, "calloc : mincode\n"); 338 | free_HUFF_TABLE(thuf_table); 339 | return(-7); 340 | } 341 | 342 | thuf_table->valptr = (int *)calloc(MAX_HUFFCOUNTS_JPEGL+1, sizeof(int)); 343 | if(thuf_table->valptr == (int *)NULL){ 344 | fprintf(stderr, "ERROR : getc_huffman_table_jpegl : "); 345 | fprintf(stderr, "calloc : valptr\n"); 346 | free_HUFF_TABLE(thuf_table); 347 | return(-8); 348 | } 349 | 350 | /*the next two routines reconstruct the huffman tables that were used 351 | in the Jpeg lossless compression*/ 352 | if((ret = build_huffsizes(&(thuf_table->huffcode_table), 353 | &(thuf_table->last_size), thuf_table->bits, 354 | MAX_HUFFCOUNTS_JPEGL))){ 355 | free_HUFF_TABLE(thuf_table); 356 | return(ret); 357 | } 358 | 359 | build_huffcodes(thuf_table->huffcode_table); 360 | 361 | /*this routine builds a set of three tables used in decoding the compressed 362 | data*/ 363 | gen_decode_table(thuf_table->huffcode_table, 364 | thuf_table->maxcode, thuf_table->mincode, 365 | thuf_table->valptr, thuf_table->bits); 366 | 367 | free(thuf_table->huffcode_table); 368 | thuf_table->huffcode_table = (HUFFCODE *)NULL; 369 | 370 | return(0); 371 | } 372 | 373 | /******************************************************/ 374 | /* Deallocate list of JPEGL huffman table structures. */ 375 | /******************************************************/ 376 | void free_HUFF_TABLES(HUF_TABLE **huf_table, const int N) 377 | { 378 | int i; 379 | 380 | for(i = 0; i < N; i++){ 381 | if(huf_table[i] != (HUF_TABLE *)NULL){ 382 | free_HUFF_TABLE(huf_table[i]); 383 | } 384 | } 385 | } 386 | 387 | /************** ********************************/ 388 | /* Deallocate a JPEGL huffman table structure. */ 389 | /***********************************************/ 390 | void free_HUFF_TABLE(HUF_TABLE *huf_table) 391 | { 392 | if(huf_table->freq != (int *)NULL) 393 | free(huf_table->freq); 394 | 395 | if(huf_table->codesize != (int *)NULL) 396 | free(huf_table->codesize); 397 | 398 | if(huf_table->bits != (unsigned char *)NULL) 399 | free(huf_table->bits); 400 | 401 | if(huf_table->values != (unsigned char *)NULL) 402 | free(huf_table->values); 403 | 404 | if(huf_table->huffcode_table != (HUFFCODE *)NULL) 405 | free(huf_table->huffcode_table); 406 | 407 | if(huf_table->maxcode != (int *)NULL) 408 | free(huf_table->maxcode); 409 | 410 | if(huf_table->mincode != (int *)NULL) 411 | free(huf_table->mincode); 412 | 413 | if(huf_table->valptr != (int *)NULL) 414 | free(huf_table->valptr); 415 | 416 | free(huf_table); 417 | } 418 | -------------------------------------------------------------------------------- /jpegl/imgdat.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | License: 4 | This software and/or related materials was developed at the National Institute 5 | of Standards and Technology (NIST) by employees of the Federal Government 6 | in the course of their official duties. Pursuant to title 17 Section 105 7 | of the United States Code, this software is not subject to copyright 8 | protection and is in the public domain. 9 | 10 | This software and/or related materials have been determined to be not subject 11 | to the EAR (see Part 734.3 of the EAR for exact details) because it is 12 | a publicly available technology and software, and is freely distributed 13 | to any interested party with no licensing requirements. Therefore, it is 14 | permissible to distribute this software as a free download from the internet. 15 | 16 | Disclaimer: 17 | This software and/or related materials was developed to promote biometric 18 | standards and biometric technology testing for the Federal Government 19 | in accordance with the USA PATRIOT Act and the Enhanced Border Security 20 | and Visa Entry Reform Act. Specific hardware and software products identified 21 | in this software were used in order to perform the software development. 22 | In no case does such identification imply recommendation or endorsement 23 | by the National Institute of Standards and Technology, nor does it imply that 24 | the products and equipment identified are necessarily the best available 25 | for the purpose. 26 | 27 | This software and/or related materials are provided "AS-IS" without warranty 28 | of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, 29 | NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY 30 | or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the 31 | licensed product, however used. In no event shall NIST be liable for any 32 | damages and/or costs, including but not limited to incidental or consequential 33 | damages of any kind, including economic damage or injury to property and lost 34 | profits, regardless of whether NIST shall be advised, have reason to know, 35 | or in fact shall know of the possibility. 36 | 37 | By using this software, you agree to bear all risk relating to quality, 38 | use and performance of the software and/or related materials. You agree 39 | to hold the Government harmless from any claim arising from your use 40 | of the software. 41 | 42 | *******************************************************************************/ 43 | 44 | 45 | /*********************************************************************** 46 | LIBRARY: JPEGL - Lossless JPEG Image Compression 47 | 48 | FILE: IMGDAT.C 49 | AUTHORS: Craig Watson 50 | Michael Garris 51 | DATE: 11/28/2000 52 | UPDATED: 03/16/2005 by MDG 53 | 54 | Contains routines responsible for manipulating an IMG_DAT 55 | (image data) structure that hold an image's pixmap and 56 | related attributes. 57 | 58 | ROUTINES: 59 | #cat: get_IMG_DAT_image - Extracts the image pixmap and returns its 60 | #cat: attributes stored in an IMG_DAT structure. 61 | #cat: setup_IMG_DAT_nonintrlv_encode - Initialize an IMG_DAT structure 62 | #cat: for JPEGL compressing a non-interleaved pixmap. 63 | #cat: setup_IMG_DAT_decode - Initialize an IMG_DAT structure for 64 | #cat: compressing a general pixmap. 65 | #cat: update_IMG_DAT_decode - Augments an IMG_DAT structure used for 66 | #cat: decompression with attributes derived from a 67 | #cat: JPEGL SCN Header, including the allocation for 68 | #cat: the reconstructred pixmap. 69 | #cat: free_IMG_DAT - Deallocates an IMG_DAT structure. 70 | 71 | ***********************************************************************/ 72 | 73 | #include 74 | #include 75 | #include 76 | #include 77 | 78 | /**************************************/ 79 | /* Extract image from image structure */ 80 | /**************************************/ 81 | int get_IMG_DAT_image(unsigned char **odata, int *olen, 82 | int *width, int *height, int *depth, int *ppi, 83 | IMG_DAT *img_dat) 84 | { 85 | int i, nsizes[MAX_CMPNTS], nlen; 86 | unsigned char *ndata, *nptr; 87 | 88 | nlen = 0; 89 | for(i = 0; i < img_dat->n_cmpnts; i++){ 90 | nsizes[i] = img_dat->samp_width[i] * img_dat->samp_height[i]; 91 | nlen += nsizes[i]; 92 | } 93 | 94 | ndata = (unsigned char *)malloc(nlen * sizeof(unsigned char)); 95 | if(ndata == (unsigned char *)NULL){ 96 | fprintf(stderr, "ERROR : get_IMG_DAT_image : malloc : ndata\n"); 97 | return(-2); 98 | } 99 | 100 | nptr = ndata; 101 | for(i = 0; i < img_dat->n_cmpnts; i++){ 102 | memcpy(nptr, img_dat->image[i], nsizes[i] * sizeof(unsigned char)); 103 | nptr += nsizes[i]; 104 | } 105 | 106 | *odata = ndata; 107 | *olen = nlen; 108 | *width = img_dat->max_width; 109 | *height = img_dat->max_height; 110 | *depth = img_dat->pix_depth; 111 | *ppi = img_dat->ppi; 112 | 113 | return(0); 114 | } 115 | 116 | /*******************************************/ 117 | /* Setup image structure to compress image */ 118 | /*******************************************/ 119 | int setup_IMG_DAT_nonintrlv_encode(IMG_DAT **oimg_dat, unsigned char *idata, 120 | const int w, const int h, const int d, const int ppi, 121 | int *hor_sampfctr, int *vrt_sampfctr, const int n_cmpnts, 122 | const unsigned char pt_val, const unsigned char pred_val) 123 | { 124 | int i, j, max_hor, max_vrt, plane_size; 125 | IMG_DAT *img_dat; 126 | unsigned char *iptr; 127 | 128 | if((d != 8) && (d != 24)){ 129 | fprintf(stderr, "ERROR : setup_IMG_DAT_nonintrlv_encode : "); 130 | fprintf(stderr, "image pixel depth %d != 8 or 24\n", d); 131 | return(-2); 132 | } 133 | 134 | if(n_cmpnts > MAX_CMPNTS){ 135 | fprintf(stderr, "ERROR : setup_IMG_DAT_nonintrlv_encode : "); 136 | fprintf(stderr, "number of components = %d > %d\n", 137 | n_cmpnts, MAX_CMPNTS); 138 | return(-3); 139 | } 140 | 141 | if(((d == 8) && (n_cmpnts != 1)) || 142 | ((d == 24) && (n_cmpnts != 3))){ 143 | fprintf(stderr, "ERROR : setup_IMG_DAT_nonintrlv_encode : "); 144 | fprintf(stderr, "depth = %d mismatched with n_cmpnts = %d\n", 145 | d, n_cmpnts); 146 | return(-4); 147 | } 148 | 149 | if((img_dat = (IMG_DAT *)calloc(1, sizeof(IMG_DAT))) == (IMG_DAT *)NULL){ 150 | fprintf(stderr, "ERROR : setup_IMG_DAT_nonintrlv_encode : "); 151 | fprintf(stderr, "calloc : img_dat\n"); 152 | return(-5); 153 | } 154 | 155 | img_dat->max_width = w; 156 | img_dat->max_height = h; 157 | img_dat->pix_depth = d; 158 | img_dat->ppi = ppi; 159 | img_dat->intrlv = NO_INTRLV; 160 | img_dat->n_cmpnts = n_cmpnts; 161 | img_dat->cmpnt_depth = 8; /* data units must be unsigned char */ 162 | 163 | /* Determine max tile dimensions across all components ... */ 164 | max_hor = -1; 165 | max_vrt = -1; 166 | for(i = 0; i < n_cmpnts; i++){ 167 | if(hor_sampfctr[i] > max_hor) 168 | max_hor = hor_sampfctr[i]; 169 | if(vrt_sampfctr[i] > max_vrt) 170 | max_vrt = vrt_sampfctr[i]; 171 | } 172 | 173 | iptr = idata; 174 | for(i = 0; i < n_cmpnts; i++){ 175 | img_dat->hor_sampfctr[i] = hor_sampfctr[i]; 176 | img_dat->vrt_sampfctr[i] = vrt_sampfctr[i]; 177 | /* Compute the pixel width & height of the component's plane. */ 178 | img_dat->samp_width[i] = (int)ceil(img_dat->max_width * 179 | (hor_sampfctr[i] / (double)max_hor)); 180 | img_dat->samp_height[i] = (int)ceil(img_dat->max_height * 181 | (vrt_sampfctr[i] / (double)max_vrt)); 182 | img_dat->point_trans[i] = pt_val; 183 | img_dat->predict[i] = pred_val; 184 | 185 | plane_size = img_dat->samp_width[i] * img_dat->samp_height[i]; 186 | img_dat->image[i] = 187 | (unsigned char *)malloc(plane_size * sizeof(unsigned char)); 188 | if(img_dat->image[i] == (unsigned char *)NULL){ 189 | fprintf(stderr, "ERROR : setup_IMG_DAT_nonintrlv_encode : "); 190 | fprintf(stderr, "malloc : img_dat->image[%d]\n", i); 191 | for(j = 0; j < i; j++) 192 | free(img_dat->image[j]); 193 | free(img_dat); 194 | return(-6); 195 | } 196 | memcpy(img_dat->image[i], iptr, plane_size); 197 | 198 | /* Bump to start of next component plane. */ 199 | iptr += plane_size; 200 | } 201 | 202 | *oimg_dat = img_dat; 203 | return(0); 204 | } 205 | 206 | /*********************************************/ 207 | int setup_IMG_DAT_decode(IMG_DAT **oimg_dat, const int ppi, 208 | FRM_HEADER_JPEGL *frm_header) 209 | { 210 | int i, max_hor, max_vrt; 211 | IMG_DAT *img_dat; 212 | 213 | img_dat = (IMG_DAT *)calloc(1, sizeof(IMG_DAT)); 214 | if(img_dat == (IMG_DAT *)NULL){ 215 | fprintf(stderr, "ERROR : setup_IMG_DAT_decode : calloc : img_dat\n"); 216 | return(-2); 217 | } 218 | 219 | img_dat->max_width = frm_header->x; 220 | img_dat->max_height = frm_header->y; 221 | img_dat->pix_depth = frm_header->Nf * 8; 222 | img_dat->ppi = ppi; 223 | img_dat->intrlv = -1; 224 | img_dat->n_cmpnts = frm_header->Nf; 225 | img_dat->cmpnt_depth = frm_header->prec; 226 | 227 | max_hor = -1; 228 | max_vrt = -1; 229 | for(i = 0; i < img_dat->n_cmpnts; i++){ 230 | img_dat->hor_sampfctr[i] = frm_header->HV[i]>>4; 231 | img_dat->vrt_sampfctr[i] = frm_header->HV[i] & 0x0F; 232 | if(max_hor < img_dat->hor_sampfctr[i]) 233 | max_hor = img_dat->hor_sampfctr[i]; 234 | if(max_vrt < img_dat->vrt_sampfctr[i]) 235 | max_vrt = img_dat->vrt_sampfctr[i]; 236 | } 237 | 238 | for(i = 0; i < img_dat->n_cmpnts; i++){ 239 | img_dat->samp_width[i] = (int)ceil(img_dat->max_width * 240 | (img_dat->hor_sampfctr[i]/(double)max_hor)); 241 | img_dat->samp_height[i] = (int)ceil(img_dat->max_height * 242 | (img_dat->vrt_sampfctr[i]/(double)max_vrt)); 243 | } 244 | 245 | *oimg_dat = img_dat; 246 | return(0); 247 | } 248 | 249 | /*********************************************/ 250 | int update_IMG_DAT_decode(IMG_DAT *img_dat, SCN_HEADER *scn_header, 251 | HUF_TABLE **huf_table) 252 | { 253 | int i, cmpnt_i; 254 | 255 | if(scn_header->Ns > 1) 256 | img_dat->intrlv = 1; 257 | else 258 | img_dat->intrlv = 0; 259 | 260 | /* NOTE: scn_header->Ns == 1 if encoded data is NOT interleaved. */ 261 | for(i = 0; i < scn_header->Ns; i++) { 262 | cmpnt_i = scn_header->Cs[i]; 263 | if((huf_table[cmpnt_i] == (HUF_TABLE *)NULL) || 264 | (huf_table[cmpnt_i]->def != 1)){ 265 | fprintf(stderr, "ERROR : update_IMG_DAT_decode : "); 266 | fprintf(stderr, "huffman table %d not defined\n", cmpnt_i); 267 | return(-2); 268 | } 269 | img_dat->point_trans[cmpnt_i] = scn_header->Ahl; 270 | img_dat->predict[cmpnt_i] = scn_header->Ss; 271 | img_dat->image[cmpnt_i] = 272 | (unsigned char *)malloc(img_dat->samp_width[cmpnt_i] * 273 | img_dat->samp_height[cmpnt_i]); 274 | if(img_dat->image[cmpnt_i] == (unsigned char *)NULL){ 275 | fprintf(stderr, "ERROR : update_IMG_DAT_decode : "); 276 | fprintf(stderr, "malloc : img_dat->image[%d]\n", cmpnt_i); 277 | return(-3); 278 | } 279 | } 280 | 281 | return(0); 282 | } 283 | 284 | /*********************************************/ 285 | int setup_IMG_DAT_decode_old(IMG_DAT **oimg_dat, const int ppi, 286 | FRM_HEADER_JPEGL *frm_header, 287 | SCN_HEADER *scn_header, HUF_TABLE **huf_table) 288 | { 289 | int i, cmpnt_i; 290 | IMG_DAT *img_dat; 291 | 292 | img_dat = (IMG_DAT *)calloc(1, sizeof(IMG_DAT)); 293 | if(img_dat == (IMG_DAT *)NULL){ 294 | fprintf(stderr, "ERROR : setup_IMG_DAT_decode : calloc : img_dat\n"); 295 | return(-2); 296 | } 297 | 298 | img_dat->n_cmpnts = frm_header->Nf; 299 | if(scn_header->Ns > 1) 300 | img_dat->intrlv = 1; 301 | else 302 | img_dat->intrlv = 0; 303 | 304 | if(!(img_dat->intrlv)) { 305 | cmpnt_i = scn_header->Cs[0]; 306 | if((huf_table[cmpnt_i] == (HUF_TABLE *)NULL) || 307 | (huf_table[cmpnt_i]->def != 1)){ 308 | fprintf(stderr, "ERROR : setup_IMG_DAT_decode : "); 309 | fprintf(stderr, "huffman table %d not defined %d\n", cmpnt_i, 310 | scn_header->Ns); 311 | free_IMG_DAT(img_dat, NO_FREE_IMAGE); 312 | return(-3); 313 | } 314 | img_dat->point_trans[cmpnt_i] = scn_header->Ahl; 315 | img_dat->predict[cmpnt_i] = scn_header->Ss; 316 | img_dat->max_width = frm_header->x; 317 | img_dat->max_height = frm_header->y; 318 | img_dat->pix_depth = frm_header->prec; 319 | img_dat->ppi = ppi; 320 | 321 | img_dat->image[cmpnt_i] = (unsigned char *)malloc(img_dat->max_width * 322 | img_dat->max_height); 323 | if(img_dat->image[cmpnt_i] == (unsigned char *)NULL){ 324 | fprintf(stderr, "ERROR : setup_IMG_DAT_decode : "); 325 | fprintf(stderr, "malloc : img_dat->image[%d]\n", cmpnt_i); 326 | free_IMG_DAT(img_dat, NO_FREE_IMAGE); 327 | return(-4); 328 | } 329 | } 330 | else { 331 | img_dat->max_width = frm_header->x; 332 | img_dat->max_height = frm_header->y; 333 | img_dat->pix_depth = frm_header->prec; 334 | img_dat->ppi = ppi; 335 | 336 | for(i = 0; i < scn_header->Ns; i++) { 337 | cmpnt_i = scn_header->Cs[i]; 338 | if((huf_table[cmpnt_i] == (HUF_TABLE *)NULL) || 339 | (huf_table[cmpnt_i]->def != 1)){ 340 | fprintf(stderr, "ERROR : setup_IMG_DAT_decode : "); 341 | fprintf(stderr, "huffman table %d not defined\n", cmpnt_i); 342 | free_IMG_DAT(img_dat, NO_FREE_IMAGE); 343 | return(-5); 344 | } 345 | img_dat->point_trans[cmpnt_i] = scn_header->Ahl; 346 | img_dat->predict[cmpnt_i] = scn_header->Ss; 347 | 348 | img_dat->image[cmpnt_i] = (unsigned char *)malloc(img_dat->max_width * 349 | img_dat->max_height); 350 | if(img_dat->image[cmpnt_i] == (unsigned char *)NULL){ 351 | fprintf(stderr, "ERROR : setup_IMG_DAT_decode : "); 352 | fprintf(stderr, "malloc : img_dat->image[%d]\n", cmpnt_i); 353 | free_IMG_DAT(img_dat, NO_FREE_IMAGE); 354 | return(-6); 355 | } 356 | } 357 | } 358 | 359 | *oimg_dat = img_dat; 360 | return(0); 361 | } 362 | 363 | 364 | /******************************/ 365 | /* Deallocate image structure */ 366 | /******************************/ 367 | void free_IMG_DAT(IMG_DAT *img_dat, const int img_flag) 368 | { 369 | int i; 370 | 371 | for(i = 0; i < img_dat->n_cmpnts; i++){ 372 | if(img_dat->diff[i] != (short *)NULL) 373 | free(img_dat->diff[i]); 374 | } 375 | 376 | if(img_flag){ 377 | for(i = 0; i < img_dat->n_cmpnts; i++){ 378 | if(img_dat->image[i] != (unsigned char *)NULL) 379 | free(img_dat->image[i]); 380 | } 381 | } 382 | 383 | free(img_dat); 384 | } 385 | -------------------------------------------------------------------------------- /jpegl/ppi.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | License: 4 | This software and/or related materials was developed at the National Institute 5 | of Standards and Technology (NIST) by employees of the Federal Government 6 | in the course of their official duties. Pursuant to title 17 Section 105 7 | of the United States Code, this software is not subject to copyright 8 | protection and is in the public domain. 9 | 10 | This software and/or related materials have been determined to be not subject 11 | to the EAR (see Part 734.3 of the EAR for exact details) because it is 12 | a publicly available technology and software, and is freely distributed 13 | to any interested party with no licensing requirements. Therefore, it is 14 | permissible to distribute this software as a free download from the internet. 15 | 16 | Disclaimer: 17 | This software and/or related materials was developed to promote biometric 18 | standards and biometric technology testing for the Federal Government 19 | in accordance with the USA PATRIOT Act and the Enhanced Border Security 20 | and Visa Entry Reform Act. Specific hardware and software products identified 21 | in this software were used in order to perform the software development. 22 | In no case does such identification imply recommendation or endorsement 23 | by the National Institute of Standards and Technology, nor does it imply that 24 | the products and equipment identified are necessarily the best available 25 | for the purpose. 26 | 27 | This software and/or related materials are provided "AS-IS" without warranty 28 | of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, 29 | NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY 30 | or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the 31 | licensed product, however used. In no event shall NIST be liable for any 32 | damages and/or costs, including but not limited to incidental or consequential 33 | damages of any kind, including economic damage or injury to property and lost 34 | profits, regardless of whether NIST shall be advised, have reason to know, 35 | or in fact shall know of the possibility. 36 | 37 | By using this software, you agree to bear all risk relating to quality, 38 | use and performance of the software and/or related materials. You agree 39 | to hold the Government harmless from any claim arising from your use 40 | of the software. 41 | 42 | *******************************************************************************/ 43 | 44 | 45 | /*********************************************************************** 46 | LIBRARY: JPEGL - Lossless JPEG Image Compression 47 | 48 | FILE: PPI.C 49 | AUTHORS: Craig Watson 50 | Michael Garris 51 | DATE: 01/17/2001 52 | 53 | Contains routines responsible for determining the scan resolution 54 | in units of pixels per inch from a JPEGL compressed datastream. 55 | 56 | ROUTINES: 57 | #cat: get_ppi_jpegl - Given a JFIF Header from a JPEGL compressed 58 | #cat: datastream, extracts/derives the pixel scan 59 | #cat: resolution in units of pixel per inch. 60 | 61 | ***********************************************************************/ 62 | 63 | #include 64 | #include 65 | 66 | #define CM_PER_INCH 2.54 67 | 68 | /************************************************************************/ 69 | int get_ppi_jpegl(int *oppi, JFIF_HEADER *jfif_header) 70 | { 71 | int ppi; 72 | 73 | /* Get and set scan density in pixels per inch. */ 74 | switch(jfif_header->units){ 75 | /* pixels per inch */ 76 | case 1: 77 | /* take the horizontal pixel density, even if the vertical is */ 78 | /* not the same */ 79 | ppi = jfif_header->dx; 80 | break; 81 | /* pixels per cm */ 82 | case 2: 83 | /* compute ppi from horizontal density even if not */ 84 | /* equal to vertical */ 85 | ppi = (int)((jfif_header->dx * CM_PER_INCH) + 0.5); 86 | break; 87 | /* unknown density */ 88 | case 0: 89 | /* set ppi to -1 == UNKNOWN */ 90 | ppi = -1; 91 | break; 92 | /* ERROR */ 93 | default: 94 | fprintf(stderr, "ERROR : get_ppi_jpegl : "); 95 | fprintf(stderr, "illegal density unit = %d\n", jfif_header->units); 96 | return(-2); 97 | } 98 | 99 | *oppi = ppi; 100 | 101 | return(0); 102 | } 103 | -------------------------------------------------------------------------------- /jpegl/sd4util.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | License: 4 | This software and/or related materials was developed at the National Institute 5 | of Standards and Technology (NIST) by employees of the Federal Government 6 | in the course of their official duties. Pursuant to title 17 Section 105 7 | of the United States Code, this software is not subject to copyright 8 | protection and is in the public domain. 9 | 10 | This software and/or related materials have been determined to be not subject 11 | to the EAR (see Part 734.3 of the EAR for exact details) because it is 12 | a publicly available technology and software, and is freely distributed 13 | to any interested party with no licensing requirements. Therefore, it is 14 | permissible to distribute this software as a free download from the internet. 15 | 16 | Disclaimer: 17 | This software and/or related materials was developed to promote biometric 18 | standards and biometric technology testing for the Federal Government 19 | in accordance with the USA PATRIOT Act and the Enhanced Border Security 20 | and Visa Entry Reform Act. Specific hardware and software products identified 21 | in this software were used in order to perform the software development. 22 | In no case does such identification imply recommendation or endorsement 23 | by the National Institute of Standards and Technology, nor does it imply that 24 | the products and equipment identified are necessarily the best available 25 | for the purpose. 26 | 27 | This software and/or related materials are provided "AS-IS" without warranty 28 | of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, 29 | NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY 30 | or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the 31 | licensed product, however used. In no event shall NIST be liable for any 32 | damages and/or costs, including but not limited to incidental or consequential 33 | damages of any kind, including economic damage or injury to property and lost 34 | profits, regardless of whether NIST shall be advised, have reason to know, 35 | or in fact shall know of the possibility. 36 | 37 | By using this software, you agree to bear all risk relating to quality, 38 | use and performance of the software and/or related materials. You agree 39 | to hold the Government harmless from any claim arising from your use 40 | of the software. 41 | 42 | *******************************************************************************/ 43 | 44 | 45 | /*********************************************************************** 46 | LIBRARY: JPEGL - Lossless JPEG Image Compression 47 | 48 | FILE: SD4UTIL.C 49 | AUTHOR: Craig Watson 50 | DATE: 12/15/2000 51 | UPDATED: 03/16/2005 by MDG 52 | 53 | Contains routines responsible for decoding an old image format 54 | used for JPEGL-compressing images in NIST Special Database 4. 55 | This format should be considered obsolete. 56 | 57 | ROUTINES: 58 | #cat: jpegl_sd4_decode_mem - Decompresses a JPEGL-compressed datastream 59 | #cat: according to the old image format used in NIST Special 60 | #cat: Database 4. This routine should be used to decompress 61 | #cat: legacy data only. This old format should be considered 62 | #cat: obsolete. 63 | 64 | ***********************************************************************/ 65 | 66 | #include 67 | #include 68 | #include 69 | 70 | static int getc_huffman_table_jpegl_sd4(HUF_TABLE **, unsigned char **, 71 | unsigned char *); 72 | static int decode_data_jpegl_sd4(int *, int *, int *, int *, 73 | unsigned char *, unsigned char **, unsigned char *, int *); 74 | static int getc_nextbits_jpegl_sd4(unsigned short *, unsigned char **, 75 | unsigned char *, int *, const int); 76 | 77 | /************************************************************************/ 78 | /* Algorithms coded from: */ 79 | /* */ 80 | /* Committee draft ISO/IEC CD 10198-1 for */ 81 | /* "Digital Compression and Coding of */ 82 | /* Continuous-tone Still images" */ 83 | /* */ 84 | /************************************************************************/ 85 | int jpegl_sd4_decode_mem(unsigned char *idata, const int ilen, const int width, 86 | const int height, const int depth, unsigned char *odata) 87 | { 88 | HUF_TABLE *huf_table[MAX_CMPNTS]; /*These match the jpegl static 89 | allocation but jpegl_sd4 only has 90 | 1 plane of data not MAX_CMPNTS*/ 91 | int i, ret; 92 | unsigned char *cbufptr, *ebufptr; 93 | unsigned char predictor; /*predictor type used*/ 94 | unsigned char Pt = 0; /*Point Transform*/ 95 | /*holds the code for all possible difference values */ 96 | /*that occur when encoding*/ 97 | int huff_decoder[MAX_CATEGORY][LARGESTDIFF+1]; 98 | 99 | int diff_cat; /*code word category*/ 100 | int bit_count = 0; /*marks the bit to receive from the input byte*/ 101 | unsigned short diff_code; /*"raw" difference pixel*/ 102 | int full_diff_code; /*difference code extend to full precision*/ 103 | short data_pred; /*prediction of pixel value*/ 104 | unsigned char *outbuf; 105 | 106 | /* Set memory buffer pointers. */ 107 | cbufptr = idata; 108 | ebufptr = idata + ilen; 109 | outbuf = odata; 110 | 111 | 112 | for(i = 0; i < MAX_CMPNTS; i++) 113 | huf_table[i] = (HUF_TABLE *)NULL; 114 | 115 | 116 | if((ret = getc_huffman_table_jpegl_sd4(huf_table, &cbufptr, ebufptr))) 117 | return(ret); 118 | 119 | if((ret = getc_byte(&predictor, &cbufptr, ebufptr))) { 120 | free_HUFF_TABLES(huf_table, 1); 121 | return(ret); 122 | } 123 | 124 | /*this routine builds a table used in 125 | decoding coded difference pixels*/ 126 | build_huff_decode_table(huff_decoder); 127 | 128 | /*decompress the pixel "differences" 129 | sequentially*/ 130 | for(i = 0; i < width*height; i++) { 131 | 132 | /*get next huffman category code from 133 | compressed input data stream*/ 134 | if((ret = decode_data_jpegl_sd4(&diff_cat, huf_table[0]->mincode, 135 | huf_table[0]->maxcode, 136 | huf_table[0]->valptr, huf_table[0]->values, 137 | &cbufptr, ebufptr, &bit_count))){ 138 | free_HUFF_TABLES(huf_table, 1); 139 | return(ret); 140 | } 141 | 142 | /*get the required bits (given by huffman 143 | code to reconstruct the difference 144 | value for the pixel*/ 145 | if((ret = getc_nextbits_jpegl_sd4(&diff_code, &cbufptr, ebufptr, 146 | &bit_count, diff_cat))){ 147 | free_HUFF_TABLES(huf_table, 1); 148 | return(ret); 149 | } 150 | 151 | /*extend the difference value to 152 | full precision*/ 153 | full_diff_code = huff_decoder[diff_cat][diff_code]; 154 | 155 | /*reverse the pixel prediction and 156 | store the pixel value in the 157 | output buffer*/ 158 | if((ret = predict(&data_pred, outbuf, width, i, depth, 159 | predictor, Pt))){ 160 | free_HUFF_TABLES(huf_table, 1); 161 | return(ret); 162 | } 163 | 164 | *outbuf = full_diff_code + data_pred; 165 | outbuf++; 166 | } 167 | free_HUFF_TABLES(huf_table, 1); 168 | 169 | return(0); 170 | } 171 | 172 | 173 | /************************************/ 174 | /*routine to get huffman code tables*/ 175 | /************************************/ 176 | static int getc_huffman_table_jpegl_sd4(HUF_TABLE **huf_table, 177 | unsigned char **cbufptr, unsigned char *ebufptr) 178 | { 179 | int i, ret; /*increment variable*/ 180 | unsigned char number; /*number of huffbits and huffvalues*/ 181 | unsigned char *huffbits, *huffvalues; 182 | HUF_TABLE *thuf_table; 183 | 184 | if(debug > 0) 185 | fprintf(stdout, "Start reading huffman table jpegl_sd4.\n"); 186 | 187 | if((ret = getc_byte(&number, cbufptr, ebufptr))) 188 | return(ret); 189 | 190 | huffbits = (unsigned char *)calloc(MAX_HUFFBITS, sizeof(unsigned char)); 191 | if(huffbits == (unsigned char *)NULL){ 192 | fprintf(stderr, 193 | "ERROR : getc_huffman_table_jpegl_sd4 : calloc : huffbits\n"); 194 | return(-2); 195 | } 196 | 197 | for (i = 0; i < MAX_HUFFBITS_JPEGL_SD4; i++) 198 | if((ret = getc_byte(&(huffbits[i]), cbufptr, ebufptr))){ 199 | free(huffbits); 200 | return(ret); 201 | } 202 | 203 | if(debug > 1) 204 | for (i = 0; i < MAX_HUFFBITS_JPEGL_SD4; i++) 205 | fprintf(stdout, "bits[%d] = %d\n", i, huffbits[i]); 206 | 207 | huffvalues = (unsigned char *)calloc(MAX_HUFFCOUNTS_JPEGL, 208 | sizeof(unsigned char)); 209 | if(huffvalues == (unsigned char *)NULL){ 210 | fprintf(stderr, 211 | "ERROR : getc_huffman_table_jpegl_sd4 : calloc : huffvalues\n"); 212 | free(huffbits); 213 | return(-3); 214 | } 215 | for (i = 0; i < (number - MAX_HUFFBITS_JPEGL_SD4); i ++) 216 | if((ret = getc_byte(&(huffvalues[i]), cbufptr, ebufptr))){ 217 | free(huffbits); 218 | free(huffvalues); 219 | return(ret); 220 | } 221 | 222 | if(debug > 1) 223 | for (i = 0; i < number-MAX_HUFFBITS_JPEGL_SD4; i++) 224 | fprintf(stdout, "values[%d] = %d\n", i, huffvalues[i]); 225 | 226 | 227 | thuf_table = (HUF_TABLE *)calloc(1, sizeof(HUF_TABLE)); 228 | if(thuf_table == (HUF_TABLE *)NULL){ 229 | fprintf(stderr, "ERROR : getc_huffman_table_jpegl_sd4 : "); 230 | fprintf(stderr, "calloc : thuf_table\n"); 231 | return(-4); 232 | } 233 | thuf_table->freq = (int *)NULL; 234 | thuf_table->codesize = (int *)NULL; 235 | 236 | thuf_table->bits = huffbits; 237 | thuf_table->values = huffvalues; 238 | 239 | huf_table[0] = thuf_table; 240 | 241 | /* Build rest of table. */ 242 | 243 | thuf_table->maxcode = (int *)calloc(MAX_HUFFCOUNTS_JPEGL+1, 244 | sizeof(int)); 245 | if(thuf_table->maxcode == (int *)NULL){ 246 | fprintf(stderr, "ERROR : getc_huffman_table_jpegl_sd4 : "); 247 | fprintf(stderr, "calloc : maxcode\n"); 248 | free_HUFF_TABLE(thuf_table); 249 | return(-5); 250 | } 251 | 252 | thuf_table->mincode = (int *)calloc(MAX_HUFFCOUNTS_JPEGL+1, 253 | sizeof(int)); 254 | if(thuf_table->mincode == (int *)NULL){ 255 | fprintf(stderr, "ERROR : getc_huffman_table_jpegl_sd4 : "); 256 | fprintf(stderr, "calloc : mincode\n"); 257 | free_HUFF_TABLE(thuf_table); 258 | return(-6); 259 | } 260 | 261 | thuf_table->valptr = (int *)calloc(MAX_HUFFCOUNTS_JPEGL+1, sizeof(int)); 262 | if(thuf_table->valptr == (int *)NULL){ 263 | fprintf(stderr, "ERROR : getc_huffman_table_jpegl_sd4 : "); 264 | fprintf(stderr, "calloc : valptr\n"); 265 | free_HUFF_TABLE(thuf_table); 266 | return(-7); 267 | } 268 | 269 | /*the next two routines reconstruct 270 | the huffman tables that were used 271 | in the Jpeg lossless compression*/ 272 | if((ret = build_huffsizes(&(thuf_table->huffcode_table), 273 | &(thuf_table->last_size), 274 | thuf_table->bits, MAX_HUFFCOUNTS_JPEGL))){ 275 | free_HUFF_TABLES(huf_table, 1); 276 | return(ret); 277 | } 278 | 279 | build_huffcodes(thuf_table->huffcode_table); 280 | 281 | /*this routine builds a set of three 282 | tables used in decoding the compressed 283 | data*/ 284 | gen_decode_table(thuf_table->huffcode_table, 285 | thuf_table->maxcode, thuf_table->mincode, 286 | thuf_table->valptr, thuf_table->bits); 287 | 288 | free(thuf_table->huffcode_table); 289 | thuf_table->huffcode_table = (HUFFCODE *)NULL; 290 | 291 | if(debug > 0) 292 | fprintf(stdout, "Done reading huffman table jpegl_sd4.\n"); 293 | 294 | return(0); 295 | } 296 | 297 | /************************************/ 298 | /*routine to decode the encoded data*/ 299 | /************************************/ 300 | static int decode_data_jpegl_sd4(int *odiff_cat, int *mincode, int *maxcode, 301 | int *valptr, unsigned char *huffvalues, 302 | unsigned char **cbufptr, unsigned char *ebufptr, 303 | int *bit_count) 304 | { 305 | int ret; 306 | int inx, inx2; /*increment variables*/ 307 | int code; /*becomes a huffman code word one bit at a time*/ 308 | unsigned short tcode, tcode2; 309 | int diff_cat; /*category of the huffman code word*/ 310 | 311 | if((ret = getc_nextbits_jpegl_sd4(&tcode, cbufptr, ebufptr, bit_count, 1))) 312 | return(ret); 313 | code = tcode; 314 | 315 | for(inx = 1; code > maxcode[inx]; inx++){ 316 | if((ret = getc_nextbits_jpegl_sd4(&tcode2, cbufptr, ebufptr, 317 | bit_count, 1))) 318 | return(ret); 319 | code = (code << 1) + tcode2; 320 | } 321 | 322 | inx2 = valptr[inx]; 323 | inx2 = inx2 + code - mincode[inx]; 324 | diff_cat = huffvalues[inx2]; 325 | 326 | *odiff_cat = diff_cat; 327 | return(0); 328 | } 329 | 330 | /**************************************************************/ 331 | /*routine to get nextbit(s) of data stream from memory buffer */ 332 | /**************************************************************/ 333 | static int getc_nextbits_jpegl_sd4(unsigned short *obits, 334 | unsigned char **cbufptr, unsigned char *ebufptr, 335 | int *bit_count, const int bits_req) 336 | { 337 | int ret; 338 | static unsigned char code; /*next byte of data*/ 339 | unsigned short bits, tbits; /*bits of current data byte requested*/ 340 | int bits_needed; /*additional bits required to finish request*/ 341 | 342 | /*used to "mask out" n number of bits from data stream*/ 343 | static unsigned char bit_mask[9] = {0x00,0x01,0x03,0x07,0x0f, 344 | 0x1f,0x3f,0x7f,0xff}; 345 | 346 | if(bits_req == 0){ 347 | *obits = 0; 348 | return(0); 349 | } 350 | 351 | if(*bit_count == 0) { 352 | if((ret = getc_byte(&code, cbufptr, ebufptr))) 353 | return(ret); 354 | *bit_count = BITSPERBYTE; 355 | } 356 | if(bits_req <= *bit_count) { 357 | bits = (code >>(*bit_count - bits_req)) & (bit_mask[bits_req]); 358 | *bit_count -= bits_req; 359 | code &= bit_mask[*bit_count]; 360 | } 361 | else { 362 | bits_needed = bits_req - *bit_count; 363 | bits = code << bits_needed; 364 | *bit_count = 0; 365 | if((ret = getc_nextbits_jpegl_sd4(&tbits, cbufptr, ebufptr, bit_count, 366 | bits_needed))) 367 | return(ret); 368 | bits |= tbits; 369 | } 370 | 371 | *obits = bits; 372 | return(0); 373 | } 374 | -------------------------------------------------------------------------------- /jpegl/util.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | License: 4 | This software and/or related materials was developed at the National Institute 5 | of Standards and Technology (NIST) by employees of the Federal Government 6 | in the course of their official duties. Pursuant to title 17 Section 105 7 | of the United States Code, this software is not subject to copyright 8 | protection and is in the public domain. 9 | 10 | This software and/or related materials have been determined to be not subject 11 | to the EAR (see Part 734.3 of the EAR for exact details) because it is 12 | a publicly available technology and software, and is freely distributed 13 | to any interested party with no licensing requirements. Therefore, it is 14 | permissible to distribute this software as a free download from the internet. 15 | 16 | Disclaimer: 17 | This software and/or related materials was developed to promote biometric 18 | standards and biometric technology testing for the Federal Government 19 | in accordance with the USA PATRIOT Act and the Enhanced Border Security 20 | and Visa Entry Reform Act. Specific hardware and software products identified 21 | in this software were used in order to perform the software development. 22 | In no case does such identification imply recommendation or endorsement 23 | by the National Institute of Standards and Technology, nor does it imply that 24 | the products and equipment identified are necessarily the best available 25 | for the purpose. 26 | 27 | This software and/or related materials are provided "AS-IS" without warranty 28 | of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, 29 | NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY 30 | or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the 31 | licensed product, however used. In no event shall NIST be liable for any 32 | damages and/or costs, including but not limited to incidental or consequential 33 | damages of any kind, including economic damage or injury to property and lost 34 | profits, regardless of whether NIST shall be advised, have reason to know, 35 | or in fact shall know of the possibility. 36 | 37 | By using this software, you agree to bear all risk relating to quality, 38 | use and performance of the software and/or related materials. You agree 39 | to hold the Government harmless from any claim arising from your use 40 | of the software. 41 | 42 | *******************************************************************************/ 43 | 44 | 45 | /*********************************************************************** 46 | LIBRARY: JPEGL - Lossless JPEG Image Compression 47 | 48 | FILE: UTIL.C 49 | AUTHORS: Craig Watson 50 | Michael Garris 51 | DATE: 11/28/2000 52 | 53 | Contains general routines responsible for supporting JPEGL 54 | (lossless) image compression. 55 | 56 | ROUTINES: 57 | #cat: predict - Used to predict the pixel values in an image. 58 | #cat: 59 | #cat: categorize - Determines the category for a given difference value. 60 | #cat: 61 | 62 | ***********************************************************************/ 63 | 64 | #include 65 | #include 66 | 67 | /**************************************************************/ 68 | /*This routine is used to predict the pixel values in an image*/ 69 | /**************************************************************/ 70 | int predict(short *odata_pred, unsigned char *indata, const int width, 71 | const int pixel_num, const int cmpnt_depth, const int pred_type, 72 | const int Pt) 73 | { 74 | short data_pred = 0; /*pixel prediction*/ 75 | 76 | if(pixel_num == 0) { /*determine predictor for first pixel*/ 77 | data_pred = (1 << (cmpnt_depth-Pt-1)); 78 | *odata_pred = data_pred; 79 | return(0); 80 | } 81 | 82 | if(pixel_num > 0 && pixel_num < width) { 83 | data_pred = *(indata - 1); /*determine predictor for first 84 | line in the non-interleaved 85 | component*/ 86 | *odata_pred = data_pred; 87 | return(0); 88 | } 89 | /*determine predictor for the 90 | rest of the pixels in the 91 | component*/ 92 | if(pixel_num > (width - 1)) { 93 | if((pixel_num % width) == 0) /*predictor if pixel is at the 94 | beginning of a line*/ 95 | data_pred = *(indata - width); 96 | else{ 97 | switch(pred_type) { /*various predictor types defined 98 | in the standard*/ 99 | case PRED1: 100 | data_pred = *(indata - 1); 101 | break; 102 | case PRED2: 103 | data_pred = *(indata - width); 104 | break; 105 | case PRED3: 106 | data_pred = *(indata -(width + 1)); 107 | break; 108 | case PRED4: 109 | data_pred = *(indata - 1) + 110 | *(indata - width) - 111 | *(indata -(width + 1)); 112 | break; 113 | case PRED5: 114 | data_pred = *(indata - 1) + 115 | ((*(indata - width) >> 1) - 116 | (*(indata -(width + 1)) >> 1)); 117 | break; 118 | case PRED6: 119 | data_pred = *(indata - width) + 120 | ((*(indata - 1) >> 1) - 121 | (*(indata -(width + 1)) >> 1)); 122 | break; 123 | case PRED7: 124 | data_pred = (*(indata -1) + *(indata - width)) / 2; 125 | break; 126 | default: 127 | fprintf(stderr, "ERORR : predict : invalid prediction type "); 128 | fprintf(stderr, "%d not in range [%d..%d]\n", 129 | pred_type, PRED1, PRED7); 130 | return(-2); 131 | } 132 | } 133 | } 134 | 135 | *odata_pred = data_pred; 136 | return(0); 137 | } 138 | 139 | /********************************************************************/ 140 | /*This function determines the category for a given difference value*/ 141 | /********************************************************************/ 142 | short categorize(const short idiff) 143 | { 144 | int bit; /*bit pointer to difference value*/ 145 | short diff; 146 | 147 | diff = idiff; 148 | 149 | if(diff == 0) 150 | return (0); /*difference category zero*/ 151 | 152 | if (diff < 0) 153 | diff *= -1; 154 | 155 | for (bit = 0; bit < MAX_HUFFBITS; bit++) { 156 | if ((diff & CATMASK) != 0) 157 | return ((short)(MAX_HUFFBITS - bit)); 158 | diff <<= 1; 159 | } 160 | return(-1); 161 | } 162 | -------------------------------------------------------------------------------- /png2wsq.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | 7 | #include "wsq.h" 8 | 9 | int debug; 10 | 11 | static int read_grey_8bit_png(FILE *fl, void **image, int *width, int *height) 12 | { 13 | unsigned char sig[8]; 14 | png_structp png; 15 | png_infop info; 16 | png_uint_32 w, h; 17 | int bit_depth, color_type; 18 | int interlace_method, compression_method, filter_method; 19 | png_bytep *rows; 20 | int y; 21 | 22 | fread(sig, 1, 8, fl); 23 | if (!png_check_sig(sig, 8)) 24 | return -__LINE__; 25 | 26 | png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); 27 | if (!png) 28 | return -__LINE__; 29 | 30 | info = png_create_info_struct(png); 31 | if (!info) { 32 | png_destroy_read_struct(&png, NULL, NULL); 33 | return -__LINE__; 34 | } 35 | 36 | png_init_io(png, fl); 37 | png_set_sig_bytes(png, 8); 38 | png_read_info(png, info); 39 | 40 | png_get_IHDR(png, info, &w, &h, &bit_depth, &color_type, 41 | &interlace_method, &compression_method, &filter_method); 42 | if (bit_depth != 8 || color_type != PNG_COLOR_TYPE_GRAY || 43 | interlace_method != PNG_INTERLACE_NONE || 44 | compression_method != PNG_COMPRESSION_TYPE_BASE || 45 | filter_method != PNG_FILTER_TYPE_BASE) { 46 | png_destroy_read_struct(&png, NULL, NULL); 47 | return -__LINE__; 48 | } 49 | *width = w; 50 | *height = h; 51 | 52 | if (setjmp(png_jmpbuf(png))) { 53 | png_destroy_read_struct(&png, NULL, NULL); 54 | return -__LINE__; 55 | } 56 | 57 | rows = malloc(sizeof(png_bytep) * h); 58 | if (!rows) { 59 | png_destroy_read_struct(&png, NULL, NULL); 60 | return -__LINE__; 61 | } 62 | for (y = 0; y < h; y++) 63 | rows[y] = malloc(png_get_rowbytes(png, info)); 64 | 65 | png_read_image(png, rows); 66 | 67 | png_destroy_read_struct(&png, NULL, NULL); 68 | 69 | *image = malloc(w * h); 70 | for (y = 0; y < h; y++) 71 | memcpy(((char *)(*image)) + (w * y), rows[y], w); 72 | 73 | for (y = 0; y < h; y++) 74 | free(rows[y]); 75 | free(rows); 76 | 77 | return 0; 78 | } 79 | 80 | static void usage(const char *comm) 81 | { 82 | fprintf(stderr, "Usage: %s [-h] [-b BITRATE] \n", comm); 83 | fprintf(stderr, "where:\n"); 84 | fprintf(stderr, "\t-h\tusage syntax (this message)\n"); 85 | fprintf(stderr, "\t-b\tcompression bitrate (0.75 by default)\n"); 86 | fprintf(stderr, "\t\tuse - instead of file name to use stdin/stdout\n"); 87 | } 88 | 89 | int main(int argc, char *argv[]) 90 | { 91 | int opt; 92 | FILE *in = NULL; 93 | FILE *out = NULL; 94 | int err; 95 | int width, height; 96 | float bitrate = 0.75; 97 | unsigned char *image; 98 | unsigned char *wsq; 99 | int size; 100 | 101 | while ((opt = getopt(argc, argv, "hb:")) != -1) { 102 | char *t; 103 | switch (opt) { 104 | case 'b': 105 | bitrate = strtof(optarg, &t); 106 | if (bitrate <= 0.0 || bitrate > 1.0 || *t) { 107 | fprintf(stderr, "Invalid bitrate '%s'\n", 108 | optarg); 109 | return 1; 110 | } 111 | break; 112 | default: 113 | usage(argv[0]); 114 | return 1; 115 | } 116 | } 117 | 118 | if (argc - optind != 2) { 119 | usage(argv[0]); 120 | return 1; 121 | } 122 | 123 | if (strcmp(argv[optind], "-") == 0) 124 | in = stdin; 125 | else 126 | in = fopen(argv[optind], "rb"); 127 | if (!in) { 128 | perror(argv[optind]); 129 | return 1; 130 | } 131 | 132 | if (strcmp(argv[optind + 1], "-") == 0) 133 | out = stdout; 134 | else 135 | out = fopen(argv[optind + 1], "wb"); 136 | if (!out) { 137 | perror(argv[optind + 1]); 138 | return 1; 139 | } 140 | 141 | err = read_grey_8bit_png(in, (void **)&image, &width, &height); 142 | if (err) { 143 | fprintf(stderr, "Failed to read PNG image! (%d)\n", err); 144 | return 1; 145 | } 146 | 147 | err = wsq_encode_mem(&wsq, &size, bitrate, 148 | image, width, height, 8, -1, NULL); 149 | if (err) { 150 | fprintf(stderr, "Failed to compress image! (%d)\n", err); 151 | return 1; 152 | } 153 | if (fwrite(wsq, size, 1, out) != 1) { 154 | perror("fwrite"); 155 | return -1; 156 | } 157 | 158 | if (in != stdin) 159 | fclose(in); 160 | 161 | if (out != stdout) 162 | fclose(out); 163 | 164 | free(image); 165 | 166 | return 0; 167 | } 168 | -------------------------------------------------------------------------------- /util/computil.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | License: 4 | This software and/or related materials was developed at the National Institute 5 | of Standards and Technology (NIST) by employees of the Federal Government 6 | in the course of their official duties. Pursuant to title 17 Section 105 7 | of the United States Code, this software is not subject to copyright 8 | protection and is in the public domain. 9 | 10 | This software and/or related materials have been determined to be not subject 11 | to the EAR (see Part 734.3 of the EAR for exact details) because it is 12 | a publicly available technology and software, and is freely distributed 13 | to any interested party with no licensing requirements. Therefore, it is 14 | permissible to distribute this software as a free download from the internet. 15 | 16 | Disclaimer: 17 | This software and/or related materials was developed to promote biometric 18 | standards and biometric technology testing for the Federal Government 19 | in accordance with the USA PATRIOT Act and the Enhanced Border Security 20 | and Visa Entry Reform Act. Specific hardware and software products identified 21 | in this software were used in order to perform the software development. 22 | In no case does such identification imply recommendation or endorsement 23 | by the National Institute of Standards and Technology, nor does it imply that 24 | the products and equipment identified are necessarily the best available 25 | for the purpose. 26 | 27 | This software and/or related materials are provided "AS-IS" without warranty 28 | of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, 29 | NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY 30 | or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the 31 | licensed product, however used. In no event shall NIST be liable for any 32 | damages and/or costs, including but not limited to incidental or consequential 33 | damages of any kind, including economic damage or injury to property and lost 34 | profits, regardless of whether NIST shall be advised, have reason to know, 35 | or in fact shall know of the possibility. 36 | 37 | By using this software, you agree to bear all risk relating to quality, 38 | use and performance of the software and/or related materials. You agree 39 | to hold the Government harmless from any claim arising from your use 40 | of the software. 41 | 42 | *******************************************************************************/ 43 | 44 | 45 | /*********************************************************************** 46 | LIBRARY: UTIL - General Purpose Utility Routines 47 | 48 | FILE: COMPUTIL.C 49 | AUTHORS: Craig Watson 50 | Michael Garris 51 | DATE: 12/24/1999 52 | UPDATED: 04/25/2005 by MDG 53 | 54 | Contains general purpose routines responsible for processing 55 | compression algorithm markers in a compressed datastream. 56 | 57 | ROUTINES: 58 | #cat: read_skip_marker_segment - skips the segment data following a 59 | #cat: JPEGB, JPEGL, or WSQ marker in the open filestream. 60 | #cat: getc_skip_marker_segment - skips the segment data following a 61 | #cat: JPEGB, JPEGL, or WSQ marker in the given memory buffer. 62 | 63 | ***********************************************************************/ 64 | #include 65 | #include 66 | #include 67 | 68 | /*****************************************************************/ 69 | /* Skips the segment data following a JPEGB, JPEGL, or WSQ */ 70 | /* marker in the open filestream. */ 71 | /*****************************************************************/ 72 | int read_skip_marker_segment(const unsigned short marker, FILE *infp) 73 | { 74 | int ret; 75 | unsigned short length; 76 | 77 | /* Get ushort Length. */ 78 | if((ret = read_ushort(&length, infp))) 79 | return(ret); 80 | 81 | length -= 2; 82 | 83 | /* Bump file pointer forward. */ 84 | if(fseek(infp, length, SEEK_CUR) < 0){ 85 | fprintf(stderr, "ERROR : read_skip_marker_segment : "); 86 | fprintf(stderr, "unable to advance file pointer to skip "); 87 | fprintf(stderr, "marker %d segment of length %d\n", marker, length); 88 | return(-2); 89 | } 90 | 91 | return(0); 92 | } 93 | 94 | /*****************************************************************/ 95 | /* Skips the segment data following a JPEGB, JPEGL, or WSQ */ 96 | /* marker in the given memory buffer. */ 97 | /*****************************************************************/ 98 | int getc_skip_marker_segment(const unsigned short marker, 99 | unsigned char **cbufptr, unsigned char *ebufptr) 100 | { 101 | int ret; 102 | unsigned short length; 103 | 104 | /* Get ushort Length. */ 105 | if((ret = getc_ushort(&length, cbufptr, ebufptr))) 106 | return(ret); 107 | 108 | length -= 2; 109 | 110 | /* Check for EOB ... */ 111 | if(((*cbufptr)+length) >= ebufptr){ 112 | fprintf(stderr, "ERROR : getc_skip_marker_segment : "); 113 | fprintf(stderr, "unexpected end of buffer when parsing "); 114 | fprintf(stderr, "marker %d segment of length %d\n", marker, length); 115 | return(-2); 116 | } 117 | 118 | /* Bump buffer pointer. */ 119 | (*cbufptr) += length; 120 | 121 | return(0); 122 | } 123 | 124 | -------------------------------------------------------------------------------- /util/fatalerr.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | License: 4 | This software and/or related materials was developed at the National Institute 5 | of Standards and Technology (NIST) by employees of the Federal Government 6 | in the course of their official duties. Pursuant to title 17 Section 105 7 | of the United States Code, this software is not subject to copyright 8 | protection and is in the public domain. 9 | 10 | This software and/or related materials have been determined to be not subject 11 | to the EAR (see Part 734.3 of the EAR for exact details) because it is 12 | a publicly available technology and software, and is freely distributed 13 | to any interested party with no licensing requirements. Therefore, it is 14 | permissible to distribute this software as a free download from the internet. 15 | 16 | Disclaimer: 17 | This software and/or related materials was developed to promote biometric 18 | standards and biometric technology testing for the Federal Government 19 | in accordance with the USA PATRIOT Act and the Enhanced Border Security 20 | and Visa Entry Reform Act. Specific hardware and software products identified 21 | in this software were used in order to perform the software development. 22 | In no case does such identification imply recommendation or endorsement 23 | by the National Institute of Standards and Technology, nor does it imply that 24 | the products and equipment identified are necessarily the best available 25 | for the purpose. 26 | 27 | This software and/or related materials are provided "AS-IS" without warranty 28 | of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, 29 | NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY 30 | or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the 31 | licensed product, however used. In no event shall NIST be liable for any 32 | damages and/or costs, including but not limited to incidental or consequential 33 | damages of any kind, including economic damage or injury to property and lost 34 | profits, regardless of whether NIST shall be advised, have reason to know, 35 | or in fact shall know of the possibility. 36 | 37 | By using this software, you agree to bear all risk relating to quality, 38 | use and performance of the software and/or related materials. You agree 39 | to hold the Government harmless from any claim arising from your use 40 | of the software. 41 | 42 | *******************************************************************************/ 43 | 44 | 45 | /*********************************************************************** 46 | LIBRARY: UTIL - General Purpose Utility Routines 47 | 48 | FILE: FATALERR.C 49 | AUTHOR: Michael Garris 50 | DATE: 12/19/1990 51 | UPDATED: 04/25/2005 by MDG 52 | 53 | Contains routines responsible for exiting upon an application error. 54 | 55 | ROUTINES: 56 | #cat: fatalerr - generic application error handler that prints a specified 57 | #cat: message to stderr and exits with a status of 1. 58 | 59 | ***********************************************************************/ 60 | 61 | /* LINTLIBRARY */ 62 | 63 | #include 64 | #include 65 | 66 | void fatalerr(char *s1, char *s2, char *s3) 67 | { 68 | 69 | (void) fflush(stdout); 70 | if (s2 == (char *) NULL) 71 | (void) fprintf(stderr,"ERROR: %s\n",s1); 72 | else if (s3 == (char *) NULL) 73 | (void) fprintf(stderr,"ERROR: %s: %s\n",s1,s2); 74 | else 75 | (void) fprintf(stderr,"ERROR: %s: %s: %s\n",s1,s2,s3); 76 | (void) fflush(stderr); 77 | 78 | exit(1); 79 | } 80 | -------------------------------------------------------------------------------- /util/syserr.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | License: 4 | This software and/or related materials was developed at the National Institute 5 | of Standards and Technology (NIST) by employees of the Federal Government 6 | in the course of their official duties. Pursuant to title 17 Section 105 7 | of the United States Code, this software is not subject to copyright 8 | protection and is in the public domain. 9 | 10 | This software and/or related materials have been determined to be not subject 11 | to the EAR (see Part 734.3 of the EAR for exact details) because it is 12 | a publicly available technology and software, and is freely distributed 13 | to any interested party with no licensing requirements. Therefore, it is 14 | permissible to distribute this software as a free download from the internet. 15 | 16 | Disclaimer: 17 | This software and/or related materials was developed to promote biometric 18 | standards and biometric technology testing for the Federal Government 19 | in accordance with the USA PATRIOT Act and the Enhanced Border Security 20 | and Visa Entry Reform Act. Specific hardware and software products identified 21 | in this software were used in order to perform the software development. 22 | In no case does such identification imply recommendation or endorsement 23 | by the National Institute of Standards and Technology, nor does it imply that 24 | the products and equipment identified are necessarily the best available 25 | for the purpose. 26 | 27 | This software and/or related materials are provided "AS-IS" without warranty 28 | of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, 29 | NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY 30 | or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the 31 | licensed product, however used. In no event shall NIST be liable for any 32 | damages and/or costs, including but not limited to incidental or consequential 33 | damages of any kind, including economic damage or injury to property and lost 34 | profits, regardless of whether NIST shall be advised, have reason to know, 35 | or in fact shall know of the possibility. 36 | 37 | By using this software, you agree to bear all risk relating to quality, 38 | use and performance of the software and/or related materials. You agree 39 | to hold the Government harmless from any claim arising from your use 40 | of the software. 41 | 42 | *******************************************************************************/ 43 | 44 | 45 | /*********************************************************************** 46 | LIBRARY: UTIL - General Purpose Utility Routines 47 | 48 | FILE: SYSERR.C 49 | AUTHOR: Michael Garris 50 | DATE: 12/19/1990 51 | UPDATED: 04/25/2005 by MDG 52 | 53 | Contains routines responsible for exiting upon an system error. 54 | 55 | ROUTINES: 56 | #cat: syserr - exits on error with a status of -1, printing to stderr a 57 | #cat: caller-defined message. 58 | 59 | ***********************************************************************/ 60 | 61 | /* LINTLIBRARY */ 62 | 63 | #include 64 | #include 65 | 66 | void syserr(char *funcname, char *syscall, char *msg) 67 | { 68 | 69 | (void) fflush(stdout); 70 | if(msg == NULL) 71 | (void) fprintf(stderr,"ERROR: %s: %s\n",funcname,syscall); 72 | else 73 | (void) fprintf(stderr,"ERROR: %s: %s: %s\n",funcname,syscall,msg); 74 | (void) fflush(stderr); 75 | 76 | exit(-1); 77 | } 78 | -------------------------------------------------------------------------------- /wsq/globals.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | License: 4 | This software and/or related materials was developed at the National Institute 5 | of Standards and Technology (NIST) by employees of the Federal Government 6 | in the course of their official duties. Pursuant to title 17 Section 105 7 | of the United States Code, this software is not subject to copyright 8 | protection and is in the public domain. 9 | 10 | This software and/or related materials have been determined to be not subject 11 | to the EAR (see Part 734.3 of the EAR for exact details) because it is 12 | a publicly available technology and software, and is freely distributed 13 | to any interested party with no licensing requirements. Therefore, it is 14 | permissible to distribute this software as a free download from the internet. 15 | 16 | Disclaimer: 17 | This software and/or related materials was developed to promote biometric 18 | standards and biometric technology testing for the Federal Government 19 | in accordance with the USA PATRIOT Act and the Enhanced Border Security 20 | and Visa Entry Reform Act. Specific hardware and software products identified 21 | in this software were used in order to perform the software development. 22 | In no case does such identification imply recommendation or endorsement 23 | by the National Institute of Standards and Technology, nor does it imply that 24 | the products and equipment identified are necessarily the best available 25 | for the purpose. 26 | 27 | This software and/or related materials are provided "AS-IS" without warranty 28 | of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, 29 | NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY 30 | or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the 31 | licensed product, however used. In no event shall NIST be liable for any 32 | damages and/or costs, including but not limited to incidental or consequential 33 | damages of any kind, including economic damage or injury to property and lost 34 | profits, regardless of whether NIST shall be advised, have reason to know, 35 | or in fact shall know of the possibility. 36 | 37 | By using this software, you agree to bear all risk relating to quality, 38 | use and performance of the software and/or related materials. You agree 39 | to hold the Government harmless from any claim arising from your use 40 | of the software. 41 | 42 | *******************************************************************************/ 43 | 44 | 45 | /*********************************************************************** 46 | LIBRARY: WSQ - Grayscale Image Compression 47 | 48 | FILE: GLOBALS.C 49 | AUTHORS: Craig Watson 50 | Michael Garris 51 | DATE: 11/24/1999 52 | UPDATED: 10/24/07 (Kenneth Ko) 53 | 54 | Contains global variable declarations and assignments 55 | that support WSQ image compression. 56 | 57 | ***********************************************************************/ 58 | 59 | #include 60 | 61 | /* 62 | int debug; 63 | */ 64 | #ifdef TARGET_OS 65 | QUANT_VALS quant_vals; 66 | 67 | W_TREE w_tree[W_TREELEN]; 68 | 69 | Q_TREE q_tree[Q_TREELEN]; 70 | 71 | DTT_TABLE dtt_table; 72 | 73 | DQT_TABLE dqt_table; 74 | 75 | DHT_TABLE dht_table[MAX_DHT_TABLES]; 76 | 77 | FRM_HEADER_WSQ frm_header_wsq; 78 | #else 79 | QUANT_VALS quant_vals = {}; 80 | 81 | W_TREE w_tree[W_TREELEN] = {}; 82 | 83 | Q_TREE q_tree[Q_TREELEN] = {}; 84 | 85 | DTT_TABLE dtt_table = {}; 86 | 87 | DQT_TABLE dqt_table = {}; 88 | 89 | DHT_TABLE dht_table[MAX_DHT_TABLES] = {}; 90 | 91 | FRM_HEADER_WSQ frm_header_wsq = {}; 92 | #endif 93 | 94 | #ifdef FILTBANK_EVEN_8X8_1 95 | float hifilt[MAX_HIFILT] = { 96 | 0.03226944131446922, 97 | -0.05261415011924844, 98 | -0.18870142780632693, 99 | 0.60328894481393847, 100 | -0.60328894481393847, 101 | 0.18870142780632693, 102 | 0.05261415011924844, 103 | -0.03226944131446922 }; 104 | 105 | float lofilt[MAX_LOFILT] = { 106 | 0.07565691101399093, 107 | -0.12335584105275092, 108 | -0.09789296778409587, 109 | 0.85269867900940344, 110 | 0.85269867900940344, 111 | -0.09789296778409587, 112 | -0.12335584105275092, 113 | 0.07565691101399093 }; 114 | #else 115 | float hifilt[MAX_HIFILT] = { 0.06453888262893845, 116 | -0.04068941760955844, 117 | -0.41809227322221221, 118 | 0.78848561640566439, 119 | -0.41809227322221221, 120 | -0.04068941760955844, 121 | 0.06453888262893845 }; 122 | 123 | float lofilt[MAX_LOFILT] = { 0.03782845550699546, 124 | -0.02384946501938000, 125 | -0.11062440441842342, 126 | 0.37740285561265380, 127 | 0.85269867900940344, 128 | 0.37740285561265380, 129 | -0.11062440441842342, 130 | -0.02384946501938000, 131 | 0.03782845550699546 }; 132 | #endif 133 | -------------------------------------------------------------------------------- /wsq/huff.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | License: 4 | This software and/or related materials was developed at the National Institute 5 | of Standards and Technology (NIST) by employees of the Federal Government 6 | in the course of their official duties. Pursuant to title 17 Section 105 7 | of the United States Code, this software is not subject to copyright 8 | protection and is in the public domain. 9 | 10 | This software and/or related materials have been determined to be not subject 11 | to the EAR (see Part 734.3 of the EAR for exact details) because it is 12 | a publicly available technology and software, and is freely distributed 13 | to any interested party with no licensing requirements. Therefore, it is 14 | permissible to distribute this software as a free download from the internet. 15 | 16 | Disclaimer: 17 | This software and/or related materials was developed to promote biometric 18 | standards and biometric technology testing for the Federal Government 19 | in accordance with the USA PATRIOT Act and the Enhanced Border Security 20 | and Visa Entry Reform Act. Specific hardware and software products identified 21 | in this software were used in order to perform the software development. 22 | In no case does such identification imply recommendation or endorsement 23 | by the National Institute of Standards and Technology, nor does it imply that 24 | the products and equipment identified are necessarily the best available 25 | for the purpose. 26 | 27 | This software and/or related materials are provided "AS-IS" without warranty 28 | of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, 29 | NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY 30 | or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the 31 | licensed product, however used. In no event shall NIST be liable for any 32 | damages and/or costs, including but not limited to incidental or consequential 33 | damages of any kind, including economic damage or injury to property and lost 34 | profits, regardless of whether NIST shall be advised, have reason to know, 35 | or in fact shall know of the possibility. 36 | 37 | By using this software, you agree to bear all risk relating to quality, 38 | use and performance of the software and/or related materials. You agree 39 | to hold the Government harmless from any claim arising from your use 40 | of the software. 41 | 42 | *******************************************************************************/ 43 | 44 | 45 | /*********************************************************************** 46 | LIBRARY: WSQ - Grayscale Image Compression 47 | 48 | FILE: HUFF.C 49 | AUTHORS: Craig Watson 50 | Michael Garris 51 | DATE: 12/02/1999 52 | 53 | Checks that huffman codes are WSQ compliant. The specification 54 | does not allow for an all 1's code in the code table. 55 | 56 | ROUTINES: 57 | #cat: check_huffcodes_wsq - Checks for an all 1's code in the code table. 58 | 59 | ***********************************************************************/ 60 | 61 | #include 62 | #include 63 | 64 | int check_huffcodes_wsq(HUFFCODE *hufftable, int last_size) 65 | { 66 | int i, k; 67 | int all_ones; 68 | 69 | for(i = 0; i < last_size; i++){ 70 | all_ones = 1; 71 | for(k = 0; (k < (hufftable+i)->size) && all_ones; k++) 72 | all_ones = (all_ones && (((hufftable+i)->code >> k) & 0x0001)); 73 | if(all_ones) { 74 | fprintf(stderr, "WARNING: A code in the hufftable contains an "); 75 | fprintf(stderr, "all 1's code.\n This image may still be "); 76 | fprintf(stderr, "decodable.\n It is not compliant with "); 77 | fprintf(stderr, "the WSQ specification.\n"); 78 | return(-1); 79 | } 80 | } 81 | return(0); 82 | } 83 | -------------------------------------------------------------------------------- /wsq/ppi.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | License: 4 | This software and/or related materials was developed at the National Institute 5 | of Standards and Technology (NIST) by employees of the Federal Government 6 | in the course of their official duties. Pursuant to title 17 Section 105 7 | of the United States Code, this software is not subject to copyright 8 | protection and is in the public domain. 9 | 10 | This software and/or related materials have been determined to be not subject 11 | to the EAR (see Part 734.3 of the EAR for exact details) because it is 12 | a publicly available technology and software, and is freely distributed 13 | to any interested party with no licensing requirements. Therefore, it is 14 | permissible to distribute this software as a free download from the internet. 15 | 16 | Disclaimer: 17 | This software and/or related materials was developed to promote biometric 18 | standards and biometric technology testing for the Federal Government 19 | in accordance with the USA PATRIOT Act and the Enhanced Border Security 20 | and Visa Entry Reform Act. Specific hardware and software products identified 21 | in this software were used in order to perform the software development. 22 | In no case does such identification imply recommendation or endorsement 23 | by the National Institute of Standards and Technology, nor does it imply that 24 | the products and equipment identified are necessarily the best available 25 | for the purpose. 26 | 27 | This software and/or related materials are provided "AS-IS" without warranty 28 | of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, 29 | NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY 30 | or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the 31 | licensed product, however used. In no event shall NIST be liable for any 32 | damages and/or costs, including but not limited to incidental or consequential 33 | damages of any kind, including economic damage or injury to property and lost 34 | profits, regardless of whether NIST shall be advised, have reason to know, 35 | or in fact shall know of the possibility. 36 | 37 | By using this software, you agree to bear all risk relating to quality, 38 | use and performance of the software and/or related materials. You agree 39 | to hold the Government harmless from any claim arising from your use 40 | of the software. 41 | 42 | *******************************************************************************/ 43 | 44 | 45 | /*********************************************************************** 46 | LIBRARY: WSQ - Grayscale Image Compression 47 | 48 | FILE: PPI.C 49 | AUTHORS: Craig Watson 50 | Michael Garris 51 | DATE: 01/17/2001 52 | UPDATED: 04/25/2005 by MDG 53 | 54 | Contains routines responsible for determining the scan 55 | resolution of a WSQ compressed image by attempting to 56 | locate and parse a NISTCOM comment in the datastream. 57 | 58 | ROUTINES: 59 | #cat: read_ppi_wsq - Given a WSQ compressed data stream, attempts to 60 | #cat: read a NISTCOM comment from an open file and 61 | #cat: if possible return the pixel scan resulution 62 | #cat: (PPI value) stored therein. 63 | #cat: getc_ppi_wsq - Given a WSQ compressed data stream, attempts to 64 | #cat: read a NISTCOM comment from a memory buffer and 65 | #cat: if possible return the pixel scan resulution 66 | #cat: (PPI value) stored therein. 67 | 68 | ***********************************************************************/ 69 | 70 | #include 71 | #include 72 | 73 | /************************************************************************/ 74 | int read_ppi_wsq(int *oppi, FILE *infp) 75 | { 76 | int ret; 77 | long savepos; 78 | int ppi; 79 | char *value; 80 | NISTCOM *nistcom; 81 | 82 | /* Save current position in filestream ... */ 83 | if((savepos = ftell(infp)) < 0){ 84 | fprintf(stderr, "ERROR : read_ppi_wsq : "); 85 | fprintf(stderr, "ftell : couldn't determine current position\n"); 86 | return(-2); 87 | } 88 | /* Set file pointer to beginning of filestream ... */ 89 | if(fseek(infp, 0L, SEEK_SET) < 0){ 90 | fprintf(stderr, "ERROR : read_ppi_wsq : "); 91 | fprintf(stderr, "fseek : couldn't set pointer to start of file\n"); 92 | return(-3); 93 | } 94 | 95 | /* Get ppi from NISTCOM, if one exists ... */ 96 | if((ret = read_nistcom_wsq(&nistcom, infp))){ 97 | /* Reset file pointer to original position in filestream ... */ 98 | if(fseek(infp, savepos, SEEK_SET) < 0){ 99 | fprintf(stderr, "ERROR : read_ppi_wsq : "); 100 | fprintf(stderr, "fseek : couldn't reset file pointer\n"); 101 | return(-4); 102 | } 103 | return(ret); 104 | } 105 | if(nistcom != (NISTCOM *)NULL){ 106 | if((ret = extractfet_ret(&value, NCM_PPI, nistcom))){ 107 | freefet(nistcom); 108 | /* Reset file pointer to original position in filestream ... */ 109 | if(fseek(infp, savepos, SEEK_SET) < 0){ 110 | fprintf(stderr, "ERROR : read_ppi_wsq : "); 111 | fprintf(stderr, "fseek : couldn't reset file pointer\n"); 112 | return(-5); 113 | } 114 | return(ret); 115 | } 116 | if(value != (char *)NULL){ 117 | ppi = atoi(value); 118 | free(value); 119 | } 120 | /* Otherwise, PPI not in NISTCOM, so ppi = -1. */ 121 | else 122 | ppi = -1; 123 | freefet(nistcom); 124 | } 125 | /* Otherwise, NISTCOM does NOT exist, so ppi = -1. */ 126 | else 127 | ppi = -1; 128 | 129 | /* Reset file pointer to original position in filestream ... */ 130 | if(fseek(infp, savepos, SEEK_SET) < 0){ 131 | fprintf(stderr, "ERROR : read_ppi_wsq : "); 132 | fprintf(stderr, "fseek : couldn't reset file pointer\n"); 133 | return(-6); 134 | } 135 | 136 | *oppi = ppi; 137 | 138 | return(0); 139 | } 140 | 141 | /************************************************************************/ 142 | int getc_ppi_wsq(int *oppi, unsigned char *idata, const int ilen) 143 | { 144 | int ret; 145 | int ppi; 146 | char *value; 147 | NISTCOM *nistcom; 148 | 149 | /* Get ppi from NISTCOM, if one exists ... */ 150 | if((ret = getc_nistcom_wsq(&nistcom, idata, ilen))) 151 | return(ret); 152 | if(nistcom != (NISTCOM *)NULL){ 153 | if((ret = extractfet_ret(&value, NCM_PPI, nistcom))){ 154 | freefet(nistcom); 155 | return(ret); 156 | } 157 | if(value != (char *)NULL){ 158 | ppi = atoi(value); 159 | free(value); 160 | } 161 | /* Otherwise, PPI not in NISTCOM, so ppi = -1. */ 162 | else 163 | ppi = -1; 164 | freefet(nistcom); 165 | } 166 | /* Otherwise, NISTCOM does NOT exist, so ppi = -1. */ 167 | else 168 | ppi = -1; 169 | 170 | *oppi = ppi; 171 | 172 | return(0); 173 | } 174 | -------------------------------------------------------------------------------- /wsq2png.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | 7 | #include "wsq.h" 8 | 9 | int debug; 10 | 11 | static int write_grey_8bit_png(FILE *fl, void *image, int width, int height) 12 | { 13 | unsigned char *pixels = image; 14 | png_structp png; 15 | png_infop info; 16 | int row; 17 | 18 | png = png_create_write_struct(PNG_LIBPNG_VER_STRING, 19 | NULL, NULL, NULL); 20 | if (!png) 21 | return -__LINE__; 22 | 23 | info = png_create_info_struct(png); 24 | if (!info) 25 | return -__LINE__; 26 | 27 | if (setjmp(png_jmpbuf(png))) { 28 | png_destroy_write_struct(&png, &info); 29 | return -__LINE__; 30 | } 31 | 32 | png_init_io(png, fl); 33 | 34 | png_set_IHDR(png, info, width, height, 35 | 8, PNG_COLOR_TYPE_GRAY, PNG_INTERLACE_NONE, 36 | PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); 37 | 38 | png_write_info(png, info); 39 | 40 | for (row = 0; row < height; row++) 41 | png_write_row(png, pixels + (width * row)); 42 | 43 | png_write_end(png, NULL); 44 | 45 | png_destroy_write_struct(&png, &info); 46 | 47 | return 0; 48 | } 49 | 50 | static void usage(const char *comm) 51 | { 52 | fprintf(stderr, "Usage: %s [-h] \n", comm); 53 | fprintf(stderr, "where:\n"); 54 | fprintf(stderr, "\t-h\tusage syntax (this message)\n"); 55 | fprintf(stderr, "\t\tuse - instead of file name to use stdin/stdout\n"); 56 | } 57 | 58 | int main(int argc, char *argv[]) 59 | { 60 | int opt; 61 | FILE *in = NULL; 62 | FILE *out = NULL; 63 | int err; 64 | int width, height, depth, ppi, lossy; 65 | unsigned char *image; 66 | 67 | while ((opt = getopt(argc, argv, "h")) != -1) { 68 | switch (opt) { 69 | default: 70 | usage(argv[0]); 71 | return 1; 72 | } 73 | } 74 | 75 | if (argc - optind != 2) { 76 | usage(argv[0]); 77 | return 1; 78 | } 79 | 80 | if (strcmp(argv[optind], "-") == 0) 81 | in = stdin; 82 | else 83 | in = fopen(argv[optind], "rb"); 84 | if (!in) { 85 | perror(argv[optind]); 86 | return 1; 87 | } 88 | 89 | if (strcmp(argv[optind + 1], "-") == 0) 90 | out = stdout; 91 | else 92 | out = fopen(argv[optind + 1], "wb"); 93 | if (!out) { 94 | perror(argv[optind + 1]); 95 | return 1; 96 | } 97 | 98 | err = wsq_decode_file(&image, &width, &height, &depth, &ppi, 99 | &lossy, in); 100 | if (err) { 101 | fprintf(stderr, "Failed to compress image! (%d)\n", err); 102 | return 1; 103 | } 104 | if (depth != 8) 105 | fprintf(stderr, "Warning: expected 8-bit image, got %d...\n", 106 | depth); 107 | 108 | err = write_grey_8bit_png(out, image, width, height); 109 | if (err) { 110 | fprintf(stderr, "Failed to read PNG image! (%d)\n", err); 111 | return 1; 112 | } 113 | 114 | if (in != stdin) 115 | fclose(in); 116 | 117 | if (out != stdout) 118 | fclose(out); 119 | 120 | free(image); 121 | 122 | return 0; 123 | } 124 | --------------------------------------------------------------------------------