mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2026-09-01 20:39:08 +00:00
Openstreetmap support (#2765)
This commit is contained in:
@@ -91,7 +91,7 @@ const float adsb_lat_lut[58] = {
|
||||
83.07199445, 83.99173563, 84.89166191, 85.75541621,
|
||||
86.53536998, 87.00000000};
|
||||
|
||||
const float PI = 3.14159265358979323846;
|
||||
#include "mathdef.hpp"
|
||||
|
||||
const float NZ = 15.0;
|
||||
|
||||
|
||||
+47
-36
@@ -52,10 +52,10 @@ void BMPFile::close() {
|
||||
bmpimage.close();
|
||||
}
|
||||
|
||||
// creates a new bmp file. for now, hardcoded to 3 byte colour depth
|
||||
// creates a new bmp file. hardcoded to 3 byte (24-bit) colour depth
|
||||
bool BMPFile::create(const std::filesystem::path& file, uint32_t x, uint32_t y) {
|
||||
is_opened = false;
|
||||
is_read_ony = true;
|
||||
is_read_only = true;
|
||||
bmpimage.close(); // if already open, close before open a new
|
||||
if (file_exists(file)) {
|
||||
delete_file(file); // overwrite
|
||||
@@ -85,7 +85,7 @@ bool BMPFile::create(const std::filesystem::path& file, uint32_t x, uint32_t y)
|
||||
bmpimage.write(&bmp_header, sizeof(bmp_header_t));
|
||||
file_pos = bmp_header.image_data;
|
||||
is_opened = true;
|
||||
is_read_ony = false;
|
||||
is_read_only = false;
|
||||
if (!expand_y(y)) return false; // will fill with 0, and update header data
|
||||
seek(0, 0);
|
||||
return true;
|
||||
@@ -94,30 +94,36 @@ bool BMPFile::create(const std::filesystem::path& file, uint32_t x, uint32_t y)
|
||||
// opens the file and parses header data. return true on success
|
||||
bool BMPFile::open(const std::filesystem::path& file, bool readonly) {
|
||||
is_opened = false;
|
||||
is_read_ony = true;
|
||||
bmpimage.close(); // if already open, close before open a new
|
||||
is_read_only = true;
|
||||
bmpimage.close();
|
||||
|
||||
auto result = bmpimage.open(file, readonly, false);
|
||||
if (!result.value().ok()) return false;
|
||||
file_pos = 0;
|
||||
bmpimage.seek(file_pos);
|
||||
auto read_size = bmpimage.read(&bmp_header, sizeof(bmp_header_t));
|
||||
if (!((bmp_header.signature == 0x4D42) && // "BM" Signature
|
||||
(bmp_header.planes == 1) && // Seems always to be 1
|
||||
(bmp_header.compression == 0 || bmp_header.compression == 3))) { // No compression
|
||||
bmpimage.read(&bmp_header, sizeof(bmp_header_t));
|
||||
if (!((bmp_header.signature == 0x4D42) &&
|
||||
(bmp_header.planes == 1) &&
|
||||
(bmp_header.compression == 0 || bmp_header.compression == 3))) {
|
||||
return false;
|
||||
}
|
||||
char buffer[257];
|
||||
|
||||
switch (bmp_header.bpp) {
|
||||
case 8:
|
||||
type = 4;
|
||||
byte_per_px = 1;
|
||||
// bmpimage.seek(sizeof(bmp_header_t));
|
||||
// bmpimage.read(color_palette, 1024);
|
||||
return false; // niy
|
||||
break;
|
||||
|
||||
case 16:
|
||||
file_pos = 0x36;
|
||||
memset(buffer, 0, 16);
|
||||
bmpimage.read(buffer, 16);
|
||||
byte_per_px = 2;
|
||||
if (buffer[1] == 0x7C)
|
||||
type = 3; // A1R5G5B5
|
||||
else
|
||||
type = 0; // R5G6B5
|
||||
type = 5;
|
||||
if (bmp_header.compression == 3) {
|
||||
return false;
|
||||
} // niy
|
||||
|
||||
break;
|
||||
case 24:
|
||||
type = 1;
|
||||
@@ -130,12 +136,11 @@ bool BMPFile::open(const std::filesystem::path& file, bool readonly) {
|
||||
default:
|
||||
// not supported
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
byte_per_row = (bmp_header.width * byte_per_px % 4 == 0) ? bmp_header.width * byte_per_px : (bmp_header.width * byte_per_px + (4 - ((bmp_header.width * byte_per_px) % 4)));
|
||||
byte_per_row = (bmp_header.width * byte_per_px + 3) & ~3;
|
||||
file_pos = bmp_header.image_data;
|
||||
is_opened = true;
|
||||
is_read_ony = readonly;
|
||||
is_read_only = readonly;
|
||||
currx = 0;
|
||||
curry = 0;
|
||||
return true;
|
||||
@@ -161,20 +166,24 @@ bool BMPFile::read_next_px(ui::Color& px, bool seek = true) {
|
||||
auto res = bmpimage.read(buffer, byte_per_px);
|
||||
if (res.is_error()) return false;
|
||||
switch (type) {
|
||||
case 0: // R5G6B5
|
||||
case 3: // A1R5G5B5
|
||||
if (!type)
|
||||
px = ui::Color((uint16_t)buffer[0] | ((uint16_t)buffer[1] << 8));
|
||||
else
|
||||
px = ui::Color(((uint16_t)buffer[0] & 0x1F) | ((uint16_t)buffer[0] & 0xE0) << 1 | ((uint16_t)buffer[1] & 0x7F) << 9);
|
||||
case 5: {
|
||||
uint16_t color16 = (uint16_t)buffer[0] | ((uint16_t)buffer[1] << 8);
|
||||
px = ui::Color(color16); // has glitches!
|
||||
break;
|
||||
}
|
||||
case 2: // 32
|
||||
px = ui::Color(buffer[2], buffer[1], buffer[0]);
|
||||
break;
|
||||
|
||||
case 4: { // 8-bit
|
||||
// uint8_t index = buffer[0];
|
||||
// px = ui::Color(color_palette[index][2], color_palette[index][1], color_palette[index][0]); // Palette is BGR
|
||||
// px = ui::Color(buffer[0]); // niy, since needs a lot of ram for the palette
|
||||
break;
|
||||
}
|
||||
case 1: // 24
|
||||
default:
|
||||
px = ui::Color(buffer[2], buffer[1], buffer[0]);
|
||||
|
||||
break;
|
||||
case 2: // 32
|
||||
px = ui::Color(buffer[2], buffer[1], buffer[0]);
|
||||
break;
|
||||
}
|
||||
if (seek) advance_curr_px();
|
||||
@@ -188,23 +197,23 @@ void BMPFile::set_bg_color(ui::Color background) {
|
||||
}
|
||||
|
||||
// delete bg color. default. creation or expansion will be fast, but the file will contain random garbage. no problem if you write all pixels later.
|
||||
void BMPFile::delete_db_color() {
|
||||
void BMPFile::delete_bg_color() {
|
||||
use_bg = false;
|
||||
}
|
||||
|
||||
// writes a color data to the current position, and advances 1 px. true on success, false on error
|
||||
bool BMPFile::write_next_px(ui::Color& px) {
|
||||
if (!is_opened) return false;
|
||||
if (is_read_ony) return false;
|
||||
if (!is_opened || is_read_only) return false;
|
||||
uint8_t buffer[4];
|
||||
switch (type) {
|
||||
case 5:
|
||||
case 0: // R5G6B5
|
||||
case 3: // A1R5G5B5
|
||||
if (!type) {
|
||||
buffer[0] = (px.r() << 3) | (px.g() >> 3); // todo test in future
|
||||
buffer[0] = (px.r() << 3) | (px.g() >> 3);
|
||||
buffer[1] = (px.g() << 5) | px.b();
|
||||
} else {
|
||||
buffer[0] = (1 << 7) | (px.r() << 2) | (px.g() >> 3); // todo test in future
|
||||
buffer[0] = (1 << 7) | (px.r() << 2) | (px.g() >> 3);
|
||||
buffer[1] = (px.g() << 5) | px.b();
|
||||
}
|
||||
break;
|
||||
@@ -220,6 +229,8 @@ bool BMPFile::write_next_px(ui::Color& px) {
|
||||
buffer[0] = px.b();
|
||||
buffer[3] = 255;
|
||||
break;
|
||||
case 4: // 8-bit
|
||||
return false;
|
||||
}
|
||||
auto res = bmpimage.write(buffer, byte_per_px);
|
||||
if (res.is_error()) return false;
|
||||
@@ -260,7 +271,7 @@ bool BMPFile::expand_y(uint32_t new_y) {
|
||||
if (!is_opened) return false; // not yet opened
|
||||
uint32_t old_height = get_real_height();
|
||||
if (new_y < old_height) return true; // already bigger
|
||||
if (is_read_ony) return false; // can't expand
|
||||
if (is_read_only) return false; // can't expand
|
||||
uint32_t delta = (new_y - old_height) * byte_per_row;
|
||||
bmp_header.size += delta;
|
||||
bmp_header.data_size += delta;
|
||||
|
||||
@@ -47,12 +47,12 @@ class BMPFile {
|
||||
uint32_t get_width();
|
||||
bool is_bottomup();
|
||||
void set_bg_color(ui::Color background);
|
||||
void delete_db_color();
|
||||
void delete_bg_color();
|
||||
|
||||
private:
|
||||
bool advance_curr_px(uint32_t num);
|
||||
bool is_opened = false;
|
||||
bool is_read_ony = true;
|
||||
bool is_read_only = true;
|
||||
|
||||
File bmpimage{};
|
||||
size_t file_pos = 0;
|
||||
@@ -64,6 +64,7 @@ class BMPFile {
|
||||
uint32_t currx = 0;
|
||||
uint32_t curry = 0;
|
||||
ui::Color bg{};
|
||||
// uint8_t color_palette[256][4];
|
||||
bool use_bg = false;
|
||||
};
|
||||
|
||||
|
||||
@@ -26,7 +26,9 @@
|
||||
#include <complex>
|
||||
#include <cmath>
|
||||
|
||||
constexpr float pi{3.141592653589793238462643383279502884f};
|
||||
#include "mathdef.hpp"
|
||||
|
||||
constexpr float pi{M_PI};
|
||||
|
||||
namespace std {
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
#define PI 3.1415926535897932384626433832795
|
||||
#define M_PI PI
|
||||
@@ -47,7 +47,7 @@ static uint8_t calfrchk[51]; // so subframes are preserved while populate
|
||||
#define pos_GPSecefY 0x114 // 0x118 // 4 byte (not actually used since Y and Z are following X, and grabbed in that same loop)
|
||||
#define pos_GPSecefZ 0x118 // 0x11C // 4 byte (same as Y)
|
||||
|
||||
#define PI 3.1415926535897932384626433832795 // 3.1416 //(3.1415926535897932384626433832795)
|
||||
#include "mathdef.hpp"
|
||||
|
||||
Packet::Packet(
|
||||
const baseband::Packet& packet,
|
||||
|
||||
Reference in New Issue
Block a user