~ubuntu-branches/ubuntu/hoary/gimp/hoary

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2005-04-04 14:51:23 UTC
  • Revision ID: james.westby@ubuntu.com-20050404145123-9py049eeelfymur8
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

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-sse.h"
 
18
 
 
19
int
 
20
gimp_composite_sse_test (int iterations, int n_pixels)
 
21
{
 
22
#if defined(COMPILE_SSE_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_sse tests...\n");
 
40
  if (gimp_composite_sse_init () == 0)
 
41
    {
 
42
      printf("gimp_composite_sse: 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
 
 
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_sse, &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
 
 
79
  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);
 
80
  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);
 
81
  ft0 = gimp_composite_regression_time_function (iterations, gimp_composite_dispatch, &generic_ctx);
 
82
  ft1 = gimp_composite_regression_time_function (iterations, gimp_composite_burn_rgba8_rgba8_rgba8_sse, &special_ctx);
 
83
  if (gimp_composite_regression_compare_contexts ("burn", &generic_ctx, &special_ctx))
 
84
    {
 
85
      printf("burn_rgba8_rgba8_rgba8 failed\n");
 
86
      return (1);
 
87
    }
 
88
  gimp_composite_regression_timer_report ("burn_rgba8_rgba8_rgba8", ft0, ft1);
 
89
 
 
90
  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);
 
91
  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);
 
92
  ft0 = gimp_composite_regression_time_function (iterations, gimp_composite_dispatch, &generic_ctx);
 
93
  ft1 = gimp_composite_regression_time_function (iterations, gimp_composite_darken_rgba8_rgba8_rgba8_sse, &special_ctx);
 
94
  if (gimp_composite_regression_compare_contexts ("darken", &generic_ctx, &special_ctx))
 
95
    {
 
96
      printf("darken_rgba8_rgba8_rgba8 failed\n");
 
97
      return (1);
 
98
    }
 
99
  gimp_composite_regression_timer_report ("darken_rgba8_rgba8_rgba8", ft0, ft1);
 
100
 
 
101
  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);
 
102
  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);
 
103
  ft0 = gimp_composite_regression_time_function (iterations, gimp_composite_dispatch, &generic_ctx);
 
104
  ft1 = gimp_composite_regression_time_function (iterations, gimp_composite_difference_rgba8_rgba8_rgba8_sse, &special_ctx);
 
105
  if (gimp_composite_regression_compare_contexts ("difference", &generic_ctx, &special_ctx))
 
106
    {
 
107
      printf("difference_rgba8_rgba8_rgba8 failed\n");
 
108
      return (1);
 
109
    }
 
110
  gimp_composite_regression_timer_report ("difference_rgba8_rgba8_rgba8", ft0, ft1);
 
111
 
 
112
  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);
 
113
  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);
 
114
  ft0 = gimp_composite_regression_time_function (iterations, gimp_composite_dispatch, &generic_ctx);
 
115
  ft1 = gimp_composite_regression_time_function (iterations, gimp_composite_grain_extract_rgba8_rgba8_rgba8_sse, &special_ctx);
 
116
  if (gimp_composite_regression_compare_contexts ("grain_extract", &generic_ctx, &special_ctx))
 
117
    {
 
118
      printf("grain_extract_rgba8_rgba8_rgba8 failed\n");
 
119
      return (1);
 
120
    }
 
121
  gimp_composite_regression_timer_report ("grain_extract_rgba8_rgba8_rgba8", ft0, ft1);
 
122
 
 
123
  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);
 
124
  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);
 
125
  ft0 = gimp_composite_regression_time_function (iterations, gimp_composite_dispatch, &generic_ctx);
 
126
  ft1 = gimp_composite_regression_time_function (iterations, gimp_composite_grain_merge_rgba8_rgba8_rgba8_sse, &special_ctx);
 
127
  if (gimp_composite_regression_compare_contexts ("grain_merge", &generic_ctx, &special_ctx))
 
128
    {
 
129
      printf("grain_merge_rgba8_rgba8_rgba8 failed\n");
 
130
      return (1);
 
131
    }
 
132
  gimp_composite_regression_timer_report ("grain_merge_rgba8_rgba8_rgba8", ft0, ft1);
 
133
 
 
134
  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);
 
135
  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);
 
136
  ft0 = gimp_composite_regression_time_function (iterations, gimp_composite_dispatch, &generic_ctx);
 
137
  ft1 = gimp_composite_regression_time_function (iterations, gimp_composite_lighten_rgba8_rgba8_rgba8_sse, &special_ctx);
 
138
  if (gimp_composite_regression_compare_contexts ("lighten", &generic_ctx, &special_ctx))
 
139
    {
 
140
      printf("lighten_rgba8_rgba8_rgba8 failed\n");
 
141
      return (1);
 
142
    }
 
143
  gimp_composite_regression_timer_report ("lighten_rgba8_rgba8_rgba8", ft0, ft1);
 
144
 
 
145
  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);
 
146
  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);
 
147
  ft0 = gimp_composite_regression_time_function (iterations, gimp_composite_dispatch, &generic_ctx);
 
148
  ft1 = gimp_composite_regression_time_function (iterations, gimp_composite_multiply_rgba8_rgba8_rgba8_sse, &special_ctx);
 
149
  if (gimp_composite_regression_compare_contexts ("multiply", &generic_ctx, &special_ctx))
 
150
    {
 
151
      printf("multiply_rgba8_rgba8_rgba8 failed\n");
 
152
      return (1);
 
153
    }
 
154
  gimp_composite_regression_timer_report ("multiply_rgba8_rgba8_rgba8", ft0, ft1);
 
155
 
 
156
  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);
 
157
  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);
 
158
  ft0 = gimp_composite_regression_time_function (iterations, gimp_composite_dispatch, &generic_ctx);
 
159
  ft1 = gimp_composite_regression_time_function (iterations, gimp_composite_scale_rgba8_rgba8_rgba8_sse, &special_ctx);
 
160
  if (gimp_composite_regression_compare_contexts ("scale", &generic_ctx, &special_ctx))
 
161
    {
 
162
      printf("scale_rgba8_rgba8_rgba8 failed\n");
 
163
      return (1);
 
164
    }
 
165
  gimp_composite_regression_timer_report ("scale_rgba8_rgba8_rgba8", ft0, ft1);
 
166
 
 
167
  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);
 
168
  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);
 
169
  ft0 = gimp_composite_regression_time_function (iterations, gimp_composite_dispatch, &generic_ctx);
 
170
  ft1 = gimp_composite_regression_time_function (iterations, gimp_composite_screen_rgba8_rgba8_rgba8_sse, &special_ctx);
 
171
  if (gimp_composite_regression_compare_contexts ("screen", &generic_ctx, &special_ctx))
 
172
    {
 
173
      printf("screen_rgba8_rgba8_rgba8 failed\n");
 
174
      return (1);
 
175
    }
 
176
  gimp_composite_regression_timer_report ("screen_rgba8_rgba8_rgba8", ft0, ft1);
 
177
 
 
178
  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);
 
179
  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);
 
180
  ft0 = gimp_composite_regression_time_function (iterations, gimp_composite_dispatch, &generic_ctx);
 
181
  ft1 = gimp_composite_regression_time_function (iterations, gimp_composite_subtract_rgba8_rgba8_rgba8_sse, &special_ctx);
 
182
  if (gimp_composite_regression_compare_contexts ("subtract", &generic_ctx, &special_ctx))
 
183
    {
 
184
      printf("subtract_rgba8_rgba8_rgba8 failed\n");
 
185
      return (1);
 
186
    }
 
187
  gimp_composite_regression_timer_report ("subtract_rgba8_rgba8_rgba8", ft0, ft1);
 
188
 
 
189
  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);
 
190
  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);
 
191
  ft0 = gimp_composite_regression_time_function (iterations, gimp_composite_dispatch, &generic_ctx);
 
192
  ft1 = gimp_composite_regression_time_function (iterations, gimp_composite_swap_rgba8_rgba8_rgba8_sse, &special_ctx);
 
193
  if (gimp_composite_regression_compare_contexts ("swap", &generic_ctx, &special_ctx))
 
194
    {
 
195
      printf("swap_rgba8_rgba8_rgba8 failed\n");
 
196
      return (1);
 
197
    }
 
198
  gimp_composite_regression_timer_report ("swap_rgba8_rgba8_rgba8", ft0, ft1);
 
199
#endif
 
200
  return (0);
 
201
}
 
202
 
 
203
int
 
204
main (int argc, char *argv[])
 
205
{
 
206
  int iterations;
 
207
  int n_pixels;
 
208
 
 
209
  srand (314159);
 
210
 
 
211
  putenv ("GIMP_COMPOSITE=0x1");
 
212
 
 
213
  iterations = 10;
 
214
  n_pixels = 8388625;
 
215
 
 
216
  argv++, argc--;
 
217
  while (argc >= 2)
 
218
    {
 
219
      if (argc > 1 && (strcmp (argv[0], "--iterations") == 0 || strcmp (argv[0], "-i") == 0))
 
220
        {
 
221
          iterations = atoi(argv[1]);
 
222
          argc -= 2, argv++; argv++;
 
223
        }
 
224
      else if (argc > 1 && (strcmp (argv[0], "--n-pixels") == 0 || strcmp (argv[0], "-n") == 0))
 
225
        {
 
226
          n_pixels = atoi (argv[1]);
 
227
          argc -= 2, argv++; argv++;
 
228
        }
 
229
      else
 
230
        {
 
231
          printf("Usage: gimp-composites-*-test [-i|--iterations n] [-n|--n-pixels n]");
 
232
          exit(1);
 
233
        }
 
234
    }
 
235
 
 
236
  gimp_composite_generic_install ();
 
237
 
 
238
  return (gimp_composite_sse_test (iterations, n_pixels));
 
239
}