~ubuntu-branches/ubuntu/maverick/gimp/maverick-updates

« back to all changes in this revision

Viewing changes to app/composite/gimp-composite-mmx-test.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2005-12-09 19:44:52 UTC
  • Revision ID: james.westby@ubuntu.com-20051209194452-yggpemjlofpjqyf4
Tags: upstream-2.2.9
ImportĀ upstreamĀ versionĀ 2.2.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "config.h"
 
2
 
 
3
#include <stdio.h>
 
4
#include <stdlib.h>
 
5
#include <string.h>
 
6
 
 
7
#include <sys/time.h>
 
8
 
 
9
#include <glib-object.h>
 
10
 
 
11
#include "base/base-types.h"
 
12
 
 
13
#include "gimp-composite.h"
 
14
#include "gimp-composite-regression.h"
 
15
#include "gimp-composite-util.h"
 
16
#include "gimp-composite-generic.h"
 
17
#include "gimp-composite-mmx.h"
 
18
 
 
19
int
 
20
gimp_composite_mmx_test (int iterations, int n_pixels)
 
21
{
 
22
#if defined(COMPILE_MMX_IS_OKAY)
 
23
  GimpCompositeContext generic_ctx;
 
24
  GimpCompositeContext special_ctx;
 
25
  double ft0;
 
26
  double ft1;
 
27
  gimp_rgba8_t *rgba8D1;
 
28
  gimp_rgba8_t *rgba8D2;
 
29
  gimp_rgba8_t *rgba8A;
 
30
  gimp_rgba8_t *rgba8B;
 
31
  gimp_rgba8_t *rgba8M;
 
32
  gimp_va8_t *va8A;
 
33
  gimp_va8_t *va8B;
 
34
  gimp_va8_t *va8M;
 
35
  gimp_va8_t *va8D1;
 
36
  gimp_va8_t *va8D2;
 
37
  int i;
 
38
 
 
39
  printf("\nRunning gimp_composite_mmx tests...\n");
 
40
  if (gimp_composite_mmx_init () == 0)
 
41
    {
 
42
      printf("gimp_composite_mmx: Instruction set is not available.\n");
 
43
      return (0);
 
44
    }
 
45
 
 
46
  rgba8A =  gimp_composite_regression_random_rgba8(n_pixels+1);
 
47
  rgba8B =  gimp_composite_regression_random_rgba8(n_pixels+1);
 
48
  rgba8M =  gimp_composite_regression_random_rgba8(n_pixels+1);
 
49
  rgba8D1 = (gimp_rgba8_t *) calloc(sizeof(gimp_rgba8_t), n_pixels+1);
 
50
  rgba8D2 = (gimp_rgba8_t *) calloc(sizeof(gimp_rgba8_t), n_pixels+1);
 
51
  va8A =    (gimp_va8_t *)   calloc(sizeof(gimp_va8_t), n_pixels+1);
 
52
  va8B =    (gimp_va8_t *)   calloc(sizeof(gimp_va8_t), n_pixels+1);
 
53
  va8M =    (gimp_va8_t *)   calloc(sizeof(gimp_va8_t), n_pixels+1);
 
54
  va8D1 =   (gimp_va8_t *)   calloc(sizeof(gimp_va8_t), n_pixels+1);
 
55
  va8D2 =   (gimp_va8_t *)   calloc(sizeof(gimp_va8_t), n_pixels+1);
 
56
 
 
57
  for (i = 0; i < n_pixels; i++)
 
58
    {
 
59
      va8A[i].v = i;
 
60
      va8A[i].a = 255-i;
 
61
      va8B[i].v = i;
 
62
      va8B[i].a = i;
 
63
      va8M[i].v = i;
 
64
      va8M[i].a = i;
 
65
    }
 
66
 
 
67
#if 0
 
68
  gimp_composite_context_init (&special_ctx, GIMP_COMPOSITE_ADDITION, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D2);
 
69
  gimp_composite_context_init (&generic_ctx, GIMP_COMPOSITE_ADDITION, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D1);
 
70
  ft0 = gimp_composite_regression_time_function (iterations, gimp_composite_dispatch, &generic_ctx);
 
71
  ft1 = gimp_composite_regression_time_function (iterations, gimp_composite_addition_rgba8_rgba8_rgba8_mmx, &special_ctx);
 
72
  if (gimp_composite_regression_compare_contexts ("addition", &generic_ctx, &special_ctx))
 
73
    {
 
74
      printf("addition_rgba8_rgba8_rgba8 failed\n");
 
75
      return (1);
 
76
    }
 
77
  gimp_composite_regression_timer_report ("addition_rgba8_rgba8_rgba8", ft0, ft1);
 
78
#endif
 
79
 
 
80
  gimp_composite_context_init (&special_ctx, GIMP_COMPOSITE_BURN, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D2);
 
81
  gimp_composite_context_init (&generic_ctx, GIMP_COMPOSITE_BURN, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D1);
 
82
  ft0 = gimp_composite_regression_time_function (iterations, gimp_composite_dispatch, &generic_ctx);
 
83
  ft1 = gimp_composite_regression_time_function (iterations, gimp_composite_burn_rgba8_rgba8_rgba8_mmx, &special_ctx);
 
84
  if (gimp_composite_regression_compare_contexts ("burn", &generic_ctx, &special_ctx))
 
85
    {
 
86
      printf("burn_rgba8_rgba8_rgba8 failed\n");
 
87
      return (1);
 
88
    }
 
89
  gimp_composite_regression_timer_report ("burn_rgba8_rgba8_rgba8", ft0, ft1);
 
90
 
 
91
  gimp_composite_context_init (&special_ctx, GIMP_COMPOSITE_DARKEN, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D2);
 
92
  gimp_composite_context_init (&generic_ctx, GIMP_COMPOSITE_DARKEN, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D1);
 
93
  ft0 = gimp_composite_regression_time_function (iterations, gimp_composite_dispatch, &generic_ctx);
 
94
  ft1 = gimp_composite_regression_time_function (iterations, gimp_composite_darken_rgba8_rgba8_rgba8_mmx, &special_ctx);
 
95
  if (gimp_composite_regression_compare_contexts ("darken", &generic_ctx, &special_ctx))
 
96
    {
 
97
      printf("darken_rgba8_rgba8_rgba8 failed\n");
 
98
      return (1);
 
99
    }
 
100
  gimp_composite_regression_timer_report ("darken_rgba8_rgba8_rgba8", ft0, ft1);
 
101
 
 
102
  gimp_composite_context_init (&special_ctx, GIMP_COMPOSITE_DIFFERENCE, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D2);
 
103
  gimp_composite_context_init (&generic_ctx, GIMP_COMPOSITE_DIFFERENCE, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D1);
 
104
  ft0 = gimp_composite_regression_time_function (iterations, gimp_composite_dispatch, &generic_ctx);
 
105
  ft1 = gimp_composite_regression_time_function (iterations, gimp_composite_difference_rgba8_rgba8_rgba8_mmx, &special_ctx);
 
106
  if (gimp_composite_regression_compare_contexts ("difference", &generic_ctx, &special_ctx))
 
107
    {
 
108
      printf("difference_rgba8_rgba8_rgba8 failed\n");
 
109
      return (1);
 
110
    }
 
111
  gimp_composite_regression_timer_report ("difference_rgba8_rgba8_rgba8", ft0, ft1);
 
112
 
 
113
  gimp_composite_context_init (&special_ctx, GIMP_COMPOSITE_GRAIN_EXTRACT, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D2);
 
114
  gimp_composite_context_init (&generic_ctx, GIMP_COMPOSITE_GRAIN_EXTRACT, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D1);
 
115
  ft0 = gimp_composite_regression_time_function (iterations, gimp_composite_dispatch, &generic_ctx);
 
116
  ft1 = gimp_composite_regression_time_function (iterations, gimp_composite_grain_extract_rgba8_rgba8_rgba8_mmx, &special_ctx);
 
117
  if (gimp_composite_regression_compare_contexts ("grain_extract", &generic_ctx, &special_ctx))
 
118
    {
 
119
      printf("grain_extract_rgba8_rgba8_rgba8 failed\n");
 
120
      return (1);
 
121
    }
 
122
  gimp_composite_regression_timer_report ("grain_extract_rgba8_rgba8_rgba8", ft0, ft1);
 
123
 
 
124
  gimp_composite_context_init (&special_ctx, GIMP_COMPOSITE_GRAIN_MERGE, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D2);
 
125
  gimp_composite_context_init (&generic_ctx, GIMP_COMPOSITE_GRAIN_MERGE, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D1);
 
126
  ft0 = gimp_composite_regression_time_function (iterations, gimp_composite_dispatch, &generic_ctx);
 
127
  ft1 = gimp_composite_regression_time_function (iterations, gimp_composite_grain_merge_rgba8_rgba8_rgba8_mmx, &special_ctx);
 
128
  if (gimp_composite_regression_compare_contexts ("grain_merge", &generic_ctx, &special_ctx))
 
129
    {
 
130
      printf("grain_merge_rgba8_rgba8_rgba8 failed\n");
 
131
      return (1);
 
132
    }
 
133
  gimp_composite_regression_timer_report ("grain_merge_rgba8_rgba8_rgba8", ft0, ft1);
 
134
 
 
135
  gimp_composite_context_init (&special_ctx, GIMP_COMPOSITE_LIGHTEN, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D2);
 
136
  gimp_composite_context_init (&generic_ctx, GIMP_COMPOSITE_LIGHTEN, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D1);
 
137
  ft0 = gimp_composite_regression_time_function (iterations, gimp_composite_dispatch, &generic_ctx);
 
138
  ft1 = gimp_composite_regression_time_function (iterations, gimp_composite_lighten_rgba8_rgba8_rgba8_mmx, &special_ctx);
 
139
  if (gimp_composite_regression_compare_contexts ("lighten", &generic_ctx, &special_ctx))
 
140
    {
 
141
      printf("lighten_rgba8_rgba8_rgba8 failed\n");
 
142
      return (1);
 
143
    }
 
144
  gimp_composite_regression_timer_report ("lighten_rgba8_rgba8_rgba8", ft0, ft1);
 
145
 
 
146
  gimp_composite_context_init (&special_ctx, GIMP_COMPOSITE_MULTIPLY, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D2);
 
147
  gimp_composite_context_init (&generic_ctx, GIMP_COMPOSITE_MULTIPLY, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D1);
 
148
  ft0 = gimp_composite_regression_time_function (iterations, gimp_composite_dispatch, &generic_ctx);
 
149
  ft1 = gimp_composite_regression_time_function (iterations, gimp_composite_multiply_rgba8_rgba8_rgba8_mmx, &special_ctx);
 
150
  if (gimp_composite_regression_compare_contexts ("multiply", &generic_ctx, &special_ctx))
 
151
    {
 
152
      printf("multiply_rgba8_rgba8_rgba8 failed\n");
 
153
      return (1);
 
154
    }
 
155
  gimp_composite_regression_timer_report ("multiply_rgba8_rgba8_rgba8", ft0, ft1);
 
156
 
 
157
  gimp_composite_context_init (&special_ctx, GIMP_COMPOSITE_SCALE, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D2);
 
158
  gimp_composite_context_init (&generic_ctx, GIMP_COMPOSITE_SCALE, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D1);
 
159
  ft0 = gimp_composite_regression_time_function (iterations, gimp_composite_dispatch, &generic_ctx);
 
160
  ft1 = gimp_composite_regression_time_function (iterations, gimp_composite_scale_rgba8_rgba8_rgba8_mmx, &special_ctx);
 
161
  if (gimp_composite_regression_compare_contexts ("scale", &generic_ctx, &special_ctx))
 
162
    {
 
163
      printf("scale_rgba8_rgba8_rgba8 failed\n");
 
164
      return (1);
 
165
    }
 
166
  gimp_composite_regression_timer_report ("scale_rgba8_rgba8_rgba8", ft0, ft1);
 
167
 
 
168
  gimp_composite_context_init (&special_ctx, GIMP_COMPOSITE_SCREEN, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D2);
 
169
  gimp_composite_context_init (&generic_ctx, GIMP_COMPOSITE_SCREEN, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D1);
 
170
  ft0 = gimp_composite_regression_time_function (iterations, gimp_composite_dispatch, &generic_ctx);
 
171
  ft1 = gimp_composite_regression_time_function (iterations, gimp_composite_screen_rgba8_rgba8_rgba8_mmx, &special_ctx);
 
172
  if (gimp_composite_regression_compare_contexts ("screen", &generic_ctx, &special_ctx))
 
173
    {
 
174
      printf("screen_rgba8_rgba8_rgba8 failed\n");
 
175
      return (1);
 
176
    }
 
177
  gimp_composite_regression_timer_report ("screen_rgba8_rgba8_rgba8", ft0, ft1);
 
178
 
 
179
  gimp_composite_context_init (&special_ctx, GIMP_COMPOSITE_SUBTRACT, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D2);
 
180
  gimp_composite_context_init (&generic_ctx, GIMP_COMPOSITE_SUBTRACT, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D1);
 
181
  ft0 = gimp_composite_regression_time_function (iterations, gimp_composite_dispatch, &generic_ctx);
 
182
  ft1 = gimp_composite_regression_time_function (iterations, gimp_composite_subtract_rgba8_rgba8_rgba8_mmx, &special_ctx);
 
183
  if (gimp_composite_regression_compare_contexts ("subtract", &generic_ctx, &special_ctx))
 
184
    {
 
185
      printf("subtract_rgba8_rgba8_rgba8 failed\n");
 
186
      return (1);
 
187
    }
 
188
  gimp_composite_regression_timer_report ("subtract_rgba8_rgba8_rgba8", ft0, ft1);
 
189
 
 
190
  gimp_composite_context_init (&special_ctx, GIMP_COMPOSITE_SWAP, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D2);
 
191
  gimp_composite_context_init (&generic_ctx, GIMP_COMPOSITE_SWAP, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D1);
 
192
  ft0 = gimp_composite_regression_time_function (iterations, gimp_composite_dispatch, &generic_ctx);
 
193
  ft1 = gimp_composite_regression_time_function (iterations, gimp_composite_swap_rgba8_rgba8_rgba8_mmx, &special_ctx);
 
194
  if (gimp_composite_regression_compare_contexts ("swap", &generic_ctx, &special_ctx))
 
195
    {
 
196
      printf("swap_rgba8_rgba8_rgba8 failed\n");
 
197
      return (1);
 
198
    }
 
199
  gimp_composite_regression_timer_report ("swap_rgba8_rgba8_rgba8", ft0, ft1);
 
200
#endif
 
201
  return (0);
 
202
}
 
203
 
 
204
int
 
205
main (int argc, char *argv[])
 
206
{
 
207
  int iterations;
 
208
  int n_pixels;
 
209
 
 
210
  srand (314159);
 
211
 
 
212
  putenv ("GIMP_COMPOSITE=0x1");
 
213
 
 
214
  iterations = 10;
 
215
  n_pixels = 8388625;
 
216
 
 
217
  argv++, argc--;
 
218
  while (argc >= 2)
 
219
    {
 
220
      if (argc > 1 && (strcmp (argv[0], "--iterations") == 0 || strcmp (argv[0], "-i") == 0))
 
221
        {
 
222
          iterations = atoi(argv[1]);
 
223
          argc -= 2, argv++; argv++;
 
224
        }
 
225
      else if (argc > 1 && (strcmp (argv[0], "--n-pixels") == 0 || strcmp (argv[0], "-n") == 0))
 
226
        {
 
227
          n_pixels = atoi (argv[1]);
 
228
          argc -= 2, argv++; argv++;
 
229
        }
 
230
      else
 
231
        {
 
232
          printf("Usage: gimp-composites-*-test [-i|--iterations n] [-n|--n-pixels n]");
 
233
          exit(1);
 
234
        }
 
235
    }
 
236
 
 
237
  gimp_composite_generic_install ();
 
238
 
 
239
  return (gimp_composite_mmx_test (iterations, n_pixels));
 
240
}