~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to app/core/gimp-transform-utils.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* The GIMP -- an image manipulation program
 
1
/* GIMP - The GNU Image Manipulation Program
2
2
 * Copyright (C) 1995-2001 Spencer Kimball, Peter Mattis, and others
3
3
 *
4
4
 * This program is free software; you can redistribute it and/or modify
28
28
 
29
29
 
30
30
void
31
 
gimp_transform_matrix_flip (GimpOrientationType  flip_type,
32
 
                            gdouble              axis,
33
 
                            GimpMatrix3         *result)
 
31
gimp_transform_matrix_flip (GimpMatrix3         *matrix,
 
32
                            GimpOrientationType  flip_type,
 
33
                            gdouble              axis)
34
34
{
35
 
  g_return_if_fail (result != NULL);
36
 
 
37
 
  gimp_matrix3_identity (result);
 
35
  g_return_if_fail (matrix != NULL);
38
36
 
39
37
  switch (flip_type)
40
38
    {
41
39
    case GIMP_ORIENTATION_HORIZONTAL:
42
 
      gimp_matrix3_translate (result, - axis, 0.0);
43
 
      gimp_matrix3_scale (result, -1.0, 1.0);
44
 
      gimp_matrix3_translate (result, axis, 0.0);
 
40
      gimp_matrix3_translate (matrix, - axis, 0.0);
 
41
      gimp_matrix3_scale (matrix, -1.0, 1.0);
 
42
      gimp_matrix3_translate (matrix, axis, 0.0);
45
43
      break;
46
44
 
47
45
    case GIMP_ORIENTATION_VERTICAL:
48
 
      gimp_matrix3_translate (result, 0.0, - axis);
49
 
      gimp_matrix3_scale (result, 1.0, -1.0);
50
 
      gimp_matrix3_translate (result, 0.0, axis);
 
46
      gimp_matrix3_translate (matrix, 0.0, - axis);
 
47
      gimp_matrix3_scale (matrix, 1.0, -1.0);
 
48
      gimp_matrix3_translate (matrix, 0.0, axis);
51
49
      break;
52
50
 
53
51
    case GIMP_ORIENTATION_UNKNOWN:
56
54
}
57
55
 
58
56
void
59
 
gimp_transform_matrix_flip_free (gint         x,
60
 
                                 gint         y,
61
 
                                 gint         width,
62
 
                                 gint         height,
 
57
gimp_transform_matrix_flip_free (GimpMatrix3 *matrix,
63
58
                                 gdouble      x1,
64
59
                                 gdouble      y1,
65
60
                                 gdouble      x2,
66
 
                                 gdouble      y2,
67
 
                                 GimpMatrix3 *result)
 
61
                                 gdouble      y2)
68
62
{
69
63
  gdouble angle;
70
64
 
71
 
  g_return_if_fail (result != NULL);
 
65
  g_return_if_fail (matrix != NULL);
72
66
 
73
67
  angle = atan2  (y2 - y1, x2 - x1);
74
68
 
75
 
  gimp_matrix3_identity  (result);
76
 
  gimp_matrix3_translate (result, -x1, -y1);
77
 
  gimp_matrix3_rotate    (result, -angle);
78
 
  gimp_matrix3_scale     (result, 1.0, -1.0);
79
 
  gimp_matrix3_rotate    (result, angle);
80
 
  gimp_matrix3_translate (result, x1, y1);
81
 
}
82
 
 
83
 
void
84
 
gimp_transform_matrix_rotate (gint         x,
85
 
                              gint         y,
86
 
                              gint         width,
87
 
                              gint         height,
88
 
                              gdouble      angle,
89
 
                              GimpMatrix3 *result)
 
69
  gimp_matrix3_identity  (matrix);
 
70
  gimp_matrix3_translate (matrix, -x1, -y1);
 
71
  gimp_matrix3_rotate    (matrix, -angle);
 
72
  gimp_matrix3_scale     (matrix, 1.0, -1.0);
 
73
  gimp_matrix3_rotate    (matrix, angle);
 
74
  gimp_matrix3_translate (matrix, x1, y1);
 
75
}
 
76
 
 
77
void
 
78
gimp_transform_matrix_rotate (GimpMatrix3         *matrix,
 
79
                              GimpRotationType     rotate_type,
 
80
                              gdouble              center_x,
 
81
                              gdouble              center_y)
 
82
{
 
83
  gdouble angle = 0;
 
84
 
 
85
  switch (rotate_type)
 
86
    {
 
87
    case GIMP_ROTATE_90:
 
88
      angle = G_PI_2;
 
89
      break;
 
90
    case GIMP_ROTATE_180:
 
91
      angle = G_PI;
 
92
      break;
 
93
    case GIMP_ROTATE_270:
 
94
      angle = - G_PI_2;
 
95
      break;
 
96
    }
 
97
 
 
98
  gimp_transform_matrix_rotate_center (matrix, center_x, center_y, angle);
 
99
}
 
100
 
 
101
void
 
102
gimp_transform_matrix_rotate_rect (GimpMatrix3 *matrix,
 
103
                                   gint         x,
 
104
                                   gint         y,
 
105
                                   gint         width,
 
106
                                   gint         height,
 
107
                                   gdouble      angle)
90
108
{
91
109
  gdouble center_x;
92
110
  gdouble center_y;
93
111
 
94
 
  g_return_if_fail (result != NULL);
 
112
  g_return_if_fail (matrix != NULL);
95
113
 
96
114
  center_x = (gdouble) x + (gdouble) width  / 2.0;
97
115
  center_y = (gdouble) y + (gdouble) height / 2.0;
98
116
 
99
 
  gimp_matrix3_identity  (result);
100
 
  gimp_matrix3_translate (result, -center_x, -center_y);
101
 
  gimp_matrix3_rotate    (result, angle);
102
 
  gimp_matrix3_translate (result, +center_x, +center_y);
 
117
  gimp_matrix3_translate (matrix, -center_x, -center_y);
 
118
  gimp_matrix3_rotate    (matrix, angle);
 
119
  gimp_matrix3_translate (matrix, +center_x, +center_y);
103
120
}
104
121
 
105
122
void
106
 
gimp_transform_matrix_rotate_center (gdouble      center_x,
 
123
gimp_transform_matrix_rotate_center (GimpMatrix3 *matrix,
 
124
                                     gdouble      center_x,
107
125
                                     gdouble      center_y,
108
 
                                     gdouble      angle,
109
 
                                     GimpMatrix3 *result)
 
126
                                     gdouble      angle)
110
127
{
111
 
  g_return_if_fail (result != NULL);
 
128
  g_return_if_fail (matrix != NULL);
112
129
 
113
 
  gimp_matrix3_identity  (result);
114
 
  gimp_matrix3_translate (result, -center_x, -center_y);
115
 
  gimp_matrix3_rotate    (result, angle);
116
 
  gimp_matrix3_translate (result, +center_x, +center_y);
 
130
  gimp_matrix3_translate (matrix, -center_x, -center_y);
 
131
  gimp_matrix3_rotate    (matrix, angle);
 
132
  gimp_matrix3_translate (matrix, +center_x, +center_y);
117
133
}
118
134
 
119
135
void
120
 
gimp_transform_matrix_scale (gint         x,
 
136
gimp_transform_matrix_scale (GimpMatrix3 *matrix,
 
137
                             gint         x,
121
138
                             gint         y,
122
139
                             gint         width,
123
140
                             gint         height,
124
141
                             gdouble      t_x,
125
142
                             gdouble      t_y,
126
143
                             gdouble      t_width,
127
 
                             gdouble      t_height,
128
 
                             GimpMatrix3 *result)
 
144
                             gdouble      t_height)
129
145
{
130
146
  gdouble scale_x = 1.0;
131
147
  gdouble scale_y = 1.0;
132
148
 
133
 
  g_return_if_fail (result != NULL);
 
149
  g_return_if_fail (matrix != NULL);
134
150
 
135
151
  if (width > 0)
136
152
    scale_x = t_width / (gdouble) width;
138
154
  if (height > 0)
139
155
    scale_y = t_height / (gdouble) height;
140
156
 
141
 
  gimp_matrix3_identity  (result);
142
 
  gimp_matrix3_translate (result, -x, -y);
143
 
  gimp_matrix3_scale     (result, scale_x, scale_y);
144
 
  gimp_matrix3_translate (result, t_x, t_y);
 
157
  gimp_matrix3_identity  (matrix);
 
158
  gimp_matrix3_translate (matrix, -x, -y);
 
159
  gimp_matrix3_scale     (matrix, scale_x, scale_y);
 
160
  gimp_matrix3_translate (matrix, t_x, t_y);
145
161
}
146
162
 
147
163
void
148
 
gimp_transform_matrix_shear (gint                 x,
 
164
gimp_transform_matrix_shear (GimpMatrix3         *matrix,
 
165
                             gint                 x,
149
166
                             gint                 y,
150
167
                             gint                 width,
151
168
                             gint                 height,
152
169
                             GimpOrientationType  orientation,
153
 
                             gdouble              amount,
154
 
                             GimpMatrix3         *result)
 
170
                             gdouble              amount)
155
171
{
156
172
  gdouble center_x;
157
173
  gdouble center_y;
158
174
 
159
 
  g_return_if_fail (result != NULL);
 
175
  g_return_if_fail (matrix != NULL);
160
176
 
161
177
  if (width == 0)
162
178
    width = 1;
167
183
  center_x = (gdouble) x + (gdouble) width  / 2.0;
168
184
  center_y = (gdouble) y + (gdouble) height / 2.0;
169
185
 
170
 
  gimp_matrix3_identity  (result);
171
 
  gimp_matrix3_translate (result, -center_x, -center_y);
 
186
  gimp_matrix3_identity  (matrix);
 
187
  gimp_matrix3_translate (matrix, -center_x, -center_y);
172
188
 
173
189
  if (orientation == GIMP_ORIENTATION_HORIZONTAL)
174
 
    gimp_matrix3_xshear (result, amount / height);
 
190
    gimp_matrix3_xshear (matrix, amount / height);
175
191
  else
176
 
    gimp_matrix3_yshear (result, amount / width);
 
192
    gimp_matrix3_yshear (matrix, amount / width);
177
193
 
178
 
  gimp_matrix3_translate (result, +center_x, +center_y);
 
194
  gimp_matrix3_translate (matrix, +center_x, +center_y);
179
195
}
180
196
 
181
197
void
182
 
gimp_transform_matrix_perspective (gint         x,
 
198
gimp_transform_matrix_perspective (GimpMatrix3 *matrix,
 
199
                                   gint         x,
183
200
                                   gint         y,
184
201
                                   gint         width,
185
202
                                   gint         height,
190
207
                                   gdouble      t_x3,
191
208
                                   gdouble      t_y3,
192
209
                                   gdouble      t_x4,
193
 
                                   gdouble      t_y4,
194
 
                                   GimpMatrix3 *result)
 
210
                                   gdouble      t_y4)
195
211
{
196
 
  GimpMatrix3 matrix;
 
212
  GimpMatrix3 trafo;
197
213
  gdouble     scalex;
198
214
  gdouble     scaley;
199
215
 
200
 
  g_return_if_fail (result != NULL);
 
216
  g_return_if_fail (matrix != NULL);
201
217
 
202
218
  scalex = scaley = 1.0;
203
219
 
207
223
  if (height > 0)
208
224
    scaley = 1.0 / (gdouble) height;
209
225
 
 
226
  gimp_matrix3_translate (matrix, -x, -y);
 
227
  gimp_matrix3_scale     (matrix, scalex, scaley);
 
228
 
210
229
  /* Determine the perspective transform that maps from
211
230
   * the unit cube to the transformed coordinates
212
231
   */
224
243
    /*  Is the mapping affine?  */
225
244
    if ((dx3 == 0.0) && (dy3 == 0.0))
226
245
      {
227
 
        matrix.coeff[0][0] = t_x2 - t_x1;
228
 
        matrix.coeff[0][1] = t_x4 - t_x2;
229
 
        matrix.coeff[0][2] = t_x1;
230
 
        matrix.coeff[1][0] = t_y2 - t_y1;
231
 
        matrix.coeff[1][1] = t_y4 - t_y2;
232
 
        matrix.coeff[1][2] = t_y1;
233
 
        matrix.coeff[2][0] = 0.0;
234
 
        matrix.coeff[2][1] = 0.0;
 
246
        trafo.coeff[0][0] = t_x2 - t_x1;
 
247
        trafo.coeff[0][1] = t_x4 - t_x2;
 
248
        trafo.coeff[0][2] = t_x1;
 
249
        trafo.coeff[1][0] = t_y2 - t_y1;
 
250
        trafo.coeff[1][1] = t_y4 - t_y2;
 
251
        trafo.coeff[1][2] = t_y1;
 
252
        trafo.coeff[2][0] = 0.0;
 
253
        trafo.coeff[2][1] = 0.0;
235
254
      }
236
255
    else
237
256
      {
240
259
        det1 = dx3 * dy2 - dy3 * dx2;
241
260
        det2 = dx1 * dy2 - dy1 * dx2;
242
261
 
243
 
        if (det1 == 0.0 && det2 == 0.0)
244
 
          matrix.coeff[2][0] = 1.0;
245
 
        else
246
 
          matrix.coeff[2][0] = det1 / det2;
 
262
        trafo.coeff[2][0] = (det2 == 0.0) ? 1.0 : det1 / det2;
247
263
 
248
264
        det1 = dx1 * dy3 - dy1 * dx3;
249
265
 
250
 
        if (det1 == 0.0 && det2 == 0.0)
251
 
          matrix.coeff[2][1] = 1.0;
252
 
        else
253
 
          matrix.coeff[2][1] = det1 / det2;
254
 
 
255
 
        matrix.coeff[0][0] = t_x2 - t_x1 + matrix.coeff[2][0] * t_x2;
256
 
        matrix.coeff[0][1] = t_x3 - t_x1 + matrix.coeff[2][1] * t_x3;
257
 
        matrix.coeff[0][2] = t_x1;
258
 
 
259
 
        matrix.coeff[1][0] = t_y2 - t_y1 + matrix.coeff[2][0] * t_y2;
260
 
        matrix.coeff[1][1] = t_y3 - t_y1 + matrix.coeff[2][1] * t_y3;
261
 
        matrix.coeff[1][2] = t_y1;
 
266
        trafo.coeff[2][1] = (det2 == 0.0) ? 1.0 : det1 / det2;
 
267
 
 
268
        trafo.coeff[0][0] = t_x2 - t_x1 + trafo.coeff[2][0] * t_x2;
 
269
        trafo.coeff[0][1] = t_x3 - t_x1 + trafo.coeff[2][1] * t_x3;
 
270
        trafo.coeff[0][2] = t_x1;
 
271
 
 
272
        trafo.coeff[1][0] = t_y2 - t_y1 + trafo.coeff[2][0] * t_y2;
 
273
        trafo.coeff[1][1] = t_y3 - t_y1 + trafo.coeff[2][1] * t_y3;
 
274
        trafo.coeff[1][2] = t_y1;
262
275
      }
263
276
 
264
 
    matrix.coeff[2][2] = 1.0;
 
277
    trafo.coeff[2][2] = 1.0;
265
278
  }
266
279
 
267
 
  gimp_matrix3_identity  (result);
268
 
  gimp_matrix3_translate (result, -x, -y);
269
 
  gimp_matrix3_scale     (result, scalex, scaley);
270
 
  gimp_matrix3_mult      (&matrix, result);
 
280
  gimp_matrix3_mult (&trafo, matrix);
271
281
}