4 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
5 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
8 int initialHeight
, initialWidth
;
9 int rotatedHeight
, rotatedWidth
;
10 int autoCropHeight
, autoCropWidth
;
13 void __attribute__((noinline
,noclone
))
14 ufraw_test(ufraw_data
*uf
)
16 int iWidth
= uf
->initialWidth
;
17 int iHeight
= uf
->initialHeight
;
18 double aspectRatio
= ((double)iWidth
) / iHeight
;
19 double midX
= iWidth
/ 2.0 - 0.5;
20 double midY
= iHeight
/ 2.0 - 0.5;
21 double maxX
= 0, maxY
= 0;
22 double minX
= 999999, minY
= 999999;
23 double lastX
= 0, lastY
= 0, area
= 0;
26 for (i
= 0; i
< iWidth
+ iHeight
- 1; i
++)
29 if (i
< iWidth
) { // Trace the left border of the image
32 } else { // Trace the bottom border of the image
36 double srcX
= x
- midX
;
37 double srcY
= y
- midY
;
38 // A digital planimeter:
39 area
+= srcY
* lastX
- srcX
* lastY
;
42 maxX
= MAX(maxX
, fabs(srcX
));
43 maxY
= MAX(maxY
, fabs(srcY
));
44 if (fabs(srcX
/ srcY
) > aspectRatio
)
45 minX
= MIN(minX
, fabs(srcX
));
47 minY
= MIN(minY
, fabs(srcY
));
49 scale
= sqrt((iWidth
- 1) * (iHeight
- 1) / area
);
50 uf
->rotatedWidth
= MIN(ceil(2 * maxX
+ 1.0) * scale
, 2 * iWidth
);
51 uf
->rotatedHeight
= MIN(ceil(2 * maxY
+ 1.0) * scale
, 2 * iHeight
);
52 uf
->autoCropWidth
= MIN(floor(2 * minX
) * scale
, 2 * iWidth
);
53 uf
->autoCropHeight
= MIN(floor(2 * minY
) * scale
, 2 * iHeight
);
54 if (uf
->autoCropWidth
!= 3)
61 ufraw_data
*uf
= &uf_data
;
63 uf
->initialHeight
= 5;
68 /* { dg-final { cleanup-tree-dump "slp" } } */