/LcdPngGenerator

An png file generator based on an input txt file with 4 digit IDs

Primary LanguageC++

LngPngGenerator

Description

This is a project for a programming exercise required for an interview. A excutable is built to generate png files which can be recognised by a LCD model from a set of 4 digits IDs listed in text file.

The project is built via CMake in C++(gcc on both linux and Windows(mingw)) with unit test. libpng is used to generate png file and also being applied in unit test for image verification.

A python application has been added since 0.2 release.

folder discription ./src contains source code and cmake configuration file ./test a unit test program supporting ctest ./docs contains documents generated by doxygen, hopefull it will be helpful to understand the code ./python source file for python version of the application

Environments and Dependencies

I was trying to use stb image library which provide header file only implementation for png writting and reading(https://github.com/nothings/stb), because it doesn't need to install dependencies and would be great to support on different OS or environment. It was good at beggining to create png file but I figured out later that it seems not support 1 bit-depth png, somehow it upscale to 8bit grayscale image and wrong. Another library 'spng'(simple png) also doesn't support 1 bit-depth too, so the official libpng got its chance to prove its the right one, typical!

Linux(mint-cinnamon) recommended

  1. install cmake: sudo apt-get install cmake
  2. install libpng: sudo apt-get install libpng-dev
  3. install zlib: sudo apt-get install zlib1g-dev

Windows(how dare you want to try?!)

  1. download cmake installer via https://cmake.org/download/
  2. install cmake and add $CMAKE_Installed_DIR\bin into system paths
  3. install msys2(for mingw-w64 gcc) from https://www.msys2.org/#installation, following the instruction, somehow easy and clear to follow
  4. install libpng via mysys console: pacman -S mingw-w64-ucrt-x86_64-libpng
  5. install zlib via mysys console: pacman -S mingw-w64-ucrt-x86_64-zlib

Python

  1. Install python 3.x
  2. Install pypng: pip install pypng

Build the program

Linux

  1. unzip the zip file to a folder
  2. open a terminal and access to the root foler in the terminal
  3. configure cmake build by command: 'cmake -S . -B build'
  4. go into build directory, and build the program by command: 'make'

Windows(CMakefilelist modification needed)

  1. unzip the zip file to a folder
  2. open a command console and access to the root folder
  3. FINDPNG and FINDZLIB in CMakeLists is not working on my case, but you may be lucker than me 3.1 set PNG and ZLIB variables manually in CMakeLists.txt like following(E:/msys64/ is where I installed msys2):

set(PNG_INCLUDE_DIR "E:/msys64/mingw64/include") set(PNG_LIBRARIES "E:/msys64/mingw64/lib/libpng.dll.a") set(ZLIB_LIBRARIES "E:/msys64/mingw64/lib/libz.dll.a")

  1. configure cmake build by command: 'cmake -S . -B build -G "MinGW Makefiles"'
  2. go into build directory, and build the program by command: 'mingw32-make.exe'

Python

Easy life, you don't need to compile anything unless...

Executing program and testing

Linux

  1. in terminal, goto $project_dir$/build/src folder
  2. run: 'LngPngGenerator ../../resource/test.txt'
  3. a set of png files will be generated under current folder

Windows

  1. in command console, goto $project_dir$\build\src folder
  2. run: 'LngPngGenerator.exe ....\resource\test.txt'
  3. a set of png files will be generated under current folder

Python

  1. go to $project_dir$/python folder
  2. run: "python PyIdToLcdPng.py -f ..\resource\test.txt -o .\results"

Authors

ex. Xing JIN

Version History

  • 0.1
    • Initial Release

License

Free without any license required

Acknowledgments

Inspiration, code snippets, etc.