#include "ast_jpeg_decoder.hpp"
#include <gmock/gmock.h>
#include <gtest/gtest.h>

#ifdef BUILD_CIMG
#define cimg_display 0
#include <CImg.h>
#endif

using namespace testing;
MATCHER_P2(IsBetween, a, b,
           std::string(negation ? "isn't" : "is") + " between " +
               PrintToString(a) + " and " + PrintToString(b)) {
  return a <= arg && arg <= b;
};

TEST(AstJpegDecoder, AllBlue) {
  ast_video::RawVideoBuffer out;

  // This binary blog was created on the aspeed hardware using a blue screen
  // consisting of the color 0x8EFFFA in a web browser window
  FILE *fp = fopen("test_resources/aspeedbluescreen.bin", "rb");
  EXPECT_NE(fp, nullptr);
  size_t bufferlen =
      fread(out.buffer.data(), sizeof(decltype(out.buffer)::value_type),
            out.buffer.size(), fp);
  fclose(fp);

  ASSERT_GT(bufferlen, 0);

  out.ySelector = 0;
  out.uvSelector = 0;
  out.mode = ast_video::YuvMode::YUV444;
  out.width = 800;
  out.height = 600;

  ast_video::AstJpegDecoder d;
  d.decode(out.buffer, out.width, out.height, out.mode, out.ySelector,
           out.uvSelector);

  int tolerance = 16;

  // All pixels should be blue (0x8EFFFA) to within a tolerance (due to jpeg
  // compression artifacts and quanitization)
  for (int i = 0; i < out.width * out.height; i++) {
    ast_video::RGB &pixel = d.outBuffer[i];
    EXPECT_GT(pixel.r, 0x8E - tolerance);
    EXPECT_LT(pixel.r, 0x8E + tolerance);
    EXPECT_GT(pixel.g, 0xFF - tolerance);
    EXPECT_LT(pixel.g, 0xFF + tolerance);
    EXPECT_GT(pixel.b, 0xF1 - tolerance);
    EXPECT_LT(pixel.b, 0xF1 + tolerance);
  }
}

TEST(AstJpegDecoder, AllBlack) {
  ast_video::RawVideoBuffer out;

  // This binary blog was created on the aspeed hardware using a black screen
  FILE *fp = fopen("test_resources/aspeedblackscreen.bin", "rb");
  EXPECT_NE(fp, nullptr);
  size_t bufferlen = fread(out.buffer.data(), sizeof(char),
                           out.buffer.size() * sizeof(long), fp);
  fclose(fp);

  ASSERT_GT(bufferlen, 0);

  out.ySelector = 0;
  out.uvSelector = 0;
  out.mode = ast_video::YuvMode::YUV444;
  out.width = 800;
  out.height = 600;

  ast_video::AstJpegDecoder d;
  d.decode(out.buffer, out.width, out.height, out.mode, out.ySelector,
           out.uvSelector);

  // All pixels should be blue (0x8EFFFA) to within a tolerance (due to jpeg
  // compression artifacts and quanitization)
  for (int x = 0; x < out.width; x++) {
    for (int y = 0; y < out.height; y++) {
      ast_video::RGB pixel = d.outBuffer[x + (y * out.width)];
      ASSERT_EQ(pixel.r, 0x00) << "X:" << x << " Y: " << y;
      ASSERT_EQ(pixel.g, 0x00) << "X:" << x << " Y: " << y;
      ASSERT_EQ(pixel.b, 0x00) << "X:" << x << " Y: " << y;
    }
  }
}

TEST(AstJpegDecoder, TestColors) {
  ast_video::RawVideoBuffer out;

  // This binary blog was created on the aspeed hardware using a blue screen
  // consisting of the color 0x8EFFFA in a web browser window
  FILE *fp = fopen("test_resources/ubuntu_444_800x600_0chrom_0lum.bin", "rb");
  EXPECT_NE(fp, nullptr);
  size_t bufferlen = fread(out.buffer.data(), sizeof(char),
                           out.buffer.size() * sizeof(long), fp);
  fclose(fp);

  ASSERT_GT(bufferlen, 0);

  out.ySelector = 0;
  out.uvSelector = 0;
  out.mode = ast_video::YuvMode::YUV444;
  out.width = 800;
  out.height = 600;

  ast_video::AstJpegDecoder d;
  d.decode(out.buffer, out.width, out.height, out.mode, out.ySelector,
           out.uvSelector);

  int tolerance = 16;
  /*
  for (int i = 0; i < out.width * out.height; i++) {
    ast_video::RGB &pixel = d.outBuffer[i];
    EXPECT_GT(pixel.r, 0x8E - tolerance);
    EXPECT_LT(pixel.r, 0x8E + tolerance);
    EXPECT_GT(pixel.g, 0xFF - tolerance);
    EXPECT_LT(pixel.g, 0xFF + tolerance);
    EXPECT_GT(pixel.b, 0xF1 - tolerance);
    EXPECT_LT(pixel.b, 0xF1 + tolerance);
  }
  */
}

// Tests the buffers around the screen aren't written to
TEST(AstJpegDecoder, BufferLimits) {
  ast_video::RawVideoBuffer out;

  // This binary blog was created on the aspeed hardware using a black screen
  FILE *fp = fopen("test_resources/aspeedblackscreen.bin", "rb");
  EXPECT_NE(fp, nullptr);
  size_t bufferlen = fread(out.buffer.data(), sizeof(char),
                           out.buffer.size() * sizeof(long), fp);
  fclose(fp);

  ASSERT_GT(bufferlen, 0);

  out.ySelector = 0;
  out.uvSelector = 0;
  out.mode = ast_video::YuvMode::YUV444;
  out.width = 800;
  out.height = 600;

  ast_video::AstJpegDecoder d;
  d.decode(out.buffer, out.width, out.height, out.mode, out.ySelector,
           out.uvSelector);
  // reserved pixel should be default value
  for (auto &pixel : d.outBuffer) {
    EXPECT_EQ(pixel.reserved, 0xAA);
  }
  // All pixels beyond the buffer should be zero
  for (int i = out.width * out.height; i < d.outBuffer.size(); i++) {
    EXPECT_EQ(d.outBuffer[i].r, 0x00) << "index:" << i;
    EXPECT_EQ(d.outBuffer[i].b, 0x00) << "index:" << i;
    EXPECT_EQ(d.outBuffer[i].g, 0x00) << "index:" << i;
  }
}