Compare commits
	
		
			3 Commits
		
	
	
		
			1bd5cb02e7
			...
			b868e76a15
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						
						
							
						
						b868e76a15
	
				 | 
					
					
						|||
| 
						
						
							
						
						2147dba8c4
	
				 | 
					
					
						|||
| 
						
						
							
						
						121c63e35e
	
				 | 
					
					
						
							
								
								
									
										32
									
								
								fastiv-io.c
									
									
									
									
									
								
							
							
						
						
									
										32
									
								
								fastiv-io.c
									
									
									
									
									
								
							@@ -741,10 +741,14 @@ open_libjpeg_turbo(const gchar *data, gsize len, GError **error)
 | 
			
		||||
	if (tjDecompress2(dec, (const unsigned char *) data, len,
 | 
			
		||||
			cairo_image_surface_get_data(surface), width, stride, height,
 | 
			
		||||
			pixel_format, TJFLAG_ACCURATEDCT)) {
 | 
			
		||||
		set_error(error, tjGetErrorStr2(dec));
 | 
			
		||||
		cairo_surface_destroy(surface);
 | 
			
		||||
		tjDestroy(dec);
 | 
			
		||||
		return NULL;
 | 
			
		||||
		if (tjGetErrorCode(dec) == TJERR_WARNING) {
 | 
			
		||||
			g_warning("%s", tjGetErrorStr2(dec));
 | 
			
		||||
		} else {
 | 
			
		||||
			set_error(error, tjGetErrorStr2(dec));
 | 
			
		||||
			cairo_surface_destroy(surface);
 | 
			
		||||
			tjDestroy(dec);
 | 
			
		||||
			return NULL;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (pixel_format == TJPF_CMYK) {
 | 
			
		||||
@@ -1492,6 +1496,26 @@ open_libtiff(const gchar *data, gsize len, const gchar *path, GError **error)
 | 
			
		||||
	if (!tiff)
 | 
			
		||||
		goto fail;
 | 
			
		||||
 | 
			
		||||
	// In Nikon NEF files, IFD0 is a tiny uncompressed thumbnail with SubIFDs--
 | 
			
		||||
	// two of them JPEGs, the remaining one is raw. libtiff cannot read either
 | 
			
		||||
	// of those better versions.
 | 
			
		||||
	//
 | 
			
		||||
	// TODO(p): If NewSubfileType is ReducedImage, and it has SubIFDs compressed
 | 
			
		||||
	// as old JPEG (6), decode JPEGInterchangeFormat/JPEGInterchangeFormatLength
 | 
			
		||||
	// with libjpeg-turbo and insert them as the starting pages.
 | 
			
		||||
	//
 | 
			
		||||
	// This is not possible with libtiff directly, because TIFFSetSubDirectory()
 | 
			
		||||
	// requires an ImageLength tag that's missing, and TIFFReadCustomDirectory()
 | 
			
		||||
	// takes a privately defined struct that cannot be omitted.
 | 
			
		||||
	uint32_t subtype = 0;
 | 
			
		||||
	uint16_t subifd_count = 0;
 | 
			
		||||
	const uint64_t *subifd_offsets = NULL;
 | 
			
		||||
	if (TIFFGetField(tiff, TIFFTAG_SUBFILETYPE, &subtype) &&
 | 
			
		||||
		(subtype & FILETYPE_REDUCEDIMAGE) &&
 | 
			
		||||
		TIFFGetField(tiff, TIFFTAG_SUBIFD, &subifd_count, &subifd_offsets) &&
 | 
			
		||||
		subifd_count > 0 && subifd_offsets) {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	do {
 | 
			
		||||
		// We inform about unsupported directories, but do not fail on them.
 | 
			
		||||
		GError *err = NULL;
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										1
									
								
								tools/.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								tools/.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -1,2 +1,3 @@
 | 
			
		||||
/pnginfo
 | 
			
		||||
/jpeginfo
 | 
			
		||||
/tiffinfo
 | 
			
		||||
 
 | 
			
		||||
@@ -5,7 +5,7 @@ CFLAGS = -g -O2 -Wall -Wextra `pkg-config --cflags $(deps)`
 | 
			
		||||
LDLIBS = -ljq `pkg-config --libs $(deps)`
 | 
			
		||||
 | 
			
		||||
deps = libpng
 | 
			
		||||
targets = pnginfo jpeginfo
 | 
			
		||||
targets = pnginfo jpeginfo tiffinfo
 | 
			
		||||
 | 
			
		||||
all: $(targets)
 | 
			
		||||
$(targets): info.h
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										10
									
								
								tools/info.h
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								tools/info.h
									
									
									
									
									
								
							@@ -551,14 +551,15 @@ static struct tiff_entry tiff_entries[] = {
 | 
			
		||||
		{}
 | 
			
		||||
	}},
 | 
			
		||||
	{"ReferenceBlackWhite", 532, NULL},
 | 
			
		||||
	{"XMP", 700, NULL},  // Adobe XMP Specification Part 3 Table 12/13/39
 | 
			
		||||
	{"ImageID", 32781, NULL},  // Adobe PageMaker 6.0 TIFF Technical Notes
 | 
			
		||||
	{"Copyright", 33432, NULL},
 | 
			
		||||
	// TODO(p): Extract IPTC DataSets, like we do directly with PSIRs.
 | 
			
		||||
	{"IPTC", 33723, NULL},  // Adobe XMP Specification Part 3 Table 12/39
 | 
			
		||||
	// TODO(p): Extract PSIRs, like we do directly with the JPEG segment.
 | 
			
		||||
	{"Photoshop", 34377, NULL},  // Adobe XMP Specification Part 3 Table 12/39
 | 
			
		||||
	{"Exif IFD Pointer", 34665, NULL},  // Exif 2.3
 | 
			
		||||
	{"GPS Info IFD Pointer", 34853, NULL},  // Exif 2.3
 | 
			
		||||
	// TODO(p): Extract IPTC DataSets, like we do directly with PSIRs.
 | 
			
		||||
	{"IPTC", 37723, NULL},  // Adobe XMP Specification Part 3 Table 12/39
 | 
			
		||||
	{"ImageSourceData", 37724, NULL},  // Adobe Photoshop TIFF Technical Notes
 | 
			
		||||
	{}
 | 
			
		||||
};
 | 
			
		||||
@@ -886,8 +887,9 @@ parse_exif_subifds(struct tiffer *T, const struct tiffer_entry *entry,
 | 
			
		||||
		offset < 0 || offset > UINT32_MAX || !tiffer_subifd(T, offset, &subT))
 | 
			
		||||
		return jv_null();
 | 
			
		||||
 | 
			
		||||
	// The chain should correspond to the values in the entry,
 | 
			
		||||
	// we are not going to verify it.
 | 
			
		||||
	// The chain should correspond to the values in the entry
 | 
			
		||||
	// (TIFF Technical Note 1), we are not going to verify it.
 | 
			
		||||
	// Note that Nikon NEFs do not follow this rule.
 | 
			
		||||
	jv a = jv_array();
 | 
			
		||||
	do a = jv_array_append(a, parse_exif_ifd(&subT, info));
 | 
			
		||||
	while (tiffer_next_ifd(&subT));
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										79
									
								
								tools/tiffinfo.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										79
									
								
								tools/tiffinfo.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,79 @@
 | 
			
		||||
//
 | 
			
		||||
// tiffinfo.c: acquire information about TIFF files in JSON format
 | 
			
		||||
//
 | 
			
		||||
// Copyright (c) 2021, Přemysl Eric Janouch <p@janouch.name>
 | 
			
		||||
//
 | 
			
		||||
// Permission to use, copy, modify, and/or distribute this software for any
 | 
			
		||||
// purpose with or without fee is hereby granted.
 | 
			
		||||
//
 | 
			
		||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 | 
			
		||||
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 | 
			
		||||
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
 | 
			
		||||
// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 | 
			
		||||
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
 | 
			
		||||
// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
 | 
			
		||||
// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
#include "info.h"
 | 
			
		||||
 | 
			
		||||
#include <jv.h>
 | 
			
		||||
 | 
			
		||||
#include <errno.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <stdbool.h>
 | 
			
		||||
 | 
			
		||||
// This is essentially the same as jpeginfo.c, but we only have an Exif segment.
 | 
			
		||||
// TODO(p): Photoshop data and ICC profiles also have their tag,
 | 
			
		||||
// they're not currently processed.
 | 
			
		||||
 | 
			
		||||
static jv
 | 
			
		||||
do_file(const char *filename, jv o)
 | 
			
		||||
{
 | 
			
		||||
	const char *err = NULL;
 | 
			
		||||
	FILE *fp = fopen(filename, "rb");
 | 
			
		||||
	if (!fp) {
 | 
			
		||||
		err = strerror(errno);
 | 
			
		||||
		goto error;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	uint8_t *data = NULL, buf[256 << 10];
 | 
			
		||||
	size_t n, len = 0;
 | 
			
		||||
	while ((n = fread(buf, sizeof *buf, sizeof buf / sizeof *buf, fp))) {
 | 
			
		||||
		data = realloc(data, len + n);
 | 
			
		||||
		memcpy(data + len, buf, n);
 | 
			
		||||
		len += n;
 | 
			
		||||
	}
 | 
			
		||||
	if (ferror(fp)) {
 | 
			
		||||
		err = strerror(errno);
 | 
			
		||||
		goto error_read;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	o = parse_exif(o, data, len);
 | 
			
		||||
 | 
			
		||||
error_read:
 | 
			
		||||
	fclose(fp);
 | 
			
		||||
	free(data);
 | 
			
		||||
error:
 | 
			
		||||
	if (err)
 | 
			
		||||
		o = add_error(o, err);
 | 
			
		||||
	return o;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
main(int argc, char *argv[])
 | 
			
		||||
{
 | 
			
		||||
	// XXX: Can't use `xargs -P0`, there's a risk of non-atomic writes.
 | 
			
		||||
	// Usage: find . -iname *.png -print0 | xargs -0 ./pnginfo
 | 
			
		||||
	for (int i = 1; i < argc; i++) {
 | 
			
		||||
		const char *filename = argv[i];
 | 
			
		||||
 | 
			
		||||
		jv o = jv_object();
 | 
			
		||||
		o = jv_object_set(o, jv_string("filename"), jv_string(filename));
 | 
			
		||||
		o = do_file(filename, o);
 | 
			
		||||
		jv_dumpf(o, stdout, 0 /* Might consider JV_PRINT_SORTED. */);
 | 
			
		||||
		fputc('\n', stdout);
 | 
			
		||||
	}
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user