MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / generateMarkdown

Method generateMarkdown

src/main/java/field/graphics/Texture.java:112–170  ·  view source on GitHub ↗
(Box inside, Dict.Prop property)

Source from the content-addressed store, hash-verified

110
111 private void reloadFrom(String filename) {
112 int[] wh = FastJPEG.j.dimensions(filename);
113 if (wh[0] == specification.width && wh[1] == specification.height)
114 FastJPEG.j.decompress(filename, specification.pixels, wh[0], wh[1]);
115 upload(specification.pixels, false);
116 }
117
118 @Override
119 public String generateMarkdown(Box inside, Dict.Prop property) {
120 Future<ByteBuffer> m = asyncDebugDownloadRGB8(null);
121
122 // repaint main window, just in case we're there
123 RunLoop.main.once(() -> {
124 Drawing.dirty(inside);
125 });
126
127 String pre
128 = "Framebuffer object has dimensions <b>" + specification.width + "</b>x<b>" + specification.height + "</b> and is bound to texture unit <b>" + specification.unit +
129 "</b><br>";
130 if (specification.forceSingleBuffered) pre += "Single-buffered updates are on; ";
131 if (specification.compressed) pre += "Target is compressed; ";
132 if (specification.highQuality)
133 pre += "Mip-maps are automatically regenerated on update; ";
134 if (specification.type == GL_FLOAT)
135 pre += "This is a floating-point resolution texture; ";
136 pre = p(pre);
137 pre
138 += p("This has been bound <b>" + warnIfZero(
139 boundCount) + "</b> time" + (boundCount == 1 ? "" : "s") + " and modified <b>" + uploadCount + "</b> time" + (uploadCount == 1 ?
140 "" : "s") + "<br>");
141
142 int tries = 0;
143 while (!m.isDone()) {
144 try {
145 Thread.sleep(100 * tries);
146 } catch (InterruptedException e) {
147 e.printStackTrace();
148 }
149 if (++tries > 5)
150 return pre + p("<b>Image data for FBO is not available (FBO must be actively repainting)<b>");
151 }
152
153 try {
154
155 File tmp = File.createTempFile("field", ".jpg");
156 new FastJPEG().compress(tmp.getAbsolutePath(), m.get(), specification.width, specification.height);
157 byte[] bytes = Files.readAllBytes(tmp.toPath());
158 java.util.Base64.Encoder e = java.util.Base64.getEncoder();
159 String v = e.encodeToString(bytes);
160
161 String uri = "data:image/jpg;base64," + v;
162 String d = "<p><b>Snapshot of contents &mdash;<br></p><img style='max-width:300px' src='" + uri + "'/></b>";
163
164 return pre + p(d);
165
166 } catch (InterruptedException e) {
167 e.printStackTrace();
168 } catch (ExecutionException e) {
169 e.printStackTrace();

Callers

nothing calls this directly

Calls 7

dirtyMethod · 0.95
pMethod · 0.95
warnIfZeroMethod · 0.95
onceMethod · 0.80
getMethod · 0.65
compressMethod · 0.45

Tested by

no test coverage detected