#
source:
trunk/third/libart_lgpl/art_rgb_affine_private.c
@
18256

Revision 18256, 3.2 KB checked in by ghudson, 22 years ago (diff) |
---|

Line | |
---|---|

1 | /* Libart_LGPL - library of basic graphic primitives |

2 | * Copyright (C) 1998 Raph Levien |

3 | * |

4 | * This library is free software; you can redistribute it and/or |

5 | * modify it under the terms of the GNU Library General Public |

6 | * License as published by the Free Software Foundation; either |

7 | * version 2 of the License, or (at your option) any later version. |

8 | * |

9 | * This library is distributed in the hope that it will be useful, |

10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |

11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |

12 | * Library General Public License for more details. |

13 | * |

14 | * You should have received a copy of the GNU Library General Public |

15 | * License along with this library; if not, write to the |

16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |

17 | * Boston, MA 02111-1307, USA. |

18 | */ |

19 | |

20 | #include "config.h" |

21 | #include "art_rgb_affine_private.h" |

22 | |

23 | #include <math.h> |

24 | #include "art_misc.h" |

25 | #include "art_point.h" |

26 | #include "art_affine.h" |

27 | |

28 | /* Private functions for the rgb affine image compositors - primarily, |

29 | the determination of runs, eliminating the need for source image |

30 | bbox calculation in the inner loop. */ |

31 | |

32 | /* Determine a "run", such that the inverse affine of all pixels from |

33 | (x0, y) inclusive to (x1, y) exclusive fit within the bounds |

34 | of the source image. |

35 | |

36 | Initial values of x0, x1, and result values stored in first two |

37 | pointer arguments. |

38 | */ |

39 | |

40 | #define EPSILON 1e-6 |

41 | |

42 | void |

43 | art_rgb_affine_run (int *p_x0, int *p_x1, int y, |

44 | int src_width, int src_height, |

45 | const double affine[6]) |

46 | { |

47 | int x0, x1; |

48 | double z; |

49 | double x_intercept; |

50 | int xi; |

51 | |

52 | x0 = *p_x0; |

53 | x1 = *p_x1; |

54 | |

55 | /* do left and right edges */ |

56 | if (affine[0] > EPSILON) |

57 | { |

58 | z = affine[2] * (y + 0.5) + affine[4]; |

59 | x_intercept = -z / affine[0]; |

60 | xi = ceil (x_intercept + EPSILON - 0.5); |

61 | if (xi > x0) |

62 | x0 = xi; |

63 | x_intercept = (-z + src_width) / affine[0]; |

64 | xi = ceil (x_intercept - EPSILON - 0.5); |

65 | if (xi < x1) |

66 | x1 = xi; |

67 | } |

68 | else if (affine[0] < -EPSILON) |

69 | { |

70 | z = affine[2] * (y + 0.5) + affine[4]; |

71 | x_intercept = (-z + src_width) / affine[0]; |

72 | xi = ceil (x_intercept + EPSILON - 0.5); |

73 | if (xi > x0) |

74 | x0 = xi; |

75 | x_intercept = -z / affine[0]; |

76 | xi = ceil (x_intercept - EPSILON - 0.5); |

77 | if (xi < x1) |

78 | x1 = xi; |

79 | } |

80 | else |

81 | { |

82 | z = affine[2] * (y + 0.5) + affine[4]; |

83 | if (z < 0 || z >= src_width) |

84 | { |

85 | *p_x1 = *p_x0; |

86 | return; |

87 | } |

88 | } |

89 | |

90 | /* do top and bottom edges */ |

91 | if (affine[1] > EPSILON) |

92 | { |

93 | z = affine[3] * (y + 0.5) + affine[5]; |

94 | x_intercept = -z / affine[1]; |

95 | xi = ceil (x_intercept + EPSILON - 0.5); |

96 | if (xi > x0) |

97 | x0 = xi; |

98 | x_intercept = (-z + src_height) / affine[1]; |

99 | xi = ceil (x_intercept - EPSILON - 0.5); |

100 | if (xi < x1) |

101 | x1 = xi; |

102 | } |

103 | else if (affine[1] < -EPSILON) |

104 | { |

105 | z = affine[3] * (y + 0.5) + affine[5]; |

106 | x_intercept = (-z + src_height) / affine[1]; |

107 | xi = ceil (x_intercept + EPSILON - 0.5); |

108 | if (xi > x0) |

109 | x0 = xi; |

110 | x_intercept = -z / affine[1]; |

111 | xi = ceil (x_intercept - EPSILON - 0.5); |

112 | if (xi < x1) |

113 | x1 = xi; |

114 | } |

115 | else |

116 | { |

117 | z = affine[3] * (y + 0.5) + affine[5]; |

118 | if (z < 0 || z >= src_height) |

119 | { |

120 | *p_x1 = *p_x0; |

121 | return; |

122 | } |

123 | } |

124 | |

125 | *p_x0 = x0; |

126 | *p_x1 = x1; |

127 | } |

**Note:**See TracBrowser for help on using the repository browser.