Michael Schmid schrieb:
> Hi all!
>
> Is it possible to compile an jpeg-image into the binary? Or do I really
> have to have all the images hanging arround in the filesystem?
>
> What I want: I use XPMs at the time, because they are compiled into the
> binary and I don't have to move all the images if I make an SW-Update to
> my embedded system. But the problem is that with XPMs my binary is
> getting to big...
>
> So I would like to have two things:
> - Compile all my images into the binary which contains my whole program
> - But the images should have the size of an jpeg and not the size of an
> XPM...
>
> FLTK-Version: 1.1.9
>
> Is there any trick or do I understand something wrong?
>
> Thanks for help!
Hi!
After I solved this problem, I have the next one now...
I have my own class now, which gets its image data not from a file but
from memory directly. Works fine.
But: I added a looot of pictures into my code today. And a lot of them
have to be decompressed the same time to be shown on a scroll area...
Now my (embedded) system gets stuck for about 4-5 sec while it is
uncompressing the images.... :-(
Does anyone know a trick to make the decompression of PNGs faster? Or do
you know if jpg is faster in decompressing (didn't find an answer)? I
allready set my PNGs to lowest compression rate (because it doesn't get
much bigger then), but that didn't speed up the process measurable...
Any suggestions?
Here is my code of the class I tinkered by myself (warning: I'm really
not familiar with c++, but it works... :-) ) -> Maybe you find a part
where it could be done faster???
****************************************************************
// ***** This class is "inspired" by Fl_PNG_Image! It does not load the
PNG from a File *****
// ***** but from memory. M.Schmid 11.02.2010 *****
// Include necessary header files...
#include <FL/Fl.H>
#include <FL/Fl_Image.H>
#include "Fl_PNG_Image_Memory.h"
#include <stdio.h>
#include <stdlib.h>
#include <zlib.h>
#include <png.h>
// This fuction is used in constructor by fuction 'png_set_read_fn()':
static void png_read_data_from_mem( png_structp png_ptr, //pointer on
struct which contains pointer on our datas
png_bytep data, //where you have
to copy the sources datas for libpng computing
png_size_t length) //length of
datas to copy
{
Png_infos *pnginfo = (Png_infos *) png_get_io_ptr(png_ptr); //get the
pointer on our struct
unsigned char *src = &pnginfo->datas_png[pnginfo->offset_png];
/* copy data from image buffer */
memcpy (data, src, length);
/* advance in the file */
pnginfo->offset_png += length;
}
// Define the constructor:
Fl_PNG_Image_Memory::Fl_PNG_Image_Memory(unsigned char *buffer_png,
const char *name_png): Fl_RGB_Image(0,0,0)
{
int i; // Looping var
int channels; // Number of color channels
png_structp pp; // PNG read pointer
png_infop info; // PNG info pointers
png_bytep *rows; // PNG row pointers
//prepare the struct
png_infos.offset_png=0;
png_infos.datas_png = buffer_png;
// Setup the PNG data structures...
// allocate and initialize a png_struct structure for reading PNG file:
pp = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
// allocate and initialize a png_info structure:
info = png_create_info_struct(pp);
/* if (setjmp(pp->jmpbuf))
{
Fl::warning("PNG file \"%s\" contains errors!\n", name_png);
return;
}*/
// Initialize the function pointer to the PNG read "engine"...
png_set_read_fn(pp, (png_voidp) &png_infos, png_read_data_from_mem);
// This replaces the normal way how to open JPG-File!!! -> Se
Fl_PNG_Image for differences!
// Get the image dimensions and convert to grayscale or RGB...
png_read_info(pp, info);
if (info->color_type == PNG_COLOR_TYPE_PALETTE)
png_set_expand(pp);
if (info->color_type & PNG_COLOR_MASK_COLOR) // color
channels = 3;
else // gray
channels = 1;
if ((info->color_type & PNG_COLOR_MASK_ALPHA) || info->num_trans)
channels ++;
w((int)(info->width));
h((int)(info->height));
d(channels);
if (info->bit_depth < 8)
{
png_set_packing(pp);
png_set_expand(pp);
}
else if (info->bit_depth == 16)
png_set_strip_16(pp);
# if defined(HAVE_PNG_GET_VALID) && defined(HAVE_PNG_SET_TRNS_TO_ALPHA)
// Handle transparency...
if (png_get_valid(pp, info, PNG_INFO_tRNS))
png_set_tRNS_to_alpha(pp);
# endif // HAVE_PNG_GET_VALID && HAVE_PNG_SET_TRNS_TO_ALPHA
array = new uchar[w() * h() * d()];
alloc_array = 1;
// Allocate pointers...
rows = new png_bytep[h()];
for (i = 0; i < h(); i ++)
rows[i] = (png_bytep)(array + i * w() * d());
// Read the image, handling interlacing as needed...
for (i = png_set_interlace_handling(pp); i > 0; i --)
png_read_rows(pp, rows, NULL, h());
// Free memory and return...
delete[] rows;
png_read_end(pp, info);
png_destroy_read_struct(&pp, &info, NULL);
}
****************************************************************
Thanks guys!
Michael
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk