|
34 | 34 | #include "private/phgP.h" |
35 | 35 | #include "private/cbP.h" |
36 | 36 | #include "private/wsglP.h" |
| 37 | +#include "private/wsxP.h" |
37 | 38 | #include "phconf.h" |
38 | 39 |
|
39 | 40 | /******************************************************************************* |
@@ -174,177 +175,175 @@ void popen_ws( |
174 | 175 | */ |
175 | 176 |
|
176 | 177 | void pclose_ws( |
177 | | - Pint ws_id |
178 | | - ) |
| 178 | + Pint ws_id |
| 179 | + ) |
179 | 180 | { |
180 | | - Ws_handle wsh; |
181 | | - Wsb_output_ws *owsb; |
182 | | - Ws_post_str *str; |
183 | | - Wst_phigs_dt *dt; |
184 | | - Psl_ws_info *wsinfo; |
185 | | - int width, height; |
186 | | - unsigned int buffer_size; |
187 | | - int error; |
188 | | - int channels; |
189 | | - int nvals; |
190 | | - int i; |
191 | | - GLubyte * pixel_buffer; |
192 | | - png_byte ** png_rows; |
193 | | - png_structp png; |
194 | | - int clean_pbuf = FALSE; |
195 | | - if (phg_ws_open(ws_id, Pfn_close_ws) != NULL) { |
196 | | - wsh = PHG_WSID(ws_id); |
197 | | - int width = wsh->type->desc_tbl.xwin_dt.tool.width; |
198 | | - int height = wsh->type->desc_tbl.xwin_dt.tool.height; |
199 | | - wsinfo = phg_psl_get_ws_info(PHG_PSL, ws_id); |
200 | | - dt = &wsinfo->wstype->desc_tbl.phigs_dt; |
201 | | - glFlush(); |
202 | | - glFinish(); |
203 | | - glPixelStorei(GL_PACK_ALIGNMENT, 1); |
204 | | - switch (dt->ws_category){ |
205 | | - case PCAT_IN: |
206 | | - case PCAT_OUT: |
207 | | - case PCAT_OUTIN: |
208 | | - case PCAT_MO: |
209 | | - case PCAT_MI: |
210 | | - break; |
211 | | - case PCAT_TGA: |
212 | | - buffer_size = 3*width*height*sizeof(GLubyte); |
213 | | - pixel_buffer = (GLubyte * ) malloc(buffer_size); |
214 | | - glXMakeContextCurrent(wsh->display, wsh->drawable_id, wsh->drawable_id, wsh->glx_context); |
215 | | - glReadPixels(0, 0, width, height, GL_BGR_EXT, GL_UNSIGNED_BYTE, pixel_buffer); |
216 | | - error = glGetError(); |
217 | | - if (error != GL_NO_ERROR ){ |
218 | | - printf("PCLOSEWS ERROR: glReadPixel returned error code %d\n", error); |
219 | | - } |
220 | | - short header[] = {0, 2, 0, 0, 0, 0, (short) width, (short) height, 24}; |
221 | | - FILE* fd = fopen(wsh->filename, "w+"); |
222 | | - fwrite(&header, sizeof(header), 1, fd); |
223 | | - fwrite(pixel_buffer, buffer_size, 1, fd); |
224 | | - fclose(fd); |
225 | | - free(pixel_buffer); |
226 | | - clean_pbuf = TRUE; |
227 | | - break; |
228 | | - case PCAT_PNG: |
229 | | - png_rows = (png_byte**)malloc(height * sizeof(png_byte*)); |
230 | | - channels = 3; |
231 | | - buffer_size = channels*width*height*sizeof(GLubyte); |
232 | | - pixel_buffer = (GLubyte*) malloc(buffer_size); |
233 | | - nvals = channels * width * height; |
234 | | - if (glXMakeContextCurrent(wsh->display, wsh->drawable_id, wsh->drawable_id, wsh->glx_context)){ |
235 | | - glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, pixel_buffer); |
236 | | - error = glGetError(); |
237 | | - if (error != GL_NO_ERROR ){ |
238 | | - printf("PCLOSEWS ERROR: glReadPixel returned error code %d\n", error); |
239 | | - } |
240 | | - for (i=0; i<height; i++){ |
241 | | - png_rows[i] = &(pixel_buffer[ (height - i - 1) * width * channels]); |
242 | | - } |
243 | | - png = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); |
244 | | - if (png) { |
245 | | - png_infop info = png_create_info_struct(png); |
246 | | - if (info){ |
247 | | - FILE* fd = fopen(wsh->filename, "w+"); |
248 | | - setjmp(png_jmpbuf(png)); |
249 | | - png_init_io(png, fd); |
250 | | - png_set_IHDR( |
251 | | - png, |
252 | | - info, |
253 | | - width, height, |
254 | | - 8, |
255 | | - PNG_COLOR_TYPE_RGB, |
256 | | - PNG_INTERLACE_NONE, |
257 | | - PNG_COMPRESSION_TYPE_DEFAULT, |
258 | | - PNG_FILTER_TYPE_DEFAULT |
259 | | - ); |
260 | | - png_write_info(png, info); |
261 | | - png_write_image(png, png_rows); |
262 | | - png_write_end(png, NULL); |
263 | | - fclose(fd); |
264 | | - } else { |
265 | | - printf("PNG export error: failed to create info structure\n"); |
266 | | - } |
267 | | - png_destroy_write_struct(&png, &info); |
| 181 | + Ws_handle wsh; |
| 182 | + Wsb_output_ws *owsb; |
| 183 | + Ws_post_str *str; |
| 184 | + Wst_phigs_dt *dt; |
| 185 | + Psl_ws_info *wsinfo; |
| 186 | + int width, height; |
| 187 | + unsigned int buffer_size; |
| 188 | + int error; |
| 189 | + int channels; |
| 190 | + int nvals; |
| 191 | + int i; |
| 192 | + GLubyte * pixel_buffer; |
| 193 | + png_byte ** png_rows; |
| 194 | + png_structp png; |
| 195 | + int clean_pbuf = FALSE; |
| 196 | + if (phg_ws_open(ws_id, Pfn_close_ws) != NULL) { |
| 197 | + wsh = PHG_WSID(ws_id); |
| 198 | + int width = wsh->type->desc_tbl.xwin_dt.tool.width; |
| 199 | + int height = wsh->type->desc_tbl.xwin_dt.tool.height; |
| 200 | + wsinfo = phg_psl_get_ws_info(PHG_PSL, ws_id); |
| 201 | + dt = &wsinfo->wstype->desc_tbl.phigs_dt; |
| 202 | + glFlush(); |
| 203 | + glFinish(); |
| 204 | + glPixelStorei(GL_PACK_ALIGNMENT, 1); |
| 205 | + switch (dt->ws_category){ |
| 206 | + case PCAT_IN: |
| 207 | + case PCAT_OUT: |
| 208 | + case PCAT_OUTIN: |
| 209 | + case PCAT_MO: |
| 210 | + case PCAT_MI: |
| 211 | + break; |
| 212 | + case PCAT_TGA: |
| 213 | + buffer_size = 3*width*height*sizeof(GLubyte); |
| 214 | + pixel_buffer = (GLubyte * ) malloc(buffer_size); |
| 215 | + glXMakeContextCurrent(wsh->display, wsh->drawable_id, wsh->drawable_id, wsh->glx_context); |
| 216 | + glReadPixels(0, 0, width, height, GL_BGR_EXT, GL_UNSIGNED_BYTE, pixel_buffer); |
| 217 | + error = glGetError(); |
| 218 | + if (error != GL_NO_ERROR ){ |
| 219 | + printf("PCLOSEWS ERROR: glReadPixel returned error code %d\n", error); |
| 220 | + } |
| 221 | + short header[] = {0, 2, 0, 0, 0, 0, (short) width, (short) height, 24}; |
| 222 | + FILE* fd = fopen(wsh->filename, "w+"); |
| 223 | + fwrite(&header, sizeof(header), 1, fd); |
| 224 | + fwrite(pixel_buffer, buffer_size, 1, fd); |
| 225 | + fclose(fd); |
| 226 | + free(pixel_buffer); |
| 227 | + clean_pbuf = TRUE; |
| 228 | + break; |
| 229 | + case PCAT_PNG: |
| 230 | + png_rows = (png_byte**)malloc(height * sizeof(png_byte*)); |
| 231 | + channels = 3; |
| 232 | + buffer_size = channels*width*height*sizeof(GLubyte); |
| 233 | + pixel_buffer = (GLubyte*) malloc(buffer_size); |
| 234 | + nvals = channels * width * height; |
| 235 | + if (glXMakeContextCurrent(wsh->display, wsh->drawable_id, wsh->drawable_id, wsh->glx_context)){ |
| 236 | + glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, pixel_buffer); |
| 237 | + error = glGetError(); |
| 238 | + if (error != GL_NO_ERROR ){ |
| 239 | + printf("PCLOSEWS ERROR: glReadPixel returned error code %d\n", error); |
| 240 | + } |
| 241 | + for (i=0; i<height; i++){ |
| 242 | + png_rows[i] = &(pixel_buffer[ (height - i - 1) * width * channels]); |
| 243 | + } |
| 244 | + png = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); |
| 245 | + if (png) { |
| 246 | + png_infop info = png_create_info_struct(png); |
| 247 | + if (info){ |
| 248 | + FILE* fd = fopen(wsh->filename, "w+"); |
| 249 | + setjmp(png_jmpbuf(png)); |
| 250 | + png_init_io(png, fd); |
| 251 | + png_set_IHDR( |
| 252 | + png, |
| 253 | + info, |
| 254 | + width, height, |
| 255 | + 8, |
| 256 | + PNG_COLOR_TYPE_RGB, |
| 257 | + PNG_INTERLACE_NONE, |
| 258 | + PNG_COMPRESSION_TYPE_DEFAULT, |
| 259 | + PNG_FILTER_TYPE_DEFAULT |
| 260 | + ); |
| 261 | + png_write_info(png, info); |
| 262 | + png_write_image(png, png_rows); |
| 263 | + png_write_end(png, NULL); |
| 264 | + fclose(fd); |
268 | 265 | } else { |
269 | | - printf("PNG export error: failed to create write structure\n"); |
| 266 | + printf("PNG export error: failed to create info structure\n"); |
270 | 267 | } |
| 268 | + png_destroy_write_struct(&png, &info); |
271 | 269 | } else { |
272 | | - printf("Cannot make the context current.\n"); |
273 | | - } |
274 | | - free(pixel_buffer); |
275 | | - free(png_rows); |
276 | | - clean_pbuf = TRUE; |
277 | | - break; |
278 | | - case PCAT_PNGA: |
279 | | - channels = 4; |
280 | | - png_rows = (png_byte**)malloc(height * sizeof(png_byte*)); |
281 | | - buffer_size = channels*width*height*sizeof(GLubyte); |
282 | | - pixel_buffer = (GLubyte*) malloc(buffer_size); |
283 | | - nvals = channels * width * height; |
284 | | - glXMakeContextCurrent(wsh->display, wsh->drawable_id, wsh->drawable_id, wsh->glx_context); |
285 | | - glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixel_buffer); |
286 | | - error = glGetError(); |
287 | | - if (error != GL_NO_ERROR ){ |
288 | | - printf("PCLOSEWS ERROR: glReadPixel returned error code %d\n", error); |
289 | | - } |
290 | | - for (i=0; i<height; i++){ |
291 | | - png_rows[i] = &(pixel_buffer[ (height - i - 1) * width * channels]); |
292 | | - } |
293 | | - png = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); |
294 | | - if (png) { |
295 | | - png_infop info = png_create_info_struct(png); |
296 | | - if (info){ |
297 | | - FILE* fd = fopen(wsh->filename, "w+"); |
298 | | - setjmp(png_jmpbuf(png)); |
299 | | - png_init_io(png, fd); |
300 | | - png_set_IHDR( |
301 | | - png, |
302 | | - info, |
303 | | - width, height, |
304 | | - 8, |
305 | | - PNG_COLOR_TYPE_RGBA, |
306 | | - PNG_INTERLACE_NONE, |
307 | | - PNG_COMPRESSION_TYPE_DEFAULT, |
308 | | - PNG_FILTER_TYPE_DEFAULT |
309 | | - ); |
310 | | - png_write_info(png, info); |
311 | | - png_write_image(png, png_rows); |
312 | | - png_write_end(png, NULL); |
313 | | - fclose(fd); |
314 | | - } else { |
315 | | - printf("PNG export error: failed to create info structure\n"); |
316 | | - } |
317 | | - png_destroy_write_struct(&png, &info); |
318 | | - } else { |
319 | | - printf("PNG export error: failed to create write structure\n"); |
320 | | - } |
321 | | - free(pixel_buffer); |
322 | | - free(png_rows); |
323 | | - clean_pbuf = TRUE; |
324 | | - break; |
325 | | - default: |
326 | | - break; |
327 | | - } |
328 | | - (*wsh->update)(wsh, PFLAG_PERFORM); |
329 | | - owsb = &wsh->out_ws.model.b; |
330 | | - str = owsb->posted.lowest.higher; |
331 | | - while (str->higher != NULL) { |
332 | | - phg_css_unpost(owsb->cssh, str->structh->struct_id, wsh); |
333 | | - str = str->higher; |
334 | | - } |
335 | | - /* cleanup */ |
336 | | - //glXMakeContextCurrent(wsh->display, None, None, NULL); |
337 | | - glXDestroyContext(wsh->display, wsh->glx_context); |
338 | | - if (clean_pbuf){ |
339 | | - glXDestroyPbuffer(wsh->display, wsh->drawable_id); |
340 | | - XFree(wsh->fbc); |
341 | | - } |
342 | | - (*wsh->close)(wsh); |
343 | | - phg_psl_rem_ws(PHG_PSL, ws_id); |
344 | | - |
345 | | - } else { |
346 | | - printf("PCLOSEWS ERROR: workstation was not open. Ignoring function."); |
347 | | - } |
| 270 | + printf("PNG export error: failed to create write structure\n"); |
| 271 | + } |
| 272 | + } else { |
| 273 | + printf("Cannot make the context current.\n"); |
| 274 | + } |
| 275 | + free(pixel_buffer); |
| 276 | + free(png_rows); |
| 277 | + clean_pbuf = TRUE; |
| 278 | + break; |
| 279 | + case PCAT_PNGA: |
| 280 | + channels = 4; |
| 281 | + png_rows = (png_byte**)malloc(height * sizeof(png_byte*)); |
| 282 | + buffer_size = channels*width*height*sizeof(GLubyte); |
| 283 | + pixel_buffer = (GLubyte*) malloc(buffer_size); |
| 284 | + nvals = channels * width * height; |
| 285 | + glXMakeContextCurrent(wsh->display, wsh->drawable_id, wsh->drawable_id, wsh->glx_context); |
| 286 | + glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixel_buffer); |
| 287 | + error = glGetError(); |
| 288 | + if (error != GL_NO_ERROR ){ |
| 289 | + printf("PCLOSEWS ERROR: glReadPixel returned error code %d\n", error); |
| 290 | + } |
| 291 | + for (i=0; i<height; i++){ |
| 292 | + png_rows[i] = &(pixel_buffer[ (height - i - 1) * width * channels]); |
| 293 | + } |
| 294 | + png = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); |
| 295 | + if (png) { |
| 296 | + png_infop info = png_create_info_struct(png); |
| 297 | + if (info){ |
| 298 | + FILE* fd = fopen(wsh->filename, "w+"); |
| 299 | + setjmp(png_jmpbuf(png)); |
| 300 | + png_init_io(png, fd); |
| 301 | + png_set_IHDR( |
| 302 | + png, |
| 303 | + info, |
| 304 | + width, height, |
| 305 | + 8, |
| 306 | + PNG_COLOR_TYPE_RGBA, |
| 307 | + PNG_INTERLACE_NONE, |
| 308 | + PNG_COMPRESSION_TYPE_DEFAULT, |
| 309 | + PNG_FILTER_TYPE_DEFAULT |
| 310 | + ); |
| 311 | + png_write_info(png, info); |
| 312 | + png_write_image(png, png_rows); |
| 313 | + png_write_end(png, NULL); |
| 314 | + fclose(fd); |
| 315 | + } else { |
| 316 | + printf("PNG export error: failed to create info structure\n"); |
| 317 | + } |
| 318 | + png_destroy_write_struct(&png, &info); |
| 319 | + } else { |
| 320 | + printf("PNG export error: failed to create write structure\n"); |
| 321 | + } |
| 322 | + free(pixel_buffer); |
| 323 | + free(png_rows); |
| 324 | + clean_pbuf = TRUE; |
| 325 | + break; |
| 326 | + default: |
| 327 | + break; |
| 328 | + } |
| 329 | + (*wsh->update)(wsh, PFLAG_PERFORM); |
| 330 | + owsb = &wsh->out_ws.model.b; |
| 331 | + str = owsb->posted.lowest.higher; |
| 332 | + while (str->higher != NULL) { |
| 333 | + phg_css_unpost(owsb->cssh, str->structh->struct_id, wsh); |
| 334 | + str = str->higher; |
| 335 | + } |
| 336 | + /* cleanup */ |
| 337 | + glXDestroyContext(wsh->display, wsh->glx_context); |
| 338 | + if (clean_pbuf){ |
| 339 | + phg_wsx_cleanup_fb(wsh); |
| 340 | + } |
| 341 | + (*wsh->close)(wsh); |
| 342 | + phg_psl_rem_ws(PHG_PSL, ws_id); |
| 343 | + |
| 344 | + } else { |
| 345 | + printf("PCLOSEWS ERROR: workstation was not open. Ignoring function."); |
| 346 | + } |
348 | 347 | } |
349 | 348 |
|
350 | 349 | /******************************************************************************* |
|
0 commit comments