[
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)