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

« back to all changes in this revision

Viewing changes to app/paint-funcs/paint-funcs.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2008-10-06 13:30:41 UTC
  • mto: This revision was merged to the branch mainline in revision 35.
  • Revision ID: james.westby@ubuntu.com-20081006133041-3panbkcanaymfsmp
Tags: upstream-2.6.0
ImportĀ upstreamĀ versionĀ 2.6.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
276
276
                                    const guchar   *src2,
277
277
                                    guchar         *dest,
278
278
                                    const guchar   *mask,
279
 
                                    guint           opacity,
 
279
                                    const guint     opacity,
280
280
                                    const gboolean *affect,
281
281
                                    guint           length,
282
 
                                    guint           bytes)
 
282
                                    const guint     bytes)
283
283
{
284
 
  gint  b;
285
 
  gint  tmp;
286
 
 
287
284
  if (mask)
288
285
    {
289
286
      const guchar *m = mask;
290
287
 
291
288
      while (length --)
292
289
        {
293
 
          guchar  new_alpha = INT_MULT (*m , opacity, tmp);
 
290
          register gulong tmp;
 
291
          const guchar    new_alpha = INT_MULT (*m , opacity, tmp);
 
292
          guint           b;
294
293
 
295
294
          for (b = 0; b < bytes; b++)
296
295
            dest[b] = (affect[b] && new_alpha > 127) ? src2[b] : src1[b];
306
305
    {
307
306
      while (length --)
308
307
        {
309
 
          guchar  new_alpha = opacity;
 
308
          guint b;
310
309
 
311
310
          for (b = 0; b < bytes; b++)
312
 
            dest[b] = (affect[b] && new_alpha > 127) ? src2[b] : src1[b];
 
311
            dest[b] = (affect[b] && opacity > 127) ? src2[b] : src1[b];
313
312
 
314
313
          src1 += bytes;
315
314
          src2 += bytes;
324
323
                                      const guchar   *src2,
325
324
                                      guchar         *dest,
326
325
                                      const guchar   *mask,
327
 
                                      guint           opacity,
 
326
                                      const guint     opacity,
328
327
                                      const gboolean *affect,
329
328
                                      guint           length,
330
 
                                      guint           bytes)
 
329
                                      const guint     bytes)
331
330
{
332
331
  const gint alpha      = 1;
333
332
  const gint src2_bytes = 2;
334
 
  glong      tmp;
335
 
  gint       b;
336
333
 
337
334
  if (mask)
338
335
    {
340
337
 
341
338
      while (length --)
342
339
        {
343
 
          guchar new_alpha = INT_MULT3 (src2[alpha], *m, opacity, tmp);
 
340
          register gulong tmp;
 
341
          const guchar    new_alpha = INT_MULT3 (src2[alpha], *m, opacity, tmp);
 
342
          guint           b;
344
343
 
345
344
          for (b = 0; b < bytes; b++)
346
345
            dest[b] = (affect[b] && new_alpha > 127) ? src2[b] : src1[b];
356
355
    {
357
356
      while (length --)
358
357
        {
359
 
          guchar new_alpha = INT_MULT (src2[alpha], opacity, tmp);
 
358
          register gulong tmp;
 
359
          const guchar    new_alpha = INT_MULT (src2[alpha], opacity, tmp);
 
360
          guint           b;
360
361
 
361
362
          for (b = 0; b < bytes; b++)
362
363
            dest[b] = (affect[b] && new_alpha > 127) ? src2[b] : src1[b];
374
375
                                        const guchar   *src2,
375
376
                                        guchar         *dest,
376
377
                                        const guchar   *mask,
377
 
                                        guint           opacity,
 
378
                                        const guint     opacity,
378
379
                                        const gboolean *affect,
379
380
                                        guint           length,
380
 
                                        guint           bytes)
 
381
                                        const guint     bytes)
381
382
{
382
383
  const gint alpha = 1;
383
 
  gint       b;
384
 
  glong      tmp;
385
384
 
386
385
  if (mask)
387
386
    {
389
388
 
390
389
      while (length --)
391
390
        {
392
 
          guchar new_alpha = INT_MULT3 (src2[alpha], *m, opacity, tmp);
 
391
          register gulong tmp;
 
392
          const guchar    new_alpha = INT_MULT3 (src2[alpha], *m, opacity, tmp);
 
393
          guint           b;
393
394
 
394
395
          for (b = 0; b < alpha; b++)
395
396
            dest[b] = (affect[b] && new_alpha > 127) ? src2[b] : src1[b];
408
409
    {
409
410
      while (length --)
410
411
        {
411
 
          guchar new_alpha = INT_MULT (src2[alpha], opacity, tmp);
 
412
          register gulong tmp;
 
413
          const guchar    new_alpha = INT_MULT (src2[alpha], opacity, tmp);
 
414
          guint           b;
412
415
 
413
416
          for (b = 0; b < alpha; b++)
414
417
            dest[b] = (affect[b] && new_alpha > 127) ? src2[b] : src1[b];
430
433
                                    guchar       *dest,
431
434
                                    const guchar *mask,
432
435
                                    const guchar *cmap,
433
 
                                    guint         opacity,
 
436
                                    const guint   opacity,
434
437
                                    guint         length,
435
 
                                    guint         bytes)
 
438
                                    const guint   bytes)
436
439
{
437
440
  const gint src2_bytes = 1;
438
 
  gint       b;
439
 
  glong      tmp;
440
441
 
441
442
  if (mask)
442
443
    {
444
445
 
445
446
      while (length --)
446
447
        {
447
 
          gint   index     = src2[0] * 3;
448
 
          guchar new_alpha = INT_MULT3 (255, *m, opacity, tmp);
 
448
          register gulong tmp;
 
449
          const guint     index     = src2[0] * 3;
 
450
          const guchar    new_alpha = INT_MULT3 (255, *m, opacity, tmp);
 
451
          guint           b;
449
452
 
450
 
          for (b = 0; b < bytes-1; b++)
 
453
          for (b = 0; b < bytes - 1; b++)
451
454
            dest[b] = (new_alpha > 127) ? cmap[index + b] : src1[b];
452
455
 
453
456
          dest[b] = (new_alpha > 127) ? OPAQUE_OPACITY : src1[b];
464
467
    {
465
468
      while (length --)
466
469
        {
467
 
          gint   index     = src2[0] * 3;
468
 
          guchar new_alpha = INT_MULT (255, opacity, tmp);
 
470
          register gulong tmp;
 
471
          const guint     index     = src2[0] * 3;
 
472
          const guchar    new_alpha = INT_MULT (255, opacity, tmp);
 
473
          guint           b;
469
474
 
470
 
          for (b = 0; b < bytes-1; b++)
 
475
          for (b = 0; b < bytes - 1; b++)
471
476
            dest[b] = (new_alpha > 127) ? cmap[index + b] : src1[b];
472
477
 
473
478
          dest[b] = (new_alpha > 127) ? OPAQUE_OPACITY : src1[b];
474
479
          /*  alpha channel is opaque  */
475
480
 
476
 
          /* m++; /Per */
477
 
 
478
481
          src1 += bytes;
479
482
          src2 += src2_bytes;
480
483
          dest += bytes;
489
492
                                      guchar       *dest,
490
493
                                      const guchar *mask,
491
494
                                      const guchar *cmap,
492
 
                                      guint         opacity,
 
495
                                      const guint   opacity,
493
496
                                      guint         length,
494
 
                                      guint         bytes)
 
497
                                      const guint   bytes)
495
498
{
496
 
  const gint alpha = 1;
 
499
  const gint alpha      = 1;
497
500
  const gint src2_bytes = 2;
498
 
  gint       b;
499
 
  glong      tmp;
500
501
 
501
502
  if (mask)
502
503
    {
504
505
 
505
506
      while (length --)
506
507
        {
507
 
          gint   index     = src2[0] * 3;
508
 
          guchar new_alpha = INT_MULT3 (src2[alpha], *m, opacity, tmp);
 
508
          register gulong tmp;
 
509
          guint           index     = src2[0] * 3;
 
510
          const guchar    new_alpha = INT_MULT3 (src2[alpha], *m, opacity, tmp);
 
511
          guint           b;
509
512
 
510
 
          for (b = 0; b < bytes-1; b++)
 
513
          for (b = 0; b < bytes - 1; b++)
511
514
            dest[b] = (new_alpha > 127) ? cmap[index + b] : src1[b];
512
515
 
513
516
          dest[b] = (new_alpha > 127) ? OPAQUE_OPACITY : src1[b];
524
527
    {
525
528
      while (length --)
526
529
        {
527
 
          gint   index     = src2[0] * 3;
528
 
          guchar new_alpha = INT_MULT (src2[alpha], opacity, tmp);
 
530
          register gulong tmp;
 
531
          guint           index     = src2[0] * 3;
 
532
          const guchar    new_alpha = INT_MULT (src2[alpha], opacity, tmp);
 
533
          guint           b;
529
534
 
530
 
          for (b = 0; b < bytes-1; b++)
 
535
          for (b = 0; b < bytes - 1; b++)
531
536
            dest[b] = (new_alpha > 127) ? cmap[index + b] : src1[b];
532
537
 
533
538
          dest[b] = (new_alpha > 127) ? OPAQUE_OPACITY : src1[b];
534
539
          /*  alpha channel is opaque  */
535
540
 
536
 
          /* m++; /Per */
537
 
 
538
541
          src1 += bytes;
539
542
          src2 += src2_bytes;
540
543
          dest += bytes;
548
551
                                const guchar   *src2,
549
552
                                guchar         *dest,
550
553
                                const guchar   *mask,
551
 
                                guint           opacity,
 
554
                                const guint     opacity,
552
555
                                const gboolean *affect,
553
556
                                guint           length,
554
 
                                guint           bytes)
 
557
                                const guint     bytes)
555
558
{
556
 
  gint  b;
557
 
  gint  tmp;
558
 
 
559
559
  if (mask)
560
560
    {
561
 
      const guchar * m = mask;
 
561
      const guchar *m = mask;
562
562
 
563
563
      while (length --)
564
564
        {
565
 
          guchar new_alpha = INT_MULT (*m, opacity, tmp);
 
565
          register gulong tmp;
 
566
          const guchar    new_alpha = INT_MULT (*m, opacity, tmp);
 
567
          guint           b;
566
568
 
567
569
          for (b = 0; b < bytes; b++)
568
570
            dest[b] = (affect[b] ?
579
581
    {
580
582
      while (length --)
581
583
        {
 
584
          register gulong tmp;
 
585
          guint           b;
582
586
 
583
587
          for (b = 0; b < bytes; b++)
584
588
            dest[b] = (affect[b] ?
597
601
                                  const guchar   *src2,
598
602
                                  guchar         *dest,
599
603
                                  const guchar   *mask,
600
 
                                  guint           opacity,
 
604
                                  const guint     opacity,
601
605
                                  const gboolean *affect,
602
606
                                  guint           length,
603
 
                                  guint           bytes)
 
607
                                  const guint     bytes)
604
608
{
605
 
  const gint      alpha      = bytes;
606
 
  const gint      src2_bytes = bytes + 1;
607
 
  gint            b;
608
 
  register glong  t1;
 
609
  const gint alpha      = bytes;
 
610
  const gint src2_bytes = bytes + 1;
609
611
 
610
612
  if (mask)
611
613
    {
613
615
 
614
616
      while (length --)
615
617
        {
616
 
          guchar new_alpha = INT_MULT3 (src2[alpha], *m, opacity, t1);
 
618
          register glong  t1;
 
619
          const guchar    new_alpha = INT_MULT3 (src2[alpha], *m, opacity, t1);
 
620
          guint           b;
617
621
 
618
622
          for (b = 0; b < bytes; b++)
619
623
            dest[b] = (affect[b] ?
631
635
        {
632
636
          while (length --)
633
637
            {
634
 
              guchar new_alpha = INT_MULT (src2[alpha],opacity,t1);
 
638
              register glong  t1;
 
639
              const guchar    new_alpha = INT_MULT (src2[alpha], opacity, t1);
635
640
 
636
 
              dest[0] = INT_BLEND (src2[0] , src1[0] , new_alpha, t1);
637
 
              dest[1] = INT_BLEND (src2[1] , src1[1] , new_alpha, t1);
638
 
              dest[2] = INT_BLEND (src2[2] , src1[2] , new_alpha, t1);
 
641
              dest[0] = INT_BLEND (src2[0], src1[0], new_alpha, t1);
 
642
              dest[1] = INT_BLEND (src2[1], src1[1], new_alpha, t1);
 
643
              dest[2] = INT_BLEND (src2[2], src1[2], new_alpha, t1);
639
644
 
640
645
              src1 += bytes;
641
646
              src2 += src2_bytes;
646
651
        {
647
652
          while (length --)
648
653
            {
649
 
              guchar new_alpha = INT_MULT (src2[alpha],opacity,t1);
 
654
              register glong  t1;
 
655
              const guchar    new_alpha = INT_MULT (src2[alpha], opacity, t1);
 
656
              guint           b;
650
657
 
651
658
              for (b = 0; b < bytes; b++)
652
659
                dest[b] = (affect[b] ?
653
 
                           INT_BLEND (src2[b] , src1[b] , new_alpha, t1) :
 
660
                           INT_BLEND (src2[b], src1[b], new_alpha, t1) :
654
661
                           src1[b]);
655
662
 
656
663
              src1 += bytes;
738
745
                                  const guchar   *src2,
739
746
                                  guchar         *dest,
740
747
                                  const guchar   *mask,
741
 
                                  guint           opacity,
 
748
                                  const guint     opacity,
742
749
                                  const gboolean *affect,
743
 
                                  gboolean        mode_affect,  /*  how does the combination mode affect alpha?  */
 
750
                                  const gboolean  mode_affect,  /*  how does the combination mode affect alpha?  */
744
751
                                  guint           length,
745
 
                                  guint           bytes)        /*  4 or 2 depending on RGBA or GRAYA  */
 
752
                                  const guint     bytes)        /*  4 or 2 depending on RGBA or GRAYA  */
746
753
{
747
 
  const gint    src2_bytes = bytes - 1;
748
 
  const gint    alpha      = bytes - 1;
749
 
  gint          b;
750
 
  gfloat        ratio;
751
 
  gfloat        compl_ratio;
752
 
  glong         tmp;
 
754
  const gint src2_bytes = bytes - 1;
 
755
  const gint alpha      = bytes - 1;
 
756
  gint       b;
 
757
  gfloat     ratio;
 
758
  gfloat     compl_ratio;
753
759
 
754
760
  if (mask)
755
761
    {
759
765
        {
760
766
          while (length--)
761
767
            {
762
 
              guchar src2_alpha = *m;
763
 
              guchar new_alpha  =
 
768
              register gulong tmp;
 
769
              guchar          src2_alpha = *m;
 
770
              guchar          new_alpha  =
764
771
                src1[alpha] + INT_MULT ((255 - src1[alpha]), src2_alpha, tmp);
765
772
 
766
773
              alphify (src2_alpha, new_alpha);
785
792
        {
786
793
          while (length--)
787
794
            {
788
 
              guchar src2_alpha = INT_MULT (*m, opacity, tmp);
789
 
              guchar new_alpha  =
 
795
              register gulong tmp;
 
796
              guchar          src2_alpha = INT_MULT (*m, opacity, tmp);
 
797
              guchar          new_alpha  =
790
798
                src1[alpha] + INT_MULT ((255 - src1[alpha]), src2_alpha, tmp);
791
799
 
792
800
              alphify (src2_alpha, new_alpha);
797
805
                }
798
806
              else
799
807
                {
800
 
                  dest[alpha] = (src1[alpha]) ? src1[alpha] :
801
 
                    (affect[alpha] ? new_alpha : src1[alpha]);
 
808
                  dest[alpha] = (src1[alpha] ?
 
809
                                 src1[alpha] : (affect[alpha] ?
 
810
                                                new_alpha : src1[alpha]));
802
811
                }
803
812
 
804
813
              m++;
812
821
    {
813
822
      while (length --)
814
823
        {
815
 
          guchar src2_alpha = opacity;
816
 
          guchar new_alpha  =
 
824
          register gulong tmp;
 
825
          guchar          src2_alpha = opacity;
 
826
          guchar          new_alpha  =
817
827
            src1[alpha] + INT_MULT ((255 - src1[alpha]), src2_alpha, tmp);
818
828
 
819
829
          alphify (src2_alpha, new_alpha);
821
831
          if (mode_affect)
822
832
            dest[alpha] = (affect[alpha]) ? new_alpha : src1[alpha];
823
833
          else
824
 
            dest[alpha] = (src1[alpha]) ? src1[alpha] : (affect[alpha] ? new_alpha : src1[alpha]);
 
834
            dest[alpha] = (src1[alpha] ?
 
835
                           src1[alpha] : (affect[alpha] ?
 
836
                                          new_alpha : src1[alpha]));
825
837
 
826
 
            src1 += bytes;
827
 
            src2 += src2_bytes;
828
 
            dest += bytes;
 
838
          src1 += bytes;
 
839
          src2 += src2_bytes;
 
840
          dest += bytes;
829
841
        }
830
842
    }
831
843
}
836
848
                                    const guchar   *src2,
837
849
                                    guchar         *dest,
838
850
                                    const guchar   *mask,
839
 
                                    guint           opacity,
 
851
                                    const guint     opacity,
840
852
                                    const gboolean *affect,
841
 
                                    gboolean        mode_affect,  /*  how does the combination mode affect alpha?  */
 
853
                                    const gboolean  mode_affect,  /*  how does the combination mode affect alpha?  */
842
854
                                    guint           length,
843
 
                                    guint           bytes)  /*  4 or 2 depending on RGBA or GRAYA  */
 
855
                                    const guint     bytes)  /*  4 or 2 depending on RGBA or GRAYA  */
844
856
{
845
857
  const guint alpha = bytes - 1;
846
858
  guint       b;
847
859
  gfloat      ratio;
848
860
  gfloat      compl_ratio;
849
 
  glong       tmp;
850
861
 
851
862
  if (mask)
852
863
    {
870
881
                  while (i--)
871
882
                    {
872
883
                      /* GUTS */
 
884
                      register gulong  tmp;
873
885
                      guchar src2_alpha = INT_MULT (src2[alpha], *m, tmp);
874
886
                      guchar new_alpha  =
875
887
                        src1[alpha] +
879
891
 
880
892
                      if (mode_affect)
881
893
                        {
882
 
                          dest[alpha] = (affect[alpha]) ? new_alpha : src1[alpha];
 
894
                          dest[alpha] = (affect[alpha] ?
 
895
                                         new_alpha : src1[alpha]);
883
896
                        }
884
897
                      else
885
898
                        {
886
 
                          dest[alpha] = (src1[alpha]) ? src1[alpha] :
887
 
                            (affect[alpha] ? new_alpha : src1[alpha]);
 
899
                          dest[alpha] = (src1[alpha] ?
 
900
                                         src1[alpha] : (affect[alpha] ?
 
901
                                                        new_alpha : src1[alpha]));
888
902
                        }
889
903
 
890
904
                      m++;
910
924
                      while (j--)
911
925
                        {
912
926
                          /* GUTS */
 
927
                          register gulong  tmp;
913
928
                          guchar src2_alpha = INT_MULT (src2[alpha], *m, tmp);
914
929
                          guchar new_alpha  =
915
930
                            src1[alpha] +
919
934
 
920
935
                          if (mode_affect)
921
936
                            {
922
 
                              dest[alpha] = (affect[alpha]) ? new_alpha : src1[alpha];
 
937
                              dest[alpha] = (affect[alpha] ?
 
938
                                             new_alpha : src1[alpha]);
923
939
                            }
924
940
                          else
925
941
                            {
926
 
                              dest[alpha] = (src1[alpha]) ? src1[alpha] :
927
 
                                (affect[alpha] ? new_alpha : src1[alpha]);
 
942
                              dest[alpha] = (src1[alpha] ?
 
943
                                             src1[alpha] : (affect[alpha] ?
 
944
                                                            new_alpha : src1[alpha]));
928
945
                            }
929
946
 
930
947
                          m++;
953
970
          while (length--)
954
971
            {
955
972
              /* GUTS */
 
973
              register gulong  tmp;
956
974
              guchar src2_alpha = INT_MULT (src2[alpha], *m, tmp);
957
975
              guchar new_alpha  =
958
976
                src1[alpha] + INT_MULT ((255 - src1[alpha]), src2_alpha, tmp);
961
979
 
962
980
              if (mode_affect)
963
981
                {
964
 
                  dest[alpha] = (affect[alpha]) ? new_alpha : src1[alpha];
 
982
                  dest[alpha] = affect[alpha] ? new_alpha : src1[alpha];
965
983
                }
966
984
              else
967
985
                {
968
 
                  dest[alpha] = (src1[alpha]) ? src1[alpha] :
969
 
                    (affect[alpha] ? new_alpha : src1[alpha]);
 
986
                  dest[alpha] = (src1[alpha] ?
 
987
                                 src1[alpha] : (affect[alpha] ?
 
988
                                                new_alpha : src1[alpha]));
970
989
                }
971
990
 
972
991
              m++;
993
1012
                  while (i--)
994
1013
                    {
995
1014
                      /* GUTS */
 
1015
                      register gulong  tmp;
996
1016
                      guchar src2_alpha = INT_MULT3 (src2[alpha], *m, opacity,
997
1017
                                                     tmp);
998
1018
                      guchar new_alpha  =
1003
1023
 
1004
1024
                      if (mode_affect)
1005
1025
                        {
1006
 
                          dest[alpha] = (affect[alpha]) ? new_alpha : src1[alpha];
 
1026
                          dest[alpha] = (affect[alpha] ?
 
1027
                                         new_alpha : src1[alpha]);
1007
1028
                        }
1008
1029
                      else
1009
1030
                        {
1010
 
                          dest[alpha] = (src1[alpha]) ? src1[alpha] :
1011
 
                            (affect[alpha] ? new_alpha : src1[alpha]);
 
1031
                          dest[alpha] = (src1[alpha] ?
 
1032
                                         src1[alpha] : (affect[alpha] ?
 
1033
                                                        new_alpha : src1[alpha]));
1012
1034
                        }
1013
1035
 
1014
1036
                      m++;
1034
1056
                     while (j--)
1035
1057
                        {
1036
1058
                          /* GUTS */
1037
 
                          guchar src2_alpha = INT_MULT3 (src2[alpha], *m, opacity, tmp);
 
1059
                          register gulong  tmp;
 
1060
                          guchar src2_alpha = INT_MULT3 (src2[alpha],
 
1061
                                                         *m, opacity, tmp);
1038
1062
                          guchar new_alpha  =
1039
1063
                            src1[alpha] +
1040
1064
                            INT_MULT ((255 - src1[alpha]), src2_alpha, tmp);
1043
1067
 
1044
1068
                          if (mode_affect)
1045
1069
                            {
1046
 
                              dest[alpha] = (affect[alpha]) ? new_alpha : src1[alpha];
 
1070
                              dest[alpha] = (affect[alpha] ?
 
1071
                                             new_alpha : src1[alpha]);
1047
1072
                            }
1048
1073
                          else
1049
1074
                            {
1050
 
                              dest[alpha] = (src1[alpha]) ? src1[alpha] :
1051
 
                                (affect[alpha] ? new_alpha : src1[alpha]);
 
1075
                              dest[alpha] = (src1[alpha] ?
 
1076
                                             src1[alpha] : (affect[alpha] ?
 
1077
                                                            new_alpha : src1[alpha]));
1052
1078
                            }
1053
1079
 
1054
1080
                          m++;
1078
1104
          while (length--)
1079
1105
            {
1080
1106
              /* GUTS */
 
1107
              register gulong  tmp;
1081
1108
              guchar src2_alpha = INT_MULT3 (src2[alpha], *m, opacity, tmp);
1082
1109
              guchar new_alpha  =
1083
1110
                src1[alpha] +
1087
1114
 
1088
1115
              if (mode_affect)
1089
1116
                {
1090
 
                  dest[alpha] = (affect[alpha]) ? new_alpha : src1[alpha];
 
1117
                  dest[alpha] = affect[alpha] ? new_alpha : src1[alpha];
1091
1118
                }
1092
1119
              else
1093
1120
                {
1094
 
                  dest[alpha] = (src1[alpha]) ? src1[alpha] :
1095
 
                    (affect[alpha] ? new_alpha : src1[alpha]);
 
1121
                  dest[alpha] = (src1[alpha] ?
 
1122
                                 src1[alpha] : (affect[alpha] ?
 
1123
                                                new_alpha : src1[alpha]));
1096
1124
                }
1097
1125
 
1098
1126
              m++;
1109
1137
        {
1110
1138
          while (length --)
1111
1139
            {
 
1140
              register gulong  tmp;
1112
1141
              guchar src2_alpha = src2[alpha];
1113
1142
              guchar new_alpha  =
1114
1143
                src1[alpha] +
1118
1147
 
1119
1148
              if (mode_affect)
1120
1149
                {
1121
 
                  dest[alpha] = (affect[alpha]) ? new_alpha : src1[alpha];
 
1150
                  dest[alpha] = affect[alpha] ? new_alpha : src1[alpha];
1122
1151
                }
1123
1152
              else
1124
1153
                {
1125
 
                  dest[alpha] = (src1[alpha]) ? src1[alpha] :
1126
 
                    (affect[alpha] ? new_alpha : src1[alpha]);
 
1154
                  dest[alpha] = (src1[alpha] ?
 
1155
                                 src1[alpha] : (affect[alpha] ?
 
1156
                                                new_alpha : src1[alpha]));
1127
1157
                }
1128
1158
 
1129
1159
              src1 += bytes;
1135
1165
        {
1136
1166
          while (length --)
1137
1167
            {
 
1168
              register gulong  tmp;
1138
1169
              guchar src2_alpha = INT_MULT (src2[alpha], opacity, tmp);
1139
1170
              guchar new_alpha  =
1140
1171
                src1[alpha] + INT_MULT ((255 - src1[alpha]), src2_alpha, tmp);
1143
1174
 
1144
1175
              if (mode_affect)
1145
1176
                {
1146
 
                  dest[alpha] = (affect[alpha]) ? new_alpha : src1[alpha];
 
1177
                  dest[alpha] = affect[alpha] ? new_alpha : src1[alpha];
1147
1178
                }
1148
1179
              else
1149
1180
                {
1150
 
                  dest[alpha] = (src1[alpha]) ? src1[alpha] :
1151
 
                    (affect[alpha] ? new_alpha : src1[alpha]);
 
1181
                  dest[alpha] = (src1[alpha] ?
 
1182
                                 src1[alpha] : (affect[alpha] ?
 
1183
                                                new_alpha : src1[alpha]));
1152
1184
                }
1153
1185
 
1154
1186
              src1 += bytes;
1165
1197
                                         const guchar *channel,
1166
1198
                                         guchar       *dest,
1167
1199
                                         const guchar *col,
1168
 
                                         guint         opacity,
 
1200
                                         const guint   opacity,
1169
1201
                                         guint         length,
1170
 
                                         guint         bytes)
 
1202
                                         const guint   bytes)
1171
1203
{
1172
1204
  const gint alpha = bytes - 1;
1173
 
  gint       b;
1174
 
  gint       t, s;
1175
1205
 
1176
1206
  while (length --)
1177
1207
    {
 
1208
      register gulong t;
1178
1209
      guchar channel_alpha = INT_MULT (255 - *channel, opacity, t);
1179
1210
 
1180
1211
      if (channel_alpha)
1181
1212
        {
1182
 
          guchar compl_alpha;
1183
 
          guchar new_alpha =
 
1213
          register gulong s;
 
1214
          const guchar new_alpha =
1184
1215
            src[alpha] + INT_MULT ((255 - src[alpha]), channel_alpha, t);
 
1216
          guchar       compl_alpha;
 
1217
          guint        b;
1185
1218
 
1186
1219
          if (new_alpha != 255)
1187
1220
            channel_alpha = (channel_alpha * 255) / new_alpha;
1200
1233
        }
1201
1234
 
1202
1235
      /*  advance pointers  */
1203
 
      src+=bytes;
1204
 
      dest+=bytes;
 
1236
      src += bytes;
 
1237
      dest += bytes;
1205
1238
      channel++;
1206
1239
    }
1207
1240
}
1212
1245
                                              const guchar *channel,
1213
1246
                                              guchar       *dest,
1214
1247
                                              const guchar *col,
1215
 
                                              guint         opacity,
 
1248
                                              const guint   opacity,
1216
1249
                                              guint         length,
1217
 
                                              guint         bytes)
 
1250
                                              const guint   bytes)
1218
1251
{
1219
1252
  const gint alpha = bytes - 1;
1220
 
  gint       b;
1221
 
  gint       t, s;
1222
1253
 
1223
1254
  while (length --)
1224
1255
    {
1225
 
      guchar channel_alpha = INT_MULT (*channel, opacity, t);
 
1256
      register gulong t;
 
1257
      guchar          channel_alpha = INT_MULT (*channel, opacity, t);
1226
1258
 
1227
1259
      if (channel_alpha)
1228
1260
        {
1229
 
          guchar compl_alpha;
1230
 
          guchar new_alpha =
 
1261
          register gulong s;
 
1262
          const guchar new_alpha =
1231
1263
            src[alpha] + INT_MULT ((255 - src[alpha]), channel_alpha, t);
 
1264
          guchar       compl_alpha;
 
1265
          guint        b;
1232
1266
 
1233
1267
          if (new_alpha != 255)
1234
1268
            channel_alpha = (channel_alpha * 255) / new_alpha;
1242
1276
          dest[b] = new_alpha;
1243
1277
        }
1244
1278
      else
1245
 
        memcpy(dest, src, bytes);
 
1279
        {
 
1280
          memcpy (dest, src, bytes);
 
1281
        }
1246
1282
 
1247
1283
      /*  advance pointers  */
1248
 
      src+=bytes;
1249
 
      dest+=bytes;
 
1284
      src += bytes;
 
1285
      dest += bytes;
1250
1286
      channel++;
1251
1287
    }
1252
1288
}
1355
1391
 *  The operation is still bounded by mask/opacity constraints
1356
1392
 */
1357
1393
 
 
1394
#define INT_DIV(a, b) ((a)/(b) + (((a) % (b)) > ((b) / 2)))
 
1395
 
1358
1396
static inline void
1359
1397
replace_inten_pixels (const guchar   *src1,
1360
1398
                      const guchar   *src2,
1366
1404
                      guint           bytes1,
1367
1405
                      guint           bytes2)
1368
1406
{
1369
 
  const guint has_alpha1 = HAS_ALPHA (bytes1);
1370
 
  const guint has_alpha2 = HAS_ALPHA (bytes2);
1371
 
  const guint bytes      = MIN (bytes1, bytes2);
1372
 
  guint b;
1373
 
  gint  tmp;
1374
 
 
1375
 
  if (mask)
1376
 
    {
1377
 
      const guchar *m = mask;
1378
 
 
1379
 
      while (length --)
1380
 
        {
1381
 
          guchar mask_alpha = INT_MULT (*m, opacity, tmp);
1382
 
 
1383
 
          for (b = 0; b < bytes; b++)
1384
 
            dest[b] = (affect[b]) ?
1385
 
              INT_BLEND (src2[b], src1[b], mask_alpha, tmp) :
1386
 
              src1[b];
1387
 
 
1388
 
          if (has_alpha1 && !has_alpha2)
1389
 
            dest[b] = src1[b];
1390
 
 
1391
 
          m++;
1392
 
 
1393
 
          src1 += bytes1;
1394
 
          src2 += bytes2;
1395
 
          dest += bytes1;
1396
 
        }
1397
 
    }
1398
 
  else
1399
 
    {
1400
 
      const guchar mask_alpha = opacity;
1401
 
 
1402
 
      while (length --)
1403
 
        {
1404
 
          for (b = 0; b < bytes; b++)
1405
 
            dest[b] = (affect[b]) ?
1406
 
              INT_BLEND (src2[b], src1[b], mask_alpha, tmp) :
1407
 
              src1[b];
1408
 
 
1409
 
          if (has_alpha1 && !has_alpha2)
1410
 
            dest[b] = src1[b];
1411
 
 
1412
 
          src1 += bytes1;
1413
 
          src2 += bytes2;
1414
 
          dest += bytes1;
1415
 
        }
1416
 
    }
 
1407
  const guint   has_alpha1 = HAS_ALPHA (bytes1);
 
1408
  const guint   has_alpha2 = HAS_ALPHA (bytes2);
 
1409
  const guint   alpha      = bytes1 - has_alpha1;
 
1410
  const guint   alpha2     = bytes2 - has_alpha2;
 
1411
  const guchar *m          = mask ? mask : &no_mask;
 
1412
  guint         b;
 
1413
  gint          tmp;
 
1414
 
 
1415
  while (length --)
 
1416
    {
 
1417
      guchar src1_alpha  = has_alpha1 ? src1[alpha]  : 255;
 
1418
      guchar src2_alpha  = has_alpha2 ? src2[alpha2] : 255;
 
1419
      guchar new_alpha   = INT_BLEND (src2_alpha, src1_alpha,
 
1420
                                      INT_MULT (*m, opacity, tmp), tmp);
 
1421
 
 
1422
      if (new_alpha)
 
1423
        {
 
1424
          guint ratio = *m * opacity;
 
1425
          ratio = ratio / 255 * src2_alpha;
 
1426
 
 
1427
          ratio = INT_DIV (ratio, new_alpha);
 
1428
 
 
1429
          for (b = 0; b < alpha; b++)
 
1430
            {
 
1431
              if (! affect[b])
 
1432
                {
 
1433
                  dest[b] = src1[b];
 
1434
                }
 
1435
              else if (src2[b] > src1[b])
 
1436
                {
 
1437
                  guint t = (src2[b] - src1[b]) * ratio;
 
1438
                  dest[b] = src1[b] + INT_DIV (t, 255);
 
1439
                }
 
1440
              else
 
1441
                {
 
1442
                  guint t = (src1[b] - src2[b]) * ratio;
 
1443
                  dest[b] = src1[b] - INT_DIV (t, 255);
 
1444
                }
 
1445
            }
 
1446
        }
 
1447
      else
 
1448
        {
 
1449
          for (b = 0; b < alpha; b++)
 
1450
            dest[b] = src1[b];
 
1451
        }
 
1452
 
 
1453
      if (has_alpha1)
 
1454
        dest[alpha] = affect[alpha] ? new_alpha : src1[alpha];
 
1455
 
 
1456
      if (mask)
 
1457
        m++;
 
1458
 
 
1459
      src1 += bytes1;
 
1460
      src2 += bytes2;
 
1461
      dest += bytes1;
 
1462
   }
1417
1463
}
1418
1464
 
1419
1465
/*  replace the contents of one pixel row with the other
1840
1886
/**************************************************/
1841
1887
 
1842
1888
void
 
1889
clear_region (PixelRegion *dest)
 
1890
{
 
1891
  gpointer pr;
 
1892
 
 
1893
  for (pr = pixel_regions_register (1, dest);
 
1894
       pr != NULL;
 
1895
       pr = pixel_regions_process (pr))
 
1896
    {
 
1897
      if (dest->w * dest->bytes == dest->rowstride)
 
1898
        {
 
1899
          memset (dest->data, 0, dest->w * dest->h * dest->bytes);
 
1900
        }
 
1901
      else
 
1902
        {
 
1903
          guchar *d = dest->data;
 
1904
          gint    h = dest->h;
 
1905
 
 
1906
          while (h--)
 
1907
            {
 
1908
              memset (d, 0, dest->w * dest->bytes);
 
1909
 
 
1910
              d += dest->rowstride;
 
1911
            }
 
1912
        }
 
1913
    }
 
1914
}
 
1915
 
 
1916
 
 
1917
void
1843
1918
color_region (PixelRegion  *dest,
1844
1919
              const guchar *col)
1845
1920
{
1875
1950
void
1876
1951
color_region_mask (PixelRegion  *dest,
1877
1952
                   PixelRegion  *mask,
1878
 
                   const guchar *col)
 
1953
                  const guchar *col)
1879
1954
{
1880
1955
  gpointer pr;
1881
1956
 
4560
4635
 
4561
4636
  /* Second check - if any single colour channel can't be affected,
4562
4637
     we can't use the opacity quickskip.
4563
 
  */
 
4638
   */
4564
4639
  if (st.opacity_quickskip_possible)
4565
4640
    {
4566
4641
      for (i = 0; i < src1->bytes - 1; i++)