Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions source/application/jpeg_header/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#
# Authored by: Robert Metchev / Chips & Scripts (rmetchev@ieee.org)
#
# CERN Open Hardware Licence Version 2 - Permissive
#
# Copyright (C) 2024 Robert Metchev
#

HEIGHT ?= 200
WIDTH ?= 200
QF ?= 50

all: header.bin
header.bin: jhdr.exe
$(<) $(HEIGHT) $(WIDTH) $(QF)
jhdr.exe: jhdr.c main.c
gcc -o $(@) $(^)

clean:
rm -f jhdr.exe jhdr.o header.bin
1 change: 1 addition & 0 deletions source/application/jpeg_header/footer.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
��
44 changes: 44 additions & 0 deletions source/application/jpeg_header/jhdr.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
Authored by: Robert Metchev / Chips & Scripts (rmetchev@ieee.org)
CERN Open Hardware Licence Version 2 - Permissive
Copyright (C) 2024 Robert Metchev

Pre-compiled JPEG header template (incl. quantization and Huffman tables).
QF = 50, height = 0, width = 0
Positions: QT0 25..88, QT1 93..156, height 163..164, width 165..166
Total length = 623
*/
#include "jhdr.h"

int scale_mult (int q, float scale) {
float t = (scale*q + 50)/100; // Round
if (t < 1) // Prevent divide by 0 error
t = 1;
else if (t > 255) // Prevent overflow
t = 255;
return (int)t;
}

void hdr(int height, int width, int qf, char header_file_name[]) {
char header[] = { 255, 216, 255, 224, 0, 16, 74, 70, 73, 70, 0, 1, 2, 0, 0, 100, 0, 100, 0, 0, 255, 219, 0, 67, 0, 16, 11, 12, 14, 12, 10, 16, 14, 13, 14, 18, 17, 16, 19, 24, 40, 26, 24, 22, 22, 24, 49, 35, 37, 29, 40, 58, 51, 61, 60, 57, 51, 56, 55, 64, 72, 92, 78, 64, 68, 87, 69, 55, 56, 80, 109, 81, 87, 95, 98, 103, 104, 103, 62, 77, 113, 121, 112, 100, 120, 92, 101, 103, 99, 255, 219, 0, 67, 1, 17, 18, 18, 24, 21, 24, 47, 26, 26, 47, 99, 66, 56, 66, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 255, 192, 0, 17, 8, 0, 0, 0, 0, 3, 1, 34, 0, 2, 17, 1, 3, 17, 1, 255, 196, 0, 31, 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 255, 196, 0, 31, 1, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 255, 196, 0, 181, 16, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 125, 1, 2, 3, 0, 4, 17, 5, 18, 33, 49, 65, 6, 19, 81, 97, 7, 34, 113, 20, 50, 129, 145, 161, 8, 35, 66, 177, 193, 21, 82, 209, 240, 36, 51, 98, 114, 130, 9, 10, 22, 23, 24, 25, 26, 37, 38, 39, 40, 41, 42, 52, 53, 54, 55, 56, 57, 58, 67, 68, 69, 70, 71, 72, 73, 74, 83, 84, 85, 86, 87, 88, 89, 90, 99, 100, 101, 102, 103, 104, 105, 106, 115, 116, 117, 118, 119, 120, 121, 122, 131, 132, 133, 134, 135, 136, 137, 138, 146, 147, 148, 149, 150, 151, 152, 153, 154, 162, 163, 164, 165, 166, 167, 168, 169, 170, 178, 179, 180, 181, 182, 183, 184, 185, 186, 194, 195, 196, 197, 198, 199, 200, 201, 202, 210, 211, 212, 213, 214, 215, 216, 217, 218, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 255, 196, 0, 181, 17, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 119, 0, 1, 2, 3, 17, 4, 5, 33, 49, 6, 18, 65, 81, 7, 97, 113, 19, 34, 50, 129, 8, 20, 66, 145, 161, 177, 193, 9, 35, 51, 82, 240, 21, 98, 114, 209, 10, 22, 36, 52, 225, 37, 241, 23, 24, 25, 26, 38, 39, 40, 41, 42, 53, 54, 55, 56, 57, 58, 67, 68, 69, 70, 71, 72, 73, 74, 83, 84, 85, 86, 87, 88, 89, 90, 99, 100, 101, 102, 103, 104, 105, 106, 115, 116, 117, 118, 119, 120, 121, 122, 130, 131, 132, 133, 134, 135, 136, 137, 138, 146, 147, 148, 149, 150, 151, 152, 153, 154, 162, 163, 164, 165, 166, 167, 168, 169, 170, 178, 179, 180, 181, 182, 183, 184, 185, 186, 194, 195, 196, 197, 198, 199, 200, 201, 202, 210, 211, 212, 213, 214, 215, 216, 217, 218, 226, 227, 228, 229, 230, 231, 232, 233, 234, 242, 243, 244, 245, 246, 247, 248, 249, 250, 255, 218, 0, 12, 3, 1, 0, 2, 17, 3, 17, 0, 63, 0};
float scale;

if (qf < 50)
scale = 5000/qf;
else
scale = 200 - 2*qf;

for (int i=25; i<=88; i++)
header[i] = scale_mult(header[i], scale);
for (int i=93; i<=156; i++)
header[i] = scale_mult(header[i], scale);

header[163] = (height >> 8) & 0xff;
header[164] = height & 0xff;
header[165] = (width >> 8) & 0xff;
header[166] = width & 0xff;

FILE *f = fopen(header_file_name, "wb");
fwrite(header, 1, 623, f);
fclose(f);
}
13 changes: 13 additions & 0 deletions source/application/jpeg_header/jhdr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
Authored by: Robert Metchev / Chips & Scripts (rmetchev@ieee.org)
CERN Open Hardware Licence Version 2 - Permissive
Copyright (C) 2024 Robert Metchev

Pre-compiled JPEG header template (incl. quantization and Huffman tables).
QF = 50, height = 0, width = 0
Positions: QT0 25..88, QT1 93..156, height 163..164, width 165..166
Total length = 623
*/
#include <stdlib.h>
#include <stdio.h>
void hdr(int height, int width, int qf, char header_file_name[]);
14 changes: 14 additions & 0 deletions source/application/jpeg_header/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
Authored by: Robert Metchev / Chips & Scripts (rmetchev@ieee.org)
CERN Open Hardware Licence Version 2 - Permissive
Copyright (C) 2024 Robert Metchev
*/
#include "jhdr.h"
int main(int argc, char *argv[]) {
if(argc <= 2)
exit(1);
// call hdr, write header to "header.bin"
hdr(atoi(argv[1]), atoi(argv[2]), argc > 3 ? atoi(argv[3]) : 50 , argc > 4 ? argv[4] : "header.bin");
return 0;
}