jcsalterego / pngpaste

Paste PNG into files, much like pbpaste does for text.
Other
487 stars 32 forks source link

The color looks like not well when I used pngpaste in Mac Mojave #16

Closed hjw6160602 closed 1 year ago

hjw6160602 commented 5 years ago

The original picture is:

When I used pngpaste

maglub commented 5 years ago

I ran into the same issue, but not when I pngpaste directly. Also, only when I use .png. JPEG works fine.

How to reproduce

Faulty image:

image

Ok image:

image

Almost ok image:

image

NightMachinery commented 4 years ago

I have this problem, too. The pasted image looks greyed out.

NightMachinery commented 3 years ago

This happens very badly for fullscreen screenshots. Any ideas?

NightMachinery commented 3 years ago

Using these instead works fine:

function pngpaste() {
    local name="${1}"
    ensure-args name @MRET
    ensure isDarwin @MRET

    [[ "$name" =~ '\.png$' ]] || name+=.png

    osascript -e "tell application \"System Events\" to ¬
                  write (the clipboard as «class PNGf») to ¬
                          (make new file at folder \"$(pwd)\" with properties ¬
                                  {name:\"${name}\"})"
}
function jpgpaste() {
    local name="${1}"
    ensure-args name @MRET
    ensure isDarwin @MRET

    [[ "$name" =~ '\.jpg$' ]] || name+=.jpg

    osascript -e "tell application \"System Events\" to ¬
                  write (the clipboard as JPEG picture) to ¬
                          (make new file at folder \"$(pwd)\" with properties ¬
                                  {name:\"${name}\"})"
}

Usage:

pngpaste a1.png
martin-braun commented 3 years ago

Yes, the color is wrong. I need this to work for png and jpg and I need the base64 output method to pipe it back to the clipboard as base64, so I cannot use @NightMachinary's solution.

jcsalterego commented 1 year ago

(Years later) Is this still an issue? :)

martin-braun commented 1 year ago

@jcsalterego Yes it is. Could you please look into it? I would really appreciate it. :)

jcsalterego commented 1 year ago

@martin-braun are you still on Mojave?

jcsalterego commented 1 year ago

still/also

martin-braun commented 1 year ago

@jcsalterego No, I'm on Monterey at the moment. The image isn't washed out anymore, but the colors are still not correct. For instance, I copied this image:

I then run pngpaste test.png and this is the result:

test

Notice how the contrast is too strong now?

Since you never touched the library and it turned around itself with the update of MacOS, I assume the original color issue was a bug in Apple's software, but is the wrong contrast at this time also Apple's fault?

jcsalterego commented 1 year ago

Interesting! Maybe there's a setting in the API that I could tweak so it doesn't mess with the contrast. Thanks for the test cases.

jcsalterego commented 1 year ago

@martin-braun I'm not seeing the same thing. Can you tell me how you copied the source file, and which pngpaste command you used for the output?

martin-braun commented 1 year ago

@jcsalterego I copied the image via right click > copy image in Brave and I pasted with pngpaste test.png which I installed with brew install pngpaste.

Screen Shot 2023-02-10 at 3 38 46 PM

Screen Shot 2023-02-10 at 3 39 17 PM

macOS 12.6 (21G115)

Output:

test

jcsalterego commented 1 year ago

@martin-braun Got it - and can you reproduce the issue in Safari? I want to rule out the source copy being the problem.

martin-braun commented 1 year ago

@jcsalterego You nailed it. On Safari the issue is not reproducible. I then tested to copy the image from Brave and paste it into another program, like Krita or Preview and the issue appears there as well, so it gets copied with the wrong contrast, thus it has to be a bug in Brave.

pngpaste works fine now, so this issue can be closed.

jcsalterego commented 1 year ago

@martin-braun Oh good, glad we tracked down the root issue.

rohitkapur commented 7 months ago

Hey @jcsalterego, I think this issue actually still exists. It seems to have to do with the Gamma metadata:

diff exif_orig.txt exif_pngpaste.txt
2c2
< File Name                       : orig.png
---
> File Name                       : pngpaste.png
5,7c5,7
< File Modification Date/Time     : 2024:05:08 09:56:11-04:00
< File Access Date/Time           : 2024:05:08 09:57:36-04:00
< File Inode Change Date/Time     : 2024:05:08 09:57:34-04:00
---
> File Modification Date/Time     : 2024:05:08 09:57:41-04:00
> File Access Date/Time           : 2024:05:08 09:57:42-04:00
> File Inode Change Date/Time     : 2024:05:08 09:57:41-04:00
19c19
< SRGB Rendering                  : Perceptual
---
> Gamma                           : 0.4545
20a21
> Color Space                     : sRGB

In certain viewers (like Windows Photo Viewer), the Gamma metadata is parsed and the image will appear faded.

njnygaard commented 3 months ago

I don't want to necrobump, but I just ran in to the issue so I wanted to post some findings for others that might face the issue. Thanks for that lead @rohitkapur. image You can see the issue here. I think it has to do with color profiles in system settings for MacOS. This is the exiftool output for the bad image:

ExifTool Version Number         : 12.76
File Name                       : 2024-08-15T00:01:54-0700.png
Directory                       : unsorted/images
File Size                       : 87 kB
File Modification Date/Time     : 2024:08:15 00:01:54-07:00
File Access Date/Time           : 2024:08:15 09:19:40-07:00
File Inode Change Date/Time     : 2024:08:15 09:19:39-07:00
File Permissions                : -rw-r--r--
File Type                       : PNG
File Type Extension             : png
MIME Type                       : image/png
Image Width                     : 971
Image Height                    : 566
Bit Depth                       : 8
Color Type                      : RGB with Alpha
Compression                     : Deflate/Inflate
Filter                          : Adaptive
Interlace                       : Noninterlaced
Gamma                           : 0.4545
Exif Byte Order                 : Big-endian (Motorola, MM)
Color Space                     : sRGB
Exif Image Width                : 971
Exif Image Height               : 566
Image Size                      : 971x566
Megapixels                      : 0.550

And this is the exiftool output for the good image:

ExifTool Version Number         : 12.76
File Name                       : another.png
Directory                       : assets
File Size                       : 71 kB
File Modification Date/Time     : 2024:08:15 09:59:22-07:00
File Access Date/Time           : 2024:08:15 09:59:25-07:00
File Inode Change Date/Time     : 2024:08:15 09:59:22-07:00
File Permissions                : -rw-r--r--
File Type                       : PNG
File Type Extension             : png
MIME Type                       : image/png
Image Width                     : 683
Image Height                    : 414
Bit Depth                       : 8
Color Type                      : RGB with Alpha
Compression                     : Deflate/Inflate
Filter                          : Adaptive
Interlace                       : Noninterlaced
Profile Name                    : kCGColorSpaceGenericRGB
Profile CMM Type                : Apple Computer Inc.
Profile Version                 : 2.2.0
Profile Class                   : Display Device Profile
Color Space Data                : RGB
Profile Connection Space        : XYZ
Profile Date Time               : 2009:02:25 11:26:11
Profile File Signature          : acsp
Primary Platform                : Apple Computer Inc.
CMM Flags                       : Not Embedded, Independent
Device Manufacturer             : Apple Computer Inc.
Device Model                    :
Device Attributes               : Reflective, Glossy, Positive, Color
Rendering Intent                : Perceptual
Connection Space Illuminant     : 0.9642 1 0.82491
Profile Creator                 : Apple Computer Inc.
Profile ID                      : 0
Profile Description             : Generic RGB Profile
...(omitted Profile Description in other languages)
Profile Copyright               : Copyright 2007 Apple Inc., all rights reserved.
Media White Point               : 0.95047 1 1.0891
Red Matrix Column               : 0.4543 0.24191 0.01489
Green Matrix Column             : 0.35335 0.67363 0.09064
Blue Matrix Column              : 0.15665 0.08446 0.71957
Red Tone Reproduction Curve     : (Binary data 14 bytes, use -b option to extract)
Chromatic Adaptation            : 1.04788 0.02292 -0.0502 0.02957 0.99049 -0.01706 -0.00923 0.01508 0.75165
Blue Tone Reproduction Curve    : (Binary data 14 bytes, use -b option to extract)
Green Tone Reproduction Curve   : (Binary data 14 bytes, use -b option to extract)
Exif Byte Order                 : Big-endian (Motorola, MM)
Exif Image Width                : 683
Exif Image Height               : 414
Image Size                      : 683x414
Megapixels                      : 0.283

You can see a whole bunch of other stuff is included after I selected the "Generic RGB Profile" over whatever was there before. I get the feeling that my color profile was just not present after I solved my display issues. If you're still having this issue, I would suggest messing around with those settings.