-
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
karm-image: Basic gif metadata extraction.
- Loading branch information
1 parent
7178b13
commit c68c1b0
Showing
12 changed files
with
111 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#pragma once | ||
|
||
// GIF Image decoder | ||
// References: | ||
// - https://www.w3.org/Graphics/GIF/spec-gif89a.txt | ||
|
||
#include <karm-gfx/buffer.h> | ||
#include <karm-io/bscan.h> | ||
|
||
namespace Gif { | ||
|
||
struct Decoder { | ||
struct Header { | ||
Array<u8, 6> signature; | ||
}; | ||
|
||
struct LogicalScreenDescriptor { | ||
u16le width; | ||
u16le height; | ||
u8 packed; | ||
u8 backgroundColorIndex; | ||
u8 pixelAspectRatio; | ||
}; | ||
|
||
static bool sniff(Bytes slice) { | ||
bool isGif = slice.len() >= 6 and | ||
slice[0] == 'G' and | ||
slice[1] == 'I' and | ||
slice[2] == 'F'; | ||
|
||
bool isGif89a = slice.len() >= 6 and | ||
slice[3] == '8' and | ||
slice[4] == '9' and | ||
slice[5] == 'a'; | ||
|
||
bool isGif87a = slice.len() >= 6 and | ||
slice[3] == '8' and | ||
slice[4] == '7' and | ||
slice[5] == 'a'; | ||
|
||
return isGif and (isGif89a or isGif87a); | ||
} | ||
|
||
static Res<Decoder> init(Bytes slice) { | ||
if (not sniff(slice)) | ||
return Error::invalidData("invalid signature"); | ||
|
||
Decoder dec{}; | ||
Io::BScan scan{slice}; | ||
|
||
Header header{}; | ||
scan.readTo(&header); | ||
|
||
LogicalScreenDescriptor lsd{}; | ||
scan.readTo(&lsd); | ||
|
||
dec._size = {lsd.width, lsd.height}; | ||
|
||
return Ok(dec); | ||
} | ||
|
||
Math::Vec2i _size; | ||
|
||
isize width() const { return _size.x; } | ||
|
||
isize height() const { return _size.y; } | ||
|
||
Res<> decode(Gfx::MutPixels pixels) { | ||
(void)pixels; | ||
return Ok(); | ||
} | ||
}; | ||
|
||
} // namespace Gif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"$schema": "https://schemas.cute.engineering/stable/cutekit.manifest.component.v1", | ||
"id": "karm-image.gif", | ||
"type": "lib", | ||
"description": "GIF image decoding and encoding", | ||
"props": { | ||
"cpp-excluded": true | ||
}, | ||
"requires": [ | ||
"karm-base" | ||
] | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters