TestImageDecoder.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Copyright (c) 2021, the SerenityOS developers.
  3. * Copyright (c) 2021, Brian Gianforcaro <bgianf@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include <AK/MappedFile.h>
  8. #include <AK/String.h>
  9. #include <LibGfx/BMPLoader.h>
  10. #include <LibGfx/GIFLoader.h>
  11. #include <LibGfx/ICOLoader.h>
  12. #include <LibGfx/ImageDecoder.h>
  13. #include <LibGfx/JPGLoader.h>
  14. #include <LibGfx/PBMLoader.h>
  15. #include <LibGfx/PGMLoader.h>
  16. #include <LibGfx/PNGLoader.h>
  17. #include <LibGfx/PPMLoader.h>
  18. #include <LibTest/TestCase.h>
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22. TEST_CASE(test_bmp)
  23. {
  24. auto file = MappedFile::map("/res/html/misc/bmpsuite_files/rgba32-1.bmp").release_value();
  25. auto bmp = Gfx::BMPImageDecoderPlugin((u8 const*)file->data(), file->size());
  26. EXPECT(bmp.frame_count());
  27. EXPECT(bmp.sniff());
  28. EXPECT(!bmp.is_animated());
  29. EXPECT(!bmp.loop_count());
  30. auto frame = bmp.frame(0).release_value_but_fixme_should_propagate_errors();
  31. EXPECT(frame.duration == 0);
  32. }
  33. TEST_CASE(test_gif)
  34. {
  35. auto file = MappedFile::map("/res/graphics/download-animation.gif").release_value();
  36. auto gif = Gfx::GIFImageDecoderPlugin((u8 const*)file->data(), file->size());
  37. EXPECT(gif.frame_count());
  38. EXPECT(gif.sniff());
  39. EXPECT(gif.is_animated());
  40. EXPECT(!gif.loop_count());
  41. auto frame = gif.frame(1).release_value_but_fixme_should_propagate_errors();
  42. EXPECT(frame.duration == 400);
  43. }
  44. TEST_CASE(test_ico)
  45. {
  46. // FIXME: Use an ico file
  47. auto file = MappedFile::map("/res/graphics/buggie.png").release_value();
  48. auto ico = Gfx::ICOImageDecoderPlugin((u8 const*)file->data(), file->size());
  49. EXPECT(ico.frame_count());
  50. EXPECT(!ico.sniff());
  51. EXPECT(!ico.is_animated());
  52. EXPECT(!ico.loop_count());
  53. EXPECT(ico.frame(0).is_error());
  54. }
  55. TEST_CASE(test_jpg)
  56. {
  57. auto file = MappedFile::map("/res/html/misc/bmpsuite_files/rgb24.jpg").release_value();
  58. auto jpg = Gfx::JPGImageDecoderPlugin((u8 const*)file->data(), file->size());
  59. EXPECT(jpg.frame_count());
  60. EXPECT(jpg.sniff());
  61. EXPECT(!jpg.is_animated());
  62. EXPECT(!jpg.loop_count());
  63. auto frame = jpg.frame(0).release_value_but_fixme_should_propagate_errors();
  64. EXPECT(frame.duration == 0);
  65. }
  66. TEST_CASE(test_pbm)
  67. {
  68. auto file = MappedFile::map("/res/html/misc/pbmsuite_files/buggie-raw.pbm").release_value();
  69. auto pbm = Gfx::PBMImageDecoderPlugin((u8 const*)file->data(), file->size());
  70. EXPECT(pbm.frame_count());
  71. EXPECT(pbm.sniff());
  72. EXPECT(!pbm.is_animated());
  73. EXPECT(!pbm.loop_count());
  74. auto frame = pbm.frame(0).release_value_but_fixme_should_propagate_errors();
  75. EXPECT(frame.duration == 0);
  76. }
  77. TEST_CASE(test_pgm)
  78. {
  79. auto file = MappedFile::map("/res/html/misc/pgmsuite_files/buggie-raw.pgm").release_value();
  80. auto pgm = Gfx::PGMImageDecoderPlugin((u8 const*)file->data(), file->size());
  81. EXPECT(pgm.frame_count());
  82. EXPECT(pgm.sniff());
  83. EXPECT(!pgm.is_animated());
  84. EXPECT(!pgm.loop_count());
  85. auto frame = pgm.frame(0).release_value_but_fixme_should_propagate_errors();
  86. EXPECT(frame.duration == 0);
  87. }
  88. TEST_CASE(test_png)
  89. {
  90. auto file = MappedFile::map("/res/graphics/buggie.png").release_value();
  91. auto png = Gfx::PNGImageDecoderPlugin((u8 const*)file->data(), file->size());
  92. EXPECT(png.frame_count());
  93. EXPECT(png.sniff());
  94. EXPECT(!png.is_animated());
  95. EXPECT(!png.loop_count());
  96. auto frame = png.frame(0).release_value_but_fixme_should_propagate_errors();
  97. EXPECT(frame.duration == 0);
  98. }
  99. TEST_CASE(test_ppm)
  100. {
  101. auto file = MappedFile::map("/res/html/misc/ppmsuite_files/buggie-raw.ppm").release_value();
  102. auto ppm = Gfx::PPMImageDecoderPlugin((u8 const*)file->data(), file->size());
  103. EXPECT(ppm.frame_count());
  104. EXPECT(ppm.sniff());
  105. EXPECT(!ppm.is_animated());
  106. EXPECT(!ppm.loop_count());
  107. auto frame = ppm.frame(0).release_value_but_fixme_should_propagate_errors();
  108. EXPECT(frame.duration == 0);
  109. }