@@ -301,56 +301,70 @@ ImageBuffer *load_xpm_image(char **data) {
301301 return result;
302302}
303303
304- void cmd_image_show (var_s *self, var_s *) {
305- ImageDisplay image;
306- image._bid = map_get_int (self, IMG_BID, -1 );
304+ void get_image_display (var_s *self, ImageDisplay *image) {
305+ image->_bid = map_get_int (self, IMG_BID, -1 );
307306
308307 List_each (ImageBuffer *, it, cache) {
309308 ImageBuffer *next = (*it);
310- if (next->_bid == image. _bid ) {
311- image. _buffer = next;
309+ if (next->_bid == image-> _bid ) {
310+ image-> _buffer = next;
312311 break ;
313312 }
314313 }
315314
316315 var_int_t x, y, z, op;
317316 int count = par_massget (" iiii" , &x, &y, &z, &op);
318317
319- if (prog_error || image. _buffer == nullptr || count == 1 || count > 4 ) {
318+ if (prog_error || image-> _buffer == nullptr || count == 1 || count > 4 ) {
320319 err_throw (ERR_PARAM);
321320 } else {
322321 // 0, 2, 3, 4 arguments accepted
323322 if (count >= 2 ) {
324- image. _x = x;
325- image. _y = y;
323+ image-> _x = x;
324+ image-> _y = y;
326325 map_set_int (self, IMG_X, x);
327326 map_set_int (self, IMG_Y, y);
328327 } else {
329- image. _x = map_get_int (self, IMG_X, -1 );
330- image. _y = map_get_int (self, IMG_Y, -1 );
328+ image-> _x = map_get_int (self, IMG_X, -1 );
329+ image-> _y = map_get_int (self, IMG_Y, -1 );
331330 }
332331 if (count >= 3 ) {
333- image. _zIndex = z;
332+ image-> _zIndex = z;
334333 map_set_int (self, IMG_ZINDEX, z);
335334 } else {
336- image. _zIndex = map_get_int (self, IMG_ZINDEX, -1 );
335+ image-> _zIndex = map_get_int (self, IMG_ZINDEX, -1 );
337336 }
338337 if (count == 4 ) {
339- image. _opacity = op;
338+ image-> _opacity = op;
340339 map_set_int (self, IMG_OPACITY, op);
341340 } else {
342- image. _opacity = map_get_int (self, IMG_OPACITY, -1 );
341+ image-> _opacity = map_get_int (self, IMG_OPACITY, -1 );
343342 }
344343
345- image._offsetLeft = map_get_int (self, IMG_OFFSET_LEFT, -1 );
346- image._offsetTop = map_get_int (self, IMG_OFFSET_TOP, -1 );
347- image._width = map_get_int (self, IMG_WIDTH, -1 );
348- image._height = map_get_int (self, IMG_HEIGHT, -1 );
349- image._id = map_get_int (self, IMG_ID, -1 );
344+ image->_offsetLeft = map_get_int (self, IMG_OFFSET_LEFT, -1 );
345+ image->_offsetTop = map_get_int (self, IMG_OFFSET_TOP, -1 );
346+ image->_width = map_get_int (self, IMG_WIDTH, -1 );
347+ image->_height = map_get_int (self, IMG_HEIGHT, -1 );
348+ image->_id = map_get_int (self, IMG_ID, -1 );
349+ }
350+ }
351+
352+ void cmd_image_show (var_s *self, var_s *) {
353+ ImageDisplay image;
354+ get_image_display (self, &image);
355+ if (!prog_error) {
350356 g_system->getOutput ()->addImage (image);
351357 }
352358}
353359
360+ void cmd_image_draw (var_s *self, var_s *) {
361+ ImageDisplay image;
362+ get_image_display (self, &image);
363+ if (!prog_error) {
364+ g_system->getOutput ()->drawImage (image);
365+ }
366+ }
367+
354368void cmd_image_hide (var_s *self, var_s *) {
355369 int id = map_get_int (self, IMG_ID, -1 );
356370 g_system->getOutput ()->removeImage (id);
@@ -397,9 +411,18 @@ void cmd_image_save(var_s *self, var_s *) {
397411 int yoffs = (4 * y * w);
398412 for (int x = 0 ; x < w; x++) {
399413 int offs = yoffs + (4 * x);
400- uint8_t r = image->_image [offs + 0 ];
401- uint8_t g = image->_image [offs + 1 ];
402- uint8_t b = image->_image [offs + 2 ];
414+ #if defined(PIXELFORMAT_RGBA8888)
415+ int r_offs = offs + 2 ;
416+ int g_offs = offs + 1 ;
417+ int b_offs = offs + 0 ;
418+ #else
419+ int r_offs = offs + 0 ;
420+ int g_offs = offs + 1 ;
421+ int b_offs = offs + 2 ;
422+ #endif
423+ uint8_t r = image->_image [r_offs];
424+ uint8_t g = image->_image [g_offs];
425+ uint8_t b = image->_image [b_offs];
403426 pixel_t px = SET_RGB (r, g, b);
404427 int pos = y * w + x;
405428 var_t *elem = v_elem (array, pos);
@@ -427,9 +450,10 @@ void create_image(var_p_t var, ImageBuffer *image) {
427450 map_add_var (var, IMG_WIDTH, image->_width );
428451 map_add_var (var, IMG_HEIGHT, image->_height );
429452 map_add_var (var, IMG_BID, image->_bid );
430- v_create_func (var, " show " , cmd_image_show );
453+ v_create_func (var, " draw " , cmd_image_draw );
431454 v_create_func (var, " hide" , cmd_image_hide);
432455 v_create_func (var, " save" , cmd_image_save);
456+ v_create_func (var, " show" , cmd_image_show);
433457}
434458
435459// loads an image for the form image input type
0 commit comments