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

« back to all changes in this revision

Viewing changes to app/composite/gimp-composite-generic.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
 
/* -*- mode: c tab-width: 2; c-basic-indent: 2; indent-tabs-mode: nil -*-
2
 
 * The GIMP -- an image manipulation program
 
1
/* GIMP - The GNU Image Manipulation Program
3
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
4
3
 *
5
4
 * This program is free software; you can redistribute it and/or modify
41
40
#define OPAQUE_OPACITY       255
42
41
#define TRANSPARENT_OPACITY  0
43
42
 
 
43
#define RANDOM_TABLE_SIZE    4096
 
44
 
44
45
 
45
46
#define INT_MULT(a,b,t)  ((t) = (a) * (b) + 0x80, ((((t) >> 8) + (t)) >> 8))
46
47
 
47
 
/* This version of INT_MULT3 is very fast, but suffers from some
48
 
   slight roundoff errors.  It returns the correct result 99.987
49
 
   percent of the time */
50
 
#define INT_MULT3(a,b,c,t)  ((t) = (a) * (b) * (c) + 0x7F5B, ((((t) >> 7) + (t)) >> 16))
51
 
/*
52
 
  This version of INT_MULT3 always gives the correct result, but runs at
53
 
  approximatly one third the speed. */
54
 
/*  #define INT_MULT3(a,b,c,t) (((a) * (b) * (c) + 32512) / 65025.0)
55
 
 */
56
 
 
57
 
#define INT_BLEND(a,b,alpha,tmp)  (INT_MULT((a) - (b), alpha, tmp) + (b))
58
 
 
59
 
#define RANDOM_TABLE_SIZE  4096
60
 
 
61
48
/* A drawable has an alphachannel if contains either 4 or 2 bytes data
62
49
 * aka GRAYA and RGBA and thus the macro below works. This will have
63
50
 * to change if we support bigger formats. We'll do it so for now because
67
54
#define HAS_ALPHA(bytes) (~bytes & 1)
68
55
 
69
56
 
70
 
static guchar add_lut[511];
71
 
static gint32 random_table[RANDOM_TABLE_SIZE];
72
 
static guchar burn_lut[256][256];
 
57
static guchar  add_lut[511];
 
58
static gint32  random_table[RANDOM_TABLE_SIZE];
 
59
static guchar  burn_lut[256][256];
73
60
 
74
61
/*
75
62
 *
89
76
{
90
77
  int i;
91
78
  int j;
92
 
  char *D = ctx->D;
93
 
  char *A = ctx->A;
 
79
  unsigned char *D = ctx->D;
 
80
  unsigned char *A = ctx->A;
94
81
  int bpp_A = gimp_composite_pixel_bpp[ctx->pixelformat_A];
95
82
  int bpp_D = gimp_composite_pixel_bpp[ctx->pixelformat_D];
96
83
 
375
362
  guint bytes2 = gimp_composite_pixel_bpp[ctx->pixelformat_B];
376
363
  const guint has_alpha1 = HAS_ALPHA(bytes1);
377
364
  const guint has_alpha2 = HAS_ALPHA(bytes2);
378
 
  guint r1, g1, b1;
379
 
  guint r2, g2, b2;
 
365
  gint r1, g1, b1;
 
366
  gint r2, g2, b2;
380
367
 
381
368
  if (bytes1 > 2)
382
369
    {
443
430
  guint bytes2 = gimp_composite_pixel_bpp[ctx->pixelformat_B];
444
431
  const guint has_alpha1 = HAS_ALPHA(bytes1);
445
432
  const guint has_alpha2 = HAS_ALPHA(bytes2);
446
 
  guint r1, g1, b1;
447
 
  guint r2, g2, b2;
 
433
  gint r1, g1, b1;
 
434
  gint r2, g2, b2;
448
435
 
449
436
  if (bytes1 > 2) {
450
437
    /*  assumes inputs are only 4 byte RGBA pixels  */
502
489
  guint bytes2 = gimp_composite_pixel_bpp[ctx->pixelformat_B];
503
490
  const guint has_alpha1 = HAS_ALPHA(bytes1);
504
491
  const guint has_alpha2 = HAS_ALPHA(bytes2);
505
 
  guint r1, g1, b1;
506
 
  guint r2, g2, b2;
 
492
  gint r1, g1, b1;
 
493
  gint r2, g2, b2;
507
494
 
508
495
  if (bytes1 > 2) {
509
496
    /*  assumes inputs are only 4 byte RGBA pixels  */
562
549
  guint bytes2 = gimp_composite_pixel_bpp[ctx->pixelformat_B];
563
550
  const guint has_alpha1 = HAS_ALPHA(bytes1);
564
551
  const guint has_alpha2 = HAS_ALPHA(bytes2);
565
 
  guint r1, g1, b1;
566
 
  guint r2, g2, b2;
 
552
  gint r1, g1, b1;
 
553
  gint r2, g2, b2;
567
554
 
568
555
  if (bytes1 > 2) {
569
556
    /*  assumes inputs are only 4 byte RGBA pixels  */
769
756
 * Perform an RGB[A] overlay operation between the pixel sources
770
757
 * ctx->A and ctx->B, using the generalised algorithm:
771
758
 *
772
 
 * D =  A * (B + (2 * B) * (255 - A))
 
759
 * D =  A * (A + (2 * B) * (255 - A))
773
760
 *
774
761
 **/
775
762
void
1232
1219
  gint sb = gimp_composite_pixel_bpp[ctx->pixelformat_B];
1233
1220
  gint x = ctx->dissolve.x;
1234
1221
  gint y = ctx->dissolve.y;
1235
 
  guchar *mask = ctx->M;
 
1222
  const guchar *mask = ctx->M;
1236
1223
  gint32 rand_val;
1237
1224
  guchar *dest = ctx->D;
1238
1225
  guchar *src = ctx->B;
1281
1268
          combined_opacity = opacity;
1282
1269
      }
1283
1270
 
1284
 
      dest[alpha] = (rand_val >= combined_opacity) ? 0 : OPAQUE_OPACITY;
 
1271
      dest[alpha] =
 
1272
        (rand_val >= combined_opacity) ? TRANSPARENT_OPACITY : OPAQUE_OPACITY;
1285
1273
 
1286
1274
      dest += db;
1287
1275
      src += sb;
1318
1306
void
1319
1307
gimp_composite_swap_any_any_any_generic (GimpCompositeContext * ctx)
1320
1308
{
1321
 
  guint length;
1322
1309
  guchar *src = ctx->A;
1323
1310
  guchar *dest = ctx->B;
1324
1311
  guint bytes1 = gimp_composite_pixel_bpp[ctx->pixelformat_A];
1325
 
  length = ctx->n_pixels * bytes1;
 
1312
  guint length = ctx->n_pixels * bytes1;
1326
1313
 
1327
1314
  while (length--)
1328
1315
    {
1329
 
      *src = *src ^ *dest;
1330
 
      *dest = *dest ^ *src;
1331
 
      *src = *src ^ *dest;
 
1316
      guchar tmp = *dest;
 
1317
 
 
1318
      *dest = *src;
 
1319
      *src = tmp;
 
1320
 
1332
1321
      src++;
1333
1322
      dest++;
1334
1323
    }