Check-in [1ff2b8e880]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:P4 PBM is packed in binary and is not in pixel bits, so write the file correctly.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 1ff2b8e880a92ee909fda8df0e316b83e13bff2f
User & Date: stephanie.gawroriski 2019-06-16 04:40:22
Context
2019-06-16
04:45
Add isValid() method to SQFFont; Add note in changelog about fixed empty strings. check-in: f6d423a9ba user: stephanie.gawroriski tags: trunk
04:40
P4 PBM is packed in binary and is not in pixel bits, so write the file correctly. check-in: 1ff2b8e880 user: stephanie.gawroriski tags: trunk
04:29
Use a much faster means of exporting image data. check-in: a594d9fb9a user: stephanie.gawroriski tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to bldt/mids/txt-to-pbm/dev/shadowtail/txttopbm/Main.java.

73
74
75
76
77
78
79
80

81
82
83

84
85
86
87
88
89
90
..
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
...
116
117
118
119
120
121
122
123
124

125
126
127
128




129
130
131
132
133
134
135
136
			// Get a large monospace font which is easy to read hopefully
			Font font = Font.getFont(Font.FACE_MONOSPACE, 0, Font.SIZE_LARGE);
			
			// Get the size properties of the font
			int fw = (font.charWidth('a') + font.charWidth('w')) >> 1,
				fh = font.getHeight();
				
			// Calculate size of image

			int iw = maxstrlen * fw,
				ih = numlines * fh,
				sa = iw * fh;

			
			// Write PBM header, use P4 format
			ps.printf("P4\n");
			ps.printf("%d %d\n", iw, ih);
			
			// Create image to contain a buffer for a single line, it is not
			// important to have an entire image because we can just pipe
................................................................................
			Image image = Image.createImage(iw, fh);
			Graphics g = image.getGraphics();
			
			// RGB pixel output for lines
			int[] rgb = new int[sa];
			
			// Bulk byte data, for the fastest possible writing
			byte[] bulk = new byte[sa];
			
			// Used to keep track of the current column since PBM cannot exceed
			// 72 characters
			int col = 1;
			
			// Process each line!
			while (!lines.isEmpty())
................................................................................
				g.setColor(0x000000);
				g.drawString(ln, 0, 0, Graphics.TOP | Graphics.LEFT);
				
				// Get RGB pixel data
				image.getRGB(rgb, 0, iw, 0, 0, iw, fh);
				
				// Go through pixels and export to bulk format
				for (int i = 0; i < sa; i++)
				{

					// Format bulk data
					int v = (rgb[i] & 0xFFFFFF);
					bulk[i] = (byte)('0' + (v & 1));
				}




				
				// Write all bytes at once
				ps.write(bulk);
			}
		}
	}
}








|
>
|

|
>







 







|







 







|
<
>
|
|
|
<
>
>
>
>








73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
..
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
...
118
119
120
121
122
123
124
125

126
127
128
129

130
131
132
133
134
135
136
137
138
139
140
141
			// Get a large monospace font which is easy to read hopefully
			Font font = Font.getFont(Font.FACE_MONOSPACE, 0, Font.SIZE_LARGE);
			
			// Get the size properties of the font
			int fw = (font.charWidth('a') + font.charWidth('w')) >> 1,
				fh = font.getHeight();
				
			// Calculate size of image, width is rounded to 8 because of
			// the pixel packing!
			int iw = ((maxstrlen * fw) + 7) & (~7),
				ih = numlines * fh,
				sa = iw * fh,
				ua = sa / 8;
			
			// Write PBM header, use P4 format
			ps.printf("P4\n");
			ps.printf("%d %d\n", iw, ih);
			
			// Create image to contain a buffer for a single line, it is not
			// important to have an entire image because we can just pipe
................................................................................
			Image image = Image.createImage(iw, fh);
			Graphics g = image.getGraphics();
			
			// RGB pixel output for lines
			int[] rgb = new int[sa];
			
			// Bulk byte data, for the fastest possible writing
			byte[] bulk = new byte[ua];
			
			// Used to keep track of the current column since PBM cannot exceed
			// 72 characters
			int col = 1;
			
			// Process each line!
			while (!lines.isEmpty())
................................................................................
				g.setColor(0x000000);
				g.drawString(ln, 0, 0, Graphics.TOP | Graphics.LEFT);
				
				// Get RGB pixel data
				image.getRGB(rgb, 0, iw, 0, 0, iw, fh);
				
				// Go through pixels and export to bulk format
				for (int i = 0, o = 0; i < sa; i += 8, o++)

					bulk[o] = (byte)(((rgb[i + 0] & 1) << 7) |
						((rgb[i + 1] & 1) << 6) |
						((rgb[i + 2] & 1) << 5) |
						((rgb[i + 3] & 1) << 4) |

						((rgb[i + 4] & 1) << 3) |
						((rgb[i + 5] & 1) << 2) |
						((rgb[i + 6] & 1) << 1) |
						((rgb[i + 7] & 1)));
				
				// Write all bytes at once
				ps.write(bulk);
			}
		}
	}
}