FLTK logo

Re: [fltk.general] Re: FLUID: how can I have SVG icons embedded in the code?

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.general  ]
 
Previous Message ]New Message | Reply ]Next Message ]

Re: Re: FLUID: how can I have SVG icons embedded in the code? "'Matthias Melcher' via fltk.general" 03:06 Apr 19  
 

Ian MacArthur schrieb am Freitag, 19. April 2024 um 10:22:11 UTC+2:
So, as a possible workaround, I tried storing the SVG file in "compressed" form in fluid, as Matt had suggested. That certainly makes it small enough (down from approx. 20K text to approx. 7K) but I can't then seem to get Fl_SVG_Image to load it, so... One for Matt maybe? As I am out of ideas now:

There are two approaches to store images that are quite different. 

--- Using the Image: field in the Widget Properties

If you use the "Image:" field in the Widget Properties panel, you can tick "compressed" (which is named wrong, I will change that today as well), which will inline the image in ints original format. If you choose an .svg file, you get the verbatim XML data, and if you choose an .svgz, FLUID will store the binary data. The compression is done by the svg writer, and it's decompressed by FLTK's svg reader. FLUID does not change the data.

If "compressed" is not ticked, FLUID will convert the image (including SVG) to RGB first and store the pixels. The advantage is, that you don't need to link your app with the svg library or any other image library. The disadvantage is having a block of uncompressed pixels in your app.

--- Using the Inline Data node:

If you use the Inline Data node, you can choose binary, text, or compressed. Inline Data does not know what kind of data you store, so you have to choose the right type, and FLUID does not know how you will use the data later. You are using it for and svg, but FLUID does not know that. If your svg is uncompressed XML, you should choose text. If it is a compressed svgz, you should choose binary. If you select "compress", the FLUID will compress the data for you using zlib, but that is completely unrelated to the type of data. You have to uncompress it before you can use it:

For example you have an Inline Data node that you want to store in the program code compressed, named AppLicense. FLUID will generate three const values for you:
unsigned char AppLicense[], an array holding the compressed data, the implicit sizeof(AppLicense), holding the size of the compressed array, and int AppLicense_size, the size of the original uncompressed array. To use the data that FLUID stores compressed, you can sod something like:

    int uncompressed_size = AppLicense_size;

    unsigned char *AppLicenseUncompressed = (unsigned char *)::malloc(uncompressed_size);

    if (uncompress(AppLicenseUncompressed, &uncompressed_size, AppLicense, sizeof(AppLicense)) != Z_OK) { 

      /* error */ 

    }


FLUID Inline Data compression is not related in any way to image compression.
 

--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/a08f7b13-002a-48d1-82ec-121b78656028n%40googlegroups.com.
Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.