MCPcopy Create free account
hub / github.com/VirtualGL/virtualgl / reload

Method reload

server/fltk/src/Fl_Shared_Image.cxx:277–321  ·  view source on GitHub ↗

Reloads the shared image from disk. */

Source from the content-addressed store, hash-verified

275
276/** Reloads the shared image from disk. */
277void Fl_Shared_Image::reload() {
278 // Load image from disk...
279 int i; // Looping var
280 int count = 0; // number of bytes read from image header
281 FILE *fp; // File pointer
282 uchar header[64]; // Buffer for auto-detecting files
283 Fl_Image *img; // New image
284
285 if (!name_) return;
286
287 if ((fp = fl_fopen(name_, "rb")) != NULL) {
288 count = (int)fread(header, 1, sizeof(header), fp);
289 fclose(fp);
290 if (count == 0)
291 return;
292 } else {
293 return;
294 }
295
296 // Load the image as appropriate...
297 if (count >= 7 && memcmp(header, "#define", 7) == 0) // XBM file
298 img = new Fl_XBM_Image(name_);
299 else if (count >= 9 && memcmp(header, "/* XPM */", 9) == 0) // XPM file
300 img = new Fl_XPM_Image(name_);
301 else {
302 // Not a standard format; try an image handler...
303 for (i = 0, img = 0; i < num_handlers_; i ++) {
304 img = (handlers_[i])(name_, header, count);
305 if (img) break;
306 }
307 }
308
309 if (img) {
310 if (alloc_image_) delete image_;
311
312 alloc_image_ = 1;
313 image_ = img;
314 int W = w();
315 int H = h();
316 update();
317 // Make sure the reloaded image gets the same drawing size as the existing one.
318 if (W)
319 scale(W, H, 0, 1);
320 }
321}
322
323/**
324 Create a resized copy of the image and wrap it into the share image class.

Callers

nothing calls this directly

Calls 5

fl_fopenFunction · 0.85
updateFunction · 0.85
wFunction · 0.50
hFunction · 0.50
scaleFunction · 0.50

Tested by

no test coverage detected