1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-29 05:16:51 +01:00

added custom wuidget code (WIP)

This commit is contained in:
Daniel Dakhno 2020-01-03 00:15:48 +01:00
parent 1e2b0ce242
commit d2ede421c1
5 changed files with 122 additions and 69 deletions

View File

@ -1,8 +1,8 @@
package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.image;
package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.encoder;
import java.io.ByteArrayOutputStream;
public class ImageRLEEncoder {
public class RLEEncoder {
public static byte[] RLEEncode(byte[] data) {
ByteArrayOutputStream bos = new ByteArrayOutputStream(data.length * 2);
@ -14,8 +14,8 @@ public class ImageRLEEncoder {
currentByte = data[i];
if (currentByte != lastByte || count >= 255) {
bos.write(data[i - 1]);
bos.write(count);
bos.write(data[i - 1]);
count = 1;
lastByte = data[i];
@ -24,8 +24,8 @@ public class ImageRLEEncoder {
}
}
bos.write(currentByte);
bos.write(count);
bos.write(currentByte);
byte[] result = bos.toByteArray();

View File

@ -1,13 +1,49 @@
package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.image;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.ColorSpace;
import androidx.annotation.ColorInt;
import java.io.IOException;
public class AssetImageFactory {
public static AssetImage createAssetImage(String fileName, byte[] fileData, int angle, int distance, int indexZ){
return new AssetImage(fileName, fileData, angle, distance, indexZ);
}
public static AssetImage createAssetImage(String fileName, Bitmap fileData, boolean RLEencode, int angle, int distance, int indexZ){
public static AssetImage createAssetImage(String fileName, Bitmap fileData, boolean RLEencode, int angle, int distance, int indexZ) throws IOException {
int height = fileData.getHeight();
int width = fileData.getWidth();
// if(fileData.getConfig() != Bitmap.Config.ALPHA_8) throw new RuntimeException("Bitmap is not ALPHA_8");
int[] pixels = new int[height * width];
fileData.getPixels(pixels, 0, width, 0, 0, width, height);
byte[] pixelBytes = new byte[width * height];
for(int i = 0; i < pixels.length; i++){
int monochrome = convertToMonochrome(pixels[i]);
monochrome >>= 6;
pixelBytes[i] = (byte) monochrome;
}
if(RLEencode){
return new AssetImage(fileName, ImageConverter.encodeToRLEImage(pixelBytes, height, width), angle, distance, indexZ);
}
return null;
}
private static @ColorInt int convertToMonochrome(@ColorInt int color){
int sum = Color.red(color) + Color.green(color) + Color.blue(color);
sum /= 3;
return sum;
}
}

View File

@ -0,0 +1,26 @@
package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.image;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.encoder.RLEEncoder;
public class ImageConverter {
public static void encodeToTwoBitImage(byte monochromeImage){
}
public static byte[] encodeToRLEImage(byte[] monochromeImage, int height, int width) throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream(monochromeImage.length * 2);
bos.write((byte) height);
bos.write((byte) width);
bos.write(RLEEncoder.RLEEncode(monochromeImage));
bos.write((byte) 0x0FF);
bos.write((byte) 0x0FF);
return bos.toByteArray();
}
}

View File

@ -7,8 +7,8 @@ import org.json.JSONObject;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.fossil.FossilWatchAdapter;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.json.JsonPutRequest;
public class ImagesPutRequest extends JsonPutRequest {
public ImagesPutRequest(AssetImage[] images, FossilWatchAdapter adapter) {
public class ImagesSetRequest extends JsonPutRequest {
public ImagesSetRequest(AssetImage[] images, FossilWatchAdapter adapter) {
super((short) 0x0503, prepareObject(images), adapter);
}