SatDump 2.0.0-alpha-520736c72
Loading...
Searching...
No Matches
segment_decoder.h
Go to the documentation of this file.
1#pragma once
2
7
9#include "image/image.h"
10#include "utils/string.h"
12#include "xrit/identify.h"
14#include "xrit/xrit_file.h"
15#include <exception>
16
17namespace satdump
18{
19 namespace xrit
20 {
24 class FY4xSegmentedImageDecoder : public SegmentedImageDecoder
25 {
26 private:
27 int seg_count = 0;
28 std::vector<bool> segments_done;
29 int seg_height = 0, seg_width = 0;
30
31 public:
32 void init(int bit_depth, int max_seg, int segment_width, int segment_height)
33 {
34 seg_count = max_seg;
35 segments_done.resize(seg_count, false);
36
37 image = image::Image(bit_depth, segment_width, segment_height * max_seg, 1);
38 seg_height = segment_height;
39 seg_width = segment_width;
40
41 image.fill(0);
42 }
43
44 FY4xSegmentedImageDecoder(XRITFile &file)
45 {
46 fy4::ImageInformationRecord image_structure_record = file.getHeader<fy4::ImageInformationRecord>();
47
48 // logger->critical("INIT %d %d", image_structure_record.columns_count, image_structure_record.lines_count);
49
50 init(image_structure_record.bit_per_pixel > 8 ? 16 : 8, //
51 image_structure_record.total_segment_count, //
52 image_structure_record.columns_count, //
53 image_structure_record.lines_count);
54 }
55
56 void pushSegment(image::Image &data, int segc, int p)
57 {
58 if (segc >= seg_count || segc < 0)
59 return;
60 // logger->critical("PUSH %d %d %d/%d %d/%d", data.width(), data.height(), p, image.height(), p + data.height(), image.height());
61 // if (data.size() != seg_height * seg_width)
62 // {
63 // logger->error("Image of the wrong size! (%d %d)", data.size(), seg_height * seg_width);
64 // return;
65 // }
66 try
67 {
68 image::imemcpy(image, /*(seg_height * seg_width)*/ seg_width * p, data, 0, data.size());
69 segments_done[segc] = true;
70 }
71 catch (std::exception &e)
72 {
73 logger->critical("Weird FY-4x stuff? %s", e.what());
74 }
75 }
76
78 {
79 auto img = getImageFromXRITFile(XRIT_FY4_AGRI, file);
80
81 fy4::ImageInformationRecord image_structure_record = file.getHeader<fy4::ImageInformationRecord>();
82
83 pushSegment(img, image_structure_record.current_segment_pos - 1, image_structure_record.current_segment_line_pos);
84 }
85
87 {
88 bool complete = true;
89 for (int i = 0; i < seg_count; i++)
90 complete = complete && segments_done[i];
91 return complete;
92 }
93
94 void reset()
95 {
96 for (int i = 0; i < seg_count; i++)
97 segments_done[i] = false;
98 image.clear();
99 }
100
101 bool hasData()
102 {
103 for (int i = 0; i < seg_count; i++)
104 if (segments_done[i])
105 return true;
106 return false;
107 }
108 };
109 } // namespace xrit
110} // namespace satdump
Definition image.h:17
size_t size() const
Returns image data size.
Definition image.h:228
bool isComplete()
Allows knowing if an image is complete, to save it instantly.
Definition segment_decoder.h:86
void reset()
Resets the decoder, to lower RAM usage.
Definition segment_decoder.h:94
bool hasData()
Allows knowing if an image has data at all (and hence, worth saving)
Definition segment_decoder.h:101
void pushSegment(XRITFile &file)
Push a segment into the work-in-progress image. These should already be filtered using file_info....
Definition segment_decoder.h:77
Abstract Segmented decoder implementation to be overriden for mission-specific decoders.
Definition segment_decoder.h:26
FY-4x HRIT/LRIT Specific Headers.
xRIT files => Images
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.
Core Image class.
Base segmented decoder class.
A collection of string-related utility functions.
Definition xrit_file.h:143