File: imageinterface.h

package info (click to toggle)
aoflagger 3.4.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,960 kB
  • sloc: cpp: 83,076; python: 10,187; sh: 260; makefile: 178
file content (53 lines) | stat: -rw-r--r-- 1,434 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifndef IMAGE_INTERFACE_H
#define IMAGE_INTERFACE_H

#include <cmath>
#include <cstring>
#include <limits>
#include <vector>

class ImageInterface {
 public:
  ImageInterface() : _width(0), _height(0), _stride(0) {}
  ImageInterface(size_t width, size_t height, size_t stride)
      : _width(width), _height(height), _stride(stride) {}
  virtual ~ImageInterface() {}
  virtual const float* Data() const = 0;
  bool Empty() const { return _width == 0 || _height == 0; }
  size_t Width() const { return _width; }
  size_t Height() const { return _height; }
  size_t Stride() const { return _stride; }

  float Maximum() const {
    if (Empty()) return 0.0;
    const float* data = Data();
    float value = std::numeric_limits<float>::min();
    for (size_t y = 0; y != _height; ++y) {
      const float* row = &data[y * _stride];
      for (size_t x = 0; x != _width; ++x) {
        if (std::isfinite(row[x]) && value < row[x]) value = row[x];
      }
    }
    return value;
  }

  float Minimum() const {
    if (Empty()) return 0.0;
    const float* data = Data();
    float value = std::numeric_limits<float>::max();
    for (size_t y = 0; y != _height; ++y) {
      const float* row = &data[y * _stride];
      for (size_t x = 0; x != _width; ++x) {
        if (std::isfinite(row[x]) && value > row[x]) value = row[x];
      }
    }
    return value;
  }

 private:
  size_t _width;
  size_t _height;
  size_t _stride;
};

#endif