MCPcopy Create free account
hub / github.com/android/ndk-samples / DisplayDimension

Class DisplayDimension

camera/texture-view/src/main/cpp/camera_manager.cpp:107–159  ·  view source on GitHub ↗

* A helper class to assist image size comparison, by comparing the absolute * size * regardless of the portrait or landscape mode. */

Source from the content-addressed store, hash-verified

105 * regardless of the portrait or landscape mode.
106 */
107class DisplayDimension {
108 public:
109 DisplayDimension(int32_t w, int32_t h) : w_(w), h_(h), portrait_(false) {
110 if (h > w) {
111 // make it landscape
112 w_ = h;
113 h_ = w;
114 portrait_ = true;
115 }
116 }
117 DisplayDimension(const DisplayDimension& other) {
118 w_ = other.w_;
119 h_ = other.h_;
120 portrait_ = other.portrait_;
121 }
122
123 DisplayDimension(void) {
124 w_ = 0;
125 h_ = 0;
126 portrait_ = false;
127 }
128 DisplayDimension& operator=(const DisplayDimension& other) {
129 w_ = other.w_;
130 h_ = other.h_;
131 portrait_ = other.portrait_;
132
133 return (*this);
134 }
135
136 bool IsSameRatio(DisplayDimension& other) {
137 return (w_ * other.h_ == h_ * other.w_);
138 }
139 bool operator>(DisplayDimension& other) {
140 return (w_ >= other.w_ & h_ >= other.h_);
141 }
142 bool operator==(DisplayDimension& other) {
143 return (w_ == other.w_ && h_ == other.h_ && portrait_ == other.portrait_);
144 }
145 DisplayDimension operator-(DisplayDimension& other) {
146 DisplayDimension delta(w_ - other.w_, h_ - other.h_);
147 return delta;
148 }
149 void Flip(void) { portrait_ = !portrait_; }
150 bool IsPortrait(void) { return portrait_; }
151 int32_t width(void) { return w_; }
152 int32_t height(void) { return h_; }
153 int32_t org_width(void) { return (portrait_ ? h_ : w_); }
154 int32_t org_height(void) { return (portrait_ ? w_ : h_); }
155
156 private:
157 int32_t w_, h_;
158 bool portrait_;
159};
160
161/**
162 * Find a compatible camera modes:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected