[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] pickles: Add new pickle for jpeg
|
From: |
Andreas Klinger |
|
Subject: |
[PATCH] pickles: Add new pickle for jpeg |
|
Date: |
Mon, 29 Jan 2024 18:19:20 +0100 |
2024-01-29 Andreas Klinger <ak@it-klinger.de>
* pickles/jpeg.pk: New pickle for jpeg files
---
This is also a RFC as there is a topic i'm not completely satisfied:
- When uncommenting
byte[] image
in JPEG_Tag it takes a long time to use the pickle.
Maybe there is a better way to define it.
- For my purposes i don't need the image but when submitting this pickle it
could be relevant to other users.
ChangeLog | 4 ++
pickles/Makefile.am | 2 +-
pickles/jpeg.pk | 114 ++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 119 insertions(+), 1 deletion(-)
create mode 100644 pickles/jpeg.pk
diff --git a/ChangeLog b/ChangeLog
index 679a1628..aa7ec183 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2024-01-29 Andreas Klinger <ak@it-klinger.de>
+
+ * pickles/jpeg.pk: New pickle for jpeg files
+
2024-01-28 Mohammad-Reza Nabipoor <mnabipoor@gnu.org>
* configure.ac (gl_HOST_CPU_ABI_32BIT): Emit an error instead of
diff --git a/pickles/Makefile.am b/pickles/Makefile.am
index 177aac70..eb993711 100644
--- a/pickles/Makefile.am
+++ b/pickles/Makefile.am
@@ -28,6 +28,6 @@ dist_pickles_DATA = ctf.pk ctf-dump.pk leb128.pk \
uuid.pk redoxfs.pk pcap.pk ieee754.pk pdap.pk \
iscan.pk iscan-str.pk base64.pk gpt-partition-attrs.pk \
gpt-partition-types.pk gpt.pk guid.pk linux.pk srec.pk \
- jojodiff.pk
+ jojodiff.pk jpeg.pk
EXTRA_DIST = README.elf
diff --git a/pickles/jpeg.pk b/pickles/jpeg.pk
new file mode 100644
index 00000000..ca07bf81
--- /dev/null
+++ b/pickles/jpeg.pk
@@ -0,0 +1,114 @@
+/* jpeg.pk - JPEG implementation for GNU poke */
+
+/* Copyright (C) 2024 Andreas Klinger */
+
+/* This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* Implemented as specified in
+ * https://en.wikipedia.org/wiki/JPEG as well as
+ * https://de.wikipedia.org/wiki/JPEG_File_Interchange_Format */
+
+/* Marker of JPEG pictures
+ * Array id 0 ("SOF0") starts at binary marker value 0xC0:
+ * 0xC0, 0xC1, ... , 0xC7
+ * 0xC8, 0xC1, ... , 0xCF
+ * 0xD0, 0xD1, ... , 0xD7
+ * ...
+ * 0xF8, 0xF1, ... , 0xFF
+ */
+var jpeg_marker =
+ ["SOF0", "SOF1", "SOF2", "SOF3", "DHT", "SOF5", "SOF6", "SOF7",
+ "JPG", "SOF9", "SOF10", "SOF11", "DAC", "SOF13", "SOF14", "SOF15",
+ "-", "-", "-", "-", "-", "-", "-", "-",
+ "SOI", "EOI", "SOS", "DQT", "-", "DRI", "-", "-",
+ "APP0", "APP1", "APP2", "APP3", "APP4", "APP5", "APP6", "APP7",
+ "APP8", "APP9", "APP10", "APP11", "APP12", "APP13", "APP14", "APP15",
+ "-", "-", "-", "-", "-", "-", "-", "-",
+ "-", "-", "-", "-", "-", "-", "COM", "-"];
+
+type JPEG_SOI =
+ struct
+ {
+ byte ff = 0xFF;
+ byte xx = 0xD8;
+ method _print = void:
+ {
+ printf ("\n#<tag: %u16x\tsymbol: %s>",
+ ff:::xx, jpeg_marker[xx - 0xC0]);
+ }
+ };
+
+type JPEG_SOS =
+ struct
+ {
+ byte ff = 0xFF;
+ byte xx = 0xDA;
+ method _print = void:
+ {
+ printf ("\n#<tag: %u16x\tsymbol: %s>",
+ ff:::xx, jpeg_marker[xx - 0xC0]);
+ }
+ };
+
+type JPEG_EOI =
+ struct
+ {
+ byte ff = 0xFF;
+ byte xx = 0xD9;
+ };
+
+type JPEG_Segment =
+ struct
+ {
+ byte ff == 0xFF;
+ byte xx : xx != 0xD8 && xx != 0xDA && xx != 0xD9 && xx >= 0xC0 && xx <
0xFF;
+ uint16 size;
+ char[size-2] data;
+ method _print = void:
+ {
+ printf ("\n#<tag: %u16x\tsymbol: %s\tsize: %u16d>",
+ ff:::xx, jpeg_marker[xx - 0xC0], size);
+ }
+ };
+
+fun JPEG_find_eoi = (byte[] image) int:
+ {
+ printf ("size: %u32d length: %u32d\n", image'size / 1#B, image'length);
+ for (var i = image'length - 1; i > 1; i--)
+ {
+ var ff = image[i - 1];
+ var xx = image[i];
+ if (ff == 0xFF && xx == 0xD9)
+ {
+ return i;
+ }
+ }
+ return 0;
+ }
+
+type JPEG_Tag =
+ struct
+ {
+ JPEG_SOI soi;
+ JPEG_Segment[] segments;
+ JPEG_SOS sos;
+/* byte[] image; */ /* could take some time for loading */
+/* var image_size = JPEG_find_eoi(image); */
+/* JPEG_EOI eoi; */
+ method get_nsegs = int:
+ {
+ return segments'length;
+ }
+ };
--
2.39.2
signature.asc
Description: PGP signature
- [PATCH] pickles: Add new pickle for jpeg,
Andreas Klinger <=