Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 8 additions & 15 deletions project/src/graphics/format/PNG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,13 @@ namespace lime {

ReadBuffer (const unsigned char* data, int length) : data (data), length (length), position (0) {}

bool Read (unsigned char* out, int count) {
bool Read (unsigned char* out, png_size_t count) {

if (position >= length) return false;
if (position > length || count > (png_size_t)(length - position)) return false;
if (count == 0) return true;

if (count > length - position) {

memcpy (out, data + position, length - position);
position = length;

} else {

memcpy (out, data + position, count);
position += count;

}
memcpy (out, data + position, count);
position += (int)count;

return true;

Expand Down Expand Up @@ -88,6 +80,7 @@ namespace lime {

FILE_HANDLE* file = NULL;
Bytes* data = NULL;
ReadBuffer buffer (NULL, 0);

if (resource->path) {

Expand Down Expand Up @@ -148,14 +141,14 @@ namespace lime {

data = new Bytes ();
data->ReadFile (resource->path);
ReadBuffer buffer (data->b, data->length);
buffer = ReadBuffer (data->b, data->length);
png_set_read_fn (png_ptr, &buffer, user_read_data_fn);

}

} else {

ReadBuffer buffer (resource->data->b, resource->data->length);
buffer = ReadBuffer (resource->data->b, resource->data->length);
png_set_read_fn (png_ptr, &buffer, user_read_data_fn);

}
Expand Down