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

Improve debug output #1115

Merged
merged 5 commits into from
Mar 31, 2025
Merged

Improve debug output #1115

merged 5 commits into from
Mar 31, 2025

Conversation

rolfhowarth
Copy link
Contributor

Include hex opcode and file offset in debug output. Condense scan line messages in readOpDirectBits().

Include hex opcode and file offset in debug output. Condense scan line messages in readOpDirectBits().
Copy link
Owner

@haraldk haraldk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First of all, thanks for taking the time to prepare all these PRs! Much appreciated!

I agree with the main intent of this PR, to clean up the debug output.

However, I need you to fix a few things:

  • Set your code style correctly, using 4 spaces as tab/indent, no tabs, 8 spaces continuation indent (but please only reformat the lines you have changed 😀 )
  • Remove the outcommented code, we don't need it (I know I have sinned against this myself, but let's make it better)

Comment on lines 395 to 397
if (DEBUG) {
System.out.println("--- opCode 0x"+Integer.toHexString(opCode)+" at pos 0x"+Long.toHexString(pStream.getStreamPosition()-2)+" ---");
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not so fond of the "---" pre-/postfix, keep it clean. 😀
Also, please use System.out.printf or String.format instead of the string concatenation. Use %04x or %08x as format strings, and skip the toHexString methods.

Comment on lines 1883 to 1886
// // Line break at the end
// if (DEBUG) {
// System.out.println();
// }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can just remove these line, no need to comment out. We have version control. 😀

Comment on lines 2079 to 2086
if (DEBUG && (scanline<6 || scanline>=srcRect.height-5)) {
if (scanline==5 && srcRect.height>10) {
System.out.println("...");
} else {
System.out.print("Line " + scanline + ", byteCount: " + packedBytesCount);
System.out.print(" dstBytes: " + dstBytes.length);
System.out.println();
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if I follow the logic here...

What is the intended output and why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point of this was just to reduce "noise" from the debug output. And the point of hyphens was so you could see each opcode, see for example following:

Done reading PICT header!
--- opCode 0x1e at pos 0x228 ---
opDefHilite
--- opCode 0x1 at pos 0x22a ---
clipRgn: java.awt.Rectangle[x=0,y=0,width=64,height=64]
--- opCode 0x9a at pos 0x236 ---
directBitsRect, rowBytes: 256, it is a PixMap, bounds: java.awt.Rectangle[x=0,y=0,width=64,height=64], pmVersion: 0, packType: 4, packSize: 0
hRes: 72.0, vRes: 72.0, RGBDirect, pixelSize:32, cmpCount:3, cmpSize:8, srcRect:java.awt.Rectangle[x=0,y=0,width=64,height=64], dstRect:java.awt.Rectangle[x=0,y=0,width=64,height=64], mode: 0
Line 0, byteCount: 4 dstBytes: 192
Line 1, byteCount: 4 dstBytes: 192
Line 2, byteCount: 4 dstBytes: 192
Line 3, byteCount: 4 dstBytes: 192
Line 4, byteCount: 4 dstBytes: 192
...
Line 59, byteCount: 4 dstBytes: 192
Line 60, byteCount: 4 dstBytes: 192
Line 61, byteCount: 4 dstBytes: 192
Line 62, byteCount: 4 dstBytes: 192
Line 63, byteCount: 4 dstBytes: 192
--- opCode 0xff at pos 0x550 ---
Done reading PICT body!

Happy to leave both of these out and follow your preferred style though.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, now I see! :-)

Makes sense. I think however it would be easier to read with something like:

Suggested change
if (DEBUG && (scanline<6 || scanline>=srcRect.height-5)) {
if (scanline==5 && srcRect.height>10) {
System.out.println("...");
} else {
System.out.print("Line " + scanline + ", byteCount: " + packedBytesCount);
System.out.print(" dstBytes: " + dstBytes.length);
System.out.println();
}
if (DEBUG) {
if (scanline < 5 || scanline >= srcRect.height - 5) {
System.out.print("Line " + scanline + ", byteCount: " + packedBytesCount);
System.out.print(" dstBytes: " + dstBytes.length);
System.out.println();
}
else if (scanline == 5) {
// Truncate any remaining scanlines...
System.out.println("...");
}
}

Or, with my preferred style these days (this code is old):

Suggested change
if (DEBUG && (scanline<6 || scanline>=srcRect.height-5)) {
if (scanline==5 && srcRect.height>10) {
System.out.println("...");
} else {
System.out.print("Line " + scanline + ", byteCount: " + packedBytesCount);
System.out.print(" dstBytes: " + dstBytes.length);
System.out.println();
}
if (DEBUG) {
if (scanline < 5 || scanline >= srcRect.height - 5) {
System.out.printf("Line %d, byteCount: %d dstBytes: %d%n", scanline, packedBytesCount, dstBytes.length);
}
else if (scanline == 5) {
// Truncate any remaining scanlines...
System.out.println("...");
}
}

Comment on lines 2200 to 2203
// // Line break at the end
// if (DEBUG) {
// System.out.println();
// }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just remove it.

@@ -2558,7 +2565,7 @@ private void verboseRegionCmd(String pCmd, Rectangle pBounds, Area pRegion) {
// for (int i = 1; pPolygon != null && i < pPolygon.npoints; i++) {
// System.out.print(", (" + pPolygon.xpoints[i] + "," + pPolygon.ypoints[i] + ")");
// }
System.out.println();
// System.out.println();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same...

@@ -2653,6 +2660,7 @@ public static void main(final String[] pArgs) {
try {
ImageInputStream input = ImageIO.createImageInputStream(file);
String title = file.getName();
System.out.println("======= "+title+" =======");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think we need this.

@rolfhowarth rolfhowarth requested a review from haraldk March 28, 2025 18:22
@rolfhowarth
Copy link
Contributor Author

Ok, I think I've made all these changes but I'm not 100% sure as I'm still not very familiar with GitHub!

Copy link
Owner

@haraldk haraldk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just reformat the changes according to the code style, and this PR is good! 👍🏻

…lugins/pict/PICTImageReader.java

Co-authored-by: Harald Kuhr <harald.kuhr@gmail.com>
Copy link
Owner

@haraldk haraldk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As said, the code changes in this PR are all good, but the formatting has to match the code style.

It's easier if you just set it up correctly from the start. 😀
But I made it very easy for you now, just accept the suggested changes here from the Github UI (web}.

Update: I figured I could just commit the changes directly, so I did. 😀

@haraldk haraldk merged commit f8b919e into haraldk:master Mar 31, 2025
21 checks passed
@rolfhowarth
Copy link
Contributor Author

Great thank you! Like you, I take code formatting very seriously, but I have my own personal style I adhere to. But when checking in changes to existing code the rule is always: follow the existing style :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants