mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 13:43:43 +00:00
examples: fixed manual loading of binary data (jpg, png, raw ect)
To load binary data operations must be performed in binary mode rather than text. The issue appears on windows platform, especially for PNG loading
This commit is contained in:
parent
7aa8f07946
commit
36d8cd12e6
13 changed files with 13 additions and 13 deletions
|
@ -124,7 +124,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
//Prepare Transformed Image
|
||||
string path(EXAMPLE_DIR"/rawimage_200x300.raw");
|
||||
|
||||
ifstream file(path);
|
||||
ifstream file(path, ios::binary);
|
||||
if (!file.is_open()) return ;
|
||||
auto data = (uint32_t*)malloc(sizeof(uint32_t) * (200*300));
|
||||
file.read(reinterpret_cast<char *>(data), sizeof (uint32_t) * 200 * 300);
|
||||
|
|
|
@ -116,7 +116,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
//Duplicate Picture - raw
|
||||
{
|
||||
string path(EXAMPLE_DIR"/rawimage_200x300.raw");
|
||||
ifstream file(path);
|
||||
ifstream file(path, ios::binary);
|
||||
if (!file.is_open()) return ;
|
||||
uint32_t* data = (uint32_t*)malloc(sizeof(uint32_t) * 200 * 300);
|
||||
file.read(reinterpret_cast<char*>(data), sizeof(uint32_t) * 200 * 300);
|
||||
|
|
|
@ -90,7 +90,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
if (canvas->push(std::move(star)) != tvg::Result::Success) return;
|
||||
|
||||
//Image
|
||||
ifstream file(EXAMPLE_DIR"/rawimage_200x300.raw");
|
||||
ifstream file(EXAMPLE_DIR"/rawimage_200x300.raw", ios::binary);
|
||||
if (!file.is_open()) return;
|
||||
auto data = (uint32_t*) malloc(sizeof(uint32_t) * (200 * 300));
|
||||
file.read(reinterpret_cast<char *>(data), sizeof (uint32_t) * 200 * 300);
|
||||
|
|
|
@ -90,7 +90,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
if (canvas->push(std::move(star)) != tvg::Result::Success) return;
|
||||
|
||||
//Image
|
||||
ifstream file(EXAMPLE_DIR"/rawimage_200x300.raw");
|
||||
ifstream file(EXAMPLE_DIR"/rawimage_200x300.raw", ios::binary);
|
||||
if (!file.is_open()) return;
|
||||
auto data = (uint32_t*) malloc(sizeof(uint32_t) * (200 * 300));
|
||||
file.read(reinterpret_cast<char *>(data), sizeof (uint32_t) * 200 * 300);
|
||||
|
|
|
@ -90,7 +90,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
if (canvas->push(std::move(star)) != tvg::Result::Success) return;
|
||||
|
||||
//Image
|
||||
ifstream file(EXAMPLE_DIR"/rawimage_200x300.raw");
|
||||
ifstream file(EXAMPLE_DIR"/rawimage_200x300.raw", ios::binary);
|
||||
if (!file.is_open()) return;
|
||||
auto data = (uint32_t*) malloc(sizeof(uint32_t) * (200 * 300));
|
||||
file.read(reinterpret_cast<char *>(data), sizeof (uint32_t) * 200 * 300);
|
||||
|
|
|
@ -92,7 +92,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
if (canvas->push(std::move(star)) != tvg::Result::Success) return;
|
||||
|
||||
//Image
|
||||
ifstream file(EXAMPLE_DIR"/rawimage_200x300.raw");
|
||||
ifstream file(EXAMPLE_DIR"/rawimage_200x300.raw", ios::binary);
|
||||
if (!file.is_open()) return;
|
||||
auto data = (uint32_t*) malloc(sizeof(uint32_t) * (200 * 300));
|
||||
file.read(reinterpret_cast<char*>(data), sizeof (uint32_t) * 200 * 300);
|
||||
|
|
|
@ -32,7 +32,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
if (!canvas) return;
|
||||
|
||||
//Image source
|
||||
ifstream file(EXAMPLE_DIR"/rawimage_200x300.raw");
|
||||
ifstream file(EXAMPLE_DIR"/rawimage_200x300.raw", ios::binary);
|
||||
if (!file.is_open()) return;
|
||||
auto data = (uint32_t*) malloc(sizeof(uint32_t) * (200 * 300));
|
||||
file.read(reinterpret_cast<char*>(data), sizeof (uint32_t) * 200 * 300);
|
||||
|
|
|
@ -48,7 +48,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
}
|
||||
|
||||
//Open file manually
|
||||
ifstream file(EXAMPLE_DIR"/test.jpg");
|
||||
ifstream file(EXAMPLE_DIR"/test.jpg", ios::binary);
|
||||
if (!file.is_open()) return;
|
||||
auto begin = file.tellg();
|
||||
file.seekg(0, std::ios::end);
|
||||
|
|
|
@ -54,7 +54,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
}
|
||||
|
||||
//Open file manually
|
||||
ifstream file(EXAMPLE_DIR"/test.png");
|
||||
ifstream file(EXAMPLE_DIR"/test.png", ios::binary);
|
||||
if (!file.is_open()) return;
|
||||
auto begin = file.tellg();
|
||||
file.seekg(0, std::ios::end);
|
||||
|
|
|
@ -40,7 +40,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
|
||||
string path(EXAMPLE_DIR"/rawimage_200x300.raw");
|
||||
|
||||
ifstream file(path);
|
||||
ifstream file(path, ios::binary);
|
||||
if (!file.is_open()) return ;
|
||||
auto data = (uint32_t*)malloc(sizeof(uint32_t) * (200*300));
|
||||
file.read(reinterpret_cast<char *>(data), sizeof (uint32_t) * 200 * 300);
|
||||
|
|
|
@ -54,7 +54,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
}
|
||||
|
||||
//Open file manually
|
||||
ifstream file(EXAMPLE_DIR"/test.webp");
|
||||
ifstream file(EXAMPLE_DIR"/test.webp", ios::binary);
|
||||
if (!file.is_open()) return;
|
||||
auto begin = file.tellg();
|
||||
file.seekg(0, std::ios::end);
|
||||
|
|
|
@ -41,7 +41,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
//Raw Image
|
||||
string path(EXAMPLE_DIR"/rawimage_200x300.raw");
|
||||
|
||||
ifstream file(path);
|
||||
ifstream file(path, ios::binary);
|
||||
if (!file.is_open()) return ;
|
||||
auto data = (uint32_t*)malloc(sizeof(uint32_t) * (200*300));
|
||||
file.read(reinterpret_cast<char *>(data), sizeof (uint32_t) * 200 * 300);
|
||||
|
|
|
@ -193,7 +193,7 @@ void exportTvg()
|
|||
//prepare image source
|
||||
const int width = 200;
|
||||
const int height = 300;
|
||||
ifstream file(EXAMPLE_DIR"/rawimage_200x300.raw");
|
||||
ifstream file(EXAMPLE_DIR"/rawimage_200x300.raw", ios::binary);
|
||||
if (!file.is_open()) return;
|
||||
uint32_t *data = (uint32_t*) malloc(sizeof(uint32_t) * width * height);
|
||||
if (!data) return;
|
||||
|
|
Loading…
Add table
Reference in a new issue