SConscript 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. from building import *
  2. import os, re
  3. group = []
  4. if not GetDepend(['RT_GRAPHIC_LOGO']):
  5. Return('group')
  6. cwd = GetCurrentDir()
  7. CPPPATH = [cwd + '/../../include']
  8. CPPDEFINES = []
  9. src = ['logo.c']
  10. logo_path = None
  11. logo_width = 0
  12. logo_height = 0
  13. logo_max_val = 0
  14. if GetDepend(['RT_GRAPHIC_LOGO_RT_THREAD_CLUT224']):
  15. logo_path = cwd + '/logo-rt-thread-clut224.ppm'
  16. if GetDepend(['RT_GRAPHIC_LOGO_RT_THREAD_WHITE_CLUT224']):
  17. logo_path = cwd + '/logo-rt-thread-white-clut224.ppm'
  18. if logo_path == None:
  19. # Find in BSP
  20. paths = None
  21. for key in BuildOptions.keys():
  22. if re.match(r'RT_GRAPHIC_LOGO_.*_PATH', key):
  23. paths = BuildOptions[key]
  24. break
  25. if paths != None and len(paths) > 0:
  26. logo_path = Dir('#').abspath + '/' + paths[1:-1]
  27. if not os.path.exists(logo_path):
  28. print("Logo file '{}' not found!".format(logo_path))
  29. exit(-1)
  30. if logo_path != None:
  31. with open(logo_path, 'rb') as ppm:
  32. data = ppm.read().split(b'\n')
  33. # PPM: <magic number>
  34. magic = data[0].decode('utf-8')
  35. # PPM: <comment>
  36. offset = 1
  37. while True:
  38. comment = str(data[offset].decode('utf-8'))
  39. if comment[0] != '#':
  40. break
  41. offset += 1
  42. # PPM: <width> <height>
  43. logo_width, logo_height = map(int, data[offset].split())
  44. # PPM: <max pixel value>
  45. logo_max_val = int(data[offset + 1])
  46. # PPM: <data>
  47. ppm.seek(0)
  48. pixels = b''.join(ppm.readlines()[offset + 2:])
  49. ppm.close()
  50. if magic == 'P1' or magic == 'P2' or magic == 'P3':
  51. # ASCII
  52. pixels = re.sub(b'\\s+', b'\n', pixels.strip()).decode('utf-8').split('\n')
  53. logo = open(cwd + '/logo.inc', "w")
  54. for dy in range(logo_height):
  55. for dx in range(logo_width):
  56. index = (dy * logo_width + dx) * 3
  57. # Red
  58. logo.write(str(pixels[index]).rjust(4) + ",")
  59. # Green
  60. logo.write(str(pixels[index + 1]).rjust(4) + ",")
  61. # Blue
  62. logo.write(str(pixels[index + 2]).rjust(4) + ",")
  63. logo.write("\n")
  64. logo.close()
  65. CPPDEFINES += ['__STARTUP_LOGO_WIDTH__=' + str(logo_width)]
  66. CPPDEFINES += ['__STARTUP_LOGO_HEIGHT__=' + str(logo_height)]
  67. CPPDEFINES += ['__STARTUP_LOGO_COLOR_MAX__=' + str(logo_max_val)]
  68. group = DefineGroup('DeviceDrivers', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)
  69. Return('group')