~ubuntu-branches/ubuntu/lucid/sawfish/lucid-updates

« back to all changes in this revision

Viewing changes to src/images.c

  • Committer: Bazaar Package Importer
  • Author(s): Christian Marillat
  • Date: 2005-02-23 16:16:46 UTC
  • mfrom: (1.2.1 upstream) (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050223161646-4id6qyw4h9lkvb0v
Tags: 1:1.3+cvs20050222-1
* New cvs release.
* Add an emacs initialisation script to load sawfish.el (Closes: #295290)
* Updated sawfish.el to 1.32

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* images.c -- Image handling
2
 
   $Id: images.c,v 1.55 2001/01/12 03:12:38 jsh Exp $
 
2
   $Id: images.c,v 1.60 2005/01/04 15:34:25 jsh Exp $
3
3
 
4
4
   Copyright (C) 1999, 2000 John Harper <john@dcs.warwick.ac.uk>
5
5
 
39
39
 
40
40
#include "sawmill.h"
41
41
#include <assert.h>
 
42
#include <string.h>
42
43
 
43
44
static Lisp_Image *image_list;
44
45
int image_type;
88
89
    else
89
90
        return 0;
90
91
#elif defined HAVE_GDK_PIXBUF
91
 
    return gdk_pixbuf_new_from_file (file);
 
92
    return gdk_pixbuf_new_from_file (file, NULL);
92
93
#endif
93
94
}
94
95
 
592
593
    else
593
594
        return Fget_color_rgb (rep_MAKE_INT(shape.r * 256),
594
595
                               rep_MAKE_INT(shape.g * 256),
595
 
                               rep_MAKE_INT(shape.b * 256));
 
596
                               rep_MAKE_INT(shape.b * 256),
 
597
                               Qnil);
596
598
#elif defined HAVE_GDK_PIXBUF
597
599
    fprintf (stderr, "shape colors are unimplemented for gdk-pixbuf\n");
598
600
    return Qnil;
743
745
}
744
746
 
745
747
static inline void
746
 
bevel_pixel (u_char *data, bool up, double bevel_fraction)
 
748
bevel_pixel (u_char *data, bool up, int bevel_percent)
747
749
{
748
 
    double pix[3];
749
 
    pix[0] = ((double)data[0]) / 256.0;
750
 
    pix[1] = ((double)data[1]) / 256.0;
751
 
    pix[2] = ((double)data[2]) / 256.0;
 
750
    unsigned int t0 = data[0], t1 = data[1], t2 = data[2];
752
751
    if (up)
753
752
    {
754
 
        pix[0] = pix[0] + (1.0 - pix[0]) * bevel_fraction;
755
 
        pix[1] = pix[1] + (1.0 - pix[1]) * bevel_fraction;
756
 
        pix[2] = pix[2] + (1.0 - pix[2]) * bevel_fraction;
757
 
        data[0] = pix[0] * 256.0;
758
 
        data[1] = pix[1] * 256.0;
759
 
        data[2] = pix[2] * 256.0;
 
753
        data[0] = t0 + (255 - t0) * bevel_percent / 100;
 
754
        data[1] = t1 + (255 - t1) * bevel_percent / 100;
 
755
        data[2] = t2 + (255 - t2) * bevel_percent / 100;
760
756
    }
761
757
    else
762
758
    {
763
 
        pix[0] = pix[0] - pix[0] * bevel_fraction;
764
 
        pix[1] = pix[1] - pix[1] * bevel_fraction;
765
 
        pix[2] = pix[2] - pix[2] * bevel_fraction;
766
 
        data[0] = pix[0] * 256.0;
767
 
        data[1] = pix[1] * 256.0;
768
 
        data[2] = pix[2] * 256.0;
 
759
        data[0] = t0 - t0 * bevel_percent / 100;
 
760
        data[1] = t1 - t1 * bevel_percent / 100;
 
761
        data[2] = t2 - t2 * bevel_percent / 100;
 
762
    }
 
763
}
 
764
 
 
765
static inline void
 
766
bevel_region (u_char *data, int row_stride, int bpp,
 
767
              int rx, int ry, int rw, int rh, bool up, int bevel_percent)
 
768
{
 
769
    int x, y;
 
770
    for (y = ry; y < ry + rh; y++)
 
771
    {
 
772
        u_char *row = data + y * row_stride + rx * bpp;
 
773
        for (x = rx; x < rx + rh; x++)
 
774
        {
 
775
            bevel_pixel (row, up, bevel_percent);
 
776
            row += bpp;
 
777
        }
769
778
    }
770
779
}
771
780
 
772
781
static inline void
773
782
bevel_horizontally (u_char *data, int width, int height,
774
783
                    int row_stride, int channels, 
775
 
                    int border, bool top, bool up, double bevel_fraction)
 
784
                    int border, bool top, bool up, int bevel_percent)
776
785
{
777
786
    int rows;
778
787
    up = top ? up : !up;
786
795
            ptr += row_stride * (height - (rows + 1)) + (rows) * channels;
787
796
        for (x = rows; x < width - (rows + 1); x++)
788
797
        {
789
 
            bevel_pixel (ptr, up, bevel_fraction);
 
798
            bevel_pixel (ptr, up, bevel_percent);
790
799
            ptr += channels;
791
800
        }
792
801
    }
795
804
static inline void
796
805
bevel_vertically (u_char *data, int width, int height,
797
806
                  int row_stride, int channels,
798
 
                  int border, bool top, bool up, double bevel_fraction)
 
807
                  int border, bool top, bool up, int bevel_percent)
799
808
{
800
809
    int cols;
801
810
    up = top ? up : !up;
809
818
            ptr += (width - (cols + 1)) * channels + ((cols) * row_stride);
810
819
        for (y = cols; y <= height - (cols + 1); y++)
811
820
        {
812
 
            bevel_pixel (ptr, up, bevel_fraction);
 
821
            bevel_pixel (ptr, up, bevel_percent);
813
822
            ptr += row_stride;
814
823
        }
815
824
    }
816
825
}
817
826
 
818
827
DEFUN("bevel-image", Fbevel_image, Sbevel_image,
819
 
      (repv image, repv border, repv up, repv bevel_percent),
 
828
      (repv image, repv border, repv up, repv bevel_percent_),
820
829
      rep_Subr4) /*
821
830
::doc:sawfish.wm.images#bevel-image::
822
831
bevel-image IMAGE BORDER UP [BEVEL-PERCENT]
828
837
intensity of the bevel created.
829
838
::end:: */
830
839
{
831
 
    double bevel_fraction = 0.75;
 
840
    int bevel_percent = 75;
832
841
    rep_DECLARE1(image, IMAGEP);
833
842
    rep_DECLARE2(border, rep_INTP);
834
843
 
835
 
    if (!rep_INTP(bevel_percent))
836
 
        bevel_percent = global_symbol_value (Qdefault_bevel_percent);
837
 
    if (rep_INTP(bevel_percent))
 
844
    if (!rep_INTP(bevel_percent_))
 
845
        bevel_percent_ = global_symbol_value (Qdefault_bevel_percent);
 
846
    if (rep_INTP(bevel_percent_))
838
847
    {
839
 
        int bp = rep_INT(bevel_percent);
840
 
        if ((bp >= 0) && (bp <= 100))
841
 
            bevel_fraction = (((double) bp) / 100.0);
 
848
        bevel_percent = rep_INT (bevel_percent_);
 
849
        bevel_percent = CLAMP (bevel_percent, 0, 100);
842
850
    }
843
851
 
844
852
    bevel_horizontally (image_pixels (VIMAGE(image)),
846
854
                        image_height (VIMAGE(image)),
847
855
                        image_row_stride (VIMAGE(image)),
848
856
                        image_channels (VIMAGE(image)),
849
 
                        rep_INT(border), TRUE, up != Qnil, bevel_fraction);
 
857
                        rep_INT(border), TRUE, up != Qnil, bevel_percent);
850
858
    bevel_vertically (image_pixels (VIMAGE(image)),
851
859
                      image_width (VIMAGE(image)),
852
860
                      image_height (VIMAGE(image)),
853
861
                      image_row_stride (VIMAGE(image)),
854
862
                      image_channels (VIMAGE(image)),
855
 
                      rep_INT(border), TRUE, up != Qnil, bevel_fraction);
 
863
                      rep_INT(border), TRUE, up != Qnil, bevel_percent);
856
864
    bevel_horizontally (image_pixels (VIMAGE(image)),
857
865
                        image_width (VIMAGE(image)),
858
866
                        image_height (VIMAGE(image)),
859
867
                        image_row_stride (VIMAGE(image)),
860
868
                        image_channels (VIMAGE(image)),
861
 
                        rep_INT(border), FALSE, up != Qnil, bevel_fraction);
 
869
                        rep_INT(border), FALSE, up != Qnil, bevel_percent);
862
870
    bevel_vertically (image_pixels (VIMAGE(image)),
863
871
                      image_width (VIMAGE(image)),
864
872
                      image_height (VIMAGE(image)),
865
873
                      image_row_stride (VIMAGE(image)),
866
874
                      image_channels (VIMAGE(image)),
867
 
                      rep_INT(border), FALSE, up != Qnil, bevel_fraction);
 
875
                      rep_INT(border), FALSE, up != Qnil, bevel_percent);
868
876
 
869
877
    image_changed (VIMAGE(image));
870
878
    return image;
1456
1464
    int gcmask = 0;
1457
1465
    Pixmap pixmap, mask;
1458
1466
    image_render (img, w, h, &pixmap, &mask);
 
1467
    gcv.graphics_exposures = False;
 
1468
    gcmask |= GCGraphicsExposures;
1459
1469
    if (mask != 0)
1460
1470
    {
1461
1471
        gcv.clip_mask = mask;