JuliaImages / ExifViewer.jl

Metadata reader in Julia, wrapper over LibExif
https://juliaimages.org/ExifViewer.jl/dev/
MIT License
27 stars 1 forks source link

`EXIF_TAG_USER_COMMENT` bug #26

Open t-bltg opened 1 year ago

t-bltg commented 1 year ago

In continuation of https://github.com/JuliaImages/ExifViewer.jl/pull/25, some bugs are observed:

using ExifViewer, TestImages
img = testimage("mandril")
tags = Dict("EXIF_TAG_USER_COMMENT" => "foo 12345")  # this comment is plain ASCII, so it should work ?
write_tags("test.jpg"; img, tags)
for (k, v) in read_tags("test.jpg")
  println("$k=$v")  # missing `EXIF_TAG_USER_COMMENT`
end

EXIF_TAG_COLOR_SPACE=Uncalibrated
EXIF_TAG_COMPONENTS_CONFIGURATION=Y Cb Cr -
EXIF_TAG_FLASH_PIX_VERSION=FlashPix Version 1.0
EXIF_TAG_Y_RESOLUTION=72
EXIF_TAG_EXIF_VERSION=Exif Version 2.1
EXIF_TAG_RESOLUTION_UNIT=Inch
EXIF_TAG_YCBCR_POSITIONING=Centered
EXIF_TAG_X_RESOLUTION=72

# ==> on current `main` branch, missing `EXIF_TAG_USER_COMMENT`

Could this be GC.@preserve related ?

Also missing on the command line, so this is a write issue:

$ exif test.jpg
EXIF tags in 'test.jpg' ('Intel' byte order):
--------------------+----------------------------------------------------------
Tag                 |Value
--------------------+----------------------------------------------------------
X-Resolution        |72
Y-Resolution        |72
Resolution Unit     |Inch
YCbCr Positioning   |Centered
Exif Version        |Exif Version 2.1
Components Configura|Y Cb Cr -
FlashPixVersion     |FlashPix Version 1.0
Color Space         |Uncalibrated
--------------------+----------------------------------------------------------
ashwani-rathee commented 1 year ago

There is a high chance it's related to GC.@preserve, I had also previously noticed that I made entries and they weren't there in output. I had been told about it @gnimuc to make sure those checks(GC.@preserve) are there but my understanding of GC is limited. @johnnychen94 could you guide on what we are missing here?

ashwani-rathee commented 1 year ago

I modify the test in write.jl a little bit:

    path = joinpath(tempdir(), "tmp.jpg")
    write_tags(path; img, tags)
    # currently only .jpg supported, different value of these were already checked
    # case where key in dict is not found needs to be handled,
    # support level issue needs to be handled
    @show "Read from file:" read_tags(path)
    @show "Original:" tags
    @test read_tags(path) == tags
    rm(path)

Results:

     Testing Running tests...
"Read from file:" = "Read from file:"
read_tags(path) = Dict("EXIF_TAG_FLASH" => "Flash fired", "EXIF_TAG_CUSTOM_RENDERED" => "Normal process", "EXIF_TAG_EXPOSURE_MODE" => "Auto exposure", "EXIF_TAG_SATURATION" => "Normal", "EXIF_TAG_YCBCR_POSITIONING" => "Co-sited", "EXIF_TAG_FNUMBER" => "f/2.8", "EXIF_TAG_SENSING_METHOD" => "One-chip color area sensor", "EXIF_TAG_PLANAR_CONFIGURATION" => "Planar format", "EXIF_TAG_FLASH_PIX_VERSION" => "FlashPix Version 1.0", "EXIF_TAG_ORIENTATION" => "Top-left", "EXIF_TAG_EXIF_VERSION" => "Exif Version 2.1", "EXIF_TAG_FOCAL_PLANE_Y_RESOLUTION" => "4.5", "EXIF_TAG_SHARPNESS" => "Normal", "EXIF_TAG_RESOLUTION_UNIT" => "Centimeter", "EXIF_TAG_COMPRESSION" => "JPEG compression", "EXIF_TAG_MODEL" => "R70", "EXIF_TAG_PIXEL_X_DIMENSION" => "2", "EXIF_TAG_USER_COMMENT" => "Dummy comment", "EXIF_TAG_COLOR_SPACE" => "sRGB", "EXIF_TAG_FOCAL_PLANE_RESOLUTION_UNIT" => "Inch", "EXIF_TAG_COMPONENTS_CONFIGURATION" => "Y Cb Cr -", "EXIF_TAG_GAIN_CONTROL" => "Normal", "EXIF_TAG_PHOTOMETRIC_INTERPRETATION" => "CieLAB", "EXIF_TAG_Y_RESOLUTION" => "300", "EXIF_TAG_ARTIST" => "Ashwani", "EXIF_TAG_PIXEL_Y_DIMENSION" => "2", "EXIF_TAG_SCENE_CAPTURE_TYPE" => "Standard", "EXIF_TAG_FOCAL_PLANE_X_RESOLUTION" => "4.5", "EXIF_TAG_SUBJECT_DISTANCE_RANGE" => "Close view", "EXIF_TAG_METERING_MODE" => "Pattern", "EXIF_TAG_MAKE" => "Canon", "EXIF_TAG_CONTRAST" => "Normal", "EXIF_TAG_X_RESOLUTION" => "300", "EXIF_TAG_WHITE_BALANCE" => "Auto white balance")
"Original:" = "Original:"
tags = Dict("EXIF_TAG_FLASH" => "Flash fired", "EXIF_TAG_CUSTOM_RENDERED" => "Normal process", "EXIF_TAG_EXPOSURE_MODE" => "Auto exposure", "EXIF_TAG_SATURATION" => "Normal", "EXIF_TAG_YCBCR_POSITIONING" => "Co-sited", "EXIF_TAG_FNUMBER" => "f/2.8", "EXIF_TAG_SENSING_METHOD" => "One-chip color area sensor", "EXIF_TAG_PLANAR_CONFIGURATION" => "Planar format", "EXIF_TAG_FLASH_PIX_VERSION" => "FlashPix Version 1.0", "EXIF_TAG_ORIENTATION" => "Top-left", "EXIF_TAG_EXIF_VERSION" => "Exif Version 2.1", "EXIF_TAG_FOCAL_PLANE_Y_RESOLUTION" => "4.5", "EXIF_TAG_SHARPNESS" => "Normal", "EXIF_TAG_RESOLUTION_UNIT" => "Centimeter", "EXIF_TAG_MODEL" => "R70", "EXIF_TAG_COMPRESSION" => "JPEG compression", "EXIF_TAG_PIXEL_X_DIMENSION" => "2", "EXIF_TAG_FOCAL_PLANE_RESOLUTION_UNIT" => "Inch", "EXIF_TAG_COLOR_SPACE" => "sRGB", "EXIF_TAG_GAIN_CONTROL" => "Normal", "EXIF_TAG_COMPONENTS_CONFIGURATION" => "Y Cb Cr -", "EXIF_TAG_USER_COMMENT" => "Dummy comment", "EXIF_TAG_Y_RESOLUTION" => "300", "EXIF_TAG_ARTIST" => "Ashwani", "EXIF_TAG_PIXEL_Y_DIMENSION" => "2", "EXIF_TAG_PHOTOMETRIC_INTERPRETATION" => "CieLAB", "EXIF_TAG_SCENE_CAPTURE_TYPE" => "Standard", "EXIF_TAG_FOCAL_PLANE_X_RESOLUTION" => "4.5", "EXIF_TAG_SUBJECT_DISTANCE_RANGE" => "Close view", "EXIF_TAG_METERING_MODE" => "Pattern", "EXIF_TAG_MAKE" => "Canon", "EXIF_TAG_CONTRAST" => "Normal", "EXIF_TAG_X_RESOLUTION" => "300", "EXIF_TAG_WHITE_BALANCE" => "Auto white balance")
Test Summary: | Pass  Total  Time
write-exif.jl |    1      1  2.6s
     Testing ExifViewer tests passed 

Both do have the "dummy comment" or even "foo 12345"

t-bltg commented 1 year ago

Yeah, this case on the "mandril" ref image is weird, and should be fixed.

There are a few GC.@preserveexamples in PNGFiles: https://github.com/JuliaIO/PNGFiles.jl/blob/master/src/utils.jl, or https://github.com/JuliaIO/PNGFiles.jl/blob/master/src/io.jl, but this might also be unrelated ...