Bladeren bron

Tests/LibGfx: More preparation for lossy and alpha handling

If someone comes along who wants to implement lossy webp decoding,
they now only need to implement decode_webp_chunk_VP8() and everything
might Just Work.

It also makes it possible to implement alpha chunk decoding before
implementing lossy decoding (by making decode_webp_chunk_VP8()
return an empty black bitmap for testing).
Nico Weber 2 jaren geleden
bovenliggende
commit
e9f5c9ab9d
1 gewijzigde bestanden met toevoegingen van 14 en 2 verwijderingen
  1. 14 2
      Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp

+ 14 - 2
Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp

@@ -299,6 +299,14 @@ static ErrorOr<VP8Header> decode_webp_chunk_VP8_header(WebPLoadingContext& conte
     return VP8Header { version, show_frame, size_of_first_partition, width, horizontal_scale, height, vertical_scale };
 }
 
+static ErrorOr<NonnullRefPtr<Bitmap>> decode_webp_chunk_VP8(WebPLoadingContext& context, Chunk const& vp8_chunk)
+{
+    VERIFY(vp8_chunk.type == FourCC("VP8 "));
+
+    // FIXME: Implement webp lossy decoding.
+    return context.error("WebPImageDecoderPlugin: decoding lossy webps not yet implemented");
+}
+
 // https://developers.google.com/speed/webp/docs/riff_container#simple_file_format_lossless
 // https://developers.google.com/speed/webp/docs/webp_lossless_bitstream_specification#7_overall_structure_of_the_format
 static ErrorOr<VP8LHeader> decode_webp_chunk_VP8L_header(WebPLoadingContext& context, Chunk const& vp8l_chunk)
@@ -1584,9 +1592,13 @@ static ErrorOr<NonnullRefPtr<Bitmap>> decode_webp_image_data(WebPLoadingContext&
     }
 
     VERIFY(image_data.image_data_chunk->type == FourCC("VP8 "));
+    auto bitmap = TRY(decode_webp_chunk_VP8(context, image_data.image_data_chunk.value()));
 
-    // FIXME: Implement.
-    return context.error("WebPImageDecoderPlugin: decoding lossy webps not yet implemented");
+    if (image_data.alpha_chunk.has_value()) {
+        // FIXME: Decode alpha chunk and store decoded alpha in `bitmap`.
+    }
+
+    return bitmap;
 }
 
 // https://developers.google.com/speed/webp/docs/riff_container#assembling_the_canvas_from_frames