From 9afa1742bef09068b3ff11ae987e0f4c50ed194d 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 d5499c1d..2f82b7e1 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 73c267f7..e86c0570 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 53216769..2a5974f9 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 76e1eaec..55dd1c5b 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 8c5af19f..a3fbd01c 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 531cfdcd..2f929773 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 8e762663..9fad049c 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 aaac53d4..e7c85ec7 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 597d9b6e..f431a387 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 51c660d3..9058e773 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 27555d89..18ab7c81 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 6bae2b31..9f077da8 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 240a2cf6..ed93daef 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;