/src/jpegoptim/jpegmarker.c
Line | Count | Source (jump to first uncovered line) |
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 | | |
25 | | #ifdef HAVE_CONFIG_H |
26 | | #include "config.h" |
27 | | #endif |
28 | | |
29 | | #include <stdio.h> |
30 | | #include <string.h> |
31 | | #include <ctype.h> |
32 | | #include <jpeglib.h> |
33 | | |
34 | | #include "jpegmarker.h" |
35 | | |
36 | | |
37 | | struct marker_name { |
38 | | unsigned char marker; |
39 | | char *name; |
40 | | }; |
41 | | |
42 | | const struct marker_name jpeg_marker_names[] = { |
43 | | { JPEG_COM, "COM" }, |
44 | | { JPEG_APP0 + 0, "APP0" }, |
45 | | { JPEG_APP0 + 1, "APP1" }, |
46 | | { JPEG_APP0 + 2, "APP2" }, |
47 | | { JPEG_APP0 + 3, "APP3" }, |
48 | | { JPEG_APP0 + 4, "APP4" }, |
49 | | { JPEG_APP0 + 5, "APP5" }, |
50 | | { JPEG_APP0 + 6, "APP6" }, |
51 | | { JPEG_APP0 + 7, "APP7" }, |
52 | | { JPEG_APP0 + 8, "APP8" }, |
53 | | { JPEG_APP0 + 9, "APP9" }, |
54 | | { JPEG_APP0 + 10, "APP10" }, |
55 | | { JPEG_APP0 + 11, "APP11" }, |
56 | | { JPEG_APP0 + 12, "APP12" }, |
57 | | { JPEG_APP0 + 13, "APP13" }, |
58 | | { JPEG_APP0 + 14, "APP14" }, |
59 | | { JPEG_APP0 + 15, "APP15" }, |
60 | | { 0, 0 } |
61 | | }; |
62 | | |
63 | | const struct jpeg_special_marker_type jpeg_special_marker_types[] = { |
64 | | { JPEG_APP0, "JFIF", 5, "JFIF\0" }, |
65 | | { JPEG_APP0, "JFXX", 5, "JFXX\0" }, |
66 | | { JPEG_APP0, "CIFF", 2, "II" }, |
67 | | { JPEG_APP0, "CIFF", 2, "MM" }, |
68 | | { JPEG_APP0, "AVI1", 4, "AVI1" }, |
69 | | { JPEG_APP0 + 1, "Exif", 6, "Exif\0\0" }, |
70 | | { JPEG_APP0 + 1, "XMP", 29, "http://ns.adobe.com/xap/1.0/\0" }, |
71 | | { JPEG_APP0 + 1, "XMP", 34, "http://ns.adobe.com/xmp/extension/\0" }, |
72 | | { JPEG_APP0 + 1, "QVCI", 5, "QVCI\0" }, |
73 | | { JPEG_APP0 + 1, "FLIR", 5, "FLIR\0" }, |
74 | | { JPEG_APP0 + 2, "ICC", 12, "ICC_PROFILE\0" }, |
75 | | { JPEG_APP0 + 2, "FPXR", 5, "FPXR\0" }, |
76 | | { JPEG_APP0 + 2, "MPF", 4, "MPF\0" }, |
77 | | { JPEG_APP0 + 3, "Meta", 6, "Meta\0\0" }, |
78 | | { JPEG_APP0 + 3, "Meta", 6, "META\0\0" }, |
79 | | { JPEG_APP0 + 3, "Meta", 6, "Exif\0\0" }, |
80 | | { JPEG_APP0 + 3, "Stim", 5, "Stim\0" }, |
81 | | { JPEG_APP0 + 3, "JPS", 8, "_JPSJPS_" }, |
82 | | { JPEG_APP0 + 4, "Scalado", 8, "SCALADO\0" }, |
83 | | { JPEG_APP0 + 4, "FPXR", 5, "FPXR\0" }, |
84 | | { JPEG_APP0 + 5, "RMETA", 6, "RMETA\0" }, |
85 | | { JPEG_APP0 + 6, "EPPIM", 6, "EPPIM\0" }, |
86 | | { JPEG_APP0 + 6, "NITF", 5, "NTIF\0" }, |
87 | | { JPEG_APP0 + 6, "GoPro", 6, "GoPro\0" }, |
88 | | { JPEG_APP0 + 8, "SPIFF", 6, "SPIFF\0" }, |
89 | | { JPEG_APP0 + 10, "AROT", 6, "AROT\0\0" }, |
90 | | { JPEG_APP0 + 11, "HDR", 6, "HDR_RI" }, |
91 | | { JPEG_APP0 + 13, "IPTC", 14, "Photoshop 3.0\0" }, |
92 | | { JPEG_APP0 + 13, "IPTC", 18, "Adobe_Photoshop2.5" }, |
93 | | { JPEG_APP0 + 13, "AdobeCM", 8, "Adobe_CM" }, |
94 | | { JPEG_APP0 + 14, "Adobe", 5, "Adobe" }, |
95 | | { 0, NULL, 0, NULL } |
96 | | }; |
97 | | |
98 | | |
99 | | |
100 | | const char* jpeg_marker_name(unsigned int marker) |
101 | 0 | { |
102 | 0 | int i = 0; |
103 | |
|
104 | 0 | while (jpeg_marker_names[i].name) { |
105 | 0 | if (jpeg_marker_names[i].marker == marker) |
106 | 0 | return jpeg_marker_names[i].name; |
107 | 0 | i++; |
108 | 0 | } |
109 | | |
110 | 0 | return "Unknown"; |
111 | 0 | } |
112 | | |
113 | | size_t jpeg_special_marker_types_count() |
114 | 814 | { |
115 | 814 | int i = 0; |
116 | | |
117 | 26.0k | while (jpeg_special_marker_types[i].name) |
118 | 25.2k | i++; |
119 | | |
120 | 814 | return i; |
121 | 814 | } |
122 | | |
123 | | int jpeg_special_marker(jpeg_saved_marker_ptr marker) |
124 | 2.56M | { |
125 | 2.56M | int i = 0; |
126 | | |
127 | 2.56M | if (!marker) |
128 | 0 | return -1; |
129 | | |
130 | 10.0M | while (jpeg_special_marker_types[i].name) { |
131 | 9.93M | const struct jpeg_special_marker_type *m = &jpeg_special_marker_types[i]; |
132 | | |
133 | 9.93M | if (marker->marker == m->marker && marker->data_length >= m->ident_len) { |
134 | 5.10M | if (m->ident_len < 1) |
135 | 0 | return i; |
136 | 5.10M | if (!memcmp(marker->data, m->ident_str, m->ident_len)) |
137 | 2.40M | return i; |
138 | 5.10M | } |
139 | 7.53M | i++; |
140 | 7.53M | } |
141 | | |
142 | 159k | return -2; |
143 | 2.56M | } |
144 | | |
145 | | |
146 | | const char* jpeg_special_marker_name(jpeg_saved_marker_ptr marker) |
147 | 1.97M | { |
148 | 1.97M | int i = jpeg_special_marker(marker); |
149 | | |
150 | 1.97M | return (i >= 0 ? jpeg_special_marker_types[i].name : "Unknown"); |
151 | 1.97M | } |
152 | | |
153 | | |
154 | | /* eof :-) */ |