winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

Sixel.cpp (1628B)


      1 // Copyright (c) Microsoft Corporation.
      2 // Licensed under the MIT License.
      3 #include "pch.h"
      4 #include "TestCommon.h"
      5 #include <Sixel.h>
      6 
      7 using namespace AppInstaller::CLI::VirtualTerminal::Sixel;
      8 
      9 void ValidateGetPixel(std::string_view info, UINT_PTR offset, UINT byteCount, UINT_PTR expected)
     10 {
     11     INFO(info);
     12     REQUIRE(offset < byteCount);
     13     REQUIRE(offset == expected);
     14 }
     15 
     16 TEST_CASE("ImageView_GetPixel", "[sixel]")
     17 {
     18     UINT width = 20;
     19     UINT height = 20;
     20     UINT stride = 32;
     21     UINT byteCount = height * stride;
     22     BYTE* byteBase = reinterpret_cast<BYTE*>(100);
     23 
     24     ImageView view{ width, height, stride, byteCount, byteBase };
     25 
     26     ValidateGetPixel("No translation", view.GetPixel(3, 17) - byteBase, byteCount, 17 * stride + 3);
     27 
     28     view.Translate(14, 8, true);
     29     ValidateGetPixel("Positive translation (tile)", view.GetPixel(3, 17) - byteBase, byteCount, 9 * stride + 9);
     30 
     31     view.Translate(-14, 8, true);
     32     ValidateGetPixel("Negative translation (tile)", view.GetPixel(3, 17) - byteBase, byteCount, 9 * stride + 17);
     33 
     34     view.Translate(14, -8, false);
     35     REQUIRE(view.GetPixel(3, 17) == nullptr);
     36     ValidateGetPixel("Negative translation (no tile)", view.GetPixel(15, 1) - byteBase, byteCount, 9 * stride + 1);
     37 }
     38 
     39 TEST_CASE("Image_Render", "[sixel]")
     40 {
     41     Image image{ TestCommon::TestDataFile("notepad.ico") };
     42     REQUIRE(!image.Render().Get().empty());
     43 
     44     image.AspectRatio(AspectRatio::ThreeToOne);
     45     image.ColorCount(64);
     46     image.RenderSizeInCells(2, 1);
     47     image.UseRepeatSequence(true);
     48     REQUIRE(!image.Render().Get().empty());
     49 }