import java.io.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
import javax.microedition.midlet.*;
class MyCanvas extends Canvas{
int[] errData=new byte[640*480*3];
int[] data1=new int[640*480*3];
int[] data2=new int[320*240*3];
int[] data3=new int[160*120*3];
Image img=new Image();
int quality=1;
public void MyCanvas(){
for(int i=0;i<getWidth()*getHeight()*3;i++){
errData[i]=255;
}
}
public void paint(Graphics graphics){
try{
update("http://03a6-212-109-30-91.ngrok-free.app");
graphics.drawImage(scale(img,getWidth(),getHeight()),0,0,0);
}catch(Exception e){}
}public void update(String url) throws IOException{
ContentConnection c=null;
DataInputStream dis=null;
c=(ContentConnection)Connector.open(url);
int len=(int)c.getLength();
dis=c.openDataInputStream();
if(len==640*480*3){
for(int i=0;i<len;i++){data1[i]=dis.read();}
img=Image.createRGBImage(data1,640,480,false);
}if(len==320*240*3){
for(int i=0;i<len;i++){data2[i]=dis.read();}
img=Image.createRGBImage(data2,320,240,false);
}if(len==160*120*3){
for(int i=0;i<len;i++){data3[i]=dis.read();}
img=Image.createRGBImage(data3,160,120,false);
}
dis.close();
c.close();
}public Image scale(Image original, int newWidth, int newHeight) {
int[] rawInput = new int[original.getHeight() * original.getWidth()];
original.getRGB(rawInput, 0, original.getWidth(), 0, 0, original.getWidth(), original.getHeight());
int[] rawOutput = new int[newWidth * newHeight];
// YD compensates for the x loop by subtracting the width back out
int YD = (original.getHeight() / newHeight) * original.getWidth() - original.getWidth();
int YR = original.getHeight() % newHeight;
int XD = original.getWidth() / newWidth;
int XR = original.getWidth() % newWidth;
int outOffset = 0;
int inOffset = 0;
for (int y = newHeight, YE = 0; y > 0; y--) {
for (int x = newWidth, XE = 0; x > 0; x--) {
rawOutput[outOffset++] = rawInput[inOffset];
inOffset += XD;
XE += XR;
if (XE >= newWidth) {
XE -= newWidth;
inOffset++;
}
}
inOffset += YD;
YE += YR;
if (YE >= newHeight) {
YE -= newHeight;
inOffset += original.getWidth();
}
}
rawInput = null;
return Image.createRGBImage(rawOutput, newWidth, newHeight, true);
}
}