From 36d8cd12e663caff07274354b7f86758df3357fb Mon Sep 17 00:00:00 2001 From: Sergii Liebodkin Date: Fri, 17 Nov 2023 13:29:02 +0200 Subject: [PATCH] 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 --- src/examples/Blending.cpp | 2 +- src/examples/Duplicate.cpp | 2 +- src/examples/InvLumaMasking.cpp | 2 +- src/examples/InvMasking.cpp | 2 +- src/examples/LumaMasking.cpp | 2 +- src/examples/Masking.cpp | 2 +- src/examples/MaskingMethods.cpp | 2 +- src/examples/PictureJpg.cpp | 2 +- src/examples/PicturePng.cpp | 2 +- src/examples/PictureRaw.cpp | 2 +- src/examples/PictureWebp.cpp | 2 +- src/examples/Texmap.cpp | 2 +- src/examples/TvgSaver.cpp | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/examples/Blending.cpp b/src/examples/Blending.cpp index cb9e6059..84b740b3 100644 --- a/src/examples/Blending.cpp +++ b/src/examples/Blending.cpp @@ -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(data), sizeof (uint32_t) * 200 * 300); diff --git a/src/examples/Duplicate.cpp b/src/examples/Duplicate.cpp index 696e2d7e..2bce96a5 100644 --- a/src/examples/Duplicate.cpp +++ b/src/examples/Duplicate.cpp @@ -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(data), sizeof(uint32_t) * 200 * 300); diff --git a/src/examples/InvLumaMasking.cpp b/src/examples/InvLumaMasking.cpp index 6ff26f97..a9dfcacc 100644 --- a/src/examples/InvLumaMasking.cpp +++ b/src/examples/InvLumaMasking.cpp @@ -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(data), sizeof (uint32_t) * 200 * 300); diff --git a/src/examples/InvMasking.cpp b/src/examples/InvMasking.cpp index a7c1f7f9..d91968a1 100644 --- a/src/examples/InvMasking.cpp +++ b/src/examples/InvMasking.cpp @@ -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(data), sizeof (uint32_t) * 200 * 300); diff --git a/src/examples/LumaMasking.cpp b/src/examples/LumaMasking.cpp index 406ff1d1..761dc7f8 100644 --- a/src/examples/LumaMasking.cpp +++ b/src/examples/LumaMasking.cpp @@ -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(data), sizeof (uint32_t) * 200 * 300); diff --git a/src/examples/Masking.cpp b/src/examples/Masking.cpp index 40daae55..42fbe19a 100644 --- a/src/examples/Masking.cpp +++ b/src/examples/Masking.cpp @@ -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(data), sizeof (uint32_t) * 200 * 300); diff --git a/src/examples/MaskingMethods.cpp b/src/examples/MaskingMethods.cpp index c5aad15f..04b7ba58 100644 --- a/src/examples/MaskingMethods.cpp +++ b/src/examples/MaskingMethods.cpp @@ -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(data), sizeof (uint32_t) * 200 * 300); diff --git a/src/examples/PictureJpg.cpp b/src/examples/PictureJpg.cpp index 3f99afe4..1f17a348 100644 --- a/src/examples/PictureJpg.cpp +++ b/src/examples/PictureJpg.cpp @@ -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); diff --git a/src/examples/PicturePng.cpp b/src/examples/PicturePng.cpp index 66854e27..5a2424d7 100644 --- a/src/examples/PicturePng.cpp +++ b/src/examples/PicturePng.cpp @@ -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); diff --git a/src/examples/PictureRaw.cpp b/src/examples/PictureRaw.cpp index a0fe3689..aed11fd4 100644 --- a/src/examples/PictureRaw.cpp +++ b/src/examples/PictureRaw.cpp @@ -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(data), sizeof (uint32_t) * 200 * 300); diff --git a/src/examples/PictureWebp.cpp b/src/examples/PictureWebp.cpp index 513873fa..b0d6d45c 100644 --- a/src/examples/PictureWebp.cpp +++ b/src/examples/PictureWebp.cpp @@ -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); diff --git a/src/examples/Texmap.cpp b/src/examples/Texmap.cpp index 5c3cc1c4..0e783c12 100644 --- a/src/examples/Texmap.cpp +++ b/src/examples/Texmap.cpp @@ -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(data), sizeof (uint32_t) * 200 * 300); diff --git a/src/examples/TvgSaver.cpp b/src/examples/TvgSaver.cpp index e808cee1..a679d687 100644 --- a/src/examples/TvgSaver.cpp +++ b/src/examples/TvgSaver.cpp @@ -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;