You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.7 KiB

  1. # This program source code file is part of KICAD, a free EDA CAD application.
  2. #
  3. # Copyright (C) 2011 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  4. # Copyright (C) 2011 Kicad Developers, see change_log.txt for contributors#.
  5. #
  6. # This program is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU General Public License
  8. # as published by the Free Software Foundation; either version 2
  9. # of the License, or (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, you may find one here:
  18. # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  19. # or you may search the http://www.gnu.org website for the version 2 license,
  20. # or you may write to the Free Software Foundation, Inc.,
  21. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. #
  23. #############################################################################
  24. #
  25. # This script converts a *.png file into a *.cpp file.
  26. # The *.cpp file will contain a BITMAP_DEF structure, which is simply a byte
  27. # array and a length of bytes which were found in the *.png file.
  28. #
  29. #
  30. # Invocation Parameters are: inputFile, outCppFile
  31. #
  32. # inputFile - Required, full path and file name of the input PNG file
  33. #
  34. # outCppFile - Required, full path and file name of where to save the
  35. # generated cpp file.
  36. file( READ ${inputFile} file_contents HEX )
  37. get_filename_component( png_name "${inputFile}" NAME_WE )
  38. # split into pairs of ASCII, where each pair gives a single byte's value
  39. string( REGEX MATCHALL "[0-9a-fA-F][0-9a-fA-F]" byte_list ${file_contents} )
  40. set( output_begin "
  41. /* Do not modify this file, it was automatically generated by the
  42. * PNG2cpp CMake script, using a *.png file as input.
  43. */
  44. #include <bitmaps_png/bitmaps_list.h>
  45. static const unsigned char png[] = {"
  46. )
  47. set( output_end "};
  48. const BITMAP_OPAQUE ${png_name}_xpm[1] = {{ png, sizeof( png ), \"${png_name}_xpm\" }};
  49. //EOF
  50. " )
  51. set( byte_count 0 )
  52. set( byte_array "" )
  53. foreach( byte ${byte_list} )
  54. math( EXPR modulus "${byte_count} % 16" )
  55. if( modulus EQUAL 0 )
  56. set( byte_array "${byte_array}\n" )
  57. endif()
  58. set( byte_array "${byte_array} 0x${byte}," )
  59. math( EXPR byte_count "${byte_count} + 1" )
  60. endforeach()
  61. set( byte_array "${byte_array}\n" )
  62. file( WRITE ${outCppFile} "${output_begin}" )
  63. file( APPEND ${outCppFile} "${byte_array}" )
  64. file( APPEND ${outCppFile} "${output_end}" )