Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle class 9 #1

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Support for RUN LENGTH image decoding
  • Loading branch information
Jean-Philippe Prade committed Jul 9, 2021
commit 14e66e805e0da86c9c65f044a5b9c34860fe12e4
29 changes: 26 additions & 3 deletions src/net/sf/jcgm/core/Tile.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,35 @@ public void paint(CGMDisplay d) {

this.bufferedImage=imageOut;
super.paint(d);
}else {
}else if(this.bytes!=null && this.compressionType==CompressionType.RUN_LENGTH) {
BufferedImage imageOut = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
byte[] imgdata = this.bytes.array();
int x = 0;
int y = 0;
for(int i=0;i<imgdata.length;i=i+5) {
int nbpixel = (imgdata[i] <<8) + unsignedToBytes(imgdata[i+1]);
byte r = imgdata[i+2];
byte g = imgdata[i+3];
byte b = imgdata[i+4];
for(int j=0;j<nbpixel;j++) {
imageOut.setRGB(x, y, (r <<16) + (g <<8) + b);
x=x+1;
if(x>=width) {
x=0;
y++;
}
}
}

this.bufferedImage=imageOut;
super.paint(d);
} else {
super.paint(d);
}
}



public static int unsignedToBytes(byte b) {
return b & 0xFF;
}

@Override
Expand Down
3 changes: 3 additions & 0 deletions src/net/sf/jcgm/core/TileElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ protected void readSdrAndBitStream() throws IOException {
case T6:
readT6();
break;
case RUN_LENGTH:
this.bytes = readBytes();
break;
default:
unsupported("unsupported compression type " + this.compressionType);
}
Expand Down