This commit is contained in:
@@ -520,6 +520,8 @@ public class GocaDecoderTest {
|
||||
// Polygon 2 (e.g. Letter 'T' stem): (18,20) to (22,20) to (22,40) to (18,40) to (18,20)
|
||||
// GEAR (0x60)
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
out.write(GocaConstants.G_GSPT);
|
||||
out.write(GocaConstants.PT_SOLID);
|
||||
out.write(GocaConstants.G_GBAR);
|
||||
out.write(0x80);
|
||||
|
||||
@@ -555,4 +557,240 @@ public class GocaDecoderTest {
|
||||
}
|
||||
assertTrue(nonZero > 50, "Expected both filled subpath polygons to render filled pixels");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPatternSetAndPatternSymbolSeparation() {
|
||||
GraphicsPlane plane = new GraphicsPlane(200, 200);
|
||||
GocaDecoder decoder = new GocaDecoder(plane);
|
||||
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
// Set Color to Blue (Color 1)
|
||||
out.write(GocaConstants.G_GSCOL);
|
||||
out.write(0x01); // Blue
|
||||
|
||||
// Set Pattern Set to 0 (default standard patterns)
|
||||
out.write(GocaConstants.G_GSPS);
|
||||
out.write(0x00);
|
||||
|
||||
// Set Pattern Symbol to 5 (D5 50% checkerboard)
|
||||
out.write(GocaConstants.G_GSPT);
|
||||
out.write(0x05);
|
||||
|
||||
// Begin Area with boundary (0x80)
|
||||
out.write(GocaConstants.G_GBAR);
|
||||
out.write(0x80);
|
||||
|
||||
// Draw rectangle (0,0) to (50,0) to (50,50) to (0,50) to (0,0)
|
||||
out.write(GocaConstants.G_GLINE);
|
||||
out.write(0x14); // 5 points * 4 bytes = 20 bytes
|
||||
out.write(0x00); out.write(0); out.write(0x00); out.write(0);
|
||||
out.write(0x00); out.write(50); out.write(0x00); out.write(0);
|
||||
out.write(0x00); out.write(50); out.write(0x00); out.write(50);
|
||||
out.write(0x00); out.write(0); out.write(0x00); out.write(50);
|
||||
out.write(0x00); out.write(0); out.write(0x00); out.write(0);
|
||||
|
||||
// End Area
|
||||
out.write(GocaConstants.G_GEAR);
|
||||
|
||||
byte[] stream = out.toByteArray();
|
||||
decoder.decodeStream(stream, 0, stream.length);
|
||||
|
||||
assertTrue(plane.hasContent());
|
||||
// Verify that D5 checkerboard pattern is NOT solid fill (it should have transparent gaps)
|
||||
int[] buffer = plane.getRgbBuffer();
|
||||
int bluePixels = 0;
|
||||
int zeroPixels = 0;
|
||||
int blueArgb = GocaConstants.GOCA_COLORS[1];
|
||||
for (int p : buffer) {
|
||||
if (p == blueArgb) bluePixels++;
|
||||
else if (p == 0) zeroPixels++;
|
||||
}
|
||||
assertTrue(bluePixels > 0, "Expected blue pixels in patterned area");
|
||||
assertTrue(zeroPixels > 0, "Expected transparent zero pixels in patterned area due to D5 checkerboard gaps");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyPatternAreaDrawsOnlyBoundary() {
|
||||
GraphicsPlane plane = new GraphicsPlane(200, 200);
|
||||
GocaDecoder decoder = new GocaDecoder(plane);
|
||||
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
// Set Color to Red (Color 2)
|
||||
out.write(GocaConstants.G_GSCOL);
|
||||
out.write(0x02);
|
||||
|
||||
// Set Pattern Symbol to PT_EMPTY (15)
|
||||
out.write(GocaConstants.G_GSPT);
|
||||
out.write(GocaConstants.PT_EMPTY);
|
||||
|
||||
// Begin Area with boundary (0x80)
|
||||
out.write(GocaConstants.G_GBAR);
|
||||
out.write(0x80);
|
||||
|
||||
// Draw rectangle
|
||||
out.write(GocaConstants.G_GLINE);
|
||||
out.write(0x14);
|
||||
out.write(0x00); out.write(10); out.write(0x00); out.write(10);
|
||||
out.write(0x00); out.write(40); out.write(0x00); out.write(10);
|
||||
out.write(0x00); out.write(40); out.write(0x00); out.write(40);
|
||||
out.write(0x00); out.write(10); out.write(0x00); out.write(40);
|
||||
out.write(0x00); out.write(10); out.write(0x00); out.write(10);
|
||||
|
||||
// End Area
|
||||
out.write(GocaConstants.G_GEAR);
|
||||
|
||||
byte[] stream = out.toByteArray();
|
||||
decoder.decodeStream(stream, 0, stream.length);
|
||||
|
||||
assertTrue(plane.hasContent());
|
||||
// Verify that center of the box is transparent (not filled)
|
||||
int centerX = plane.mapX(25);
|
||||
int centerY = plane.mapY(25);
|
||||
int centerPixel = plane.getRgbBuffer()[centerY * plane.getCanvasWidth() + centerX];
|
||||
assertEquals(0, centerPixel, "Expected interior of PT_EMPTY area to remain transparent");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGearFollowedByNopOrder() {
|
||||
GraphicsPlane plane = new GraphicsPlane(200, 200);
|
||||
GocaDecoder decoder = new GocaDecoder(plane);
|
||||
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
// Area with PT_EMPTY
|
||||
out.write(GocaConstants.G_GSPT);
|
||||
out.write(GocaConstants.PT_EMPTY);
|
||||
out.write(GocaConstants.G_GBAR);
|
||||
out.write(0x80);
|
||||
out.write(GocaConstants.G_GLINE);
|
||||
out.write(0x10);
|
||||
out.write(0x00); out.write(0); out.write(0x00); out.write(0);
|
||||
out.write(0x00); out.write(10); out.write(0x00); out.write(0);
|
||||
out.write(0x00); out.write(10); out.write(0x00); out.write(10);
|
||||
out.write(0x00); out.write(0); out.write(0x00); out.write(0);
|
||||
out.write(GocaConstants.G_GEAR); // 0x60
|
||||
out.write(GocaConstants.G_NOP1); // 0x00 NOP - must not be consumed as part of GEAR!
|
||||
|
||||
// Followed by a line
|
||||
out.write(GocaConstants.G_GSCOL);
|
||||
out.write(0x03); // Pink
|
||||
out.write(GocaConstants.G_GLINE);
|
||||
out.write(0x08);
|
||||
out.write(0x00); out.write(20); out.write(0x00); out.write(20);
|
||||
out.write(0x00); out.write(40); out.write(0x00); out.write(40);
|
||||
|
||||
byte[] stream = out.toByteArray();
|
||||
decoder.decodeStream(stream, 0, stream.length);
|
||||
|
||||
assertTrue(plane.hasContent());
|
||||
int pinkArgb = GocaConstants.GOCA_COLORS[3];
|
||||
boolean foundPink = false;
|
||||
for (int p : plane.getRgbBuffer()) {
|
||||
if (p == pinkArgb) {
|
||||
foundPink = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
assertTrue(foundPink, "Expected pink line after GEAR + NOP to be drawn");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdmopsSlidePreviewSequence() {
|
||||
GraphicsPlane plane = new GraphicsPlane(200, 200);
|
||||
GocaDecoder decoder = new GocaDecoder(plane);
|
||||
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
|
||||
// 1. Draw Blue stippled slide background (Pattern 6, Blue color 1)
|
||||
out.write(GocaConstants.G_GSCOL); out.write(0x01); // Blue
|
||||
out.write(GocaConstants.G_GSPT); out.write(0x06); // Pattern 6
|
||||
out.write(GocaConstants.G_GBAR); out.write(0x80);
|
||||
out.write(GocaConstants.G_GLINE); out.write(0x14); // 5 points
|
||||
out.write(0x00); out.write(10); out.write(0x00); out.write(10);
|
||||
out.write(0x00); out.write(90); out.write(0x00); out.write(10);
|
||||
out.write(0x00); out.write(90); out.write(0x00); out.write(90);
|
||||
out.write(0x00); out.write(10); out.write(0x00); out.write(90);
|
||||
out.write(0x00); out.write(10); out.write(0x00); out.write(10);
|
||||
out.write(GocaConstants.G_GEAR);
|
||||
|
||||
// 2. Draw Red banner at top (Solid Pattern 16, Red color 2)
|
||||
out.write(GocaConstants.G_GSCOL); out.write(0x02); // Red
|
||||
out.write(GocaConstants.G_GSPT); out.write(0x10); // Solid
|
||||
out.write(GocaConstants.G_GBAR); out.write(0x80);
|
||||
out.write(GocaConstants.G_GLINE); out.write(0x14); // 5 points
|
||||
out.write(0x00); out.write(10); out.write(0x00); out.write(10);
|
||||
out.write(0x00); out.write(90); out.write(0x00); out.write(10);
|
||||
out.write(0x00); out.write(90); out.write(0x00); out.write(30);
|
||||
out.write(0x00); out.write(10); out.write(0x00); out.write(30);
|
||||
out.write(0x00); out.write(10); out.write(0x00); out.write(10);
|
||||
out.write(GocaConstants.G_GEAR);
|
||||
|
||||
// 3. Draw Yellow bullet text (Color 6, default modal solid pattern)
|
||||
out.write(GocaConstants.G_GSCOL); out.write(0x06); // Yellow
|
||||
out.write(GocaConstants.G_GBAR); out.write(0x80);
|
||||
out.write(GocaConstants.G_GLINE); out.write(0x14); // 5 points
|
||||
out.write(0x00); out.write(20); out.write(0x00); out.write(40);
|
||||
out.write(0x00); out.write(80); out.write(0x00); out.write(40);
|
||||
out.write(0x00); out.write(80); out.write(0x00); out.write(50);
|
||||
out.write(0x00); out.write(20); out.write(0x00); out.write(50);
|
||||
out.write(0x00); out.write(20); out.write(0x00); out.write(40);
|
||||
out.write(GocaConstants.G_GEAR);
|
||||
|
||||
// 4. Draw White slide boundary frame (Color set to 8/Black before GBAR, GSCOL White inside GBAR)
|
||||
out.write(GocaConstants.G_GSCOL); out.write(0x08); // Black (background)
|
||||
out.write(GocaConstants.G_GBAR); out.write(0x80);
|
||||
out.write(GocaConstants.G_GSCOL); out.write(0x07); // White line color
|
||||
out.write(GocaConstants.G_GSLT); out.write(GocaConstants.LT_DOT); // Dotted line
|
||||
out.write(GocaConstants.G_GLINE); out.write(0x14); // 5 points
|
||||
out.write(0x00); out.write(10); out.write(0x00); out.write(10);
|
||||
out.write(0x00); out.write(90); out.write(0x00); out.write(10);
|
||||
out.write(0x00); out.write(90); out.write(0x00); out.write(90);
|
||||
out.write(0x00); out.write(10); out.write(0x00); out.write(90);
|
||||
out.write(0x00); out.write(10); out.write(0x00); out.write(10);
|
||||
out.write(GocaConstants.G_GEAR);
|
||||
|
||||
byte[] stream = out.toByteArray();
|
||||
decoder.decodeStream(stream, 0, stream.length);
|
||||
|
||||
assertTrue(plane.hasContent());
|
||||
|
||||
// Verify that the red banner (e.g. at (50, 20)) was NOT overwritten by black/white!
|
||||
int bannerX = plane.mapX(50);
|
||||
int bannerY = plane.mapY(20);
|
||||
int bannerPixel = plane.getRgbBuffer()[bannerY * plane.getCanvasWidth() + bannerX];
|
||||
int redArgb = GocaConstants.GOCA_COLORS[2];
|
||||
assertEquals(redArgb, bannerPixel, "Red header banner must be solid red and preserved");
|
||||
|
||||
// Verify that the yellow text (e.g. at (50, 45)) was NOT overwritten!
|
||||
int textX = plane.mapX(50);
|
||||
int textY = plane.mapY(45);
|
||||
int textPixel = plane.getRgbBuffer()[textY * plane.getCanvasWidth() + textX];
|
||||
int yellowArgb = GocaConstants.GOCA_COLORS[6];
|
||||
assertEquals(yellowArgb, textPixel, "Yellow bullet text must be solid yellow and preserved");
|
||||
|
||||
// Verify that the blue stipple (in body region (20..80, 60..80)) contains blue pixels and was NOT overwritten by white!
|
||||
int blueArgb = GocaConstants.GOCA_COLORS[1];
|
||||
boolean foundBlue = false;
|
||||
int yMin = Math.min(plane.mapY(60), plane.mapY(80));
|
||||
int yMax = Math.max(plane.mapY(60), plane.mapY(80));
|
||||
int xMin = Math.min(plane.mapX(20), plane.mapX(80));
|
||||
int xMax = Math.max(plane.mapX(20), plane.mapX(80));
|
||||
for (int y = yMin; y <= yMax; y++) {
|
||||
for (int x = xMin; x <= xMax; x++) {
|
||||
int pix = plane.getRgbBuffer()[y * plane.getCanvasWidth() + x];
|
||||
if (pix == blueArgb) {
|
||||
foundBlue = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (foundBlue) break;
|
||||
}
|
||||
assertTrue(foundBlue, "Slide body must contain stippled blue pixels");
|
||||
|
||||
// Verify that the boundary (e.g. at (10, 50)) is drawn in White!
|
||||
int whiteArgb = GocaConstants.GOCA_COLORS[7];
|
||||
int borderX = plane.mapX(10);
|
||||
int borderY = plane.mapY(50);
|
||||
int borderPixel = plane.getRgbBuffer()[borderY * plane.getCanvasWidth() + borderX];
|
||||
assertEquals(whiteArgb, borderPixel, "Slide border outline must be drawn in White");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user