Coverage Report

Created: 2025-07-07 10:01

/work/workdir/UnpackedTarball/pixman/pixman/pixman-image.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright © 2000 SuSE, Inc.
3
 * Copyright © 2007 Red Hat, Inc.
4
 *
5
 * Permission to use, copy, modify, distribute, and sell this software and its
6
 * documentation for any purpose is hereby granted without fee, provided that
7
 * the above copyright notice appear in all copies and that both that
8
 * copyright notice and this permission notice appear in supporting
9
 * documentation, and that the name of SuSE not be used in advertising or
10
 * publicity pertaining to distribution of the software without specific,
11
 * written prior permission.  SuSE makes no representations about the
12
 * suitability of this software for any purpose.  It is provided "as is"
13
 * without express or implied warranty.
14
 *
15
 * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
16
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE
17
 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
19
 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21
 */
22
23
#ifdef HAVE_CONFIG_H
24
#include <config.h>
25
#endif
26
27
#include <stdlib.h>
28
#include <stdio.h>
29
#include <string.h>
30
#include <assert.h>
31
32
#include "pixman-private.h"
33
34
static const pixman_color_t transparent_black = { 0, 0, 0, 0 };
35
36
static void
37
gradient_property_changed (pixman_image_t *image)
38
3.06k
{
39
3.06k
    gradient_t *gradient = &image->gradient;
40
3.06k
    int n = gradient->n_stops;
41
3.06k
    pixman_gradient_stop_t *stops = gradient->stops;
42
3.06k
    pixman_gradient_stop_t *begin = &(gradient->stops[-1]);
43
3.06k
    pixman_gradient_stop_t *end = &(gradient->stops[n]);
44
45
3.06k
    switch (gradient->common.repeat)
46
3.06k
    {
47
0
    default:
48
0
    case PIXMAN_REPEAT_NONE:
49
0
  begin->x = INT32_MIN;
50
0
  begin->color = transparent_black;
51
0
  end->x = INT32_MAX;
52
0
  end->color = transparent_black;
53
0
  break;
54
55
0
    case PIXMAN_REPEAT_NORMAL:
56
0
  begin->x = stops[n - 1].x - pixman_fixed_1;
57
0
  begin->color = stops[n - 1].color;
58
0
  end->x = stops[0].x + pixman_fixed_1;
59
0
  end->color = stops[0].color;
60
0
  break;
61
62
0
    case PIXMAN_REPEAT_REFLECT:
63
0
  begin->x = - stops[0].x;
64
0
  begin->color = stops[0].color;
65
0
  end->x = pixman_int_to_fixed (2) - stops[n - 1].x;
66
0
  end->color = stops[n - 1].color;
67
0
  break;
68
69
3.06k
    case PIXMAN_REPEAT_PAD:
70
3.06k
  begin->x = INT32_MIN;
71
3.06k
  begin->color = stops[0].color;
72
3.06k
  end->x = INT32_MAX;
73
3.06k
  end->color = stops[n - 1].color;
74
3.06k
  break;
75
3.06k
    }
76
3.06k
}
77
78
pixman_bool_t
79
_pixman_init_gradient (gradient_t *                  gradient,
80
                       const pixman_gradient_stop_t *stops,
81
                       int                           n_stops)
82
3.06k
{
83
3.06k
    return_val_if_fail (n_stops > 0, FALSE);
84
85
    /* We allocate two extra stops, one before the beginning of the stop list,
86
     * and one after the end. These stops are initialized to whatever color
87
     * would be used for positions outside the range of the stop list.
88
     *
89
     * This saves a bit of computation in the gradient walker.
90
     *
91
     * The pointer we store in the gradient_t struct still points to the
92
     * first user-supplied struct, so when freeing, we will have to
93
     * subtract one.
94
     */
95
3.06k
    gradient->stops =
96
3.06k
  pixman_malloc_ab (n_stops + 2, sizeof (pixman_gradient_stop_t));
97
3.06k
    if (!gradient->stops)
98
0
  return FALSE;
99
100
3.06k
    gradient->stops += 1;
101
3.06k
    memcpy (gradient->stops, stops, n_stops * sizeof (pixman_gradient_stop_t));
102
3.06k
    gradient->n_stops = n_stops;
103
104
3.06k
    gradient->common.property_changed = gradient_property_changed;
105
106
3.06k
    return TRUE;
107
3.06k
}
108
109
void
110
_pixman_image_init (pixman_image_t *image)
111
4.98M
{
112
4.98M
    image_common_t *common = &image->common;
113
114
4.98M
    pixman_region32_init (&common->clip_region);
115
116
4.98M
    common->alpha_count = 0;
117
4.98M
    common->have_clip_region = FALSE;
118
4.98M
    common->clip_sources = FALSE;
119
4.98M
    common->transform = NULL;
120
4.98M
    common->repeat = PIXMAN_REPEAT_NONE;
121
4.98M
    common->filter = PIXMAN_FILTER_NEAREST;
122
4.98M
    common->filter_params = NULL;
123
4.98M
    common->n_filter_params = 0;
124
4.98M
    common->alpha_map = NULL;
125
4.98M
    common->component_alpha = FALSE;
126
4.98M
    common->ref_count = 1;
127
4.98M
    common->property_changed = NULL;
128
4.98M
    common->client_clip = FALSE;
129
4.98M
    common->destroy_func = NULL;
130
4.98M
    common->destroy_data = NULL;
131
4.98M
    common->dirty = TRUE;
132
4.98M
}
133
134
pixman_bool_t
135
_pixman_image_fini (pixman_image_t *image)
136
2.48M
{
137
2.48M
    image_common_t *common = (image_common_t *)image;
138
139
2.48M
    common->ref_count--;
140
141
2.48M
    if (common->ref_count == 0)
142
2.48M
    {
143
2.48M
  if (image->common.destroy_func)
144
0
      image->common.destroy_func (image, image->common.destroy_data);
145
146
2.48M
  pixman_region32_fini (&common->clip_region);
147
148
2.48M
  free (common->transform);
149
2.48M
  free (common->filter_params);
150
151
2.48M
  if (common->alpha_map)
152
0
      pixman_image_unref ((pixman_image_t *)common->alpha_map);
153
154
2.48M
  if (image->type == LINEAR ||
155
2.48M
      image->type == RADIAL ||
156
2.48M
      image->type == CONICAL)
157
3.06k
  {
158
3.06k
      if (image->gradient.stops)
159
3.06k
      {
160
    /* See _pixman_init_gradient() for an explanation of the - 1 */
161
3.06k
    free (image->gradient.stops - 1);
162
3.06k
      }
163
164
      /* This will trigger if someone adds a property_changed
165
       * method to the linear/radial/conical gradient overwriting
166
       * the general one.
167
       */
168
3.06k
      assert (
169
3.06k
    image->common.property_changed == gradient_property_changed);
170
3.06k
  }
171
172
2.48M
  if (image->type == BITS && image->bits.free_me)
173
2.42M
      free (image->bits.free_me);
174
175
2.48M
  return TRUE;
176
2.48M
    }
177
178
0
    return FALSE;
179
2.48M
}
180
181
pixman_image_t *
182
_pixman_image_allocate (void)
183
2.50M
{
184
2.50M
    pixman_image_t *image = malloc (sizeof (pixman_image_t));
185
186
2.50M
    if (image)
187
2.50M
  _pixman_image_init (image);
188
189
2.50M
    return image;
190
2.50M
}
191
192
static void
193
image_property_changed (pixman_image_t *image)
194
6.84k
{
195
6.84k
    image->common.dirty = TRUE;
196
6.84k
}
197
198
/* Ref Counting */
199
PIXMAN_EXPORT pixman_image_t *
200
pixman_image_ref (pixman_image_t *image)
201
0
{
202
0
    image->common.ref_count++;
203
204
0
    return image;
205
0
}
206
207
/* returns TRUE when the image is freed */
208
PIXMAN_EXPORT pixman_bool_t
209
pixman_image_unref (pixman_image_t *image)
210
2.48M
{
211
2.48M
    if (_pixman_image_fini (image))
212
2.48M
    {
213
2.48M
  free (image);
214
2.48M
  return TRUE;
215
2.48M
    }
216
217
0
    return FALSE;
218
2.48M
}
219
220
PIXMAN_EXPORT void
221
pixman_image_set_destroy_function (pixman_image_t *            image,
222
                                   pixman_image_destroy_func_t func,
223
                                   void *                      data)
224
0
{
225
0
    image->common.destroy_func = func;
226
0
    image->common.destroy_data = data;
227
0
}
228
229
PIXMAN_EXPORT void *
230
pixman_image_get_destroy_data (pixman_image_t *image)
231
0
{
232
0
  return image->common.destroy_data;
233
0
}
234
235
void
236
_pixman_image_reset_clip_region (pixman_image_t *image)
237
2.48M
{
238
2.48M
    image->common.have_clip_region = FALSE;
239
2.48M
}
240
241
/* Executive Summary: This function is a no-op that only exists
242
 * for historical reasons.
243
 *
244
 * There used to be a bug in the X server where it would rely on
245
 * out-of-bounds accesses when it was asked to composite with a
246
 * window as the source. It would create a pixman image pointing
247
 * to some bogus position in memory, but then set a clip region
248
 * to the position where the actual bits were.
249
 *
250
 * Due to a bug in old versions of pixman, where it would not clip
251
 * against the image bounds when a clip region was set, this would
252
 * actually work. So when the pixman bug was fixed, a workaround was
253
 * added to allow certain out-of-bound accesses. This function disabled
254
 * those workarounds.
255
 *
256
 * Since 0.21.2, pixman doesn't do these workarounds anymore, so now
257
 * this function is a no-op.
258
 */
259
PIXMAN_EXPORT void
260
pixman_disable_out_of_bounds_workaround (void)
261
0
{
262
0
}
263
264
static void
265
compute_image_info (pixman_image_t *image)
266
136k
{
267
136k
    pixman_format_code_t code;
268
136k
    uint32_t flags = 0;
269
270
    /* Transform */
271
136k
    if (!image->common.transform)
272
134k
    {
273
134k
  flags |= (FAST_PATH_ID_TRANSFORM  |
274
134k
      FAST_PATH_X_UNIT_POSITIVE  |
275
134k
      FAST_PATH_Y_UNIT_ZERO    |
276
134k
      FAST_PATH_AFFINE_TRANSFORM);
277
134k
    }
278
2.47k
    else
279
2.47k
    {
280
2.47k
  flags |= FAST_PATH_HAS_TRANSFORM;
281
282
2.47k
  if (image->common.transform->matrix[2][0] == 0      &&
283
2.47k
      image->common.transform->matrix[2][1] == 0      &&
284
2.47k
      image->common.transform->matrix[2][2] == pixman_fixed_1)
285
2.47k
  {
286
2.47k
      flags |= FAST_PATH_AFFINE_TRANSFORM;
287
288
2.47k
      if (image->common.transform->matrix[0][1] == 0 &&
289
2.47k
    image->common.transform->matrix[1][0] == 0)
290
2.47k
      {
291
2.47k
    if (image->common.transform->matrix[0][0] == -pixman_fixed_1 &&
292
2.47k
        image->common.transform->matrix[1][1] == -pixman_fixed_1)
293
0
    {
294
0
        flags |= FAST_PATH_ROTATE_180_TRANSFORM;
295
0
    }
296
2.47k
    flags |= FAST_PATH_SCALE_TRANSFORM;
297
2.47k
      }
298
0
      else if (image->common.transform->matrix[0][0] == 0 &&
299
0
               image->common.transform->matrix[1][1] == 0)
300
0
      {
301
0
    pixman_fixed_t m01 = image->common.transform->matrix[0][1];
302
0
    pixman_fixed_t m10 = image->common.transform->matrix[1][0];
303
304
0
    if (m01 == -pixman_fixed_1 && m10 == pixman_fixed_1)
305
0
        flags |= FAST_PATH_ROTATE_90_TRANSFORM;
306
0
    else if (m01 == pixman_fixed_1 && m10 == -pixman_fixed_1)
307
0
        flags |= FAST_PATH_ROTATE_270_TRANSFORM;
308
0
      }
309
2.47k
  }
310
311
2.47k
  if (image->common.transform->matrix[0][0] > 0)
312
2.07k
      flags |= FAST_PATH_X_UNIT_POSITIVE;
313
314
2.47k
  if (image->common.transform->matrix[1][0] == 0)
315
2.47k
      flags |= FAST_PATH_Y_UNIT_ZERO;
316
2.47k
    }
317
318
    /* Filter */
319
136k
    switch (image->common.filter)
320
136k
    {
321
136k
    case PIXMAN_FILTER_NEAREST:
322
136k
    case PIXMAN_FILTER_FAST:
323
136k
  flags |= (FAST_PATH_NEAREST_FILTER | FAST_PATH_NO_CONVOLUTION_FILTER);
324
136k
  break;
325
326
130
    case PIXMAN_FILTER_BILINEAR:
327
130
    case PIXMAN_FILTER_GOOD:
328
130
    case PIXMAN_FILTER_BEST:
329
130
  flags |= (FAST_PATH_BILINEAR_FILTER | FAST_PATH_NO_CONVOLUTION_FILTER);
330
331
  /* Here we have a chance to optimize BILINEAR filter to NEAREST if
332
   * they are equivalent for the currently used transformation matrix.
333
   */
334
130
  if (flags & FAST_PATH_ID_TRANSFORM)
335
0
  {
336
0
      flags |= FAST_PATH_NEAREST_FILTER;
337
0
  }
338
130
  else if (flags & FAST_PATH_AFFINE_TRANSFORM)
339
130
  {
340
      /* Suppose the transform is
341
       *
342
       *    [ t00, t01, t02 ]
343
       *    [ t10, t11, t12 ]
344
       *    [   0,   0,   1 ]
345
       *
346
       * and the destination coordinates are (n + 0.5, m + 0.5). Then
347
       * the transformed x coordinate is:
348
       *
349
       *     tx = t00 * (n + 0.5) + t01 * (m + 0.5) + t02
350
       *        = t00 * n + t01 * m + t02 + (t00 + t01) * 0.5
351
       *
352
       * which implies that if t00, t01 and t02 are all integers
353
       * and (t00 + t01) is odd, then tx will be an integer plus 0.5,
354
       * which means a BILINEAR filter will reduce to NEAREST. The same
355
       * applies in the y direction
356
       */
357
130
      pixman_fixed_t (*t)[3] = image->common.transform->matrix;
358
359
130
      if ((pixman_fixed_frac (
360
130
         t[0][0] | t[0][1] | t[0][2] |
361
130
         t[1][0] | t[1][1] | t[1][2]) == 0)     &&
362
130
    (pixman_fixed_to_int (
363
0
        (t[0][0] + t[0][1]) & (t[1][0] + t[1][1])) % 2) == 1)
364
0
      {
365
    /* FIXME: there are some affine-test failures, showing that
366
     * handling of BILINEAR and NEAREST filter is not quite
367
     * equivalent when getting close to 32K for the translation
368
     * components of the matrix. That's likely some bug, but for
369
     * now just skip BILINEAR->NEAREST optimization in this case.
370
     */
371
0
    pixman_fixed_t magic_limit = pixman_int_to_fixed (30000);
372
0
    if (image->common.transform->matrix[0][2] <= magic_limit  &&
373
0
        image->common.transform->matrix[1][2] <= magic_limit  &&
374
0
        image->common.transform->matrix[0][2] >= -magic_limit &&
375
0
        image->common.transform->matrix[1][2] >= -magic_limit)
376
0
    {
377
0
        flags |= FAST_PATH_NEAREST_FILTER;
378
0
    }
379
0
      }
380
130
  }
381
130
  break;
382
383
0
    case PIXMAN_FILTER_CONVOLUTION:
384
0
  break;
385
386
94
    case PIXMAN_FILTER_SEPARABLE_CONVOLUTION:
387
94
  flags |= FAST_PATH_SEPARABLE_CONVOLUTION_FILTER;
388
94
  break;
389
390
0
    default:
391
0
  flags |= FAST_PATH_NO_CONVOLUTION_FILTER;
392
0
  break;
393
136k
    }
394
395
    /* Repeat mode */
396
136k
    switch (image->common.repeat)
397
136k
    {
398
133k
    case PIXMAN_REPEAT_NONE:
399
133k
  flags |=
400
133k
      FAST_PATH_NO_REFLECT_REPEAT    |
401
133k
      FAST_PATH_NO_PAD_REPEAT    |
402
133k
      FAST_PATH_NO_NORMAL_REPEAT;
403
133k
  break;
404
405
0
    case PIXMAN_REPEAT_REFLECT:
406
0
  flags |=
407
0
      FAST_PATH_NO_PAD_REPEAT    |
408
0
      FAST_PATH_NO_NONE_REPEAT    |
409
0
      FAST_PATH_NO_NORMAL_REPEAT;
410
0
  break;
411
412
3.50k
    case PIXMAN_REPEAT_PAD:
413
3.50k
  flags |=
414
3.50k
      FAST_PATH_NO_REFLECT_REPEAT    |
415
3.50k
      FAST_PATH_NO_NONE_REPEAT    |
416
3.50k
      FAST_PATH_NO_NORMAL_REPEAT;
417
3.50k
  break;
418
419
0
    default:
420
0
  flags |=
421
0
      FAST_PATH_NO_REFLECT_REPEAT    |
422
0
      FAST_PATH_NO_PAD_REPEAT    |
423
0
      FAST_PATH_NO_NONE_REPEAT;
424
0
  break;
425
136k
    }
426
427
    /* Component alpha */
428
136k
    if (image->common.component_alpha)
429
414
  flags |= FAST_PATH_COMPONENT_ALPHA;
430
136k
    else
431
136k
  flags |= FAST_PATH_UNIFIED_ALPHA;
432
433
136k
    flags |= (FAST_PATH_NO_ACCESSORS | FAST_PATH_NARROW_FORMAT);
434
435
    /* Type specific checks */
436
136k
    switch (image->type)
437
136k
    {
438
18.7k
    case SOLID:
439
18.7k
  code = PIXMAN_solid;
440
441
18.7k
  if (image->solid.color.alpha == 0xffff)
442
17.8k
      flags |= FAST_PATH_IS_OPAQUE;
443
18.7k
  break;
444
445
114k
    case BITS:
446
114k
  if (image->bits.width == 1  &&
447
114k
      image->bits.height == 1  &&
448
114k
      image->common.repeat != PIXMAN_REPEAT_NONE)
449
207
  {
450
207
      code = PIXMAN_solid;
451
207
  }
452
114k
  else
453
114k
  {
454
114k
      code = image->bits.format;
455
114k
      flags |= FAST_PATH_BITS_IMAGE;
456
114k
  }
457
458
114k
  if (!PIXMAN_FORMAT_A (image->bits.format)       &&
459
114k
      PIXMAN_FORMAT_TYPE (image->bits.format) != PIXMAN_TYPE_GRAY    &&
460
114k
      PIXMAN_FORMAT_TYPE (image->bits.format) != PIXMAN_TYPE_COLOR)
461
1.45k
  {
462
1.45k
      flags |= FAST_PATH_SAMPLES_OPAQUE;
463
464
1.45k
      if (image->common.repeat != PIXMAN_REPEAT_NONE)
465
41
    flags |= FAST_PATH_IS_OPAQUE;
466
1.45k
  }
467
468
114k
  if (image->bits.read_func || image->bits.write_func)
469
0
      flags &= ~FAST_PATH_NO_ACCESSORS;
470
471
114k
  if (PIXMAN_FORMAT_IS_WIDE (image->bits.format))
472
0
      flags &= ~FAST_PATH_NARROW_FORMAT;
473
114k
  break;
474
475
2.48k
    case RADIAL:
476
2.48k
  code = PIXMAN_unknown;
477
478
  /*
479
   * As explained in pixman-radial-gradient.c, every point of
480
   * the plane has a valid associated radius (and thus will be
481
   * colored) if and only if a is negative (i.e. one of the two
482
   * circles contains the other one).
483
   */
484
485
2.48k
        if (image->radial.a >= 0)
486
0
      break;
487
488
  /* Fall through */
489
490
2.48k
    case CONICAL:
491
3.06k
    case LINEAR:
492
3.06k
  code = PIXMAN_unknown;
493
494
3.06k
  if (image->common.repeat != PIXMAN_REPEAT_NONE)
495
3.06k
  {
496
3.06k
      int i;
497
498
3.06k
      flags |= FAST_PATH_IS_OPAQUE;
499
9.18k
      for (i = 0; i < image->gradient.n_stops; ++i)
500
6.12k
      {
501
6.12k
    if (image->gradient.stops[i].color.alpha != 0xffff)
502
0
    {
503
0
        flags &= ~FAST_PATH_IS_OPAQUE;
504
0
        break;
505
0
    }
506
6.12k
      }
507
3.06k
  }
508
3.06k
  break;
509
510
0
    default:
511
0
  code = PIXMAN_unknown;
512
0
  break;
513
136k
    }
514
515
    /* Alpha maps are only supported for BITS images, so it's always
516
     * safe to ignore their presense for non-BITS images
517
     */
518
136k
    if (!image->common.alpha_map || image->type != BITS)
519
136k
    {
520
136k
  flags |= FAST_PATH_NO_ALPHA_MAP;
521
136k
    }
522
0
    else
523
0
    {
524
0
  if (PIXMAN_FORMAT_IS_WIDE (image->common.alpha_map->format))
525
0
      flags &= ~FAST_PATH_NARROW_FORMAT;
526
0
    }
527
528
    /* Both alpha maps and convolution filters can introduce
529
     * non-opaqueness in otherwise opaque images. Also
530
     * an image with component alpha turned on is only opaque
531
     * if all channels are opaque, so we simply turn it off
532
     * unconditionally for those images.
533
     */
534
136k
    if (image->common.alpha_map            ||
535
136k
  image->common.filter == PIXMAN_FILTER_CONVOLUTION    ||
536
136k
        image->common.filter == PIXMAN_FILTER_SEPARABLE_CONVOLUTION     ||
537
136k
  image->common.component_alpha)
538
508
    {
539
508
  flags &= ~(FAST_PATH_IS_OPAQUE | FAST_PATH_SAMPLES_OPAQUE);
540
508
    }
541
542
136k
    image->common.flags = flags;
543
136k
    image->common.extended_format_code = code;
544
136k
}
545
546
void
547
_pixman_image_validate (pixman_image_t *image)
548
304k
{
549
304k
    if (image->common.dirty)
550
136k
    {
551
136k
  compute_image_info (image);
552
553
  /* It is important that property_changed is
554
   * called *after* compute_image_info() because
555
   * property_changed() can make use of the flags
556
   * to set up accessors etc.
557
   */
558
136k
  if (image->common.property_changed)
559
117k
      image->common.property_changed (image);
560
561
136k
  image->common.dirty = FALSE;
562
136k
    }
563
564
304k
    if (image->common.alpha_map)
565
0
  _pixman_image_validate ((pixman_image_t *)image->common.alpha_map);
566
304k
}
567
568
PIXMAN_EXPORT pixman_bool_t
569
pixman_image_set_clip_region32 (pixman_image_t *   image,
570
                                pixman_region32_t *region)
571
0
{
572
0
    image_common_t *common = (image_common_t *)image;
573
0
    pixman_bool_t result;
574
575
0
    if (region)
576
0
    {
577
0
  if ((result = pixman_region32_copy (&common->clip_region, region)))
578
0
      image->common.have_clip_region = TRUE;
579
0
    }
580
0
    else
581
0
    {
582
0
  _pixman_image_reset_clip_region (image);
583
584
0
  result = TRUE;
585
0
    }
586
587
0
    image_property_changed (image);
588
589
0
    return result;
590
0
}
591
592
PIXMAN_EXPORT pixman_bool_t
593
pixman_image_set_clip_region (pixman_image_t *   image,
594
                              pixman_region16_t *region)
595
0
{
596
0
    image_common_t *common = (image_common_t *)image;
597
0
    pixman_bool_t result;
598
599
0
    if (region)
600
0
    {
601
0
  if ((result = pixman_region32_copy_from_region16 (&common->clip_region, region)))
602
0
      image->common.have_clip_region = TRUE;
603
0
    }
604
0
    else
605
0
    {
606
0
  _pixman_image_reset_clip_region (image);
607
608
0
  result = TRUE;
609
0
    }
610
611
0
    image_property_changed (image);
612
613
0
    return result;
614
0
}
615
616
PIXMAN_EXPORT void
617
pixman_image_set_has_client_clip (pixman_image_t *image,
618
                                  pixman_bool_t   client_clip)
619
0
{
620
0
    image->common.client_clip = client_clip;
621
0
}
622
623
PIXMAN_EXPORT pixman_bool_t
624
pixman_image_set_transform (pixman_image_t *          image,
625
                            const pixman_transform_t *transform)
626
2.70k
{
627
2.70k
    static const pixman_transform_t id =
628
2.70k
    {
629
2.70k
  { { pixman_fixed_1, 0, 0 },
630
2.70k
    { 0, pixman_fixed_1, 0 },
631
2.70k
    { 0, 0, pixman_fixed_1 } }
632
2.70k
    };
633
634
2.70k
    image_common_t *common = (image_common_t *)image;
635
2.70k
    pixman_bool_t result;
636
637
2.70k
    if (common->transform == transform)
638
0
  return TRUE;
639
640
2.70k
    if (!transform || memcmp (&id, transform, sizeof (pixman_transform_t)) == 0)
641
223
    {
642
223
  free (common->transform);
643
223
  common->transform = NULL;
644
223
  result = TRUE;
645
646
223
  goto out;
647
223
    }
648
649
2.47k
    if (common->transform &&
650
2.47k
  memcmp (common->transform, transform, sizeof (pixman_transform_t)) == 0)
651
0
    {
652
0
  return TRUE;
653
0
    }
654
655
2.47k
    if (common->transform == NULL)
656
2.47k
  common->transform = malloc (sizeof (pixman_transform_t));
657
658
2.47k
    if (common->transform == NULL)
659
0
    {
660
0
  result = FALSE;
661
662
0
  goto out;
663
0
    }
664
665
2.47k
    memcpy (common->transform, transform, sizeof(pixman_transform_t));
666
667
2.47k
    result = TRUE;
668
669
2.70k
out:
670
2.70k
    image_property_changed (image);
671
672
2.70k
    return result;
673
2.47k
}
674
675
PIXMAN_EXPORT void
676
pixman_image_set_repeat (pixman_image_t *image,
677
                         pixman_repeat_t repeat)
678
3.50k
{
679
3.50k
    if (image->common.repeat == repeat)
680
0
  return;
681
682
3.50k
    image->common.repeat = repeat;
683
684
3.50k
    image_property_changed (image);
685
3.50k
}
686
687
PIXMAN_EXPORT void
688
pixman_image_set_dither (pixman_image_t *image,
689
       pixman_dither_t dither)
690
0
{
691
0
    if (image->type == BITS)
692
0
    {
693
0
  if (image->bits.dither == dither)
694
0
      return;
695
696
0
  image->bits.dither = dither;
697
698
0
  image_property_changed (image);
699
0
    }
700
0
}
701
702
PIXMAN_EXPORT void
703
pixman_image_set_dither_offset (pixman_image_t *image,
704
        int             offset_x,
705
        int             offset_y)
706
0
{
707
0
    if (image->type == BITS)
708
0
    {
709
0
  if (image->bits.dither_offset_x == offset_x &&
710
0
      image->bits.dither_offset_y == offset_y)
711
0
  {
712
0
      return;
713
0
  }
714
715
0
  image->bits.dither_offset_x = offset_x;
716
0
  image->bits.dither_offset_y = offset_y;
717
718
0
  image_property_changed (image);
719
0
    }
720
0
}
721
722
PIXMAN_EXPORT pixman_bool_t
723
pixman_image_set_filter (pixman_image_t *      image,
724
                         pixman_filter_t       filter,
725
                         const pixman_fixed_t *params,
726
                         int                   n_params)
727
447
{
728
447
    image_common_t *common = (image_common_t *)image;
729
447
    pixman_fixed_t *new_params;
730
731
447
    if (params == common->filter_params && filter == common->filter)
732
223
  return TRUE;
733
734
224
    if (filter == PIXMAN_FILTER_SEPARABLE_CONVOLUTION)
735
94
    {
736
94
  int width = pixman_fixed_to_int (params[0]);
737
94
  int height = pixman_fixed_to_int (params[1]);
738
94
  int x_phase_bits = pixman_fixed_to_int (params[2]);
739
94
  int y_phase_bits = pixman_fixed_to_int (params[3]);
740
94
  int n_x_phases = (1 << x_phase_bits);
741
94
  int n_y_phases = (1 << y_phase_bits);
742
743
94
  return_val_if_fail (
744
94
      n_params == 4 + n_x_phases * width + n_y_phases * height, FALSE);
745
94
    }
746
    
747
224
    new_params = NULL;
748
224
    if (params)
749
94
    {
750
94
  new_params = pixman_malloc_ab (n_params, sizeof (pixman_fixed_t));
751
94
  if (!new_params)
752
0
      return FALSE;
753
754
94
  memcpy (new_params,
755
94
          params, n_params * sizeof (pixman_fixed_t));
756
94
    }
757
758
224
    common->filter = filter;
759
760
224
    if (common->filter_params)
761
0
  free (common->filter_params);
762
763
224
    common->filter_params = new_params;
764
224
    common->n_filter_params = n_params;
765
766
224
    image_property_changed (image);
767
224
    return TRUE;
768
224
}
769
770
PIXMAN_EXPORT void
771
pixman_image_set_source_clipping (pixman_image_t *image,
772
                                  pixman_bool_t   clip_sources)
773
0
{
774
0
    if (image->common.clip_sources == clip_sources)
775
0
  return;
776
777
0
    image->common.clip_sources = clip_sources;
778
779
0
    image_property_changed (image);
780
0
}
781
782
/* Unlike all the other property setters, this function does not
783
 * copy the content of indexed. Doing this copying is simply
784
 * way, way too expensive.
785
 */
786
PIXMAN_EXPORT void
787
pixman_image_set_indexed (pixman_image_t *        image,
788
                          const pixman_indexed_t *indexed)
789
0
{
790
0
    bits_image_t *bits = (bits_image_t *)image;
791
792
0
    if (bits->indexed == indexed)
793
0
  return;
794
795
0
    bits->indexed = indexed;
796
797
0
    image_property_changed (image);
798
0
}
799
800
PIXMAN_EXPORT void
801
pixman_image_set_alpha_map (pixman_image_t *image,
802
                            pixman_image_t *alpha_map,
803
                            int16_t         x,
804
                            int16_t         y)
805
0
{
806
0
    image_common_t *common = (image_common_t *)image;
807
808
0
    return_if_fail (!alpha_map || alpha_map->type == BITS);
809
810
0
    if (alpha_map && common->alpha_count > 0)
811
0
    {
812
  /* If this image is being used as an alpha map itself,
813
   * then you can't give it an alpha map of its own.
814
   */
815
0
  return;
816
0
    }
817
818
0
    if (alpha_map && alpha_map->common.alpha_map)
819
0
    {
820
  /* If the image has an alpha map of its own,
821
   * then it can't be used as an alpha map itself
822
   */
823
0
  return;
824
0
    }
825
826
0
    if (common->alpha_map != (bits_image_t *)alpha_map)
827
0
    {
828
0
  if (common->alpha_map)
829
0
  {
830
0
      common->alpha_map->common.alpha_count--;
831
832
0
      pixman_image_unref ((pixman_image_t *)common->alpha_map);
833
0
  }
834
835
0
  if (alpha_map)
836
0
  {
837
0
      common->alpha_map = (bits_image_t *)pixman_image_ref (alpha_map);
838
839
0
      common->alpha_map->common.alpha_count++;
840
0
  }
841
0
  else
842
0
  {
843
0
      common->alpha_map = NULL;
844
0
  }
845
0
    }
846
847
0
    common->alpha_origin_x = x;
848
0
    common->alpha_origin_y = y;
849
850
0
    image_property_changed (image);
851
0
}
852
853
PIXMAN_EXPORT void
854
pixman_image_set_component_alpha   (pixman_image_t *image,
855
                                    pixman_bool_t   component_alpha)
856
414
{
857
414
    if (image->common.component_alpha == component_alpha)
858
0
  return;
859
860
414
    image->common.component_alpha = component_alpha;
861
862
414
    image_property_changed (image);
863
414
}
864
865
PIXMAN_EXPORT pixman_bool_t
866
pixman_image_get_component_alpha   (pixman_image_t       *image)
867
0
{
868
0
    return image->common.component_alpha;
869
0
}
870
871
PIXMAN_EXPORT void
872
pixman_image_set_accessors (pixman_image_t *           image,
873
                            pixman_read_memory_func_t  read_func,
874
                            pixman_write_memory_func_t write_func)
875
0
{
876
0
    return_if_fail (image != NULL);
877
878
0
    if (image->type == BITS)
879
0
    {
880
  /* Accessors only work for <= 32 bpp. */
881
0
  if (PIXMAN_FORMAT_BPP(image->bits.format) > 32)
882
0
      return_if_fail (!read_func && !write_func);
883
884
0
  image->bits.read_func = read_func;
885
0
  image->bits.write_func = write_func;
886
887
0
  image_property_changed (image);
888
0
    }
889
0
}
890
891
PIXMAN_EXPORT uint32_t *
892
pixman_image_get_data (pixman_image_t *image)
893
2.39M
{
894
2.39M
    if (image->type == BITS)
895
2.39M
  return image->bits.bits;
896
897
0
    return NULL;
898
2.39M
}
899
900
PIXMAN_EXPORT int
901
pixman_image_get_width (pixman_image_t *image)
902
2.39M
{
903
2.39M
    if (image->type == BITS)
904
2.39M
  return image->bits.width;
905
906
0
    return 0;
907
2.39M
}
908
909
PIXMAN_EXPORT int
910
pixman_image_get_height (pixman_image_t *image)
911
2.39M
{
912
2.39M
    if (image->type == BITS)
913
2.39M
  return image->bits.height;
914
915
0
    return 0;
916
2.39M
}
917
918
PIXMAN_EXPORT int
919
pixman_image_get_stride (pixman_image_t *image)
920
2.39M
{
921
2.39M
    if (image->type == BITS)
922
2.39M
  return image->bits.rowstride * (int) sizeof (uint32_t);
923
924
0
    return 0;
925
2.39M
}
926
927
PIXMAN_EXPORT int
928
pixman_image_get_depth (pixman_image_t *image)
929
2.39M
{
930
2.39M
    if (image->type == BITS)
931
2.39M
  return PIXMAN_FORMAT_DEPTH (image->bits.format);
932
933
0
    return 0;
934
2.39M
}
935
936
PIXMAN_EXPORT pixman_format_code_t
937
pixman_image_get_format (pixman_image_t *image)
938
25.7k
{
939
25.7k
    if (image->type == BITS)
940
25.7k
  return image->bits.format;
941
942
0
    return PIXMAN_null;
943
25.7k
}
944
945
uint32_t
946
_pixman_image_get_solid (pixman_implementation_t *imp,
947
       pixman_image_t *         image,
948
                         pixman_format_code_t     format)
949
13.3k
{
950
13.3k
    uint32_t result;
951
952
13.3k
    if (image->type == SOLID)
953
13.3k
    {
954
13.3k
  result = image->solid.color_32;
955
13.3k
    }
956
0
    else if (image->type == BITS)
957
0
    {
958
0
  if (image->bits.format == PIXMAN_a8r8g8b8)
959
0
      result = image->bits.bits[0];
960
0
  else if (image->bits.format == PIXMAN_x8r8g8b8)
961
0
      result = image->bits.bits[0] | 0xff000000;
962
0
  else if (image->bits.format == PIXMAN_a8)
963
0
      result = (uint32_t)(*(uint8_t *)image->bits.bits) << 24;
964
0
  else
965
0
      goto otherwise;
966
0
    }
967
0
    else
968
0
    {
969
0
  pixman_iter_t iter;
970
971
0
    otherwise:
972
0
  _pixman_implementation_iter_init (
973
0
      imp, &iter, image, 0, 0, 1, 1,
974
0
      (uint8_t *)&result,
975
0
      ITER_NARROW | ITER_SRC, image->common.flags);
976
  
977
0
  result = *iter.get_scanline (&iter, NULL);
978
979
0
  if (iter.fini)
980
0
      iter.fini (&iter);
981
0
    }
982
983
    /* If necessary, convert RGB <--> BGR. */
984
13.3k
    if (PIXMAN_FORMAT_TYPE (format) != PIXMAN_TYPE_ARGB
985
13.3k
  && PIXMAN_FORMAT_TYPE (format) != PIXMAN_TYPE_ARGB_SRGB)
986
0
    {
987
0
  result = (((result & 0xff000000) >>  0) |
988
0
            ((result & 0x00ff0000) >> 16) |
989
0
            ((result & 0x0000ff00) >>  0) |
990
0
            ((result & 0x000000ff) << 16));
991
0
    }
992
993
13.3k
    return result;
994
13.3k
}