TestRgbImage.cpp 963 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // STL includes
  2. #include <iostream>
  3. // Utils includes
  4. #include <utils/Image.h>
  5. #include <utils/ColorRgba.h>
  6. #include <utils/ColorRgb.h>
  7. #include <utils/ColorBgr.h>
  8. #include <hyperion/ImageProcessor.h>
  9. int main()
  10. {
  11. std::cout << "Constructing image" << std::endl;
  12. int width = 64;
  13. int height = 64;
  14. Image<ColorRgb> image_rgb(width, height, ColorRgb::BLACK);
  15. Image<ColorBgr> image_bgr(image_rgb.width(), image_rgb.height(), ColorBgr::BLACK);
  16. std::cout << "Writing image" << std::endl;
  17. unsigned l = width * height;
  18. // BGR
  19. for (unsigned i=0; i<l; ++i)
  20. image_bgr.memptr()[i] = ColorBgr{0,128,255};
  21. // to RGB
  22. image_bgr.toRgb(image_rgb);
  23. // test
  24. for (unsigned i=0; i<l; ++i)
  25. {
  26. const ColorRgb rgb = image_rgb.memptr()[i];
  27. if ( rgb.red != 255 || rgb.green != 128 || rgb.blue != 0 )
  28. std::cout << "RGB error idx " << i << " " << rgb << std::endl;
  29. }
  30. std::cout << "Finished (destruction will be performed)" << std::endl;
  31. return 0;
  32. }