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:
Sergii Liebodkin 2023-11-17 13:29:02 +02:00 committed by Hermet Park
parent 7aa8f07946
commit 36d8cd12e6
13 changed files with 13 additions and 13 deletions

View file

@ -124,7 +124,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
//Prepare Transformed Image //Prepare Transformed Image
string path(EXAMPLE_DIR"/rawimage_200x300.raw"); string path(EXAMPLE_DIR"/rawimage_200x300.raw");
ifstream file(path); ifstream file(path, ios::binary);
if (!file.is_open()) return ; if (!file.is_open()) return ;
auto data = (uint32_t*)malloc(sizeof(uint32_t) * (200*300)); auto data = (uint32_t*)malloc(sizeof(uint32_t) * (200*300));
file.read(reinterpret_cast<char *>(data), sizeof (uint32_t) * 200 * 300); file.read(reinterpret_cast<char *>(data), sizeof (uint32_t) * 200 * 300);

View file

@ -116,7 +116,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
//Duplicate Picture - raw //Duplicate Picture - raw
{ {
string path(EXAMPLE_DIR"/rawimage_200x300.raw"); string path(EXAMPLE_DIR"/rawimage_200x300.raw");
ifstream file(path); ifstream file(path, ios::binary);
if (!file.is_open()) return ; if (!file.is_open()) return ;
uint32_t* data = (uint32_t*)malloc(sizeof(uint32_t) * 200 * 300); uint32_t* data = (uint32_t*)malloc(sizeof(uint32_t) * 200 * 300);
file.read(reinterpret_cast<char*>(data), sizeof(uint32_t) * 200 * 300); file.read(reinterpret_cast<char*>(data), sizeof(uint32_t) * 200 * 300);

View file

@ -90,7 +90,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
if (canvas->push(std::move(star)) != tvg::Result::Success) return; if (canvas->push(std::move(star)) != tvg::Result::Success) return;
//Image //Image
ifstream file(EXAMPLE_DIR"/rawimage_200x300.raw"); ifstream file(EXAMPLE_DIR"/rawimage_200x300.raw", ios::binary);
if (!file.is_open()) return; if (!file.is_open()) return;
auto data = (uint32_t*) malloc(sizeof(uint32_t) * (200 * 300)); auto data = (uint32_t*) malloc(sizeof(uint32_t) * (200 * 300));
file.read(reinterpret_cast<char *>(data), sizeof (uint32_t) * 200 * 300); file.read(reinterpret_cast<char *>(data), sizeof (uint32_t) * 200 * 300);

View file

@ -90,7 +90,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
if (canvas->push(std::move(star)) != tvg::Result::Success) return; if (canvas->push(std::move(star)) != tvg::Result::Success) return;
//Image //Image
ifstream file(EXAMPLE_DIR"/rawimage_200x300.raw"); ifstream file(EXAMPLE_DIR"/rawimage_200x300.raw", ios::binary);
if (!file.is_open()) return; if (!file.is_open()) return;
auto data = (uint32_t*) malloc(sizeof(uint32_t) * (200 * 300)); auto data = (uint32_t*) malloc(sizeof(uint32_t) * (200 * 300));
file.read(reinterpret_cast<char *>(data), sizeof (uint32_t) * 200 * 300); file.read(reinterpret_cast<char *>(data), sizeof (uint32_t) * 200 * 300);

View file

@ -90,7 +90,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
if (canvas->push(std::move(star)) != tvg::Result::Success) return; if (canvas->push(std::move(star)) != tvg::Result::Success) return;
//Image //Image
ifstream file(EXAMPLE_DIR"/rawimage_200x300.raw"); ifstream file(EXAMPLE_DIR"/rawimage_200x300.raw", ios::binary);
if (!file.is_open()) return; if (!file.is_open()) return;
auto data = (uint32_t*) malloc(sizeof(uint32_t) * (200 * 300)); auto data = (uint32_t*) malloc(sizeof(uint32_t) * (200 * 300));
file.read(reinterpret_cast<char *>(data), sizeof (uint32_t) * 200 * 300); file.read(reinterpret_cast<char *>(data), sizeof (uint32_t) * 200 * 300);

View file

@ -92,7 +92,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
if (canvas->push(std::move(star)) != tvg::Result::Success) return; if (canvas->push(std::move(star)) != tvg::Result::Success) return;
//Image //Image
ifstream file(EXAMPLE_DIR"/rawimage_200x300.raw"); ifstream file(EXAMPLE_DIR"/rawimage_200x300.raw", ios::binary);
if (!file.is_open()) return; if (!file.is_open()) return;
auto data = (uint32_t*) malloc(sizeof(uint32_t) * (200 * 300)); auto data = (uint32_t*) malloc(sizeof(uint32_t) * (200 * 300));
file.read(reinterpret_cast<char*>(data), sizeof (uint32_t) * 200 * 300); file.read(reinterpret_cast<char*>(data), sizeof (uint32_t) * 200 * 300);

View file

@ -32,7 +32,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
if (!canvas) return; if (!canvas) return;
//Image source //Image source
ifstream file(EXAMPLE_DIR"/rawimage_200x300.raw"); ifstream file(EXAMPLE_DIR"/rawimage_200x300.raw", ios::binary);
if (!file.is_open()) return; if (!file.is_open()) return;
auto data = (uint32_t*) malloc(sizeof(uint32_t) * (200 * 300)); auto data = (uint32_t*) malloc(sizeof(uint32_t) * (200 * 300));
file.read(reinterpret_cast<char*>(data), sizeof (uint32_t) * 200 * 300); file.read(reinterpret_cast<char*>(data), sizeof (uint32_t) * 200 * 300);

View file

@ -48,7 +48,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
} }
//Open file manually //Open file manually
ifstream file(EXAMPLE_DIR"/test.jpg"); ifstream file(EXAMPLE_DIR"/test.jpg", ios::binary);
if (!file.is_open()) return; if (!file.is_open()) return;
auto begin = file.tellg(); auto begin = file.tellg();
file.seekg(0, std::ios::end); file.seekg(0, std::ios::end);

View file

@ -54,7 +54,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
} }
//Open file manually //Open file manually
ifstream file(EXAMPLE_DIR"/test.png"); ifstream file(EXAMPLE_DIR"/test.png", ios::binary);
if (!file.is_open()) return; if (!file.is_open()) return;
auto begin = file.tellg(); auto begin = file.tellg();
file.seekg(0, std::ios::end); file.seekg(0, std::ios::end);

View file

@ -40,7 +40,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
string path(EXAMPLE_DIR"/rawimage_200x300.raw"); string path(EXAMPLE_DIR"/rawimage_200x300.raw");
ifstream file(path); ifstream file(path, ios::binary);
if (!file.is_open()) return ; if (!file.is_open()) return ;
auto data = (uint32_t*)malloc(sizeof(uint32_t) * (200*300)); auto data = (uint32_t*)malloc(sizeof(uint32_t) * (200*300));
file.read(reinterpret_cast<char *>(data), sizeof (uint32_t) * 200 * 300); file.read(reinterpret_cast<char *>(data), sizeof (uint32_t) * 200 * 300);

View file

@ -54,7 +54,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
} }
//Open file manually //Open file manually
ifstream file(EXAMPLE_DIR"/test.webp"); ifstream file(EXAMPLE_DIR"/test.webp", ios::binary);
if (!file.is_open()) return; if (!file.is_open()) return;
auto begin = file.tellg(); auto begin = file.tellg();
file.seekg(0, std::ios::end); file.seekg(0, std::ios::end);

View file

@ -41,7 +41,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
//Raw Image //Raw Image
string path(EXAMPLE_DIR"/rawimage_200x300.raw"); string path(EXAMPLE_DIR"/rawimage_200x300.raw");
ifstream file(path); ifstream file(path, ios::binary);
if (!file.is_open()) return ; if (!file.is_open()) return ;
auto data = (uint32_t*)malloc(sizeof(uint32_t) * (200*300)); auto data = (uint32_t*)malloc(sizeof(uint32_t) * (200*300));
file.read(reinterpret_cast<char *>(data), sizeof (uint32_t) * 200 * 300); file.read(reinterpret_cast<char *>(data), sizeof (uint32_t) * 200 * 300);

View file

@ -193,7 +193,7 @@ void exportTvg()
//prepare image source //prepare image source
const int width = 200; const int width = 200;
const int height = 300; 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; if (!file.is_open()) return;
uint32_t *data = (uint32_t*) malloc(sizeof(uint32_t) * width * height); uint32_t *data = (uint32_t*) malloc(sizeof(uint32_t) * width * height);
if (!data) return; if (!data) return;