@@ -176,7 +176,7 @@ void AddressableLight::mark_shown_() {
176
176
}
177
177
178
178
int32_t PartitionLightOutput::size () const {
179
- auto last_seg = this ->segments_ [this ->segments_ .size () - 1 ];
179
+ auto & last_seg = this ->segments_ [this ->segments_ .size () - 1 ];
180
180
return last_seg.get_dst_offset () + last_seg.get_size ();
181
181
}
182
182
ESPColorView PartitionLightOutput::operator [](int32_t index) const {
@@ -194,13 +194,17 @@ ESPColorView PartitionLightOutput::operator[](int32_t index) const {
194
194
lo = hi = mid;
195
195
}
196
196
}
197
- auto seg = this ->segments_ [lo];
198
- auto view = (*seg.get_src ())[index - seg.get_src_offset ()];
197
+ auto &seg = this ->segments_ [lo];
198
+ // offset within the segment
199
+ int32_t seg_off = index - seg.get_dst_offset ();
200
+ // offset within the src
201
+ int32_t src_off = seg.get_src_offset () + seg_off;
202
+ auto view = (*seg.get_src ())[src_off];
199
203
view.set_color_correction_ (&this ->correction_ );
200
204
return view;
201
205
}
202
206
void PartitionLightOutput::clear_effect_data () {
203
- for (auto seg : this ->segments_ ) {
207
+ for (auto & seg : this ->segments_ ) {
204
208
seg.get_src ()->clear_effect_data ();
205
209
}
206
210
}
@@ -209,7 +213,7 @@ LightTraits PartitionLightOutput::get_traits() {
209
213
}
210
214
PartitionLightOutput::PartitionLightOutput (const std::vector<AddressableSegment> &segments) : segments_(segments) {
211
215
int32_t off = 0 ;
212
- for (auto seg : this ->segments_ ) {
216
+ for (auto & seg : this ->segments_ ) {
213
217
seg.set_dst_offset (off);
214
218
off += seg.get_size ();
215
219
}
0 commit comments