[jira] [Commented] (IMAGING-319) updateExifMetadataLossless lost the first character of a String
[ https://issues.apache.org/jira/browse/IMAGING-319?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17886279#comment-17886279 ] Sicheng Yang commented on IMAGING-319: -- [~stefanoltmann] [~kinow] Hi! Sorry I was really busy these days. I own all the materials, including code and images, feel free to share to anyone if it can helps you all to fix the code. > updateExifMetadataLossless lost the first character of a String > --- > > Key: IMAGING-319 > URL: https://issues.apache.org/jira/browse/IMAGING-319 > Project: Commons Imaging > Issue Type: Bug > Components: Format: JPEG >Affects Versions: 1.0-alpha2 >Reporter: Sicheng Yang >Assignee: Bruno P. Kinoshita >Priority: Major > Fix For: 1.0.0-alpha5 > > Attachments: Screen Shot 2021-11-26 at 4.01.06 PM-1.png, Screen Shot > 2021-11-26 at 4.01.21 PM-1.png, iPhone12-geotag.JPG > > Time Spent: 40m > Remaining Estimate: 0h > > I try to use TiffOutputSet to generate a new image. However, if a tag that > contains String, the program may miss the first character of the String. > {noformat} > package org.apache.commons.imaging; > import org.apache.commons.imaging.common.ImageMetadata; > import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata; > import org.apache.commons.imaging.formats.jpeg.exif.ExifRewriter; > import org.apache.commons.imaging.formats.tiff.TiffImageMetadata; > import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; > import java.io.BufferedOutputStream; > import java.io.File; > import java.io.FileOutputStream; > import java.io.IOException; > public class LibraryTest { > public static void main(String[] args) throws ImagingException, > IOException { > File source = new File("/home/kinow/Desktop/iPhone12-geotag.JPG"); > File result = new > File("/home/kinow/Desktop/editted-iPhone12-geotag.JPG"); > final ImageMetadata metadata = Imaging.getMetadata(source); > final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; > final TiffImageMetadata exif = jpegMetadata.getExif(); > TiffOutputSet outputSet = exif.getOutputSet(); > BufferedOutputStream bufferedOutputStream = new > BufferedOutputStream(new FileOutputStream(result)); > new ExifRewriter().updateExifMetadataLossless(source, > bufferedOutputStream, outputSet); > } > }{noformat} > This is the sample code. > Tag value in original image > !image-2021-11-26-16-01-58-645.png! > Tag value in output image > !image-2021-11-26-16-04-12-185.png! -- This message was sent by Atlassian Jira (v8.20.10#820010)
[jira] [Commented] (IMAGING-319) updateExifMetadataLossless lost the first character of a String
[ https://issues.apache.org/jira/browse/IMAGING-319?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17836866#comment-17836866 ] Bruno P. Kinoshita commented on IMAGING-319: Couldn't find any images on my local disk, nor on public domain images. But just to record the test code somewhere: {noformat} package org.apache.commons.imaging; import org.apache.commons.imaging.common.ImageMetadata; import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata; import org.apache.commons.imaging.formats.jpeg.exif.ExifRewriter; import org.apache.commons.imaging.formats.tiff.TiffImageMetadata; import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; import org.apache.commons.io.IOUtils; import java.io.BufferedOutputStream; import java.io.File; import java.io.IOException; import java.nio.charset.Charset; import java.nio.file.Files; import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * Search for images that cause the bug in IMAGING-319. */ public class LibraryTest { public static void main(String[] args) throws ImagingException, IOException, InterruptedException { File path = new File("/home/kinow/Desktop/haystack/"); String needle = "Offset Time\\s+:\\s+"; Pattern pattern = Pattern.compile(String.format("^%s$", needle), Pattern.MULTILINE); for (File source : Objects.requireNonNull(path.listFiles(s -> s.getName().toLowerCase().endsWith(".jpg" { File result = Files.createTempFile("test_", ".jpg").toFile(); try { final ImageMetadata metadata = Imaging.getMetadata(source); final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; if (jpegMetadata != null) { final TiffImageMetadata exif = jpegMetadata.getExif(); if (exif != null) { TiffOutputSet outputSet = exif.getOutputSet(); BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(Files.newOutputStream(result.toPath())); new ExifRewriter().updateExifMetadataLossless(source, bufferedOutputStream, outputSet); String[] cmd = { "/bin/sh", "-c", String.format("exiftool %s | grep \"Offset Time\"", result.getAbsolutePath()) }; Process process = Runtime.getRuntime().exec(cmd); process.waitFor(); String output = IOUtils.toString(process.getInputStream(), Charset.defaultCharset()); // System.out.println(output); Matcher m = pattern.matcher(output); if (m.find()) { System.out.printf("Bug detected in %s%n", source.getAbsolutePath()); } } } } catch (RuntimeException|ImagingException ignore) { ignore.printStackTrace(); } // invalid metadata or bad format } } }{noformat} > updateExifMetadataLossless lost the first character of a String > --- > > Key: IMAGING-319 > URL: https://issues.apache.org/jira/browse/IMAGING-319 > Project: Commons Imaging > Issue Type: Bug > Components: Format: JPEG >Affects Versions: 1.0-alpha2 >Reporter: Sicheng Yang >Assignee: Bruno P. Kinoshita >Priority: Major > Attachments: Screen Shot 2021-11-26 at 4.01.06 PM-1.png, Screen Shot > 2021-11-26 at 4.01.21 PM-1.png, iPhone12-geotag.JPG > > Time Spent: 40m > Remaining Estimate: 0h > > I try to use TiffOutputSet to generate a new image. However, if a tag that > contains String, the program may miss the first character of the String. > {noformat} > package org.apache.commons.imaging; > import org.apache.commons.imaging.common.ImageMetadata; > import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata; > import org.apache.commons.imaging.formats.jpeg.exif.ExifRewriter; > import org.apache.commons.imaging.formats.tiff.TiffImageMetadata; > import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; > import java.io.BufferedOutputStream; > import java.io.File; > import java.io.FileOutputStream; > import java.io.IOException; > public class LibraryTest { > public static void main(String[] args) throws ImagingException, > IOException { > File source = new File("/home/kinow/Desktop/iPhone12-geotag.JPG"); > File result = new > File("/home/kinow/Desktop/editted-iPhone12-geotag.JPG"); > final ImageMetadata metadata = Imaging.getMetadata(source); > final JpegImageMeta
[jira] [Commented] (IMAGING-319) updateExifMetadataLossless lost the first character of a String
[ https://issues.apache.org/jira/browse/IMAGING-319?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17836857#comment-17836857 ] Stefan Oltmann commented on IMAGING-319: It's really hard to reproduce a problematic file. I tried copying the tags over using exiftool, but that does result in another file. Manually adding tags to a new file to enforce this bug also did not work out. The file needs to be in a very specific problematic condition to trigger the bug. > updateExifMetadataLossless lost the first character of a String > --- > > Key: IMAGING-319 > URL: https://issues.apache.org/jira/browse/IMAGING-319 > Project: Commons Imaging > Issue Type: Bug > Components: Format: JPEG >Affects Versions: 1.0-alpha2 >Reporter: Sicheng Yang >Assignee: Bruno P. Kinoshita >Priority: Major > Attachments: Screen Shot 2021-11-26 at 4.01.06 PM-1.png, Screen Shot > 2021-11-26 at 4.01.21 PM-1.png, iPhone12-geotag.JPG > > Time Spent: 40m > Remaining Estimate: 0h > > I try to use TiffOutputSet to generate a new image. However, if a tag that > contains String, the program may miss the first character of the String. > {noformat} > package org.apache.commons.imaging; > import org.apache.commons.imaging.common.ImageMetadata; > import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata; > import org.apache.commons.imaging.formats.jpeg.exif.ExifRewriter; > import org.apache.commons.imaging.formats.tiff.TiffImageMetadata; > import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; > import java.io.BufferedOutputStream; > import java.io.File; > import java.io.FileOutputStream; > import java.io.IOException; > public class LibraryTest { > public static void main(String[] args) throws ImagingException, > IOException { > File source = new File("/home/kinow/Desktop/iPhone12-geotag.JPG"); > File result = new > File("/home/kinow/Desktop/editted-iPhone12-geotag.JPG"); > final ImageMetadata metadata = Imaging.getMetadata(source); > final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; > final TiffImageMetadata exif = jpegMetadata.getExif(); > TiffOutputSet outputSet = exif.getOutputSet(); > BufferedOutputStream bufferedOutputStream = new > BufferedOutputStream(new FileOutputStream(result)); > new ExifRewriter().updateExifMetadataLossless(source, > bufferedOutputStream, outputSet); > } > }{noformat} > This is the sample code. > Tag value in original image > !image-2021-11-26-16-01-58-645.png! > Tag value in output image > !image-2021-11-26-16-04-12-185.png! -- This message was sent by Atlassian Jira (v8.20.10#820010)
[jira] [Commented] (IMAGING-319) updateExifMetadataLossless lost the first character of a String
[ https://issues.apache.org/jira/browse/IMAGING-319?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17836853#comment-17836853 ] Stefan Oltmann commented on IMAGING-319: It's not a problem with this specific field. The test image I attached to my PR fails on a different field. What happens is that Commons Imaging does not write the fields in the same order as the original. It sorts the fields by size. In the code it's called "best-fit". Tiff offsets have to be at a multiple of 2. In rare cases it can happen that after the the re-ordering they are not at a multiple of 2. The original code already checked for this case, but it did not adapt the length after this offset shift change. That's the bug. Without re-ordering this bug may not affect this file. But it still could affect other files when the content length of them change in a way, that the field following it gets an odd offset. > updateExifMetadataLossless lost the first character of a String > --- > > Key: IMAGING-319 > URL: https://issues.apache.org/jira/browse/IMAGING-319 > Project: Commons Imaging > Issue Type: Bug > Components: Format: JPEG >Affects Versions: 1.0-alpha2 >Reporter: Sicheng Yang >Assignee: Bruno P. Kinoshita >Priority: Major > Attachments: Screen Shot 2021-11-26 at 4.01.06 PM-1.png, Screen Shot > 2021-11-26 at 4.01.21 PM-1.png, iPhone12-geotag.JPG > > Time Spent: 40m > Remaining Estimate: 0h > > I try to use TiffOutputSet to generate a new image. However, if a tag that > contains String, the program may miss the first character of the String. > {noformat} > package org.apache.commons.imaging; > import org.apache.commons.imaging.common.ImageMetadata; > import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata; > import org.apache.commons.imaging.formats.jpeg.exif.ExifRewriter; > import org.apache.commons.imaging.formats.tiff.TiffImageMetadata; > import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; > import java.io.BufferedOutputStream; > import java.io.File; > import java.io.FileOutputStream; > import java.io.IOException; > public class LibraryTest { > public static void main(String[] args) throws ImagingException, > IOException { > File source = new File("/home/kinow/Desktop/iPhone12-geotag.JPG"); > File result = new > File("/home/kinow/Desktop/editted-iPhone12-geotag.JPG"); > final ImageMetadata metadata = Imaging.getMetadata(source); > final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; > final TiffImageMetadata exif = jpegMetadata.getExif(); > TiffOutputSet outputSet = exif.getOutputSet(); > BufferedOutputStream bufferedOutputStream = new > BufferedOutputStream(new FileOutputStream(result)); > new ExifRewriter().updateExifMetadataLossless(source, > bufferedOutputStream, outputSet); > } > }{noformat} > This is the sample code. > Tag value in original image > !image-2021-11-26-16-01-58-645.png! > Tag value in output image > !image-2021-11-26-16-04-12-185.png! -- This message was sent by Atlassian Jira (v8.20.10#820010)
[jira] [Commented] (IMAGING-319) updateExifMetadataLossless lost the first character of a String
[ https://issues.apache.org/jira/browse/IMAGING-319?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17836851#comment-17836851 ] Bruno P. Kinoshita commented on IMAGING-319: Tried with an image taken in Brazil, -03:00 Time Offset, couldn't reproduce the issue. Might be some other field or combination/order of fields. Tricky to find a good image to test the pull request. > updateExifMetadataLossless lost the first character of a String > --- > > Key: IMAGING-319 > URL: https://issues.apache.org/jira/browse/IMAGING-319 > Project: Commons Imaging > Issue Type: Bug > Components: Format: JPEG >Affects Versions: 1.0-alpha2 >Reporter: Sicheng Yang >Assignee: Bruno P. Kinoshita >Priority: Major > Attachments: Screen Shot 2021-11-26 at 4.01.06 PM-1.png, Screen Shot > 2021-11-26 at 4.01.21 PM-1.png, iPhone12-geotag.JPG > > Time Spent: 40m > Remaining Estimate: 0h > > I try to use TiffOutputSet to generate a new image. However, if a tag that > contains String, the program may miss the first character of the String. > {noformat} > package org.apache.commons.imaging; > import org.apache.commons.imaging.common.ImageMetadata; > import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata; > import org.apache.commons.imaging.formats.jpeg.exif.ExifRewriter; > import org.apache.commons.imaging.formats.tiff.TiffImageMetadata; > import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; > import java.io.BufferedOutputStream; > import java.io.File; > import java.io.FileOutputStream; > import java.io.IOException; > public class LibraryTest { > public static void main(String[] args) throws ImagingException, > IOException { > File source = new File("/home/kinow/Desktop/iPhone12-geotag.JPG"); > File result = new > File("/home/kinow/Desktop/editted-iPhone12-geotag.JPG"); > final ImageMetadata metadata = Imaging.getMetadata(source); > final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; > final TiffImageMetadata exif = jpegMetadata.getExif(); > TiffOutputSet outputSet = exif.getOutputSet(); > BufferedOutputStream bufferedOutputStream = new > BufferedOutputStream(new FileOutputStream(result)); > new ExifRewriter().updateExifMetadataLossless(source, > bufferedOutputStream, outputSet); > } > }{noformat} > This is the sample code. > Tag value in original image > !image-2021-11-26-16-01-58-645.png! > Tag value in output image > !image-2021-11-26-16-04-12-185.png! -- This message was sent by Atlassian Jira (v8.20.10#820010)
[jira] [Commented] (IMAGING-319) updateExifMetadataLossless lost the first character of a String
[ https://issues.apache.org/jira/browse/IMAGING-319?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17836850#comment-17836850 ] Bruno P. Kinoshita commented on IMAGING-319: Hmm, odd. I have a photo I took with my Samsung phone in New Zealand, where Offset Time is +12:00 in exiftool. When I run the example code, it works fine with the old and the new code. Might be some other field in my test image, or negative/positive sign. > updateExifMetadataLossless lost the first character of a String > --- > > Key: IMAGING-319 > URL: https://issues.apache.org/jira/browse/IMAGING-319 > Project: Commons Imaging > Issue Type: Bug > Components: Format: JPEG >Affects Versions: 1.0-alpha2 >Reporter: Sicheng Yang >Assignee: Bruno P. Kinoshita >Priority: Major > Attachments: Screen Shot 2021-11-26 at 4.01.06 PM-1.png, Screen Shot > 2021-11-26 at 4.01.21 PM-1.png, iPhone12-geotag.JPG > > Time Spent: 40m > Remaining Estimate: 0h > > I try to use TiffOutputSet to generate a new image. However, if a tag that > contains String, the program may miss the first character of the String. > {noformat} > package org.apache.commons.imaging; > import org.apache.commons.imaging.common.ImageMetadata; > import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata; > import org.apache.commons.imaging.formats.jpeg.exif.ExifRewriter; > import org.apache.commons.imaging.formats.tiff.TiffImageMetadata; > import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; > import java.io.BufferedOutputStream; > import java.io.File; > import java.io.FileOutputStream; > import java.io.IOException; > public class LibraryTest { > public static void main(String[] args) throws ImagingException, > IOException { > File source = new File("/home/kinow/Desktop/iPhone12-geotag.JPG"); > File result = new > File("/home/kinow/Desktop/editted-iPhone12-geotag.JPG"); > final ImageMetadata metadata = Imaging.getMetadata(source); > final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; > final TiffImageMetadata exif = jpegMetadata.getExif(); > TiffOutputSet outputSet = exif.getOutputSet(); > BufferedOutputStream bufferedOutputStream = new > BufferedOutputStream(new FileOutputStream(result)); > new ExifRewriter().updateExifMetadataLossless(source, > bufferedOutputStream, outputSet); > } > }{noformat} > This is the sample code. > Tag value in original image > !image-2021-11-26-16-01-58-645.png! > Tag value in output image > !image-2021-11-26-16-04-12-185.png! -- This message was sent by Atlassian Jira (v8.20.10#820010)
[jira] [Commented] (IMAGING-319) updateExifMetadataLossless lost the first character of a String
[ https://issues.apache.org/jira/browse/IMAGING-319?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17836848#comment-17836848 ] Bruno P. Kinoshita commented on IMAGING-319: My bad, I think I forgot to re-build the project after changing the code. With `commons-imaging-1.0-alpha3-RC2` (no Offset Time ?): {noformat} kinow@ranma:~/Desktop$ exiftool editted-iPhone12-geotag.JPG | grep "Offset Time" Offset Time : Offset Time Original : -05:00 Offset Time Digitized : -05:00 {noformat} With `rel/commons-imaging-1.0.0-alpha4` (same): {noformat} kinow@ranma:~/Desktop$ exiftool editted-iPhone12-geotag.JPG | grep "Offset Time" Offset Time : Offset Time Original : -05:00 Offset Time Digitized : -05:00 {noformat} With `master`, commit `6fb8d7bf42d58b6b343e9059a8657c8ed2abe54d`: {noformat} kinow@ranma:~/Desktop$ exiftool editted-iPhone12-geotag.JPG | grep "Offset Time" Offset Time : Offset Time Original : -05:00 Offset Time Digitized : -05:00 {noformat} With the branch of the PR by Stefan: {noformat} kinow@ranma:~/Desktop$ exiftool editted-iPhone12-geotag.JPG | grep "Offset Time" Offset Time : -05:00 Offset Time Original : -05:00 Offset Time Digitized : -05:00 {noformat} > updateExifMetadataLossless lost the first character of a String > --- > > Key: IMAGING-319 > URL: https://issues.apache.org/jira/browse/IMAGING-319 > Project: Commons Imaging > Issue Type: Bug > Components: Format: JPEG >Affects Versions: 1.0-alpha2 >Reporter: Sicheng Yang >Assignee: Bruno P. Kinoshita >Priority: Major > Attachments: Screen Shot 2021-11-26 at 4.01.06 PM-1.png, Screen Shot > 2021-11-26 at 4.01.21 PM-1.png, iPhone12-geotag.JPG > > Time Spent: 40m > Remaining Estimate: 0h > > I try to use TiffOutputSet to generate a new image. However, if a tag that > contains String, the program may miss the first character of the String. > {noformat} > package org.apache.commons.imaging; > import org.apache.commons.imaging.common.ImageMetadata; > import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata; > import org.apache.commons.imaging.formats.jpeg.exif.ExifRewriter; > import org.apache.commons.imaging.formats.tiff.TiffImageMetadata; > import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; > import java.io.BufferedOutputStream; > import java.io.File; > import java.io.FileOutputStream; > import java.io.IOException; > public class LibraryTest { > public static void main(String[] args) throws ImagingException, > IOException { > File source = new File("/home/kinow/Desktop/iPhone12-geotag.JPG"); > File result = new > File("/home/kinow/Desktop/editted-iPhone12-geotag.JPG"); > final ImageMetadata metadata = Imaging.getMetadata(source); > final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; > final TiffImageMetadata exif = jpegMetadata.getExif(); > TiffOutputSet outputSet = exif.getOutputSet(); > BufferedOutputStream bufferedOutputStream = new > BufferedOutputStream(new FileOutputStream(result)); > new ExifRewriter().updateExifMetadataLossless(source, > bufferedOutputStream, outputSet); > } > }{noformat} > This is the sample code. > Tag value in original image > !image-2021-11-26-16-01-58-645.png! > Tag value in output image > !image-2021-11-26-16-04-12-185.png! -- This message was sent by Atlassian Jira (v8.20.10#820010)
[jira] [Commented] (IMAGING-319) updateExifMetadataLossless lost the first character of a String
[ https://issues.apache.org/jira/browse/IMAGING-319?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17836846#comment-17836846 ] Bruno P. Kinoshita commented on IMAGING-319: Hmmm, even though the Thumbnail Offset is different, the Offset time seems to be correct in both cases {noformat} kinow@ranma:~/Desktop$ exiftool iPhone12-geotag.JPG | grep "Offset Time" Offset Time : -05:00 Offset Time Original : -05:00 Offset Time Digitized : -05:00 {noformat} {noformat} kinow@ranma:~/Desktop$ exiftool editted-iPhone12-geotag.JPG | grep "Offset Time" Offset Time : -05:00 Offset Time Original : -05:00 Offset Time Digitized : -05:00 {noformat} I will try to reproduce the "-05:00" -> "05:00" as reported by the user using the alpha tags. > updateExifMetadataLossless lost the first character of a String > --- > > Key: IMAGING-319 > URL: https://issues.apache.org/jira/browse/IMAGING-319 > Project: Commons Imaging > Issue Type: Bug > Components: Format: JPEG >Affects Versions: 1.0-alpha2 >Reporter: Sicheng Yang >Assignee: Bruno P. Kinoshita >Priority: Major > Attachments: Screen Shot 2021-11-26 at 4.01.06 PM-1.png, Screen Shot > 2021-11-26 at 4.01.21 PM-1.png, iPhone12-geotag.JPG > > Time Spent: 40m > Remaining Estimate: 0h > > I try to use TiffOutputSet to generate a new image. However, if a tag that > contains String, the program may miss the first character of the String. > {noformat} > package org.apache.commons.imaging; > import org.apache.commons.imaging.common.ImageMetadata; > import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata; > import org.apache.commons.imaging.formats.jpeg.exif.ExifRewriter; > import org.apache.commons.imaging.formats.tiff.TiffImageMetadata; > import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; > import java.io.BufferedOutputStream; > import java.io.File; > import java.io.FileOutputStream; > import java.io.IOException; > public class LibraryTest { > public static void main(String[] args) throws ImagingException, > IOException { > File source = new File("/home/kinow/Desktop/iPhone12-geotag.JPG"); > File result = new > File("/home/kinow/Desktop/editted-iPhone12-geotag.JPG"); > final ImageMetadata metadata = Imaging.getMetadata(source); > final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; > final TiffImageMetadata exif = jpegMetadata.getExif(); > TiffOutputSet outputSet = exif.getOutputSet(); > BufferedOutputStream bufferedOutputStream = new > BufferedOutputStream(new FileOutputStream(result)); > new ExifRewriter().updateExifMetadataLossless(source, > bufferedOutputStream, outputSet); > } > }{noformat} > This is the sample code. > Tag value in original image > !image-2021-11-26-16-01-58-645.png! > Tag value in output image > !image-2021-11-26-16-04-12-185.png! -- This message was sent by Atlassian Jira (v8.20.10#820010)
[jira] [Commented] (IMAGING-319) updateExifMetadataLossless lost the first character of a String
[ https://issues.apache.org/jira/browse/IMAGING-319?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17836844#comment-17836844 ] Bruno P. Kinoshita commented on IMAGING-319: Hi [~yangsicheng] , your code and instructions were very clear, thank you very much. I followed the instructions (updated code example with `noformat` for JIRA) and then used `exiftool` + `diff`: {noformat} kinow@ranma:~/Desktop$ diff <(exiftool --dump iPhone12-geotag.JPG) <(exiftool editted-iPhone12-geotag.JPG) 2c2 < File Name : iPhone12-geotag.JPG --- > File Name : editted-iPhone12-geotag.JPG 5,7c5,7 < File Modification Date/Time : 2024:04:13 19:45:28+02:00 < File Access Date/Time : 2024:04:13 19:46:21+02:00 < File Inode Change Date/Time : 2024:04:13 19:45:28+02:00 --- > File Modification Date/Time : 2024:04:13 19:57:02+02:00 > File Access Date/Time : 2024:04:13 19:57:02+02:00 > File Inode Change Date/Time : 2024:04:13 19:57:02+02:00 77c77 < Thumbnail Offset : 2642 --- > Thumbnail Offset : 2192 {noformat} So the offset field is really incorrect (as pointed in earlier comments). I'm slowly trying to understand what's happening here, while reviewing the PR [https://github.com/apache/commons-imaging/pull/359] too. > updateExifMetadataLossless lost the first character of a String > --- > > Key: IMAGING-319 > URL: https://issues.apache.org/jira/browse/IMAGING-319 > Project: Commons Imaging > Issue Type: Bug > Components: Format: JPEG >Affects Versions: 1.0-alpha2 >Reporter: Sicheng Yang >Assignee: Bruno P. Kinoshita >Priority: Major > Attachments: Screen Shot 2021-11-26 at 4.01.06 PM-1.png, Screen Shot > 2021-11-26 at 4.01.21 PM-1.png, iPhone12-geotag.JPG > > Time Spent: 40m > Remaining Estimate: 0h > > I try to use TiffOutputSet to generate a new image. However, if a tag that > contains String, the program may miss the first character of the String. > {noformat} > package org.apache.commons.imaging; > import org.apache.commons.imaging.common.ImageMetadata; > import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata; > import org.apache.commons.imaging.formats.jpeg.exif.ExifRewriter; > import org.apache.commons.imaging.formats.tiff.TiffImageMetadata; > import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; > import java.io.BufferedOutputStream; > import java.io.File; > import java.io.FileOutputStream; > import java.io.IOException; > public class LibraryTest { > public static void main(String[] args) throws ImagingException, > IOException { > File source = new File("/home/kinow/Desktop/iPhone12-geotag.JPG"); > File result = new > File("/home/kinow/Desktop/editted-iPhone12-geotag.JPG"); > final ImageMetadata metadata = Imaging.getMetadata(source); > final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; > final TiffImageMetadata exif = jpegMetadata.getExif(); > TiffOutputSet outputSet = exif.getOutputSet(); > BufferedOutputStream bufferedOutputStream = new > BufferedOutputStream(new FileOutputStream(result)); > new ExifRewriter().updateExifMetadataLossless(source, > bufferedOutputStream, outputSet); > } > }{noformat} > This is the sample code. > Tag value in original image > !image-2021-11-26-16-01-58-645.png! > Tag value in output image > !image-2021-11-26-16-04-12-185.png! -- This message was sent by Atlassian Jira (v8.20.10#820010)
[jira] [Commented] (IMAGING-319) updateExifMetadataLossless lost the first character of a String
[ https://issues.apache.org/jira/browse/IMAGING-319?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17832282#comment-17832282 ] Stefan Oltmann commented on IMAGING-319: Hi [~yangsicheng], we have a fix for the problem, but we haven't it commited to the sources as we lack a test image for the unit tests. Is the image you attached to this ticket yours? Do you own the rights to it? If so, would you allow us to add it to the projects sources (for unit tests) under Apache 2 license? @[~kinow] FYI > updateExifMetadataLossless lost the first character of a String > --- > > Key: IMAGING-319 > URL: https://issues.apache.org/jira/browse/IMAGING-319 > Project: Commons Imaging > Issue Type: Bug > Components: Format: JPEG >Affects Versions: 1.0-alpha2 >Reporter: Sicheng Yang >Assignee: Bruno P. Kinoshita >Priority: Major > Attachments: Screen Shot 2021-11-26 at 4.01.06 PM-1.png, Screen Shot > 2021-11-26 at 4.01.21 PM-1.png, iPhone12-geotag.JPG > > Time Spent: 40m > Remaining Estimate: 0h > > I try to use TiffOutputSet to generate a new image. However, if a tag that > contains String, the program may miss the first character of the String. > > import java.io.*; > import org.apache.commons.imaging.ImageReadException; > import org.apache.commons.imaging.ImageWriteException; > import org.apache.commons.imaging.Imaging; > import org.apache.commons.imaging.common.ImageMetadata; > import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata; > import org.apache.commons.imaging.formats.jpeg.exif.ExifRewriter; > import org.apache.commons.imaging.formats.tiff.TiffImageMetadata; > import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; > public class LibraryTest { > public static void main(String[] args) throws ImageReadException, > IOException, ImageWriteException { > File source = new File("./assets/iPhone12-geotag.JPG"); > File result = new > File("./assets/results/editted-iPhone12-geotag.JPG"); > final ImageMetadata metadata = Imaging.getMetadata(source); > final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; > final TiffImageMetadata exif = jpegMetadata.getExif(); > TiffOutputSet outputSet = exif.getOutputSet(); > BufferedOutputStream bufferedOutputStream = new > BufferedOutputStream(new FileOutputStream(result)); > new ExifRewriter().updateExifMetadataLossless(source, > bufferedOutputStream, outputSet); > } > } > > This is the sample code. > Tag value in original image > !image-2021-11-26-16-01-58-645.png! > Tag value in output image > !image-2021-11-26-16-04-12-185.png! -- This message was sent by Atlassian Jira (v8.20.10#820010)
[jira] [Commented] (IMAGING-319) updateExifMetadataLossless lost the first character of a String
[ https://issues.apache.org/jira/browse/IMAGING-319?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17771983#comment-17771983 ] Sicheng Yang commented on IMAGING-319: -- It is glad to see that the bug is fixed. I really appreciate that my effort is noticed. You guys debug process also benefits me a lot. Have a nice day! > updateExifMetadataLossless lost the first character of a String > --- > > Key: IMAGING-319 > URL: https://issues.apache.org/jira/browse/IMAGING-319 > Project: Commons Imaging > Issue Type: Bug > Components: Format: JPEG >Affects Versions: 1.0-alpha2 >Reporter: Sicheng Yang >Assignee: Bruno P. Kinoshita >Priority: Major > Attachments: Screen Shot 2021-11-26 at 4.01.06 PM-1.png, Screen Shot > 2021-11-26 at 4.01.21 PM-1.png, iPhone12-geotag.JPG > > Time Spent: 40m > Remaining Estimate: 0h > > I try to use TiffOutputSet to generate a new image. However, if a tag that > contains String, the program may miss the first character of the String. > > import java.io.*; > import org.apache.commons.imaging.ImageReadException; > import org.apache.commons.imaging.ImageWriteException; > import org.apache.commons.imaging.Imaging; > import org.apache.commons.imaging.common.ImageMetadata; > import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata; > import org.apache.commons.imaging.formats.jpeg.exif.ExifRewriter; > import org.apache.commons.imaging.formats.tiff.TiffImageMetadata; > import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; > public class LibraryTest { > public static void main(String[] args) throws ImageReadException, > IOException, ImageWriteException { > File source = new File("./assets/iPhone12-geotag.JPG"); > File result = new > File("./assets/results/editted-iPhone12-geotag.JPG"); > final ImageMetadata metadata = Imaging.getMetadata(source); > final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; > final TiffImageMetadata exif = jpegMetadata.getExif(); > TiffOutputSet outputSet = exif.getOutputSet(); > BufferedOutputStream bufferedOutputStream = new > BufferedOutputStream(new FileOutputStream(result)); > new ExifRewriter().updateExifMetadataLossless(source, > bufferedOutputStream, outputSet); > } > } > > This is the sample code. > Tag value in original image > !image-2021-11-26-16-01-58-645.png! > Tag value in output image > !image-2021-11-26-16-04-12-185.png! -- This message was sent by Atlassian Jira (v8.20.10#820010)
[jira] [Commented] (IMAGING-319) updateExifMetadataLossless lost the first character of a String
[ https://issues.apache.org/jira/browse/IMAGING-319?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17724643#comment-17724643 ] Gary D. Gregory commented on IMAGING-319: - (y) > updateExifMetadataLossless lost the first character of a String > --- > > Key: IMAGING-319 > URL: https://issues.apache.org/jira/browse/IMAGING-319 > Project: Commons Imaging > Issue Type: Bug > Components: Format: JPEG >Affects Versions: 1.0-alpha2 >Reporter: Sicheng Yang >Assignee: Bruno P. Kinoshita >Priority: Major > Attachments: Screen Shot 2021-11-26 at 4.01.06 PM-1.png, Screen Shot > 2021-11-26 at 4.01.21 PM-1.png, iPhone12-geotag.JPG > > Time Spent: 40m > Remaining Estimate: 0h > > I try to use TiffOutputSet to generate a new image. However, if a tag that > contains String, the program may miss the first character of the String. > > import java.io.*; > import org.apache.commons.imaging.ImageReadException; > import org.apache.commons.imaging.ImageWriteException; > import org.apache.commons.imaging.Imaging; > import org.apache.commons.imaging.common.ImageMetadata; > import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata; > import org.apache.commons.imaging.formats.jpeg.exif.ExifRewriter; > import org.apache.commons.imaging.formats.tiff.TiffImageMetadata; > import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; > public class LibraryTest { > public static void main(String[] args) throws ImageReadException, > IOException, ImageWriteException { > File source = new File("./assets/iPhone12-geotag.JPG"); > File result = new > File("./assets/results/editted-iPhone12-geotag.JPG"); > final ImageMetadata metadata = Imaging.getMetadata(source); > final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; > final TiffImageMetadata exif = jpegMetadata.getExif(); > TiffOutputSet outputSet = exif.getOutputSet(); > BufferedOutputStream bufferedOutputStream = new > BufferedOutputStream(new FileOutputStream(result)); > new ExifRewriter().updateExifMetadataLossless(source, > bufferedOutputStream, outputSet); > } > } > > This is the sample code. > Tag value in original image > !image-2021-11-26-16-01-58-645.png! > Tag value in output image > !image-2021-11-26-16-04-12-185.png! -- This message was sent by Atlassian Jira (v8.20.10#820010)
[jira] [Commented] (IMAGING-319) updateExifMetadataLossless lost the first character of a String
[ https://issues.apache.org/jira/browse/IMAGING-319?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17724579#comment-17724579 ] Gary Lucas commented on IMAGING-319: On further review, it appears that the section of the code that looks for best-fit is actually correct... It's just confusing. So I will be adding comments to clarify what it does. The reason that it works is that the unclaimed-memory elements are kept in sorted order, from largest to smallest. However, the logic related to the element length is still wrong. I am implementing a fix and will activate thr JUnit test ExifRewriterRoundtripTest once I get things working. > updateExifMetadataLossless lost the first character of a String > --- > > Key: IMAGING-319 > URL: https://issues.apache.org/jira/browse/IMAGING-319 > Project: Commons Imaging > Issue Type: Bug > Components: Format: JPEG >Affects Versions: 1.0-alpha2 >Reporter: Sicheng Yang >Assignee: Bruno P. Kinoshita >Priority: Major > Attachments: Screen Shot 2021-11-26 at 4.01.06 PM-1.png, Screen Shot > 2021-11-26 at 4.01.21 PM-1.png, iPhone12-geotag.JPG > > Time Spent: 40m > Remaining Estimate: 0h > > I try to use TiffOutputSet to generate a new image. However, if a tag that > contains String, the program may miss the first character of the String. > > import java.io.*; > import org.apache.commons.imaging.ImageReadException; > import org.apache.commons.imaging.ImageWriteException; > import org.apache.commons.imaging.Imaging; > import org.apache.commons.imaging.common.ImageMetadata; > import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata; > import org.apache.commons.imaging.formats.jpeg.exif.ExifRewriter; > import org.apache.commons.imaging.formats.tiff.TiffImageMetadata; > import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; > public class LibraryTest { > public static void main(String[] args) throws ImageReadException, > IOException, ImageWriteException { > File source = new File("./assets/iPhone12-geotag.JPG"); > File result = new > File("./assets/results/editted-iPhone12-geotag.JPG"); > final ImageMetadata metadata = Imaging.getMetadata(source); > final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; > final TiffImageMetadata exif = jpegMetadata.getExif(); > TiffOutputSet outputSet = exif.getOutputSet(); > BufferedOutputStream bufferedOutputStream = new > BufferedOutputStream(new FileOutputStream(result)); > new ExifRewriter().updateExifMetadataLossless(source, > bufferedOutputStream, outputSet); > } > } > > This is the sample code. > Tag value in original image > !image-2021-11-26-16-01-58-645.png! > Tag value in output image > !image-2021-11-26-16-04-12-185.png! -- This message was sent by Atlassian Jira (v8.20.10#820010)
[jira] [Commented] (IMAGING-319) updateExifMetadataLossless lost the first character of a String
[ https://issues.apache.org/jira/browse/IMAGING-319?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17724573#comment-17724573 ] Gary D. Gregory commented on IMAGING-319: - I'd say do what you think is best since you know the code better. > updateExifMetadataLossless lost the first character of a String > --- > > Key: IMAGING-319 > URL: https://issues.apache.org/jira/browse/IMAGING-319 > Project: Commons Imaging > Issue Type: Bug > Components: Format: JPEG >Affects Versions: 1.0-alpha2 >Reporter: Sicheng Yang >Assignee: Bruno P. Kinoshita >Priority: Major > Attachments: Screen Shot 2021-11-26 at 4.01.06 PM-1.png, Screen Shot > 2021-11-26 at 4.01.21 PM-1.png, iPhone12-geotag.JPG > > Time Spent: 40m > Remaining Estimate: 0h > > I try to use TiffOutputSet to generate a new image. However, if a tag that > contains String, the program may miss the first character of the String. > > import java.io.*; > import org.apache.commons.imaging.ImageReadException; > import org.apache.commons.imaging.ImageWriteException; > import org.apache.commons.imaging.Imaging; > import org.apache.commons.imaging.common.ImageMetadata; > import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata; > import org.apache.commons.imaging.formats.jpeg.exif.ExifRewriter; > import org.apache.commons.imaging.formats.tiff.TiffImageMetadata; > import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; > public class LibraryTest { > public static void main(String[] args) throws ImageReadException, > IOException, ImageWriteException { > File source = new File("./assets/iPhone12-geotag.JPG"); > File result = new > File("./assets/results/editted-iPhone12-geotag.JPG"); > final ImageMetadata metadata = Imaging.getMetadata(source); > final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; > final TiffImageMetadata exif = jpegMetadata.getExif(); > TiffOutputSet outputSet = exif.getOutputSet(); > BufferedOutputStream bufferedOutputStream = new > BufferedOutputStream(new FileOutputStream(result)); > new ExifRewriter().updateExifMetadataLossless(source, > bufferedOutputStream, outputSet); > } > } > > This is the sample code. > Tag value in original image > !image-2021-11-26-16-01-58-645.png! > Tag value in output image > !image-2021-11-26-16-04-12-185.png! -- This message was sent by Atlassian Jira (v8.20.10#820010)
[jira] [Commented] (IMAGING-319) updateExifMetadataLossless lost the first character of a String
[ https://issues.apache.org/jira/browse/IMAGING-319?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17724572#comment-17724572 ] Gary Lucas commented on IMAGING-319: I am looking at this now. One thing I've noticed is that the code contains a block described as "search for the smallest possible element large enough to hold the item". But it is actually a "first-fit" approach rather than a "best-fit" approach. Does anyone see a motivation for refactoring this to actually use a best-fit criteria? Or should I just correct the comments? I seem to recall, from a long time ago, reading an article that claimed that malloc() uses a first-fit approach because best-fit leads to fragmented memory... but I don't recall any kind of proof or analysis for that claim. Here's the code in question. It starts at line 194 of TiffImageWriterLossless.java {code:java} final TiffOutputItem outputItem = unplacedItems.remove(0); final int outputItemLength = outputItem.getItemLength(); // search for the smallest possible element large enough to hold the // item. TiffElement bestFit = null; for (final TiffElement element : unusedElements) { if (element.length < outputItemLength) { break; } bestFit = element; } {code} > updateExifMetadataLossless lost the first character of a String > --- > > Key: IMAGING-319 > URL: https://issues.apache.org/jira/browse/IMAGING-319 > Project: Commons Imaging > Issue Type: Bug > Components: Format: JPEG >Affects Versions: 1.0-alpha2 >Reporter: Sicheng Yang >Assignee: Bruno P. Kinoshita >Priority: Major > Attachments: Screen Shot 2021-11-26 at 4.01.06 PM-1.png, Screen Shot > 2021-11-26 at 4.01.21 PM-1.png, iPhone12-geotag.JPG > > Time Spent: 40m > Remaining Estimate: 0h > > I try to use TiffOutputSet to generate a new image. However, if a tag that > contains String, the program may miss the first character of the String. > > import java.io.*; > import org.apache.commons.imaging.ImageReadException; > import org.apache.commons.imaging.ImageWriteException; > import org.apache.commons.imaging.Imaging; > import org.apache.commons.imaging.common.ImageMetadata; > import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata; > import org.apache.commons.imaging.formats.jpeg.exif.ExifRewriter; > import org.apache.commons.imaging.formats.tiff.TiffImageMetadata; > import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; > public class LibraryTest { > public static void main(String[] args) throws ImageReadException, > IOException, ImageWriteException { > File source = new File("./assets/iPhone12-geotag.JPG"); > File result = new > File("./assets/results/editted-iPhone12-geotag.JPG"); > final ImageMetadata metadata = Imaging.getMetadata(source); > final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; > final TiffImageMetadata exif = jpegMetadata.getExif(); > TiffOutputSet outputSet = exif.getOutputSet(); > BufferedOutputStream bufferedOutputStream = new > BufferedOutputStream(new FileOutputStream(result)); > new ExifRewriter().updateExifMetadataLossless(source, > bufferedOutputStream, outputSet); > } > } > > This is the sample code. > Tag value in original image > !image-2021-11-26-16-01-58-645.png! > Tag value in output image > !image-2021-11-26-16-04-12-185.png! -- This message was sent by Atlassian Jira (v8.20.10#820010)
[jira] [Commented] (IMAGING-319) updateExifMetadataLossless lost the first character of a String
[ https://issues.apache.org/jira/browse/IMAGING-319?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17720910#comment-17720910 ] Gary D. Gregory commented on IMAGING-319: - I pulled in the unit test from the PR and annotated it with \@Disabled. > updateExifMetadataLossless lost the first character of a String > --- > > Key: IMAGING-319 > URL: https://issues.apache.org/jira/browse/IMAGING-319 > Project: Commons Imaging > Issue Type: Bug > Components: Format: JPEG >Affects Versions: 1.0-alpha2 >Reporter: Sicheng Yang >Assignee: Bruno P. Kinoshita >Priority: Major > Attachments: Screen Shot 2021-11-26 at 4.01.06 PM-1.png, Screen Shot > 2021-11-26 at 4.01.21 PM-1.png, iPhone12-geotag.JPG > > Time Spent: 40m > Remaining Estimate: 0h > > I try to use TiffOutputSet to generate a new image. However, if a tag that > contains String, the program may miss the first character of the String. > > import java.io.*; > import org.apache.commons.imaging.ImageReadException; > import org.apache.commons.imaging.ImageWriteException; > import org.apache.commons.imaging.Imaging; > import org.apache.commons.imaging.common.ImageMetadata; > import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata; > import org.apache.commons.imaging.formats.jpeg.exif.ExifRewriter; > import org.apache.commons.imaging.formats.tiff.TiffImageMetadata; > import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; > public class LibraryTest { > public static void main(String[] args) throws ImageReadException, > IOException, ImageWriteException { > File source = new File("./assets/iPhone12-geotag.JPG"); > File result = new > File("./assets/results/editted-iPhone12-geotag.JPG"); > final ImageMetadata metadata = Imaging.getMetadata(source); > final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; > final TiffImageMetadata exif = jpegMetadata.getExif(); > TiffOutputSet outputSet = exif.getOutputSet(); > BufferedOutputStream bufferedOutputStream = new > BufferedOutputStream(new FileOutputStream(result)); > new ExifRewriter().updateExifMetadataLossless(source, > bufferedOutputStream, outputSet); > } > } > > This is the sample code. > Tag value in original image > !image-2021-11-26-16-01-58-645.png! > Tag value in output image > !image-2021-11-26-16-04-12-185.png! -- This message was sent by Atlassian Jira (v8.20.10#820010)
[jira] [Commented] (IMAGING-319) updateExifMetadataLossless lost the first character of a String
[ https://issues.apache.org/jira/browse/IMAGING-319?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17720904#comment-17720904 ] Gary Lucas commented on IMAGING-319: I will take a look. I've been away from Commons Imaging for awhile, so it's going to take some time to get set up again. As I recall, the code fix worked for the sample submitted by the original author. Perhaps something has shifted in the code base since then. I'll also look at pull 275. If you have any recommendations, please let me know. > updateExifMetadataLossless lost the first character of a String > --- > > Key: IMAGING-319 > URL: https://issues.apache.org/jira/browse/IMAGING-319 > Project: Commons Imaging > Issue Type: Bug > Components: Format: JPEG >Affects Versions: 1.0-alpha2 >Reporter: Sicheng Yang >Assignee: Bruno P. Kinoshita >Priority: Major > Attachments: Screen Shot 2021-11-26 at 4.01.06 PM-1.png, Screen Shot > 2021-11-26 at 4.01.21 PM-1.png, iPhone12-geotag.JPG > > Time Spent: 40m > Remaining Estimate: 0h > > I try to use TiffOutputSet to generate a new image. However, if a tag that > contains String, the program may miss the first character of the String. > > import java.io.*; > import org.apache.commons.imaging.ImageReadException; > import org.apache.commons.imaging.ImageWriteException; > import org.apache.commons.imaging.Imaging; > import org.apache.commons.imaging.common.ImageMetadata; > import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata; > import org.apache.commons.imaging.formats.jpeg.exif.ExifRewriter; > import org.apache.commons.imaging.formats.tiff.TiffImageMetadata; > import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; > public class LibraryTest { > public static void main(String[] args) throws ImageReadException, > IOException, ImageWriteException { > File source = new File("./assets/iPhone12-geotag.JPG"); > File result = new > File("./assets/results/editted-iPhone12-geotag.JPG"); > final ImageMetadata metadata = Imaging.getMetadata(source); > final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; > final TiffImageMetadata exif = jpegMetadata.getExif(); > TiffOutputSet outputSet = exif.getOutputSet(); > BufferedOutputStream bufferedOutputStream = new > BufferedOutputStream(new FileOutputStream(result)); > new ExifRewriter().updateExifMetadataLossless(source, > bufferedOutputStream, outputSet); > } > } > > This is the sample code. > Tag value in original image > !image-2021-11-26-16-01-58-645.png! > Tag value in output image > !image-2021-11-26-16-04-12-185.png! -- This message was sent by Atlassian Jira (v8.20.10#820010)
[jira] [Commented] (IMAGING-319) updateExifMetadataLossless lost the first character of a String
[ https://issues.apache.org/jira/browse/IMAGING-319?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17720695#comment-17720695 ] Gary D. Gregory commented on IMAGING-319: - [~gwlucas] Would you please try org.apache.commons.imaging.formats.jpeg.exif.ExifRewriterRoundtripTest with your fix? It does not pass for me. Either I applied the fix incorrectly, the fix is incomplete, or the test is wrong. > updateExifMetadataLossless lost the first character of a String > --- > > Key: IMAGING-319 > URL: https://issues.apache.org/jira/browse/IMAGING-319 > Project: Commons Imaging > Issue Type: Bug > Components: Format: JPEG >Affects Versions: 1.0-alpha2 >Reporter: Sicheng Yang >Assignee: Bruno P. Kinoshita >Priority: Major > Attachments: Screen Shot 2021-11-26 at 4.01.06 PM-1.png, Screen Shot > 2021-11-26 at 4.01.21 PM-1.png, iPhone12-geotag.JPG > > Time Spent: 40m > Remaining Estimate: 0h > > I try to use TiffOutputSet to generate a new image. However, if a tag that > contains String, the program may miss the first character of the String. > > import java.io.*; > import org.apache.commons.imaging.ImageReadException; > import org.apache.commons.imaging.ImageWriteException; > import org.apache.commons.imaging.Imaging; > import org.apache.commons.imaging.common.ImageMetadata; > import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata; > import org.apache.commons.imaging.formats.jpeg.exif.ExifRewriter; > import org.apache.commons.imaging.formats.tiff.TiffImageMetadata; > import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; > public class LibraryTest { > public static void main(String[] args) throws ImageReadException, > IOException, ImageWriteException { > File source = new File("./assets/iPhone12-geotag.JPG"); > File result = new > File("./assets/results/editted-iPhone12-geotag.JPG"); > final ImageMetadata metadata = Imaging.getMetadata(source); > final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; > final TiffImageMetadata exif = jpegMetadata.getExif(); > TiffOutputSet outputSet = exif.getOutputSet(); > BufferedOutputStream bufferedOutputStream = new > BufferedOutputStream(new FileOutputStream(result)); > new ExifRewriter().updateExifMetadataLossless(source, > bufferedOutputStream, outputSet); > } > } > > This is the sample code. > Tag value in original image > !image-2021-11-26-16-01-58-645.png! > Tag value in output image > !image-2021-11-26-16-04-12-185.png! -- This message was sent by Atlassian Jira (v8.20.10#820010)
[jira] [Commented] (IMAGING-319) updateExifMetadataLossless lost the first character of a String
[ https://issues.apache.org/jira/browse/IMAGING-319?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17720690#comment-17720690 ] Gary D. Gregory commented on IMAGING-319: - Unit test https://github.com/apache/commons-imaging/pull/275 > updateExifMetadataLossless lost the first character of a String > --- > > Key: IMAGING-319 > URL: https://issues.apache.org/jira/browse/IMAGING-319 > Project: Commons Imaging > Issue Type: Bug > Components: Format: JPEG >Affects Versions: 1.0-alpha2 >Reporter: Sicheng Yang >Assignee: Bruno P. Kinoshita >Priority: Major > Attachments: Screen Shot 2021-11-26 at 4.01.06 PM-1.png, Screen Shot > 2021-11-26 at 4.01.21 PM-1.png, iPhone12-geotag.JPG > > Time Spent: 40m > Remaining Estimate: 0h > > I try to use TiffOutputSet to generate a new image. However, if a tag that > contains String, the program may miss the first character of the String. > > import java.io.*; > import org.apache.commons.imaging.ImageReadException; > import org.apache.commons.imaging.ImageWriteException; > import org.apache.commons.imaging.Imaging; > import org.apache.commons.imaging.common.ImageMetadata; > import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata; > import org.apache.commons.imaging.formats.jpeg.exif.ExifRewriter; > import org.apache.commons.imaging.formats.tiff.TiffImageMetadata; > import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; > public class LibraryTest { > public static void main(String[] args) throws ImageReadException, > IOException, ImageWriteException { > File source = new File("./assets/iPhone12-geotag.JPG"); > File result = new > File("./assets/results/editted-iPhone12-geotag.JPG"); > final ImageMetadata metadata = Imaging.getMetadata(source); > final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; > final TiffImageMetadata exif = jpegMetadata.getExif(); > TiffOutputSet outputSet = exif.getOutputSet(); > BufferedOutputStream bufferedOutputStream = new > BufferedOutputStream(new FileOutputStream(result)); > new ExifRewriter().updateExifMetadataLossless(source, > bufferedOutputStream, outputSet); > } > } > > This is the sample code. > Tag value in original image > !image-2021-11-26-16-01-58-645.png! > Tag value in output image > !image-2021-11-26-16-04-12-185.png! -- This message was sent by Atlassian Jira (v8.20.10#820010)
[jira] [Commented] (IMAGING-319) updateExifMetadataLossless lost the first character of a String
[ https://issues.apache.org/jira/browse/IMAGING-319?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17491005#comment-17491005 ] Gary Lucas commented on IMAGING-319: Okay, found it. In the code below, the method looped through all the available free elements and found one it calls "bestFit". It is going to store the new data into the available space. But TIFF files have a rule that the offsets have to be an even multiple of 2. So there's a check to see if the offset is odd and, if it is, the code advances the offset forward one. The problem is that it doesn't recognize that by advancing the offset, it's reduced the amount of available space (bestFit.length). So, the "excessLength" computation below will be incorrect. If some subsequent element is an exact match for the incorrect excessLength value, it will overwrite the unused space and clobber whatever follows. In this case, the thing that got clobbered was the first byte of EXIF tag 0x9010. The probability of this happening is small, but non zero. It is just luck that Sicheng Yang's data sample triggered the issue. {quote} long offset = bestFit.offset; if ((offset & 1L) != 0) { offset += 1; } outputItem.setOffset(offset); unusedElements.remove(bestFit); if (bestFit.length > outputItemLength) { // not a perfect fit. final long excessOffset = bestFit.offset + outputItemLength; final int excessLength = bestFit.length - outputItemLength; unusedElements.add(new TiffElement.Stub(excessOffset, excessLength)); // make sure the new element is in the correct order. unusedElements.sort(ELEMENT_SIZE_COMPARATOR); Collections.reverse(unusedElements); } } {quote} I re-wrote the code as follows. It works. Writing a JUnit test for this is going to be extremely difficult. {quote} unusedElements.remove(bestFit); long offset = bestFit.offset; int length = bestFit.length; if ((offset & 1L) != 0) { // offsets have to be at a multiple of 2 offset += 1; length -=1; } outputItem.setOffset(offset); if (length > outputItemLength) { // not a perfect fit. final long excessOffset = offset + outputItemLength; final int excessLength = length - outputItemLength; unusedElements.add(new TiffElement.Stub(excessOffset, excessLength)); // make sure the new element is in the correct order. unusedElements.sort(ELEMENT_SIZE_COMPARATOR); Collections.reverse(unusedElements); } {quote} > updateExifMetadataLossless lost the first character of a String > --- > > Key: IMAGING-319 > URL: https://issues.apache.org/jira/browse/IMAGING-319 > Project: Commons Imaging > Issue Type: Bug > Components: Format: JPEG >Affects Versions: 1.0-alpha2 >Reporter: Sicheng Yang >Priority: Major > Attachments: Screen Shot 2021-11-26 at 4.01.06 PM-1.png, Screen Shot > 2021-11-26 at 4.01.21 PM-1.png, iPhone12-geotag.JPG > > > I try to use TiffOutputSet to generate a new image. However, if a tag that > contains String, the program may miss the first character of the String. > > import java.io.*; > import org.apache.commons.imaging.ImageReadException; > import org.apache.commons.imaging.ImageWriteException; > import org.apache.commons.imaging.Imaging; > import org.apache.commons.imaging.common.ImageMetadata; > import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata; > import org.apache.commons.imaging.formats.jpeg.exif.ExifRewriter; > import org.apache.commons.imaging.formats.tiff.TiffImageMetadata; > import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; > public class LibraryTest { > public static void main(String[] args) throws ImageReadException, > IOException, ImageWriteException { > File source = new File("./assets/iPhone12-geotag.JPG"); > File result = new > File("./assets/results/editted-iPhone12-geotag.JPG"); > final ImageMetadata metadata = Imaging.getMetadata(source); > final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; > final TiffImageMetadata exif = jpegMetadata.getExif(); > TiffOutputSet outputSet = exif.getOutputSet(); > BufferedOutputStream bufferedOutputStream
[jira] [Commented] (IMAGING-319) updateExifMetadataLossless lost the first character of a String
[ https://issues.apache.org/jira/browse/IMAGING-319?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17490983#comment-17490983 ] Gary Lucas commented on IMAGING-319: I haven't figured this out yet, but I've narrowed down the cause to TiffImageWriterLossless. There is a method that attempts to update the file positions (offsets) of the various EXIF tags. It's called updateOffsetsSteps(). The code is very confusing. As far as I can tell, at some point some of the space in the output file is determined to be "unused" and updateOffsetSteps() attempts to reuse it by finding available space and setting the tag output position to the available space. If you bypass this operation by adding a diagnostic call to unusedElements.clear() right after the unusedElements list is established, everything works fine. The call stack is basically ExifRewriter.updateExifMetadataLossles ExifRewriter.writeExifSegment TiffImageWriterLossless.write TiffImageWriterLossless.updateOffsetsStep > updateExifMetadataLossless lost the first character of a String > --- > > Key: IMAGING-319 > URL: https://issues.apache.org/jira/browse/IMAGING-319 > Project: Commons Imaging > Issue Type: Bug > Components: Format: JPEG >Affects Versions: 1.0-alpha2 >Reporter: Sicheng Yang >Priority: Major > Attachments: Screen Shot 2021-11-26 at 4.01.06 PM-1.png, Screen Shot > 2021-11-26 at 4.01.21 PM-1.png, iPhone12-geotag.JPG > > > I try to use TiffOutputSet to generate a new image. However, if a tag that > contains String, the program may miss the first character of the String. > > import java.io.*; > import org.apache.commons.imaging.ImageReadException; > import org.apache.commons.imaging.ImageWriteException; > import org.apache.commons.imaging.Imaging; > import org.apache.commons.imaging.common.ImageMetadata; > import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata; > import org.apache.commons.imaging.formats.jpeg.exif.ExifRewriter; > import org.apache.commons.imaging.formats.tiff.TiffImageMetadata; > import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; > public class LibraryTest { > public static void main(String[] args) throws ImageReadException, > IOException, ImageWriteException { > File source = new File("./assets/iPhone12-geotag.JPG"); > File result = new > File("./assets/results/editted-iPhone12-geotag.JPG"); > final ImageMetadata metadata = Imaging.getMetadata(source); > final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; > final TiffImageMetadata exif = jpegMetadata.getExif(); > TiffOutputSet outputSet = exif.getOutputSet(); > BufferedOutputStream bufferedOutputStream = new > BufferedOutputStream(new FileOutputStream(result)); > new ExifRewriter().updateExifMetadataLossless(source, > bufferedOutputStream, outputSet); > } > } > > This is the sample code. > Tag value in original image > !image-2021-11-26-16-01-58-645.png! > Tag value in output image > !image-2021-11-26-16-04-12-185.png! -- This message was sent by Atlassian Jira (v8.20.1#820001)