-
Notifications
You must be signed in to change notification settings - Fork 19
Image Conversion
James Sutton edited this page Jan 15, 2017
·
2 revisions
In order to send the image to the SP-2, it needs to be converted from it's Bitmap format into the proprietary byte array format that is sent by Command 82.
int[] array1 = new int[height x width]
int[] array2 = new int[height x width]
fill array1 with '16777215'
bitmap.getPixels(dst=array2, offset=0, stride=width, x=0, y=0, width=width, height=height)
int var1 = (height - width) / 2
int var2 = (width - height) / 2
for x in range(height):
copyArray(src=array2, srcPos=(x * width), dst=array1, dstPos=((x + var2) * height), length=width)
byte[] imagePayload
for w in range(width):
for h in range(height):
imagePayload[(((w * height) * 3) + (height * 0)) + h] = (byte) ((array1[(w * height) + h] >> 16) & 255)
imagePayload[(((w * height) * 3) + (height * 1)) + h] = (byte) ((array1[(w * height) + h] >> 8) & 255)
imagePayload[(((w * height) * 3) + (height * 2)) + h] = (byte) ((array1[(w * height) + h] >> 0) & 255)
int numberOfMessages = len(imagePayload) / maxPayloadSize
int lastMessage = len(imagePayload) % maxPayloadSize
int messageNum = 0;
for msg in range(numberOfMessages):
byte[] packet = new byte[maxPayloadSize + 4]
packet[0] = (byte) ((messageNum >> 24) & 255)
packet[1] = (byte) ((messageNum >> 16) & 255)
packet[2] = (byte) ((messageNum >> 8) & 255)
packet[3] = (byte) ((messageNum >> 0) & 255)
copyArray(src=imagePayload, srcPos=(maxPayloadSize * msg), dst=packet, dstPos=4, length=maxPayloadSize)
messageToSend = generatePayload(82, packet)
msgResponse = sendMessage(messageToSend)
processedMsg = processResponse(msgResponse)
if processedMsg.response == ErrorCodes.Error:
# We have failed to send the message somehow
break;
# We should have sent all the messages successfully now