SConscript 2.2 KB

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