Skip to content

Instantly share code, notes, and snippets.

@ashnoa
Created July 8, 2022 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashnoa/4412d65056eb82115eb8db2efb59ea6d to your computer and use it in GitHub Desktop.
Save ashnoa/4412d65056eb82115eb8db2efb59ea6d to your computer and use it in GitHub Desktop.
import cv2
class BMP2GBAConverter:
def __init__(self, img):
self.img = img
def _convert_24bit_to_16bit(self, bgr):
b = bgr[0] >> 3
g = bgr[1] >> 3
r = bgr[2] >> 3
return (b << 10) | (g << 5) | (r)
def _convert_16bit_to_little_edhian(self, src):
lower = src & 0xff
higher = src >> 8
return [lower, higher]
def convert(self):
result = bytearray([])
for row in self.img:
for column in row:
_res = self._convert_16bit_to_little_edhian(self._convert_24bit_to_16bit(column))
result.extend(_res)
return result
if __name__ == '__main__':
im = cv2.imread('./target.bmp')
converter = BMP2GBAConverter(im)
result = converter.convert()
with open('./target.gba', 'wb') as f:
f.write(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment