From 5b3294180103d506e46959ba0190ab293c9e1892 Mon Sep 17 00:00:00 2001 From: paxcut <53811119+paxcut@users.noreply.github.com> Date: Sun, 4 Jun 2023 13:38:25 -0700 Subject: [PATCH] patterns: Added visualizers to image patterns (#117) * Added image visualizers to image patterns that were supported * missing include files * Small style fixes --------- Co-authored-by: Nik --- patterns/bmp.hexpat | 4 +++- patterns/gif.hexpat | 3 ++- patterns/jpeg.hexpat | 2 +- patterns/png.hexpat | 3 +++ patterns/tga.hexpat | 1 + 5 files changed, 10 insertions(+), 3 deletions(-) diff --git a/patterns/bmp.hexpat b/patterns/bmp.hexpat index 98972e2..f7345a9 100644 --- a/patterns/bmp.hexpat +++ b/patterns/bmp.hexpat @@ -1,5 +1,6 @@ #pragma MIME image/bmp #pragma endian little +#include struct BitmapFileHeader { u8 bfType[2]; @@ -31,6 +32,7 @@ struct Colors { }; struct Bitmap { + u8 data[std::mem::size()] [[no_unique_address, hidden]]; BitmapFileHeader bmfh; BitmapInfoHeader bmih; @@ -46,6 +48,6 @@ struct Bitmap { u8 lineData[bmih.biSizeImage]; else u8 lineData[bmfh.bfSize - $]; -}; +} [[hex::visualize("image", this.data)]]; Bitmap bitmap @ 0x00; diff --git a/patterns/gif.hexpat b/patterns/gif.hexpat index 37b6548..27fd4f0 100644 --- a/patterns/gif.hexpat +++ b/patterns/gif.hexpat @@ -173,10 +173,11 @@ namespace format { } struct Gif { + u8 data[std::mem::size()] [[no_unique_address, hidden]]; Header header; std::assert_warn(header.version == "89a" || header.version == "87a", "Unsupported format version"); LogicalScreenDescriptor logicalScreenDescriptor; Block blocks[while(!std::mem::eof())]; -}; +} [[hex::visualize("image", this.data)]]; Gif gif @ 0x00; \ No newline at end of file diff --git a/patterns/jpeg.hexpat b/patterns/jpeg.hexpat index 542c9f7..6c96982 100644 --- a/patterns/jpeg.hexpat +++ b/patterns/jpeg.hexpat @@ -119,4 +119,4 @@ struct Segment { } }; -Segment segments[while(!std::mem::eof())] @ 0x00; \ No newline at end of file +Segment segments[while(!std::mem::eof())] @ 0x00 [[hex::visualize("image", this)]]; \ No newline at end of file diff --git a/patterns/png.hexpat b/patterns/png.hexpat index bddb6fb..980ac33 100644 --- a/patterns/png.hexpat +++ b/patterns/png.hexpat @@ -1,6 +1,8 @@ #pragma MIME image/png #pragma endian big +#include + struct header_t { u8 highBitByte; char signature[3]; @@ -178,6 +180,7 @@ struct chunk_set { chunk_t chunks[while(builtin::std::mem::read_string($ + 4, 4) != "IEND")] [[inline]]; } [[inline]]; +u8 visualizer[std::mem::size()] @ 0x00 [[sealed, hex::visualize("image", this)]]; header_t header @ 0x00 [[comment("PNG file signature"), name("Signature")]]; chunk_t ihdr_chunk @ 0x08 [[comment("PNG Header chunk"), name("IHDR")]]; chunk_set set @ $ [[comment("PNG Chunks"), name("Chunks"), inline]]; diff --git a/patterns/tga.hexpat b/patterns/tga.hexpat index af58cfa..db111f2 100644 --- a/patterns/tga.hexpat +++ b/patterns/tga.hexpat @@ -75,5 +75,6 @@ struct Footer { char zero; }; +u8 visualizer[std::mem::size()] @ 0x00 [[sealed, hex::visualize("image", this)]]; Header header @ 0x0; Footer footer @ std::mem::size() - 0x1A;