gems: strict warning fixes

Issue #3094
This commit is contained in:
Norman Feske 2018-12-23 21:29:42 +01:00
parent cd29ca3c40
commit f7d33010e5
4 changed files with 98 additions and 62 deletions

View File

@ -28,7 +28,7 @@ class Animator
friend class Item;
Genode::List<Genode::List_element<Item> > _items;
Genode::List<Genode::List_element<Item> > _items { };
public:

View File

@ -21,6 +21,12 @@ class File
{
private:
/*
* Noncopyable
*/
File(File const &);
File & operator = (File const &);
Genode::Allocator &_alloc;
Genode::size_t const _file_size;
void *_data;

View File

@ -49,90 +49,120 @@ class Png_image
Genode::Region_map &_rm;
Genode::Allocator &_alloc;
struct Read_struct
class Read_struct
{
/* start of PNG data */
png_bytep const data;
private:
/* read position, maintained by 'read_callback' */
unsigned pos = 0;
/*
* Noncopyable
*/
Read_struct(Read_struct const &);
Read_struct & operator = (Read_struct const &);
static void callback(png_structp png_ptr, png_bytep dst, png_size_t len)
{
Read_struct &read_struct = *(Read_struct *)png_get_io_ptr(png_ptr);
Genode::memcpy(dst, read_struct.data + read_struct.pos, len);
read_struct.pos += len;
}
public:
png_structp png_ptr =
_assert_non_null<Read_struct_failed>(
png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0));
/* start of PNG data */
png_bytep const data;
Read_struct(void *data) : data((png_bytep)data)
{
png_set_read_fn(png_ptr, this, callback);
}
/* read position, maintained by 'read_callback' */
unsigned pos = 0;
~Read_struct()
{
png_destroy_read_struct(&png_ptr, nullptr, nullptr);
}
static void callback(png_structp png_ptr, png_bytep dst, png_size_t len)
{
Read_struct &read_struct = *(Read_struct *)png_get_io_ptr(png_ptr);
Genode::memcpy(dst, read_struct.data + read_struct.pos, len);
read_struct.pos += len;
}
png_structp png_ptr =
_assert_non_null<Read_struct_failed>(
png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0));
Read_struct(void *data) : data((png_bytep)data)
{
png_set_read_fn(png_ptr, this, callback);
}
~Read_struct()
{
png_destroy_read_struct(&png_ptr, nullptr, nullptr);
}
};
Read_struct _read_struct;
struct Info
class Info
{
png_structp png_ptr;
png_infop info_ptr;
private:
int bit_depth, color_type, interlace_type;
png_uint_32 img_w, img_h;
/*
* Noncopyable
*/
Info(Info const &);
Info & operator = (Info const &);
Info(png_structp png_ptr)
:
png_ptr(png_ptr),
info_ptr(_assert_non_null<Info_failed>(png_create_info_struct(png_ptr)))
{
png_read_info(png_ptr, info_ptr);
public:
png_get_IHDR(png_ptr, info_ptr, &img_w, &img_h, &bit_depth, &color_type,
&interlace_type, nullptr, nullptr);
png_structp png_ptr;
png_infop info_ptr;
if (color_type == PNG_COLOR_TYPE_PALETTE)
png_set_palette_to_rgb(png_ptr);
int bit_depth = 0, color_type = 0, interlace_type = 0;
png_uint_32 img_w = 0, img_h = 0;
if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
png_set_gray_to_rgb(png_ptr);
Info(png_structp png_ptr)
:
png_ptr(png_ptr),
info_ptr(_assert_non_null<Info_failed>(png_create_info_struct(png_ptr)))
{
png_read_info(png_ptr, info_ptr);
if (bit_depth < 8) png_set_packing(png_ptr);
if (bit_depth == 16) png_set_strip_16(png_ptr);
}
png_get_IHDR(png_ptr, info_ptr, &img_w, &img_h, &bit_depth, &color_type,
&interlace_type, nullptr, nullptr);
~Info()
{
png_destroy_info_struct(png_ptr, &info_ptr);
}
if (color_type == PNG_COLOR_TYPE_PALETTE)
png_set_palette_to_rgb(png_ptr);
if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
png_set_gray_to_rgb(png_ptr);
if (bit_depth < 8) png_set_packing(png_ptr);
if (bit_depth == 16) png_set_strip_16(png_ptr);
}
~Info()
{
png_destroy_info_struct(png_ptr, &info_ptr);
}
} _info { _read_struct.png_ptr };
struct Row
class Row
{
Genode::Allocator &alloc;
size_t const row_num_bytes;
png_bytep const row_ptr;
private:
Row(Genode::Allocator &alloc, png_structp png_ptr, png_infop info_ptr)
:
alloc(alloc),
row_num_bytes(png_get_rowbytes(png_ptr, info_ptr)*8),
row_ptr((png_bytep)alloc.alloc(row_num_bytes))
{ }
/*
* Noncopyable
*/
Row(Row const &);
Row & operator = (Row const &);
~Row()
{
alloc.free(row_ptr, row_num_bytes);
}
public:
Genode::Allocator &alloc;
size_t const row_num_bytes;
png_bytep const row_ptr;
Row(Genode::Allocator &alloc, png_structp png_ptr, png_infop info_ptr)
:
alloc(alloc),
row_num_bytes(png_get_rowbytes(png_ptr, info_ptr)*8),
row_ptr((png_bytep)alloc.alloc(row_num_bytes))
{ }
~Row()
{
alloc.free(row_ptr, row_num_bytes);
}
} _row { _alloc, _read_struct.png_ptr, _info.info_ptr };
public:

View File

@ -36,7 +36,7 @@ static inline void Polygon::interpolate_rgba(Polygon::Color start,
PT *dst,
unsigned char *dst_alpha,
unsigned num_values,
int x, int y)
int, int)
{
/* sanity check */
if (num_values == 0) return;