SatDump 2.0.0-alpha-520736c72
Loading...
Searching...
No Matches
get_img.h
Go to the documentation of this file.
1#pragma once
2
7
8#include "image/image.h"
9#include "logger.h"
10#include "xrit/identify.h"
11#include "xrit/xrit_file.h"
12
14
15namespace satdump
16{
17 namespace xrit
18 {
29 {
30 PrimaryHeader primary_header = file.getHeader<PrimaryHeader>();
31
32 if (!file.hasHeader<ImageStructureRecord>())
33 {
34 logger->error("Tried to parse XRIT image but no image header!");
35 return image::Image();
36 }
37
38 if (type == XRIT_FY4_AGRI)
39 {
40 logger->trace("Using FY-4x Specific Image Header!");
41 fy4::ImageInformationRecord image_structure_record = file.getHeader<fy4::ImageInformationRecord>(); //(&lrit_data[all_headers[ImageStructureRecord::TYPE]]);
42
43 size_t required_buffer_size = (image_structure_record.bit_per_pixel > 8 ? 2 : 1) * image_structure_record.columns_count * image_structure_record.lines_count;
44 if (required_buffer_size <= file.lrit_data.size() - primary_header.total_header_length)
45 {
46 image::Image image(&file.lrit_data[primary_header.total_header_length], image_structure_record.bit_per_pixel > 8 ? 16 : 8, image_structure_record.columns_count,
47 image_structure_record.lines_count, 1);
48
49 return image;
50 }
51 else
52 {
53 logger->error("File is an image but the file is too small!");
54 return image::Image();
55 }
56 }
57 else
58 {
59 ImageStructureRecord image_structure_record = file.getHeader<ImageStructureRecord>(); //(&lrit_data[all_headers[ImageStructureRecord::TYPE]]);
60
61 size_t required_buffer_size = (image_structure_record.bit_per_pixel > 8 ? 2 : 1) * image_structure_record.columns_count * image_structure_record.lines_count;
62 if (required_buffer_size <= file.lrit_data.size() - primary_header.total_header_length)
63 {
64 image::Image image(&file.lrit_data[primary_header.total_header_length], image_structure_record.bit_per_pixel > 8 ? 16 : 8, image_structure_record.columns_count,
65 image_structure_record.lines_count, 1);
66
67 if (type == XRIT_HIMAWARI_AHI)
68 {
69 if (image_structure_record.bit_per_pixel == 16)
70 {
71 // Special case as Himawari sends it in Big Endian...?
72 image::Image image2(16, image_structure_record.columns_count, image_structure_record.lines_count, 1);
73
74 for (long long int i = 0; i < image_structure_record.columns_count * image_structure_record.lines_count; i++)
75 image2.set(i, ((&file.lrit_data[primary_header.total_header_length])[i * 2 + 0] << 8 | (&file.lrit_data[primary_header.total_header_length])[i * 2 + 1]));
76
77 image = image2;
78
79 if (image2.get(0) >= 16383)
80 {
81 // Needs to be shifted up by 2
82 for (long long int i = 0; i < image_structure_record.columns_count * image_structure_record.lines_count; i++)
83 image.set(i, image.get(i) << 2);
84 }
85 else if (image2.get(0) >= 4095)
86 {
87 // Needs to be shifted up by 4
88 for (long long int i = 0; i < image_structure_record.columns_count * image_structure_record.lines_count; i++)
89 image.set(i, image.get(i) << 4);
90 }
91 else
92 {
93 // Needs to be shifted up by 6
94 for (long long int i = 0; i < image_structure_record.columns_count * image_structure_record.lines_count; i++)
95 image.set(i, image.get(i) << 6);
96 }
97 }
98 }
99
100 return image;
101 }
102 else
103 {
104 logger->error("File is an image but the file is too small!");
105 return image::Image();
106 }
107 }
108 }
109
110 } // namespace xrit
111} // namespace satdump
Definition image.h:17
void set(size_t p, int v)
Standard int set. No bound check! Variants to pass a channel index and X / Y position are also availa...
Definition image.h:336
int get(size_t p)
Standard int get. No bound check! Variants to pass a channel index and X / Y position are also availa...
Definition image.h:351
FY-4x HRIT/LRIT Specific Headers.
image::Image getImageFromXRITFile(xrit_file_type_t type, XRITFile &file)
This converts a xRIT file (given its type) into an image object handling missing-specific details and...
Definition get_img.h:28
Contains functions to identify and process xRIT files.
xrit_file_type_t
Identifier to differentiate different format of xRIT files (do note some are duplicate!...
Definition identify.h:22
Core Image class.
Definition xrit_file.h:37
Definition xrit_file.h:16
Definition xrit_file.h:143