Created
July 8, 2022 16:18
-
-
Save ashnoa/4412d65056eb82115eb8db2efb59ea6d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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