• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

paulmthompson / WhiskerToolbox / 17928671275

22 Sep 2025 08:06PM UTC coverage: 68.862% (-3.1%) from 71.97%
17928671275

push

github

paulmthompson
fix inability to save with line widget and point widget

41652 of 60486 relevant lines covered (68.86%)

1138.71 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

30.77
/src/DataManager/Media/Media_Data.hpp
1
#ifndef WHISKERTOOLBOX_MEDIA_DATA_HPP
2
#define WHISKERTOOLBOX_MEDIA_DATA_HPP
3

4
#include "CoreGeometry/ImageSize.hpp"
5
#include "Observer/Observer_Data.hpp"
6
#include "TimeFrame/TimeFrame.hpp"
7
#include "ImageProcessor.hpp"
8
#include "MediaStorage.hpp"
9

10
#include <cstdint>
11
#include <functional>
12
#include <map>
13
#include <memory>
14
#include <string>
15
#include <vector>
16

17
class MediaData : public ObserverData {
18
public:
19
    enum class MediaType {
20
        Video,
21
        Images,
22
        HDF5
23
    };
24

25
    // Use shared MediaStorage types
26
    using BitDepth = MediaStorage::BitDepth;
27
    using DataStorage = MediaStorage::ImageDataVariant;
28

29
    MediaData();
30

31
    virtual ~MediaData();
32

33
    /**
34
     * @brief Get the media type of this instance
35
     * @return The MediaType enum value
36
     */
37
    virtual MediaType getMediaType() const = 0;
38

39
    [[nodiscard]] std::string getFilename() const { return _filename; };
40
    void setFilename(std::string const & filename) { _filename = filename; };
×
41

42
    enum DisplayFormat {
43
        Gray,
44
        Color
45
    };
46

47
    void setFormat(DisplayFormat format);
48

49
    [[nodiscard]] DisplayFormat getFormat() const { return _format; };
×
50

51
    [[nodiscard]] int getHeight() const { return _height; };
×
52
    [[nodiscard]] int getWidth() const { return _width; };
×
53
    [[nodiscard]] ImageSize getImageSize() const {return ImageSize{.width=_width, .height=_height};};
7✔
54

55
    void updateHeight(int height);
56

57
    void updateWidth(int width);
58

59
    [[nodiscard]] int getTotalFrameCount() const { return _totalFrameCount; };
×
60
    void setTotalFrameCount(int total_frame_count) { _totalFrameCount = total_frame_count; };
5✔
61

62
    // ========== Bit Depth Management ==========
63
    
64
    /**
65
     * @brief Get the current bit depth of the media data
66
     * @return Current BitDepth enum value
67
     */
68
    [[nodiscard]] BitDepth getBitDepth() const { return _bit_depth; }
69
    
70
    /**
71
     * @brief Set the bit depth (can be used to override auto-detected depth)
72
     * @param depth The desired bit depth
73
     */
74
    void setBitDepth(BitDepth depth);
75
    
76
    /**
77
     * @brief Check if the media data is using 8-bit storage
78
     * @return true if using 8-bit, false if using 32-bit float
79
     */
80
    [[nodiscard]] bool is8Bit() const { return MediaStorage::is8Bit(_rawData); }
12✔
81
    
82
    /**
83
     * @brief Check if the media data is using 32-bit float storage
84
     * @return true if using 32-bit float, false if using 8-bit
85
     */
86
    [[nodiscard]] bool is32Bit() const { return MediaStorage::is32Bit(_rawData); }
2✔
87

88
    /**
89
     *
90
     *
91
     *
92
     * @brief LoadMedia
93
     * @param name points to the path to the file or folder
94
     */
95
    void LoadMedia(std::string const & name);
96

97
    /**
98
     *
99
     * Subclasses will specify how to load a specific frame given by frame_id
100
     * This will populate the data class member with a vector of raw uint8_t
101
     *
102
     *
103
     *
104
     * @brief LoadFrame
105
     * @param frame_id
106
     */
107
    void LoadFrame(int frame_id);
108

109
    [[nodiscard]] virtual std::string GetFrameID(int frame_id) const {
×
110
        static_cast<void>(frame_id);
111
        return "";
×
112
    };
113

114
    virtual int getFrameIndexFromNumber(int frame_id) {
×
115
        static_cast<void>(frame_id);
116
        return 0;
×
117
    };
118

119
    // ========== Data Access Methods ==========
120
    
121
    /**
122
     * @brief Get raw data as uint8_t (for 8-bit data or converted from 32-bit)
123
     * @param frame_number Frame number to load
124
     * @return Reference to uint8_t vector
125
     */
126
    std::vector<uint8_t> const & getRawData8(int frame_number);
127
    
128
    /**
129
     * @brief Get raw data as float (for 32-bit data or converted from 8-bit)
130
     * @param frame_number Frame number to load
131
     * @return Reference to float vector
132
     */
133
    std::vector<float> const & getRawData32(int frame_number);
134
    
135
    /**
136
     * @brief Get processed data as uint8_t (for 8-bit data or converted from 32-bit)
137
     * @param frame_number Frame number to load
138
     * @return Copy of uint8_t vector (since processing may modify it)
139
     */
140
    std::vector<uint8_t> getProcessedData8(int frame_number);
141
    
142
    /**
143
     * @brief Get processed data as float (for 32-bit data or converted from 8-bit)
144
     * @param frame_number Frame number to load
145
     * @return Copy of float vector (since processing may modify it)
146
     */
147
    std::vector<float> getProcessedData32(int frame_number);
148
    
149
    /**
150
     * @brief Get raw data as variant (native format)
151
     * @param frame_number Frame number to load
152
     * @return DataStorage variant containing the raw data
153
     */
154
    DataStorage const& getRawDataVariant(int frame_number);
155
    
156
    /**
157
     * @brief Get processed data as variant (native format)
158
     * @param frame_number Frame number to load
159
     * @return DataStorage variant containing the processed data
160
     */
161
    DataStorage getProcessedDataVariant(int frame_number);
162
    
163
    /**
164
     * @brief Legacy method - get raw data (defaults to 8-bit behavior for compatibility)
165
     * @param frame_number Frame number to load
166
     * @return Reference to uint8_t vector
167
     */
168
    std::vector<uint8_t> const & getRawData(int frame_number) { return getRawData8(frame_number); }
169
    
170
    /**
171
     * @brief Legacy method - get processed data (defaults to 8-bit behavior for compatibility)
172
     * @param frame_number Frame number to load
173
     * @return Copy of uint8_t vector
174
     */
175
    std::vector<uint8_t> getProcessedData(int frame_number) { return getProcessedData8(frame_number); }
×
176
    
177
    /**
178
     * @brief Set raw data from uint8_t vector
179
     * @param data The 8-bit data to set
180
     */
181
    void setRawData(MediaStorage::ImageData8 data);
182
    
183
    /**
184
     * @brief Set raw data from float vector (normalized to 0-255 range)
185
     * @param data The 32-bit float data to set
186
     */
187
    void setRawData(MediaStorage::ImageData32 data);
188

189
    // Image processing methods using ImageProcessor system
190
    /**
191
     * @brief Set the image processor backend (e.g., "opencv", "simd", etc.)
192
     * @param processor_name Name of the registered processor
193
     * @return true if the processor was successfully set, false otherwise
194
     */
195
    bool setImageProcessor(std::string const& processor_name);
196

197
    /**
198
     * @brief Get the current image processor backend name
199
     * @return Name of the current processor, or empty string if none set
200
     */
201
    std::string getImageProcessorName() const;
202

203
    /**
204
     * @brief Add a processing step using the current processor
205
     * @param key Unique identifier for the processing step
206
     * @param processor Generic processing function
207
     */
208
    void addProcessingStep(std::string const& key, std::function<void(void*)> processor);
209

210
    /**
211
     * @brief Remove a processing step
212
     * @param key Identifier of the processing step to remove
213
     */
214
    void removeProcessingStep(std::string const& key);
215

216
    /**
217
     * @brief Clear all processing steps
218
     */
219
    void clearProcessingSteps();
220

221
    /**
222
     * @brief Check if a processing step exists
223
     * @param key Identifier to check
224
     * @return true if the step exists, false otherwise
225
     */
226
    bool hasProcessingStep(std::string const& key) const;
227

228
    /**
229
     * @brief Get the number of processing steps
230
     * @return Number of steps in the processing chain
231
     */
232
    size_t getProcessingStepCount() const;
233

234
    // ========== Time Frame ==========
235

236
    /**
237
     * @brief Set the time frame
238
     * 
239
     * @param time_frame The time frame to set
240
     */
241
    void setTimeFrame(std::shared_ptr<TimeFrame> time_frame) { _time_frame = time_frame; }
363✔
242

243
protected:
244
    virtual void doLoadMedia(std::string const & name) {
×
245
        static_cast<void>(name);
246
    };
×
247
    virtual void doLoadFrame(int frame_id) {
×
248
        static_cast<void>(frame_id);
249
    };
×
250

251
private:
252
    std::string _filename;
253
    int _totalFrameCount = 0;
254

255
    int _height = 480;
256
    int _width = 640;
257
    DisplayFormat _format = DisplayFormat::Gray;
258
    int _display_format_bytes = 1;
259

260
    // Bit depth and data storage
261
    BitDepth _bit_depth = BitDepth::Bit8;
262
    DataStorage _rawData;
263
    DataStorage _processedData;
264
    
265
    // Temporary conversion buffers (to avoid repeated allocations)
266
    mutable MediaStorage::ImageData8 _temp_8bit_buffer;
267
    mutable MediaStorage::ImageData32 _temp_32bit_buffer;
268
    
269
    // Flexible processing system
270
    std::unique_ptr<ImageProcessing::ImageProcessor> _image_processor;
271
    std::string _processor_name;
272
    
273
    int _last_loaded_frame = -1;
274
    int _last_processed_frame = -1;
275

276
    std::shared_ptr<TimeFrame> _time_frame {nullptr};
277

278
    void _processData();
279
    
280
    // Helper methods for data conversion
281
    void _convertTo8Bit(MediaStorage::ImageData32 const& source, MediaStorage::ImageData8& target) const;
282
    void _convertTo32Bit(MediaStorage::ImageData8 const& source, MediaStorage::ImageData32& target) const;
283
    
284
    // Helper to resize data storage based on current format and bit depth
285
    void _resizeDataStorage();
286
};
287

288
/**
289
 * @brief Empty MediaData implementation for default/placeholder use
290
 * 
291
 * This class provides a concrete implementation of MediaData that can be
292
 * used as a default/placeholder when no specific media type is loaded.
293
 */
294
class EmptyMediaData : public MediaData {
295
public:
296
    EmptyMediaData() = default;
325✔
297
    
298
    MediaType getMediaType() const override { 
123✔
299
        // Return Video as a default - this matches the old behavior
300
        // where MediaData defaulted to Video type detection
301
        return MediaType::Video; 
123✔
302
    }
303
    
304
protected:
305
    void doLoadMedia(std::string const& name) override {
×
306
        // No-op for empty media data
307
        static_cast<void>(name);
308
    }
×
309
    
310
    void doLoadFrame(int frame_id) override {
×
311
        // No-op for empty media data
312
        static_cast<void>(frame_id);
313
    }
×
314
};
315

316

317
#endif//WHISKERTOOLBOX_MEDIA_DATA_HPP
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc