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"
11#include "xrit/identify.h"
13
14namespace satdump
15{
16 namespace xrit
17 {
21 class HimawariSegmentedImageDecoder : public SegmentedImageDecoder
22 {
23 private:
24 int seg_count = 0;
25 std::vector<bool> segments_done;
26 int seg_height = 0, seg_width = 0;
27
28 public:
29 void init(int bit_depth, int max_seg, int segment_width, int segment_height)
30 {
31 seg_count = max_seg;
32 segments_done.resize(seg_count, false);
33
34 image = image::Image(bit_depth, segment_width, segment_height * max_seg, 1);
35 seg_height = segment_height;
36 seg_width = segment_width;
37
38 image.fill(0);
39 }
40
41 HimawariSegmentedImageDecoder(XRITFile &file)
42 {
43 ImageStructureRecord image_structure_record = file.getHeader<ImageStructureRecord>();
44
45 init(image_structure_record.bit_per_pixel > 8 ? 16 : 8, //
46 10, //
47 image_structure_record.columns_count, //
48 image_structure_record.lines_count);
49 }
50
51 void pushSegment(image::Image &data, int segc)
52 {
53 if (segc >= seg_count || segc < 0)
54 return;
55 if (data.size() != seg_height * seg_width)
56 {
57 logger->error("Image of the wrong size! (%s) %dx%d Got %dx%d", info.channel.c_str(), seg_width, seg_height, data.width(), data.height());
58 return;
59 }
60 image::imemcpy(image, (seg_height * seg_width) * segc, data, 0, seg_height * seg_width);
61 segments_done[segc] = true;
62 }
63
65 {
66 auto img = getImageFromXRITFile(XRIT_HIMAWARI_AHI, file);
67
68 std::vector<std::string> header_parts = splitString(file.filename, '_');
69
70 int segment = std::stoi(file.filename.substr(file.filename.size() - 3, file.filename.size())) - 1;
71
72 pushSegment(img, segment);
73 }
74
76 {
77 bool complete = true;
78 for (int i = 0; i < seg_count; i++)
79 complete = complete && segments_done[i];
80 return complete;
81 }
82
83 void reset()
84 {
85 for (int i = 0; i < seg_count; i++)
86 segments_done[i] = false;
87 image.clear();
88 }
89
90 bool hasData()
91 {
92 for (int i = 0; i < seg_count; i++)
93 if (segments_done[i])
94 return true;
95 return false;
96 }
97 };
98 } // namespace xrit
99} // namespace satdump
Definition image.h:17
size_t size() const
Returns image data size.
Definition image.h:228
size_t height() const
Returns image height.
Definition image.h:216
size_t width() const
Returns image width.
Definition image.h:210
bool hasData()
Allows knowing if an image has data at all (and hence, worth saving)
Definition segment_decoder.h:90
bool isComplete()
Allows knowing if an image is complete, to save it instantly.
Definition segment_decoder.h:75
void reset()
Resets the decoder, to lower RAM usage.
Definition segment_decoder.h:83
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:64
Abstract Segmented decoder implementation to be overriden for mission-specific decoders.
Definition segment_decoder.h:26
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:37
Definition xrit_file.h:143