Coder Social home page Coder Social logo

im2a's Introduction

HAI 1.2
  CAN HAS STDIO?
  VISIBLE "HAI WORLD!!!1!"
KTHXBYE

im2a's People

Contributors

onitake avatar tzvetkoff avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

im2a's Issues

Buffer overflow through fuzzing with AFL++

Hi,

I decided to do some fuzz-testing on your project with AFL++ as it seemed like an interesting task. I found some issues. I used the octocat picture you used as an example as input for the fuzzer:
octocat

AFL++ morphed the file into the one contained in this zip: crash6.zip

If you compile im2a the following way:

Compilation steps

  1. Pull from git
  2. ./bootstrap
  3. AFL_USE_ASAN=1 ./configure CC=/usr/bin/afl-gcc CXX=/usr/bin/afl-g++ --enable-debug
  4. make install

and then run it as follows:
im2a -p -g <crash-file>

You will get the following error from ASAN:
crash6

Note: I had to comment out the precompiler options #if IMAGEMAGICK_VERSION >= 0x7 for ImageMagick version 7 as my version is below that (as you will see in the Versions section) and otherwise I could not compile im2a with the AFL compilers.

There were some other crashes as well, but they don't seem reproducible outside AFL.

If you would like to fuzz the program yourself, I used the following command:
afl-fuzz -i <folder_containing_input_pic> -o <output_folder> -m none /path/to/im2a -p -g @@.
Beware, I did not find any issues (save for some timeouts) before an hour had passed. I ran this for a total of 12 hours. ~3000 crashes occurred, but the unique issues were only 7, of which the only manually reproducible one I shared with you.

I used the following versions for OS/software/libraries:

Versions:
im2a: 0.6.2 / commit 8a2111b (current master)
Fuzzer: AFL++ 4.0.0c
OS: Kali Linux 2022.3 (kali-rolling)
ImageMagick: 6.9.11
libncurses: 6.3+20220423-2

autoconf Magic++-config option is wrong

configure.ac mentions one should use --with-imagemagick-config=<path> to specify the location of Magic++-config, but according to m4/imagemagick.m4, it should be --with-magick++-config=<path>.

This can lead to misleading ./configure output.
Please fix the corresponding line. Thanks.

Dithering support

Could you add support for dithering?

(To avoid flat, unsightly areas that appear in some images after colour reduction.)

Since you're using ImageMagick this should be simple.

PS! Thanks for a nice and simple utility.

Transparency support

It would be very cool if im2a supported transparency.
Partial transparency will be difficult to do, but 100% transparent areas could be mapped to the default terminal background color using \e[49m.

It may be necessary to use and in addition to for partial pixels, however.

height doesn't work

the following command doesn't work, it won't output with 40 row, same for width

im2a --height=40 --grayscale https://cdn.meme.am/cache/instances/folder668/500x/63425668.jpg

Won't compile (detailed error report inside)

I set up my linux environment to have all dependencies, but something called "PixelPacket" causes severe errors. Please help me, I really want to use your software on my armhf Raspberry Pi 2, so far I got everything working there.

/im2a/im2a$ sudo make install
Making install in src
make[1]: Entering directory '/home/ubuntu/im2a/im2a/src'
g++ -DHAVE_CONFIG_H -I. -I.. -fopenmp -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16 -fopenmp -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16 -fopenmp -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16 -I/usr/local/include/ImageMagick-7 -g -O2 -MT asciifier.o -MD -MP -MF .deps/asciifier.Tpo -c -o asciifier.o asciifier.cpp
asciifier.cpp: In member function ‘void im2a::Asciifier::asciify()’:
asciifier.cpp:173:5: error: ‘PixelPacket’ is not a member of ‘Magick’
Magick::PixelPacket _pixels = _image->getPixels(0, 0, _image->columns(),
^
asciifier.cpp:173:5: note: suggested alternative:
In file included from /usr/local/include/ImageMagick-7/MagickCore/color.h:21:0,
from /usr/local/include/ImageMagick-7/MagickCore/image.h:21,
from /usr/local/include/ImageMagick-7/MagickCore/draw.h:22,
from /usr/local/include/ImageMagick-7/MagickCore/annotate.h:21,
from /usr/local/include/ImageMagick-7/MagickCore/MagickCore.h:79,
from /usr/local/include/ImageMagick-7/Magick++/Include.h:42,
from /usr/local/include/ImageMagick-7/Magick++.h:10,
from asciifier.h:15,
from asciifier.cpp:19:
/usr/local/include/ImageMagick-7/MagickCore/pixel.h:204:3: note: ‘MagickCore::PixelPacket’
} PixelPacket;
^
asciifier.cpp:173:26: error: ‘pixels’ was not declared in this scope
Magick::PixelPacket *pixels = _image->getPixels(0, 0, image->columns(),
^
asciifier.cpp:191:13: error: ‘PixelPacket’ is not a member of ‘Magick’
Magick::PixelPacket *pixel = pixels + offset;
^
asciifier.cpp:191:13: note: suggested alternative:
In file included from /usr/local/include/ImageMagick-7/MagickCore/color.h:21:0,
from /usr/local/include/ImageMagick-7/MagickCore/image.h:21,
from /usr/local/include/ImageMagick-7/MagickCore/draw.h:22,
from /usr/local/include/ImageMagick-7/MagickCore/annotate.h:21,
from /usr/local/include/ImageMagick-7/MagickCore/MagickCore.h:79,
from /usr/local/include/ImageMagick-7/Magick++/Include.h:42,
from /usr/local/include/ImageMagick-7/Magick++.h:10,
from asciifier.h:15,
from asciifier.cpp:19:
/usr/local/include/ImageMagick-7/MagickCore/pixel.h:204:3: note: ‘MagickCore::PixelPacket’
} PixelPacket;
^
asciifier.cpp:191:34: error: ‘pixel’ was not declared in this scope
Magick::PixelPacket *pixel = pixels + offset;
^
asciifier.cpp:211:32: error: ‘class Magick::Color’ has no member named ‘redQuantum’
pow(color->redQuantum() - gs, 2) +
^
asciifier.cpp:212:32: error: ‘class Magick::Color’ has no member named ‘greenQuantum’
pow(color->greenQuantum() - gs, 2) +
^
asciifier.cpp:213:32: error: ‘class Magick::Color’ has no member named ‘blueQuantum’
pow(color->blueQuantum() - gs, 2)
^
asciifier.cpp:243:36: error: ‘class Magick::Color’ has no member named ‘redQuantum’
pow(color->redQuantum() - pixel->red, 2) +
^
asciifier.cpp:244:36: error: ‘class Magick::Color’ has no member named ‘greenQuantum’
pow(color->greenQuantum() - pixel->green, 2) +
^
asciifier.cpp:245:36: error: ‘class Magick::Color’ has no member named ‘blueQuantum’
pow(color->blueQuantum() - pixel->blue, 2)
^
Makefile:402: recipe for target 'asciifier.o' failed
make[1]: *
* [asciifier.o] Error 1
make[1]: Leaving directory '/home/ubuntu/im2a/im2a/src'
Makefile:458: recipe for target 'install-recursive' failed
make: *** [install-recursive] Error 1

After successful compilation im2a will only display --help when trying to ASCIIfi a file

Sorry to bother you again, but it seems not to work. the same command runs fine with jp2a:

ubuntu@ubuntu:~$ im2a --height=170 test0.jpg

im2a 0.4.0

Convert image files to ASCII art
Copyright (C) 2013 Latchezar Tzvetkoff
Distributed under The Beerware License

Usage:
im2a [options]

Options:
-h, --help Prints this message
-v, --version Prints version string
-m, --html Output HTML
-i, --invert Invert the image
-t, --center Center the image
-W, --width=N Set output width
-H, --height=M Set output height
-c, --charset=CHARSET Set output charset
-g, --grayscale Grayscale output instead of 256-color
-R, --red-weight=RW Set red component weight (default: 0.2989)
-G, --green-weight=GW Set green component weight (default: 0.5866)
-B, --blue-weight=BW Set blue component weight (default: 0.1145)

Project homepage: https://github.com/tzvetkoff/im2a
Report bugs to https://github.com/tzvetkoff/im2a/issues
ubuntu@ubuntu:~$

Odd number of rows yields garbage in last row

In pixel mode, when processing images with an odd number of rows, the last line is filled up with garbage.

It would be better if the default background is used instead - or at least the same color as the other part of the character.

Fails to build with Ubuntu Bionic

Build log:

$ make
make  all-recursive
make[1]: Entering directory '/tmp/im2a'
Making all in src
make[2]: Entering directory '/tmp/im2a/src'
g++ -DHAVE_CONFIG_H -I. -I..    -Wall -g -fno-strict-aliasing -O2 -pthread -g -O2 -MT asciifier.o -MD -MP -MF .deps/asciifier.Tpo -c -o asciifier.o asciifier.cpp
asciifier.cpp: In constructor ‘im2a::Asciifier::Asciifier(im2a::Options*, im2a::TermInfo*, Magick::Image*)’:
asciifier.cpp:183:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         (scale_width != _image->columns() || scale_height != _image->rows())) {
          ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
asciifier.cpp:183:59: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         (scale_width != _image->columns() || scale_height != _image->rows())) {
                                              ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
asciifier.cpp: In member function ‘void im2a::Asciifier::asciify()’:
asciifier.cpp:221:23: error: cannot convert ‘MagickLib::PixelPacket* {aka MagickLib::_PixelPacket*}’ to ‘MagickLib::Quantum* {aka short unsigned int*}’ in initialization
         _image->rows());
                       ^
asciifier.cpp:237:59: error: ‘class Magick::Image’ has no member named ‘alpha’
     bool transparent = _options->transparent() && _image->alpha();
                                                           ^~~~~
asciifier.cpp:239:9: error: ‘MagickCore’ has not been declared
         MagickCore::GetPixelChannelOffset(_image->image(),
         ^~~~~~~~~~
asciifier.cpp:240:13: error: ‘MagickCore’ has not been declared
             MagickCore::AlphaPixelChannel) : -1;
             ^~~~~~~~~~
asciifier.cpp:24:35: error: ‘MAGICKCORE_QUANTUM_DEPTH’ was not declared in this scope
 #define MAGICK_QUANTUM_MAX ((1 << MAGICKCORE_QUANTUM_DEPTH) - 1)
                                   ^
asciifier.cpp:243:55: note: in expansion of macro ‘MAGICK_QUANTUM_MAX’
         (1.0f - _options->transparency_threshold()) * MAGICK_QUANTUM_MAX;
                                                       ^~~~~~~~~~~~~~~~~~
asciifier.cpp:24:35: note: suggested alternative: ‘MAGICK_QUANTUM_MAX’
 #define MAGICK_QUANTUM_MAX ((1 << MAGICKCORE_QUANTUM_DEPTH) - 1)
                                   ^
asciifier.cpp:243:55: note: in expansion of macro ‘MAGICK_QUANTUM_MAX’
         (1.0f - _options->transparency_threshold()) * MAGICK_QUANTUM_MAX;
                                                       ^~~~~~~~~~~~~~~~~~
asciifier.cpp:260:26: error: ‘MagickCore’ has not been declared
                 offset * MagickCore::GetPixelChannels(_image->image());
                          ^~~~~~~~~~
asciifier.cpp:291:32: error: ‘class Magick::Color’ has no member named ‘quantumRed’
                     pow(color->quantumRed() - gs, 2) +
                                ^~~~~~~~~~
asciifier.cpp:292:32: error: ‘class Magick::Color’ has no member named ‘quantumGreen’
                     pow(color->quantumGreen() - gs, 2) +
                                ^~~~~~~~~~~~
asciifier.cpp:293:32: error: ‘class Magick::Color’ has no member named ‘quantumBlue’
                     pow(color->quantumBlue() - gs, 2)
                                ^~~~~~~~~~~
asciifier.cpp:330:36: error: ‘class Magick::Color’ has no member named ‘quantumRed’
                         pow(color->quantumRed() - pixel[0], 2) +
                                    ^~~~~~~~~~
asciifier.cpp:331:36: error: ‘class Magick::Color’ has no member named ‘quantumGreen’
                         pow(color->quantumGreen() - pixel[1], 2) +
                                    ^~~~~~~~~~~~
asciifier.cpp:332:36: error: ‘class Magick::Color’ has no member named ‘quantumBlue’
                         pow(color->quantumBlue() - pixel[2], 2)
                                    ^~~~~~~~~~~
Makefile:382: recipe for target 'asciifier.o' failed
make[2]: *** [asciifier.o] Error 1
make[2]: Leaving directory '/tmp/im2a/src'
Makefile:411: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/tmp/im2a'
Makefile:331: recipe for target 'all' failed
make: *** [all] Error 2

Sequence optimisation

Currently, im2a generates escape codes for every single pixel.

This could be optimised by comparing each pixel with the previous one and keeping the foreground/background color if it is unchanged.

It would also be nice if pixel pairs with the same color could be turned into a blank character ( ) instead of the default . This would allow setting only the background color.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.