@@ -278,11 +278,12 @@ void ImageSet::readLine(PixelArray &pixels) {
278
278
279
279
for (size_t i = 0 ; i < decoders.size (); i++) {
280
280
decoders[i]->readRows (1 , row.data ());
281
+ int x_offset = offsets.size () ? offsets[i].x () : 0 ;
281
282
282
283
for (int x = left; x < right; x++) {
283
- pixels[x - left][i].r = row[x *3 + 0 ];
284
- pixels[x - left][i].g = row[x *3 + 1 ];
285
- pixels[x - left][i].b = row[x *3 + 2 ];
284
+ pixels[x - left][i].r = row[(x + x_offset) *3 + 0 ];
285
+ pixels[x - left][i].g = row[(x + x_offset) *3 + 1 ];
286
+ pixels[x - left][i].b = row[(x + x_offset) *3 + 2 ];
286
287
}
287
288
}
288
289
if (light3d) {
@@ -387,11 +388,40 @@ void ImageSet::restart() {
387
388
current_line = 0 ;
388
389
}
389
390
391
+ void ImageSet::setCrop (QRect &_crop, std::vector<QPointF> &_offsets) {
392
+ std::vector<QPoint> int_offsets;
393
+ for (QPointF &p: _offsets)
394
+ int_offsets.push_back (p.toPoint ());
395
+
396
+ // find min and max of offsets to adjust the maxCrop;
397
+ int l = 0 ;
398
+ int r = 0 ;
399
+ int t = image_width;
400
+ int b = image_height;
401
+ for (QPoint &o: int_offsets) {
402
+ l = std::max (l, -o.x ());
403
+ r = std::min (image_width, -o.x ());
404
+ t = std::max (b, -o.y ());
405
+ b = std::min (image_height, -o.y ());
406
+ }
407
+ // TODO check +1 problem
408
+ QRect max_crop (l, t, r -l, t - b);
409
+ if (_crop.isNull ())
410
+ _crop = max_crop;
411
+ else
412
+ _crop = max_crop.intersected (_crop);
413
+
414
+ left =_crop.left ();
415
+ crop (_crop.left (), _crop.top (), _crop.width (), _crop.height ());
416
+ offsets = int_offsets;
417
+ }
418
+
390
419
void ImageSet::skipToTop () {
391
420
std::vector<uint8_t > row (image_width*3 );
392
421
393
422
for (uint32_t i = 0 ; i < decoders.size (); i++) {
394
- for (int y = 0 ; y < top; y++)
423
+ int y_offset = offsets.size () ? offsets[i].y () : 0 ;
424
+ for (int y = 0 ; y < top + y_offset; y++)
395
425
decoders[i]->readRows (1 , row.data ());
396
426
397
427
if (callback && !(*callback)(" Skipping cropped lines..." , 100 *i/(decoders.size ()-1 )))
@@ -400,3 +430,4 @@ void ImageSet::skipToTop() {
400
430
current_line += top;
401
431
}
402
432
433
+
0 commit comments