| [10edeb0] | 1 | #!/usr/bin/python
|
|---|
| 2 | '''
|
|---|
| 3 | Copyright (C) 2016 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
|
|---|
| 4 |
|
|---|
| 5 | This program is free software: you can redistribute it and/or modify
|
|---|
| 6 | it under the terms of the GNU General Public License as published by
|
|---|
| 7 | the Free Software Foundation, either version 3 of the License, or
|
|---|
| 8 | (at your option) any later version.
|
|---|
| 9 |
|
|---|
| 10 | This program is distributed in the hope that it will be useful,
|
|---|
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 13 | GNU General Public License for more details.
|
|---|
| 14 |
|
|---|
| 15 | You should have received a copy of the GNU General Public License
|
|---|
| 16 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|---|
| 17 | '''
|
|---|
| 18 |
|
|---|
| 19 | import sys
|
|---|
| 20 | import os
|
|---|
| 21 | import getopt
|
|---|
| [cfdd201] | 22 | try:
|
|---|
| [6f09609] | 23 | from PIL import Image
|
|---|
| 24 | from PIL import ImageOps
|
|---|
| 25 | from EPD import EPD
|
|---|
| 26 | epdEnabled = True
|
|---|
| [cfdd201] | 27 | except:
|
|---|
| [6f09609] | 28 | epdEnabled = False
|
|---|
| 29 |
|
|---|
| [10edeb0] | 30 |
|
|---|
| 31 | def displayImage(epd, imageFilePath):
|
|---|
| [6f09609] | 32 | image = Image.open(imageFilePath)
|
|---|
| 33 | image = ImageOps.grayscale(image)
|
|---|
| 34 | imageResized = image.resize((epd.width, epd.height))
|
|---|
| 35 | imageBlackWhite = imageResized.convert("1", dither=Image.FLOYDSTEINBERG)
|
|---|
| 36 | epd.display(imageBlackWhite)
|
|---|
| 37 | epd.update()
|
|---|
| 38 |
|
|---|
| [0272b16] | 39 |
|
|---|
| 40 | def usage():
|
|---|
| [b45e75d] | 41 | print("Usage of gnuboat-splashscreen:")
|
|---|
| 42 | print(" gnuboat-splashscreen [-h] -i PATH_TO_IMAGE_TO_DISPLAY")
|
|---|
| 43 | print("")
|
|---|
| 44 | print(" -h --help Print this help")
|
|---|
| 45 | print(" -i --image Path to the image, which should be displayed")
|
|---|
| [6f09609] | 46 | sys.exit()
|
|---|
| [10edeb0] | 47 |
|
|---|
| 48 |
|
|---|
| [6f09609] | 49 | def main(argv):
|
|---|
| 50 | image = ""
|
|---|
| 51 | try:
|
|---|
| 52 | opts, args = getopt.getopt(argv, "hi:", ["help", "image="])
|
|---|
| 53 | except getopt.GetoptError:
|
|---|
| 54 | usage()
|
|---|
| 55 | sys.exit(2)
|
|---|
| [0272b16] | 56 |
|
|---|
| [6f09609] | 57 | for option, argument in opts:
|
|---|
| 58 | if option == ("-h", "--help"):
|
|---|
| 59 | usage()
|
|---|
| 60 | sys.exit()
|
|---|
| 61 | elif option in ("-i", "--image"):
|
|---|
| 62 | image = argument
|
|---|
| 63 | else:
|
|---|
| 64 | assert False, "unhandled option"
|
|---|
| 65 |
|
|---|
| 66 | if not os.path.exists(image):
|
|---|
| [b45e75d] | 67 | print("Image {} not found".format(image))
|
|---|
| [6f09609] | 68 | usage()
|
|---|
| 69 | sys.exit(2)
|
|---|
| [10edeb0] | 70 |
|
|---|
| [6f09609] | 71 | if not epdEnabled:
|
|---|
| [b45e75d] | 72 | print("Could not initialize EPD or PIL python packages")
|
|---|
| [6f09609] | 73 | sys.exit(2)
|
|---|
| [cfdd201] | 74 |
|
|---|
| [6f09609] | 75 | epd = EPD()
|
|---|
| 76 | epd.clear()
|
|---|
| 77 | displayImage(epd, image)
|
|---|
| [10edeb0] | 78 |
|
|---|
| 79 | if __name__ == "__main__":
|
|---|
| [6f09609] | 80 | main(sys.argv[1:])
|
|---|