FineFindus / artem

Convert images from multiple formats (jpg, png, webp, etc…) to ASCII art, written in Rust
Mozilla Public License 2.0
293 stars 9 forks source link

Issues with black-on-alpha png images #9

Closed eosti closed 2 years ago

eosti commented 2 years ago

Describe the bug When attempting to convert an image that has exclusively black content with an alpha (transparent) background, artem considers black and alpha to be the same colour, resulting in no output.

To Reproduce Image that is black-on-alpha: icon

Output (yes, it's blank):

Expected behavior This is the same file, but saved with no alpha, which becomes a white background: icon_noalpha

Output:

MMMMMMMMMMMMMMMMMMMMMMMMMMMMMNKOdl:'.      .':lxOKWMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMXkc.                      .lONMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMKo.                              'xXMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMWx.                                    ;OMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMNo                                         'kMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMk                                             ,KMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMW;                .lk0XNWWWWNX0xc.                dMMMMMMMMMMMMMMM
MMMMMMMMMMMMMN,              .xXMMMMMMMMMMMMMMMMKd               oMMMMMMMMMMMMMM
MMMMMMMMMMMMW'             .kWMMMMMMMMMMMMMMMMMMMMWx              oMMMMMMMMMMMMM
MMMMMMMMMMMMd             :WMMMMMMMMMMMMMMMMMMMMMMMMN,             0MMMMMMMMMMMM
MMMMMMMMMMMN             :MMMMMMMMMMMMMMMMMMMMMMMMMMMW,            ,MMMMMMMMMMMM
MMMMMMMMMMMO             NMMMMMMMMMMMMMMMMMMMMMMMMMMMMK             XMMMMMMMMMMM
MMMMMMMMMMMd             MMMMMMMMMMMMMMMMMMMMMMMMMMMMMW             OMMMMMMMMMMM
MMMMMMMMMMMd             MMMMMMMMMMMMMMMMMMMMMMMMMMMMMN             OMMMMMMMMMMM
MMMMMMMMMMM0             0MMMMMMMMMMMMMMMMMMMMMMMMMMMMk             XMMMMMMMMMMM
MMMMMMMMMMMM.            .XMMMMMMMMMMMMMMMMMMMMMMMMMMK             'MMMMMMMMMMMM
MMMMMMMMMMMMO             .0MMMMMMMMMMMMMMMMMMMMMMMMk              OMMMMMMMMMMMM
MMMMMMMMMMMMM:              cKMMMMMMMMMMMMMMMMMMMM0;              ;MMMMMMMMMMMMM
MMMMMMMMMMMMMM:               .dKWMMMMMMMMMMMMW0o.               ,WMMMMMMMMMMMMM
MMMMMMMMMMMMMMM:                  'ldkOOOOkdl.                  'WMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMo                                              :WMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMO                                            dMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMX:                                        '0MMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMx                                      lWMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMNc                                  ,KMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMO.                               dWMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMWl                            :NMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMX;                        ,KMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMO.                    .kMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMWc                  cWMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM0'              '0MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWo            dWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMK.        .XMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWc      lWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMd    kMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMO.'0MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM

It would be nice if artem would be able to autodetect the black-on-alpha condition and make the alpha equivilant to white, instead of black. There are many icon-type images that are formatted like this, and it's a bit tedious to have to convert each to a non-alpha image first.

Information

MacOS Monterey, zsh, artem 1.1.5

Output

Output ``` > artem icon.png [INFO ] Checking inputs [DEBUG] Input icon.png is a file [INFO ] Using default characters [DEBUG] Characters used: "MWNXK0Okxdolc:;,'... " [DEBUG] Target Size: 80 [DEBUG] Scale: 0.42 [DEBUG] Invert is set to: false [DEBUG] BackgroundColor is set to: false [INFO ] Using colored ascii [INFO ] Using truecolor ascii [INFO ] Using border: false [DEBUG] Flipping X-Axis: false [DEBUG] Flipping Y-Axis: false [DEBUG] Centering X-Axis: false [DEBUG] Center Y-Axis: false [DEBUG] Outline: false [DEBUG] Target: Shell [INFO ] Opening image [INFO ] Converting img: icon.png [DEBUG] Using inverted color: false [DEBUG] Input Image Width: 512 [DEBUG] Input Image Height: 512 [DEBUG] Columns: 80 [DEBUG] Rows: 36 [DEBUG] Tile Width: 6 [DEBUG] Tile Height: 14 [INFO ] Resizing image to fit new dimensions [DEBUG] Resized Image Width: 480 [DEBUG] Resized Image Height: 504 [INFO ] Starting conversion to ascii [INFO ] Printing output [[blank output, as shown above]] ```
FineFindus commented 2 years ago

Thanks for report this issue. As far as artem is concerned, those are actually two very different images, since pixels with an alpha value of 0 are the same as black pixels. So the first image is basically black of black. Nevertheless I agree that the first image does not produce a desired output.

Sadly, I think it would not be a very practical solution to check if black-on-alpha exist. It would be better to use the alpha value in the calculation, but I will have to think about this.

FineFindus commented 2 years ago

After thinking about it for a bit, I came to the conclusion that the best solution, without breaking conversions of different images, would be to add the ability to replace certain colors, but I think that would be out of scope and better be suited for an image editor, which this does project does not aim to be.

And if artem would recognize black-on-alpha, the black would be rated as a lighter color, so the result would look more like this, which still would not be similar to your expected result.

                              .':ldOKNMMMMNKOdl;'.                              
                         .,oXMMMMMMMMMMMMMMMMMMMMMM0l'                          
                      .cKMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMO;.                      
                    ;KMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMx'                    
                  cNMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMO,                  
                ,NMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMk.                
               xMMMMMMMMMMMMMMMMKl,..      ..;oXMMMMMMMMMMMMMMMM:               
              kMMMMMMMMMMMMMMX;.                .:NMMMMMMMMMMMMMMc              
             OMMMMMMMMMMMMMK,                      ;NMMMMMMMMMMMMMc             
            :MMMMMMMMMMMMMd                          kMMMMMMMMMMMMM.            
            WMMMMMMMMMMMMd                            kMMMMMMMMMMMMk            
           'MMMMMMMMMMMMM                             .MMMMMMMMMMMMM.           
           :MMMMMMMMMMMMM                              MMMMMMMMMMMMM'           
           :MMMMMMMMMMMMM                              MMMMMMMMMMMMM'           
           .MMMMMMMMMMMMM.                            ,MMMMMMMMMMMMM.           
            0MMMMMMMMMMMMK.                          .WMMMMMMMMMMMMO            
            'MMMMMMMMMMMMMX.                        ,WMMMMMMMMMMMMM'            
             dMMMMMMMMMMMMMMo.                    .xMMMMMMMMMMMMMMx             
              dMMMMMMMMMMMMMMM0:.              .cKMMMMMMMMMMMMMMMk              
               dMMMMMMMMMMMMMMMMMMOl:,'''',:l0MMMMMMMMMMMMMMMMMMO               
                cMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMd                
                 'WMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM:                 
                  .dMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMO.                  
                    ;NMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMl                    
                      oMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMk.                     
                       'KMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMW:                       
                         lMMMMMMMMMMMMMMMMMMMMMMMMMMMMd                         
                          .xMMMMMMMMMMMMMMMMMMMMMMMMk.                          
                            'KMMMMMMMMMMMMMMMMMMMMX,                            
                              oMMMMMMMMMMMMMMMMMMo                              
                               .OMMMMMMMMMMMMMMO.                               
                                 cMMMMMMMMMMMM:                                 
                                  .KMMMMMMMM0.                                  
                                    oMMMMMMl                                    
                                     :MMMM,                                     
                                      'KO.                                      

I'm closing this for now, if you disagree, feel free to reopen this issue and discuss a better solution, or open a pr with it.