diff --git a/src/examples/PictureJpg.cpp b/src/examples/PictureJpg.cpp index 84d53e24..11d4ae94 100644 --- a/src/examples/PictureJpg.cpp +++ b/src/examples/PictureJpg.cpp @@ -20,8 +20,8 @@ * SOFTWARE. */ -#include "Common.h" #include +#include "Common.h" /************************************************************************/ /* Drawing Commands */ @@ -34,7 +34,7 @@ void tvgDrawCmds(tvg::Canvas* canvas) //Load jpg file from path for (int i = 0; i < 5; ++i) { auto picture = tvg::Picture::gen(); - if (picture->load(EXAMPLE_DIR"/logo.jpg") != tvg::Result::Success) { + if (picture->load(EXAMPLE_DIR"/test.jpg") != tvg::Result::Success) { cout << "JPG is not supported. Did you enable JPG Loader?" << endl; return; } @@ -45,11 +45,14 @@ void tvgDrawCmds(tvg::Canvas* canvas) } //Open file manually - ifstream file(EXAMPLE_DIR"/logo.jpg"); + ifstream file(EXAMPLE_DIR"/test.jpg"); if (!file.is_open()) return; - auto size = sizeof(uint32_t) * (1000*1000); + auto begin = file.tellg(); + file.seekg(0, std::ios::end); + auto size = file.tellg() - begin; auto data = (char*)malloc(size); if (!data) return; + file.seekg(0, std::ios::beg); file.read(data, size); file.close(); @@ -61,7 +64,7 @@ void tvgDrawCmds(tvg::Canvas* canvas) free(data); picture->translate(400, 0); - picture->scale(0.4); + picture->scale(0.8); canvas->push(move(picture)); } diff --git a/src/examples/PicturePng.cpp b/src/examples/PicturePng.cpp index 4e7ba8b0..52f40fde 100644 --- a/src/examples/PicturePng.cpp +++ b/src/examples/PicturePng.cpp @@ -20,6 +20,7 @@ * SOFTWARE. */ +#include #include "Common.h" /************************************************************************/ @@ -30,10 +31,11 @@ void tvgDrawCmds(tvg::Canvas* canvas) { if (!canvas) return; + //Load png file from path for (int i = 0; i < 5; ++i) { auto picture = tvg::Picture::gen(); - if (picture->load(EXAMPLE_DIR"/logo.png") != tvg::Result::Success) { - cout << "PNG is not supported, Did you enable PNG Loader??" << endl; + if (picture->load(EXAMPLE_DIR"/test.png") != tvg::Result::Success) { + cout << "PNG is not supported. Did you enable PNG Loader?" << endl; return; } picture->translate(i* 150, i * 150); @@ -41,6 +43,29 @@ void tvgDrawCmds(tvg::Canvas* canvas) picture->size(200, 200); if (canvas->push(move(picture)) != tvg::Result::Success) return; } + + //Open file manually + ifstream file(EXAMPLE_DIR"/test.png"); + if (!file.is_open()) return; + auto begin = file.tellg(); + file.seekg(0, std::ios::end); + auto size = file.tellg() - begin; + auto data = (char*)malloc(size); + if (!data) return; + file.seekg(0, std::ios::beg); + file.read(data, size); + file.close(); + + auto picture = tvg::Picture::gen(); + if (picture->load(data, size, true) != tvg::Result::Success) { + cout << "Couldnt load PNG file from data." << endl; + return; + } + + free(data); + picture->translate(400, 0); + picture->scale(0.8); + canvas->push(move(picture)); } diff --git a/src/examples/images/logo.jpg b/src/examples/images/logo.jpg deleted file mode 100644 index 097d608f..00000000 Binary files a/src/examples/images/logo.jpg and /dev/null differ diff --git a/src/examples/images/logo.png b/src/examples/images/logo.png deleted file mode 100644 index 1fefd0f2..00000000 Binary files a/src/examples/images/logo.png and /dev/null differ diff --git a/src/examples/images/test.jpg b/src/examples/images/test.jpg new file mode 100644 index 00000000..73a40e4c Binary files /dev/null and b/src/examples/images/test.jpg differ diff --git a/src/examples/images/test.png b/src/examples/images/test.png new file mode 100644 index 00000000..59ef68aa Binary files /dev/null and b/src/examples/images/test.png differ diff --git a/test/capi/capiPicture.cpp b/test/capi/capiPicture.cpp index 24483a45..f9c7ae87 100644 --- a/test/capi/capiPicture.cpp +++ b/test/capi/capiPicture.cpp @@ -112,7 +112,7 @@ TEST_CASE("Load Png file in Picture", "[capiPicture]") REQUIRE(tvg_picture_load(picture, "invalid.png") == TVG_RESULT_INVALID_ARGUMENT); //Load Png file - REQUIRE(tvg_picture_load(picture, TEST_DIR"/logo.png") == TVG_RESULT_SUCCESS); + REQUIRE(tvg_picture_load(picture, TEST_DIR"/test.png") == TVG_RESULT_SUCCESS); //Verify Size float w, h; diff --git a/test/images/logo.jpg b/test/images/logo.jpg deleted file mode 100644 index 097d608f..00000000 Binary files a/test/images/logo.jpg and /dev/null differ diff --git a/test/images/logo.png b/test/images/logo.png deleted file mode 100644 index 1fefd0f2..00000000 Binary files a/test/images/logo.png and /dev/null differ diff --git a/test/images/test.jpg b/test/images/test.jpg new file mode 100644 index 00000000..73a40e4c Binary files /dev/null and b/test/images/test.jpg differ diff --git a/test/images/test.png b/test/images/test.png new file mode 100644 index 00000000..59ef68aa Binary files /dev/null and b/test/images/test.png differ diff --git a/test/testPicture.cpp b/test/testPicture.cpp index 45c51203..a468463d 100644 --- a/test/testPicture.cpp +++ b/test/testPicture.cpp @@ -103,13 +103,13 @@ TEST_CASE("Load PNG file from path", "[tvgPicture]") //Invalid file REQUIRE(picture->load("invalid.png") == Result::InvalidArguments); - REQUIRE(picture->load(TEST_DIR"/logo.png") == Result::Success); + REQUIRE(picture->load(TEST_DIR"/test.png") == Result::Success); float w, h; REQUIRE(picture->size(&w, &h) == Result::Success); - REQUIRE(w == 1000); - REQUIRE(h == 1000); + REQUIRE(w == 512); + REQUIRE(h == 512); } TEST_CASE("Load PNG file from data", "[tvgPicture]") @@ -118,7 +118,7 @@ TEST_CASE("Load PNG file from data", "[tvgPicture]") REQUIRE(picture); //Open file - ifstream file(TEST_DIR"/logo.png"); + ifstream file(TEST_DIR"/test.png"); REQUIRE(file.is_open()); auto size = sizeof(uint32_t) * (1000*1000); auto data = (char*)malloc(size); @@ -130,8 +130,8 @@ TEST_CASE("Load PNG file from data", "[tvgPicture]") float w, h; REQUIRE(picture->size(&w, &h) == Result::Success); - REQUIRE(w == 1000); - REQUIRE(h == 1000); + REQUIRE(w == 512); + REQUIRE(h == 512); free(data); } @@ -144,13 +144,13 @@ TEST_CASE("Load JPG file from path", "[tvgPicture]") //Invalid file REQUIRE(picture->load("invalid.jpg") == Result::InvalidArguments); - REQUIRE(picture->load(TEST_DIR"/logo.jpg") == Result::Success); + REQUIRE(picture->load(TEST_DIR"/test.jpg") == Result::Success); float w, h; REQUIRE(picture->size(&w, &h) == Result::Success); - REQUIRE(w == 1000); - REQUIRE(h == 1000); + REQUIRE(w == 512); + REQUIRE(h == 512); } TEST_CASE("Load JPG file from data", "[tvgPicture]") @@ -159,10 +159,13 @@ TEST_CASE("Load JPG file from data", "[tvgPicture]") REQUIRE(picture); //Open file - ifstream file(TEST_DIR"/logo.jpg"); + ifstream file(TEST_DIR"/test.jpg"); REQUIRE(file.is_open()); - auto size = sizeof(uint32_t) * (1000*1000); + auto begin = file.tellg(); + file.seekg(0, std::ios::end); + auto size = file.tellg() - begin; auto data = (char*)malloc(size); + file.seekg(0, std::ios::beg); file.read(data, size); file.close(); @@ -171,8 +174,8 @@ TEST_CASE("Load JPG file from data", "[tvgPicture]") float w, h; REQUIRE(picture->size(&w, &h) == Result::Success); - REQUIRE(w == 1000); - REQUIRE(h == 1000); + REQUIRE(w == 512); + REQUIRE(h == 512); free(data); } @@ -231,7 +234,7 @@ TEST_CASE("Load PNG file and render", "[tvgPicture]") auto picture = Picture::gen(); REQUIRE(picture); - REQUIRE(picture->load(TEST_DIR"/logo.png") == Result::Success); + REQUIRE(picture->load(TEST_DIR"/test.png") == Result::Success); REQUIRE(canvas->push(move(picture)) == Result::Success); @@ -251,7 +254,7 @@ TEST_CASE("Load JPG file and render", "[tvgPicture]") auto picture = Picture::gen(); REQUIRE(picture); - REQUIRE(picture->load(TEST_DIR"/logo.jpg") == Result::Success); + REQUIRE(picture->load(TEST_DIR"/test.jpg") == Result::Success); REQUIRE(canvas->push(move(picture)) == Result::Success);