/imgtools/src/lib/wsq/ppi.c

https://github.com/lessandro/nbis · C · 173 lines · 81 code · 13 blank · 79 comment · 17 complexity · d38096e06d54047a6f7579ec9688ecd3 MD5 · raw file

  1. /*******************************************************************************
  2. License:
  3. This software and/or related materials was developed at the National Institute
  4. of Standards and Technology (NIST) by employees of the Federal Government
  5. in the course of their official duties. Pursuant to title 17 Section 105
  6. of the United States Code, this software is not subject to copyright
  7. protection and is in the public domain.
  8. This software and/or related materials have been determined to be not subject
  9. to the EAR (see Part 734.3 of the EAR for exact details) because it is
  10. a publicly available technology and software, and is freely distributed
  11. to any interested party with no licensing requirements. Therefore, it is
  12. permissible to distribute this software as a free download from the internet.
  13. Disclaimer:
  14. This software and/or related materials was developed to promote biometric
  15. standards and biometric technology testing for the Federal Government
  16. in accordance with the USA PATRIOT Act and the Enhanced Border Security
  17. and Visa Entry Reform Act. Specific hardware and software products identified
  18. in this software were used in order to perform the software development.
  19. In no case does such identification imply recommendation or endorsement
  20. by the National Institute of Standards and Technology, nor does it imply that
  21. the products and equipment identified are necessarily the best available
  22. for the purpose.
  23. This software and/or related materials are provided "AS-IS" without warranty
  24. of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY,
  25. NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY
  26. or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the
  27. licensed product, however used. In no event shall NIST be liable for any
  28. damages and/or costs, including but not limited to incidental or consequential
  29. damages of any kind, including economic damage or injury to property and lost
  30. profits, regardless of whether NIST shall be advised, have reason to know,
  31. or in fact shall know of the possibility.
  32. By using this software, you agree to bear all risk relating to quality,
  33. use and performance of the software and/or related materials. You agree
  34. to hold the Government harmless from any claim arising from your use
  35. of the software.
  36. *******************************************************************************/
  37. /***********************************************************************
  38. LIBRARY: WSQ - Grayscale Image Compression
  39. FILE: PPI.C
  40. AUTHORS: Craig Watson
  41. Michael Garris
  42. DATE: 01/17/2001
  43. UPDATED: 04/25/2005 by MDG
  44. Contains routines responsible for determining the scan
  45. resolution of a WSQ compressed image by attempting to
  46. locate and parse a NISTCOM comment in the datastream.
  47. ROUTINES:
  48. #cat: read_ppi_wsq - Given a WSQ compressed data stream, attempts to
  49. #cat: read a NISTCOM comment from an open file and
  50. #cat: if possible return the pixel scan resulution
  51. #cat: (PPI value) stored therein.
  52. #cat: getc_ppi_wsq - Given a WSQ compressed data stream, attempts to
  53. #cat: read a NISTCOM comment from a memory buffer and
  54. #cat: if possible return the pixel scan resulution
  55. #cat: (PPI value) stored therein.
  56. ***********************************************************************/
  57. #include <stdio.h>
  58. #include <wsq.h>
  59. /************************************************************************/
  60. int read_ppi_wsq(int *oppi, FILE *infp)
  61. {
  62. int ret;
  63. long savepos;
  64. int ppi;
  65. char *value;
  66. NISTCOM *nistcom;
  67. /* Save current position in filestream ... */
  68. if((savepos = ftell(infp)) < 0){
  69. fprintf(stderr, "ERROR : read_ppi_wsq : ");
  70. fprintf(stderr, "ftell : couldn't determine current position\n");
  71. return(-2);
  72. }
  73. /* Set file pointer to beginning of filestream ... */
  74. if(fseek(infp, 0L, SEEK_SET) < 0){
  75. fprintf(stderr, "ERROR : read_ppi_wsq : ");
  76. fprintf(stderr, "fseek : couldn't set pointer to start of file\n");
  77. return(-3);
  78. }
  79. /* Get ppi from NISTCOM, if one exists ... */
  80. if((ret = read_nistcom_wsq(&nistcom, infp))){
  81. /* Reset file pointer to original position in filestream ... */
  82. if(fseek(infp, savepos, SEEK_SET) < 0){
  83. fprintf(stderr, "ERROR : read_ppi_wsq : ");
  84. fprintf(stderr, "fseek : couldn't reset file pointer\n");
  85. return(-4);
  86. }
  87. return(ret);
  88. }
  89. if(nistcom != (NISTCOM *)NULL){
  90. if((ret = extractfet_ret(&value, NCM_PPI, nistcom))){
  91. freefet(nistcom);
  92. /* Reset file pointer to original position in filestream ... */
  93. if(fseek(infp, savepos, SEEK_SET) < 0){
  94. fprintf(stderr, "ERROR : read_ppi_wsq : ");
  95. fprintf(stderr, "fseek : couldn't reset file pointer\n");
  96. return(-5);
  97. }
  98. return(ret);
  99. }
  100. if(value != (char *)NULL){
  101. ppi = atoi(value);
  102. free(value);
  103. }
  104. /* Otherwise, PPI not in NISTCOM, so ppi = -1. */
  105. else
  106. ppi = -1;
  107. freefet(nistcom);
  108. }
  109. /* Otherwise, NISTCOM does NOT exist, so ppi = -1. */
  110. else
  111. ppi = -1;
  112. /* Reset file pointer to original position in filestream ... */
  113. if(fseek(infp, savepos, SEEK_SET) < 0){
  114. fprintf(stderr, "ERROR : read_ppi_wsq : ");
  115. fprintf(stderr, "fseek : couldn't reset file pointer\n");
  116. return(-6);
  117. }
  118. *oppi = ppi;
  119. return(0);
  120. }
  121. /************************************************************************/
  122. int getc_ppi_wsq(int *oppi, unsigned char *idata, const int ilen)
  123. {
  124. int ret;
  125. int ppi;
  126. char *value;
  127. NISTCOM *nistcom;
  128. /* Get ppi from NISTCOM, if one exists ... */
  129. if((ret = getc_nistcom_wsq(&nistcom, idata, ilen)))
  130. return(ret);
  131. if(nistcom != (NISTCOM *)NULL){
  132. if((ret = extractfet_ret(&value, NCM_PPI, nistcom))){
  133. freefet(nistcom);
  134. return(ret);
  135. }
  136. if(value != (char *)NULL){
  137. ppi = atoi(value);
  138. free(value);
  139. }
  140. /* Otherwise, PPI not in NISTCOM, so ppi = -1. */
  141. else
  142. ppi = -1;
  143. freefet(nistcom);
  144. }
  145. /* Otherwise, NISTCOM does NOT exist, so ppi = -1. */
  146. else
  147. ppi = -1;
  148. *oppi = ppi;
  149. return(0);
  150. }