jpegmarker.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /* jpegmarker.c - JPEG marker functions
  2. *
  3. * Copyright (c) 1997-2023 Timo Kokkonen
  4. * All Rights Reserved.
  5. *
  6. *
  7. * SPDX-License-Identifier: GPL-3.0-or-later
  8. *
  9. * This file is part of JPEGinfo.
  10. *
  11. * JPEGinfo is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation, either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * JPEGinfo is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with JPEGinfo. If not, see <https://www.gnu.org/licenses/>.
  23. */
  24. #ifdef HAVE_CONFIG_H
  25. #include "config.h"
  26. #endif
  27. #include <stdio.h>
  28. #include <string.h>
  29. #include <ctype.h>
  30. #include <jpeglib.h>
  31. #include "jpegmarker.h"
  32. struct marker_name {
  33. unsigned char marker;
  34. char *name;
  35. };
  36. const struct marker_name jpeg_marker_names[] = {
  37. { JPEG_COM, "COM" },
  38. { JPEG_APP0 + 0, "APP0" },
  39. { JPEG_APP0 + 1, "APP1" },
  40. { JPEG_APP0 + 2, "APP2" },
  41. { JPEG_APP0 + 3, "APP3" },
  42. { JPEG_APP0 + 4, "APP4" },
  43. { JPEG_APP0 + 5, "APP5" },
  44. { JPEG_APP0 + 6, "APP6" },
  45. { JPEG_APP0 + 7, "APP7" },
  46. { JPEG_APP0 + 8, "APP8" },
  47. { JPEG_APP0 + 9, "APP9" },
  48. { JPEG_APP0 + 10, "APP10" },
  49. { JPEG_APP0 + 11, "APP11" },
  50. { JPEG_APP0 + 12, "APP12" },
  51. { JPEG_APP0 + 13, "APP13" },
  52. { JPEG_APP0 + 14, "APP14" },
  53. { JPEG_APP0 + 15, "APP15" },
  54. { 0, 0 }
  55. };
  56. const struct jpeg_special_marker_type jpeg_special_marker_types[] = {
  57. { JPEG_APP0, "JFIF", 5, "JFIF\0" },
  58. { JPEG_APP0, "JFXX", 5, "JFXX\0" },
  59. { JPEG_APP0, "CIFF", 2, "II" },
  60. { JPEG_APP0, "CIFF", 2, "MM" },
  61. { JPEG_APP0, "AVI1", 4, "AVI1" },
  62. { JPEG_APP0 + 1, "Exif", 6, "Exif\0\0" },
  63. { JPEG_APP0 + 1, "XMP", 29, "http://ns.adobe.com/xap/1.0/\0" },
  64. { JPEG_APP0 + 1, "XMP", 34, "http://ns.adobe.com/xmp/extension/\0" },
  65. { JPEG_APP0 + 1, "QVCI", 5, "QVCI\0" },
  66. { JPEG_APP0 + 1, "FLIR", 5, "FLIR\0" },
  67. { JPEG_APP0 + 2, "ICC", 12, "ICC_PROFILE\0" },
  68. { JPEG_APP0 + 2, "FPXR", 5, "FPXR\0" },
  69. { JPEG_APP0 + 2, "MPF", 4, "MPF\0" },
  70. { JPEG_APP0 + 3, "Meta", 6, "Meta\0\0" },
  71. { JPEG_APP0 + 3, "Meta", 6, "META\0\0" },
  72. { JPEG_APP0 + 3, "Meta", 6, "Exif\0\0" },
  73. { JPEG_APP0 + 3, "Stim", 5, "Stim\0" },
  74. { JPEG_APP0 + 3, "JPS", 8, "_JPSJPS_" },
  75. { JPEG_APP0 + 4, "Scalado", 8, "SCALADO\0" },
  76. { JPEG_APP0 + 4, "FPXR", 5, "FPXR\0" },
  77. { JPEG_APP0 + 5, "RMETA", 6, "RMETA\0" },
  78. { JPEG_APP0 + 6, "EPPIM", 6, "EPPIM\0" },
  79. { JPEG_APP0 + 6, "NITF", 5, "NTIF\0" },
  80. { JPEG_APP0 + 6, "GoPro", 6, "GoPro\0" },
  81. { JPEG_APP0 + 8, "SPIFF", 6, "SPIFF\0" },
  82. { JPEG_APP0 + 10, "AROT", 6, "AROT\0\0" },
  83. { JPEG_APP0 + 11, "HDR", 6, "HDR_RI" },
  84. { JPEG_APP0 + 13, "IPTC", 14, "Photoshop 3.0\0" },
  85. { JPEG_APP0 + 13, "IPTC", 18, "Adobe_Photoshop2.5" },
  86. { JPEG_APP0 + 13, "AdobeCM", 8, "Adobe_CM" },
  87. { JPEG_APP0 + 14, "Adobe", 5, "Adobe" },
  88. { 0, NULL, 0, NULL }
  89. };
  90. const char* jpeg_marker_name(unsigned int marker)
  91. {
  92. int i = 0;
  93. while (jpeg_marker_names[i].name) {
  94. if (jpeg_marker_names[i].marker == marker)
  95. return jpeg_marker_names[i].name;
  96. i++;
  97. }
  98. return "Unknown";
  99. }
  100. size_t jpeg_special_marker_types_count()
  101. {
  102. int i = 0;
  103. while (jpeg_special_marker_types[i].name)
  104. i++;
  105. return i;
  106. }
  107. int jpeg_special_marker(jpeg_saved_marker_ptr marker)
  108. {
  109. int i = 0;
  110. if (!marker)
  111. return -1;
  112. while (jpeg_special_marker_types[i].name) {
  113. const struct jpeg_special_marker_type *m = &jpeg_special_marker_types[i];
  114. if (marker->marker == m->marker && marker->data_length >= m->ident_len) {
  115. if (m->ident_len < 1)
  116. return i;
  117. if (!memcmp(marker->data, m->ident_str, m->ident_len))
  118. return i;
  119. }
  120. i++;
  121. }
  122. return -2;
  123. }
  124. const char* jpeg_special_marker_name(jpeg_saved_marker_ptr marker)
  125. {
  126. int i = jpeg_special_marker(marker);
  127. return (i >= 0 ? jpeg_special_marker_types[i].name : "Unknown");
  128. }
  129. /* eof :-) */