瀏覽代碼

LibPDF: Implement the DCT filter

This filter basically tells us that we are dealing with a JPEG.
Note that by serializing the resulting image we assume that this filter
is the last one in the chain, everything else would be highly unlikely.
Julian Offenhäuser 2 年之前
父節點
當前提交
f926dfe36b
共有 1 個文件被更改,包括 5 次插入3 次删除
  1. 5 3
      Userland/Libraries/LibPDF/Filter.cpp

+ 5 - 3
Userland/Libraries/LibPDF/Filter.cpp

@@ -6,6 +6,7 @@
 
 #include <AK/Hex.h>
 #include <LibCompress/Deflate.h>
+#include <LibGfx/JPGLoader.h>
 #include <LibPDF/CommonNames.h>
 #include <LibPDF/Filter.h>
 
@@ -153,10 +154,11 @@ ErrorOr<ByteBuffer> Filter::decode_jbig2(ReadonlyBytes)
     TODO();
 };
 
-ErrorOr<ByteBuffer> Filter::decode_dct(ReadonlyBytes)
+ErrorOr<ByteBuffer> Filter::decode_dct(ReadonlyBytes bytes)
 {
-    // FIXME: Support dct decoding
-    TODO();
+    Gfx::JPGImageDecoderPlugin decoder(bytes.data(), bytes.size());
+    auto frame = TRY(decoder.frame(0));
+    return frame.image->serialize_to_byte_buffer();
 };
 
 ErrorOr<ByteBuffer> Filter::decode_jpx(ReadonlyBytes)