pixbufutils 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -1,4 +1,94 @@
1
1
  pixbufutils
2
2
  ===========
3
3
 
4
- gdk-pixbuf related utils for ruby
4
+ gdk-pixbuf related utils for ruby
5
+
6
+
7
+ Methods:
8
+ --------
9
+
10
+ Methods that modify source pixbuf
11
+ * PixbufUtils.greyscale!(Gdk::Pixbuf src)
12
+
13
+
14
+ * PixbufUtils.greyscale_go!(Gdk::Pixbuf src)
15
+
16
+
17
+ * PixbufUtils.gamma!(Gdk::Pixbuf src, double level)
18
+
19
+
20
+ * PixbufUtils.soften_edges!(Gdk::Pixbuf src, Integer size)
21
+
22
+
23
+
24
+ Methods that return a modified copy
25
+
26
+ * PixbufUtils.remove_alpha(Gdk::Pixbuf src, Gdk::Color col)
27
+
28
+ returns new pixbuf with no alpha channel
29
+
30
+
31
+ * PixbufUtils.sharpen(Gdk::Pixbuf src, Integer radius)
32
+
33
+ returns new pixbuf
34
+
35
+
36
+ * PixbufUtils.extract_alpha(Gdk::Pixbuf src, Integer cutoff, Boolean force_2bit)
37
+ returns new pixbuf
38
+
39
+
40
+ * PixbufUtils.blur(Gdk::Pixbuf src, Integer radius)
41
+ returns new pixbuf
42
+
43
+ * PixbufUtils.rotate_90(Gdk::Pixbuf src, Boolean counter_clockwise)
44
+
45
+
46
+ * PixbufUtils.rotate_cw(Gdk::Pixbuf src)
47
+
48
+
49
+ * PixbufUtils.rotate_180(Gdk::Pixbuf src)
50
+
51
+
52
+ * PixbufUtils.rotate(Gdk::Pixbuf src, Integer angle)
53
+
54
+
55
+ * PixbufUtils.rotate_ccw(Gdk::Pixbuf src)
56
+
57
+
58
+ * PixbufUtils.gamma(Gdk::Pixbuf src, double level)
59
+
60
+
61
+ * PixbufUtils.to_tiff(Gdk::Pixbuf src, String filename)
62
+
63
+
64
+ * PixbufUtils.greyscale(Gdk::Pixbuf src)
65
+
66
+
67
+ * PixbufUtils.greyscale_go(Gdk::Pixbuf src)
68
+
69
+
70
+ * PixbufUtils.tint(Gdk::Pixbuf src, Integer r, Integer g, Integer b, Integer alpha=255)
71
+
72
+ Tint an image - alpha=0 -> no tint, alpha=255 -> pure tint
73
+
74
+
75
+ * PixbufUtils.perspect_v(Gdk::Pixbuf src, Integer top_x1, Integer top_x2, Integer bot_x1, Integer bot_x2)
76
+
77
+
78
+ * PixbufUtils.mask(Gdk::Pixbuf src, Gdk::Pixbuf mask)
79
+
80
+
81
+ * PixbufUtils.blend5050(Gdk::Pixbuf src1, Gdk::Pixbuf src2)
82
+
83
+
84
+ * PixbufUtils.mask_area(Gdk::Pixbuf mask, Integer cutoff)
85
+
86
+
87
+ * PixbufUtils.scale_max(Gdk::Pixbuf src, gulong max, Gdk::InterpType interp)
88
+
89
+
90
+ * PixbufUtils.draw_scaled(Gdk::Drawable drawable, Gdk::Pixbuf src, Integer x, Integer y, Integer width, Integer height, GdkInterpType interp)
91
+
92
+
93
+ * PixbufUtils.draw_scaled_clip(Gdk::Drawable drawable, Gdk::Pixbuf src, Integer x, Integer y, Integer width, Integer height, Gdk::Rectangle clip_area, Gdk::InterpType interp)
94
+
data/Rakefile CHANGED
@@ -22,7 +22,7 @@ spec = Gem::Specification.new do |s|
22
22
  s.name = "pixbufutils"
23
23
  s.author = "Geoff Youngs"
24
24
  s.email = "git@intersect-uk.co.uk"
25
- s.version = "0.0.2"
25
+ s.version = "0.0.3"
26
26
  s.homepage = "http://github.com/geoffyoungs/pixbufutils"
27
27
  s.summary = "Additional utils for Gdk::Pixbuf"
28
28
  s.add_dependency("rubber-generate", ">= 0.0.17")
@@ -54,7 +54,7 @@ PixbufUtils_CLASS_greyscale_go_pling(VALUE self, VALUE __v_src);
54
54
  static VALUE
55
55
  PixbufUtils_CLASS_greyscale_go(VALUE self, VALUE __v_src);
56
56
  static VALUE
57
- PixbufUtils_CLASS_tint(VALUE self, VALUE __v_src, VALUE __v_r, VALUE __v_g, VALUE __v_b);
57
+ PixbufUtils_CLASS_tint(int __p_argc, VALUE *__p_argv, VALUE self);
58
58
  static VALUE
59
59
  PixbufUtils_CLASS_perspect_v(VALUE self, VALUE __v_src, VALUE __v_top_x1, VALUE __v_top_x2, VALUE __v_bot_x1, VALUE __v_bot_x2);
60
60
  static VALUE
@@ -1089,12 +1089,13 @@ static GdkPixbuf *pixbuf_greyscale_go(GdkPixbuf *src, GdkPixbuf *dest)
1089
1089
  return dest;
1090
1090
  }
1091
1091
 
1092
- static inline char pu_clamp(int x, int min, int max)
1092
+ static inline unsigned char pu_clamp(int x)
1093
1093
  {
1094
- return (x > max) ? max : (x < min ? min : x);
1094
+ unsigned char i = (x > 255) ? 255 : (x < 0 ? 0 : x);
1095
+ return i;
1095
1096
  }
1096
1097
 
1097
- static GdkPixbuf *pixbuf_tint(GdkPixbuf *src, GdkPixbuf *dest, int r, int g, int b)
1098
+ static GdkPixbuf *pixbuf_tint(GdkPixbuf *src, GdkPixbuf *dest, int r, int g, int b, int alpha)
1098
1099
  {
1099
1100
  int s_has_alpha, d_has_alpha;
1100
1101
  int s_width, s_height, s_rowstride;
@@ -1130,10 +1131,13 @@ static GdkPixbuf *pixbuf_tint(GdkPixbuf *src, GdkPixbuf *dest, int r, int g, int
1130
1131
 
1131
1132
  for (j = 0; j < s_width; j++) {
1132
1133
  grey = GO_RGB_TO_GREY(sp[0], sp[1], sp[2]);
1133
-
1134
- dp[0] = pu_clamp(grey + r, 0, 255); /* red */
1135
- dp[1] = pu_clamp(grey + g, 0, 255); /* green */
1136
- dp[2] = pu_clamp(grey + b, 0, 255); /* blue */
1134
+
1135
+ dp[0] = pu_clamp(pu_clamp(((int)grey + r) * alpha / 255) + pu_clamp((int)sp[0] * (255 - alpha) / 255)); /* red */
1136
+
1137
+ //fprintf(stderr, "alpha=%i, r=%i, grey=%i -> %i + %i = %i\n", alpha, r, grey, pu_clamp(((int)grey + r) * alpha / 255), pu_clamp((int)sp[0] * (255 - alpha) / 255), dp[0]); /* red */
1138
+
1139
+ dp[1] = pu_clamp(pu_clamp((grey + g) * alpha / 255) + pu_clamp((int)sp[1] * (255 - alpha) / 255)); /* green */
1140
+ dp[2] = pu_clamp(pu_clamp((grey + b) * alpha / 255) + pu_clamp((int)sp[2] * (255 - alpha) / 255)); /* blue */
1137
1141
 
1138
1142
  if (s_has_alpha)
1139
1143
  {
@@ -1405,7 +1409,7 @@ PixbufUtils_CLASS_remove_alpha(VALUE self, VALUE __v_src, VALUE __v_col)
1405
1409
  __orig_src = src = GDK_PIXBUF(RVAL2GOBJ(__v_src));
1406
1410
  __orig_col = col = RVAL2BOXED(__v_col, GDK_TYPE_COLOR);
1407
1411
 
1408
- #line 1360 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1412
+ #line 1364 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1409
1413
 
1410
1414
  do {
1411
1415
  GdkPixbuf * dest ;
@@ -1437,7 +1441,7 @@ PixbufUtils_CLASS_sharpen(VALUE self, VALUE __v_src, VALUE __v_radius)
1437
1441
  __orig_src = src = GDK_PIXBUF(RVAL2GOBJ(__v_src));
1438
1442
  __orig_radius = radius = NUM2INT(__v_radius);
1439
1443
 
1440
- #line 1381 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1444
+ #line 1385 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1441
1445
  IGNORE(self);
1442
1446
  do { __p_retval = unref_pixbuf((pixbuf_sharpen(src, radius))); goto out; } while(0);
1443
1447
  out:
@@ -1473,7 +1477,7 @@ PixbufUtils_CLASS_extract_alpha(int __p_argc, VALUE *__p_argv, VALUE self)
1473
1477
  force_2bit = FALSE;
1474
1478
 
1475
1479
 
1476
- #line 1385 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1480
+ #line 1389 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1477
1481
  IGNORE(self);
1478
1482
  do { __p_retval = unref_pixbuf((pixbuf_extract_alpha(src, cutoff, force_2bit))); goto out; } while(0);
1479
1483
  out:
@@ -1490,7 +1494,7 @@ PixbufUtils_CLASS_blur(VALUE self, VALUE __v_src, VALUE __v_radius)
1490
1494
  __orig_src = src = GDK_PIXBUF(RVAL2GOBJ(__v_src));
1491
1495
  __orig_radius = radius = NUM2INT(__v_radius);
1492
1496
 
1493
- #line 1389 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1497
+ #line 1393 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1494
1498
  IGNORE(self);
1495
1499
  do { __p_retval = unref_pixbuf((pixbuf_blur(gdk_pixbuf_copy(src), radius))); goto out; } while(0);
1496
1500
  out:
@@ -1507,7 +1511,7 @@ PixbufUtils_CLASS_rotate_90(VALUE self, VALUE __v_src, VALUE __v_counter_clockwi
1507
1511
  __orig_src = src = GDK_PIXBUF(RVAL2GOBJ(__v_src));
1508
1512
  __orig_counter_clockwise = counter_clockwise = RTEST(__v_counter_clockwise);
1509
1513
 
1510
- #line 1393 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1514
+ #line 1397 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1511
1515
  IGNORE(self);
1512
1516
  do { __p_retval = unref_pixbuf((pixbuf_rotate(src, counter_clockwise ? ANGLE_270 : ANGLE_90))); goto out; } while(0);
1513
1517
  out:
@@ -1522,7 +1526,7 @@ PixbufUtils_CLASS_rotate_cw(VALUE self, VALUE __v_src)
1522
1526
  GdkPixbuf * src; GdkPixbuf * __orig_src;
1523
1527
  __orig_src = src = GDK_PIXBUF(RVAL2GOBJ(__v_src));
1524
1528
 
1525
- #line 1397 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1529
+ #line 1401 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1526
1530
  IGNORE(self);
1527
1531
  do { __p_retval = unref_pixbuf((pixbuf_rotate(src, ANGLE_90))); goto out; } while(0);
1528
1532
  out:
@@ -1537,7 +1541,7 @@ PixbufUtils_CLASS_rotate_180(VALUE self, VALUE __v_src)
1537
1541
  GdkPixbuf * src; GdkPixbuf * __orig_src;
1538
1542
  __orig_src = src = GDK_PIXBUF(RVAL2GOBJ(__v_src));
1539
1543
 
1540
- #line 1401 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1544
+ #line 1405 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1541
1545
  IGNORE(self);
1542
1546
  do { __p_retval = unref_pixbuf((pixbuf_rotate(src, ANGLE_180))); goto out; } while(0);
1543
1547
  out:
@@ -1554,7 +1558,7 @@ PixbufUtils_CLASS_rotate(VALUE self, VALUE __v_src, VALUE __v_angle)
1554
1558
  __orig_src = src = GDK_PIXBUF(RVAL2GOBJ(__v_src));
1555
1559
  __orig_angle = angle = NUM2INT(__v_angle);
1556
1560
 
1557
- #line 1405 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1561
+ #line 1409 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1558
1562
  IGNORE(self);
1559
1563
  g_assert(angle == 0 || angle == 90 || angle == 180 || angle == 270);
1560
1564
  do { __p_retval = unref_pixbuf((pixbuf_rotate(src, (rotate_angle_t)angle))); goto out; } while(0);
@@ -1570,7 +1574,7 @@ PixbufUtils_CLASS_rotate_ccw(VALUE self, VALUE __v_src)
1570
1574
  GdkPixbuf * src; GdkPixbuf * __orig_src;
1571
1575
  __orig_src = src = GDK_PIXBUF(RVAL2GOBJ(__v_src));
1572
1576
 
1573
- #line 1410 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1577
+ #line 1414 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1574
1578
  IGNORE(self);
1575
1579
  do { __p_retval = unref_pixbuf((pixbuf_rotate(src, ANGLE_270))); goto out; } while(0);
1576
1580
  out:
@@ -1587,7 +1591,7 @@ PixbufUtils_CLASS_gamma_pling(VALUE self, VALUE __v_src, VALUE __v_level)
1587
1591
  __orig_src = src = GDK_PIXBUF(RVAL2GOBJ(__v_src));
1588
1592
  __orig_level = level = NUM2DBL(__v_level);
1589
1593
 
1590
- #line 1414 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1594
+ #line 1418 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1591
1595
  IGNORE(self);
1592
1596
  do { __p_retval = GOBJ2RVAL(pixbuf_gamma(src, src, level)); goto out; } while(0);
1593
1597
  out:
@@ -1604,7 +1608,7 @@ PixbufUtils_CLASS_soften_edges_pling(VALUE self, VALUE __v_src, VALUE __v_size)
1604
1608
  __orig_src = src = GDK_PIXBUF(RVAL2GOBJ(__v_src));
1605
1609
  __orig_size = size = NUM2INT(__v_size);
1606
1610
 
1607
- #line 1418 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1611
+ #line 1422 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1608
1612
  IGNORE(self);
1609
1613
  do { __p_retval = GOBJ2RVAL(pixbuf_soften_edges(src, size)); goto out; } while(0);
1610
1614
  out:
@@ -1621,7 +1625,7 @@ PixbufUtils_CLASS_gamma(VALUE self, VALUE __v_src, VALUE __v_level)
1621
1625
  __orig_src = src = GDK_PIXBUF(RVAL2GOBJ(__v_src));
1622
1626
  __orig_level = level = NUM2DBL(__v_level);
1623
1627
 
1624
- #line 1422 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1628
+ #line 1426 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1625
1629
  IGNORE(self);
1626
1630
  do { __p_retval = unref_pixbuf((pixbuf_gamma(src, gdk_pixbuf_copy(src), level))); goto out; } while(0);
1627
1631
  out:
@@ -1636,7 +1640,7 @@ PixbufUtils_CLASS_greyscale_pling(VALUE self, VALUE __v_src)
1636
1640
  GdkPixbuf * src; GdkPixbuf * __orig_src;
1637
1641
  __orig_src = src = GDK_PIXBUF(RVAL2GOBJ(__v_src));
1638
1642
 
1639
- #line 1426 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1643
+ #line 1430 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1640
1644
  IGNORE(self);
1641
1645
  do { __p_retval = GOBJ2RVAL(pixbuf_greyscale(src, src)); goto out; } while(0);
1642
1646
  out:
@@ -1653,7 +1657,7 @@ PixbufUtils_CLASS_to_tiff(VALUE self, VALUE __v_src, VALUE __v_filename)
1653
1657
  __orig_src = src = GDK_PIXBUF(RVAL2GOBJ(__v_src));
1654
1658
  __orig_filename = filename = ( NIL_P(__v_filename) ? NULL : StringValuePtr(__v_filename) );
1655
1659
 
1656
- #line 1430 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1660
+ #line 1434 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1657
1661
  IGNORE(self);
1658
1662
  do { __p_retval = ((pixbuf_save_tiff(src, filename)) ? Qtrue : Qfalse); goto out; } while(0);
1659
1663
  out:
@@ -1668,7 +1672,7 @@ PixbufUtils_CLASS_greyscale(VALUE self, VALUE __v_src)
1668
1672
  GdkPixbuf * src; GdkPixbuf * __orig_src;
1669
1673
  __orig_src = src = GDK_PIXBUF(RVAL2GOBJ(__v_src));
1670
1674
 
1671
- #line 1434 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1675
+ #line 1438 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1672
1676
  IGNORE(self);
1673
1677
  do { __p_retval = unref_pixbuf((pixbuf_greyscale(src, gdk_pixbuf_copy(src)))); goto out; } while(0);
1674
1678
  out:
@@ -1683,7 +1687,7 @@ PixbufUtils_CLASS_greyscale_go_pling(VALUE self, VALUE __v_src)
1683
1687
  GdkPixbuf * src; GdkPixbuf * __orig_src;
1684
1688
  __orig_src = src = GDK_PIXBUF(RVAL2GOBJ(__v_src));
1685
1689
 
1686
- #line 1438 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1690
+ #line 1442 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1687
1691
  IGNORE(self);
1688
1692
  do { __p_retval = GOBJ2RVAL(pixbuf_greyscale_go(src, src)); goto out; } while(0);
1689
1693
  out:
@@ -1698,7 +1702,7 @@ PixbufUtils_CLASS_greyscale_go(VALUE self, VALUE __v_src)
1698
1702
  GdkPixbuf * src; GdkPixbuf * __orig_src;
1699
1703
  __orig_src = src = GDK_PIXBUF(RVAL2GOBJ(__v_src));
1700
1704
 
1701
- #line 1442 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1705
+ #line 1446 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1702
1706
  IGNORE(self);
1703
1707
  do { __p_retval = unref_pixbuf((pixbuf_greyscale_go(src, gdk_pixbuf_copy(src)))); goto out; } while(0);
1704
1708
  out:
@@ -1707,21 +1711,41 @@ out:
1707
1711
  }
1708
1712
 
1709
1713
  static VALUE
1710
- PixbufUtils_CLASS_tint(VALUE self, VALUE __v_src, VALUE __v_r, VALUE __v_g, VALUE __v_b)
1714
+ PixbufUtils_CLASS_tint(int __p_argc, VALUE *__p_argv, VALUE self)
1711
1715
  {
1712
1716
  VALUE __p_retval = Qnil;
1717
+ VALUE __v_src = Qnil;
1713
1718
  GdkPixbuf * src; GdkPixbuf * __orig_src;
1719
+ VALUE __v_r = Qnil;
1714
1720
  int r; int __orig_r;
1721
+ VALUE __v_g = Qnil;
1715
1722
  int g; int __orig_g;
1723
+ VALUE __v_b = Qnil;
1716
1724
  int b; int __orig_b;
1725
+ VALUE __v_alpha = Qnil;
1726
+ int alpha; int __orig_alpha;
1727
+
1728
+ /* Scan arguments */
1729
+ rb_scan_args(__p_argc, __p_argv, "41",&__v_src, &__v_r, &__v_g, &__v_b, &__v_alpha);
1730
+
1731
+ /* Set defaults */
1717
1732
  __orig_src = src = GDK_PIXBUF(RVAL2GOBJ(__v_src));
1733
+
1718
1734
  __orig_r = r = NUM2INT(__v_r);
1735
+
1719
1736
  __orig_g = g = NUM2INT(__v_g);
1737
+
1720
1738
  __orig_b = b = NUM2INT(__v_b);
1721
1739
 
1722
- #line 1446 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1740
+ if (__p_argc > 4)
1741
+ __orig_alpha = alpha = NUM2INT(__v_alpha);
1742
+ else
1743
+ alpha = 255;
1744
+
1745
+
1746
+ #line 1450 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1723
1747
  IGNORE(self);
1724
- do { __p_retval = unref_pixbuf((pixbuf_tint(src, gdk_pixbuf_copy(src), r, g, b))); goto out; } while(0);
1748
+ do { __p_retval = unref_pixbuf((pixbuf_tint(src, gdk_pixbuf_copy(src), r, g, b, alpha))); goto out; } while(0);
1725
1749
  out:
1726
1750
  ;
1727
1751
  return __p_retval;
@@ -1742,7 +1766,7 @@ PixbufUtils_CLASS_perspect_v(VALUE self, VALUE __v_src, VALUE __v_top_x1, VALUE
1742
1766
  __orig_bot_x1 = bot_x1 = NUM2INT(__v_bot_x1);
1743
1767
  __orig_bot_x2 = bot_x2 = NUM2INT(__v_bot_x2);
1744
1768
 
1745
- #line 1450 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1769
+ #line 1454 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1746
1770
  IGNORE(self);
1747
1771
  do { __p_retval = unref_pixbuf((pixbuf_perspect_v(src, top_x1, top_x2, bot_x1, bot_x2))); goto out; } while(0);
1748
1772
  out:
@@ -1759,7 +1783,7 @@ PixbufUtils_CLASS_mask(VALUE self, VALUE __v_src, VALUE __v_mask)
1759
1783
  __orig_src = src = GDK_PIXBUF(RVAL2GOBJ(__v_src));
1760
1784
  __orig_mask = mask = GDK_PIXBUF(RVAL2GOBJ(__v_mask));
1761
1785
 
1762
- #line 1454 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1786
+ #line 1458 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1763
1787
  IGNORE(self);
1764
1788
  do { __p_retval = unref_pixbuf((pixbuf_mask(src, mask))); goto out; } while(0);
1765
1789
  out:
@@ -1777,7 +1801,7 @@ PixbufUtils_CLASS_blend5050(VALUE self, VALUE __v_src1, VALUE __v_src2)
1777
1801
  __orig_src1 = src1 = GDK_PIXBUF(RVAL2GOBJ(__v_src1));
1778
1802
  __orig_src2 = src2 = GDK_PIXBUF(RVAL2GOBJ(__v_src2));
1779
1803
 
1780
- #line 1458 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1804
+ #line 1462 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1781
1805
  IGNORE(self);
1782
1806
  do { __p_retval = unref_pixbuf((pixbuf_blend5050(src1, src2))); goto out; } while(0);
1783
1807
  out:
@@ -1807,7 +1831,7 @@ PixbufUtils_CLASS_mask_area(int __p_argc, VALUE *__p_argv, VALUE self)
1807
1831
  cutoff = 127;
1808
1832
 
1809
1833
 
1810
- #line 1462 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1834
+ #line 1466 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1811
1835
  IGNORE(self);
1812
1836
  do { __p_retval = pixbuf_mask_area(mask, cutoff); goto out; } while(0);
1813
1837
  out:
@@ -1840,7 +1864,7 @@ PixbufUtils_CLASS_scale_max(int __p_argc, VALUE *__p_argv, VALUE self)
1840
1864
  interp = GDK_INTERP_BILINEAR;
1841
1865
 
1842
1866
 
1843
- #line 1466 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1867
+ #line 1470 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1844
1868
 
1845
1869
  do {
1846
1870
  gulong width, height, largest;
@@ -1902,7 +1926,7 @@ PixbufUtils_CLASS_draw_scaled(int __p_argc, VALUE *__p_argv, VALUE self)
1902
1926
  interp = GDK_INTERP_BILINEAR;
1903
1927
 
1904
1928
 
1905
- #line 1484 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1929
+ #line 1488 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1906
1930
 
1907
1931
  do {
1908
1932
  GdkPixbuf * tmp ;
@@ -1970,7 +1994,7 @@ PixbufUtils_CLASS_draw_scaled_clip(int __p_argc, VALUE *__p_argv, VALUE self)
1970
1994
  interp = GDK_INTERP_BILINEAR;
1971
1995
 
1972
1996
 
1973
- #line 1520 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1997
+ #line 1524 "/home/geoff/Projects/pixbufutils/ext/pixbufutils/pixbufutils.cr"
1974
1998
 
1975
1999
  do {
1976
2000
  GdkPixbuf * tmp ;
@@ -2020,7 +2044,7 @@ Init_pixbufutils(void)
2020
2044
  rb_define_singleton_method(mPixbufUtils, "greyscale", PixbufUtils_CLASS_greyscale, 1);
2021
2045
  rb_define_singleton_method(mPixbufUtils, "greyscale_go!", PixbufUtils_CLASS_greyscale_go_pling, 1);
2022
2046
  rb_define_singleton_method(mPixbufUtils, "greyscale_go", PixbufUtils_CLASS_greyscale_go, 1);
2023
- rb_define_singleton_method(mPixbufUtils, "tint", PixbufUtils_CLASS_tint, 4);
2047
+ rb_define_singleton_method(mPixbufUtils, "tint", PixbufUtils_CLASS_tint, -1);
2024
2048
  rb_define_singleton_method(mPixbufUtils, "perspect_v", PixbufUtils_CLASS_perspect_v, 5);
2025
2049
  rb_define_singleton_method(mPixbufUtils, "mask", PixbufUtils_CLASS_mask, 2);
2026
2050
  rb_define_singleton_method(mPixbufUtils, "blend5050", PixbufUtils_CLASS_blend5050, 2);
@@ -1036,12 +1036,13 @@ static GdkPixbuf *pixbuf_greyscale_go(GdkPixbuf *src, GdkPixbuf *dest)
1036
1036
  return dest;
1037
1037
  }
1038
1038
 
1039
- static inline char pu_clamp(int x, int min, int max)
1039
+ static inline unsigned char pu_clamp(int x)
1040
1040
  {
1041
- return (x > max) ? max : (x < min ? min : x);
1041
+ unsigned char i = (x > 255) ? 255 : (x < 0 ? 0 : x);
1042
+ return i;
1042
1043
  }
1043
1044
 
1044
- static GdkPixbuf *pixbuf_tint(GdkPixbuf *src, GdkPixbuf *dest, int r, int g, int b)
1045
+ static GdkPixbuf *pixbuf_tint(GdkPixbuf *src, GdkPixbuf *dest, int r, int g, int b, int alpha)
1045
1046
  {
1046
1047
  int s_has_alpha, d_has_alpha;
1047
1048
  int s_width, s_height, s_rowstride;
@@ -1077,10 +1078,13 @@ static GdkPixbuf *pixbuf_tint(GdkPixbuf *src, GdkPixbuf *dest, int r, int g, int
1077
1078
 
1078
1079
  for (j = 0; j < s_width; j++) {
1079
1080
  grey = GO_RGB_TO_GREY(sp[0], sp[1], sp[2]);
1080
-
1081
- dp[0] = pu_clamp(grey + r, 0, 255); /* red */
1082
- dp[1] = pu_clamp(grey + g, 0, 255); /* green */
1083
- dp[2] = pu_clamp(grey + b, 0, 255); /* blue */
1081
+
1082
+ dp[0] = pu_clamp(pu_clamp(((int)grey + r) * alpha / 255) + pu_clamp((int)sp[0] * (255 - alpha) / 255)); /* red */
1083
+
1084
+ //fprintf(stderr, "alpha=%i, r=%i, grey=%i -> %i + %i = %i\n", alpha, r, grey, pu_clamp(((int)grey + r) * alpha / 255), pu_clamp((int)sp[0] * (255 - alpha) / 255), dp[0]); /* red */
1085
+
1086
+ dp[1] = pu_clamp(pu_clamp((grey + g) * alpha / 255) + pu_clamp((int)sp[1] * (255 - alpha) / 255)); /* green */
1087
+ dp[2] = pu_clamp(pu_clamp((grey + b) * alpha / 255) + pu_clamp((int)sp[2] * (255 - alpha) / 255)); /* blue */
1084
1088
 
1085
1089
  if (s_has_alpha)
1086
1090
  {
@@ -1443,9 +1447,9 @@ module PixbufUtils
1443
1447
  IGNORE(self);
1444
1448
  return pixbuf_greyscale_go(src, gdk_pixbuf_copy(src));
1445
1449
  end
1446
- def unref_pixbuf:self.tint(GdkPixbuf *src, int r, int g, int b)
1450
+ def unref_pixbuf:self.tint(GdkPixbuf *src, int r, int g, int b, int alpha=255)
1447
1451
  IGNORE(self);
1448
- return pixbuf_tint(src, gdk_pixbuf_copy(src), r, g, b);
1452
+ return pixbuf_tint(src, gdk_pixbuf_copy(src), r, g, b, alpha);
1449
1453
  end
1450
1454
  def unref_pixbuf:self.perspect_v(GdkPixbuf *src, int top_x1, int top_x2, int bot_x1, int bot_x2)
1451
1455
  IGNORE(self);
@@ -50,7 +50,7 @@
50
50
  --- PixbufUtils.greyscale_go(GdkPixbuf* src)
51
51
 
52
52
 
53
- --- PixbufUtils.tint(GdkPixbuf* src, Integer r, Integer g, Integer b)
53
+ --- PixbufUtils.tint(GdkPixbuf* src, Integer r, Integer g, Integer b, Integer alpha)
54
54
 
55
55
 
56
56
  --- PixbufUtils.perspect_v(GdkPixbuf* src, Integer top_x1, Integer top_x2, Integer bot_x1, Integer bot_x2)
metadata CHANGED
@@ -1,65 +1,81 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: pixbufutils
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.2
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 3
10
+ version: 0.0.3
5
11
  platform: ruby
6
- authors:
12
+ authors:
7
13
  - Geoff Youngs
8
14
  autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
- date: 2013-04-30 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
17
+
18
+ date: 2013-08-14 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
14
21
  name: rubber-generate
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - '>='
18
- - !ruby/object:Gem::Version
19
- version: 0.0.17
20
- type: :runtime
21
22
  prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - '>='
25
- - !ruby/object:Gem::Version
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 61
29
+ segments:
30
+ - 0
31
+ - 0
32
+ - 17
26
33
  version: 0.0.17
27
- - !ruby/object:Gem::Dependency
28
- name: glib2
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - '>='
32
- - !ruby/object:Gem::Version
33
- version: 1.1.6
34
34
  type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: glib2
35
38
  prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - '>='
39
- - !ruby/object:Gem::Version
40
- version: 1.1.6
41
- - !ruby/object:Gem::Dependency
42
- name: gdk_pixbuf2
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - '>='
46
- - !ruby/object:Gem::Version
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 31
45
+ segments:
46
+ - 1
47
+ - 1
48
+ - 6
47
49
  version: 1.1.6
48
50
  type: :runtime
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ name: gdk_pixbuf2
49
54
  prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - '>='
53
- - !ruby/object:Gem::Version
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 31
61
+ segments:
62
+ - 1
63
+ - 1
64
+ - 6
54
65
  version: 1.1.6
66
+ type: :runtime
67
+ version_requirements: *id003
55
68
  description: |
56
69
  Misc functions for alpha channel extraction, gamma, tinting, masking, blur etc.
70
+
57
71
  email: git@intersect-uk.co.uk
58
72
  executables: []
59
- extensions:
73
+
74
+ extensions:
60
75
  - ext/pixbufutils/extconf.rb
61
76
  extra_rdoc_files: []
62
- files:
77
+
78
+ files:
63
79
  - ext/pixbufutils/pixbufutils.c
64
80
  - ext/pixbufutils/pixbufutils.cr
65
81
  - ext/pixbufutils/pixbufutils.rd
@@ -69,25 +85,36 @@ files:
69
85
  - ext/pixbufutils/extconf.rb
70
86
  homepage: http://github.com/geoffyoungs/pixbufutils
71
87
  licenses: []
72
- metadata: {}
88
+
73
89
  post_install_message:
74
90
  rdoc_options: []
75
- require_paths:
91
+
92
+ require_paths:
76
93
  - lib
77
- required_ruby_version: !ruby/object:Gem::Requirement
78
- requirements:
79
- - - '>='
80
- - !ruby/object:Gem::Version
81
- version: '0'
82
- required_rubygems_version: !ruby/object:Gem::Requirement
83
- requirements:
84
- - - '>='
85
- - !ruby/object:Gem::Version
86
- version: '0'
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ hash: 3
100
+ segments:
101
+ - 0
102
+ version: "0"
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ hash: 3
109
+ segments:
110
+ - 0
111
+ version: "0"
87
112
  requirements: []
113
+
88
114
  rubyforge_project:
89
- rubygems_version: 2.0.0.rc.2
115
+ rubygems_version: 1.8.15
90
116
  signing_key:
91
- specification_version: 4
117
+ specification_version: 3
92
118
  summary: Additional utils for Gdk::Pixbuf
93
119
  test_files: []
120
+
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: cf5ffcd50ee23580a40150ae57074706865a792e
4
- data.tar.gz: a856f0dd549e1b91d017a2e8117ab29b03adb1d9
5
- SHA512:
6
- metadata.gz: db960d74b9cd12d827f5a317a6de628a4ec0b0763b40c16513478249b0bf5ed8044d22bb5b641b0a216a6924df3a45bbf233cf3fa20281174c16fa79ad279623
7
- data.tar.gz: 0fd96ecc683c7a48c9d21dac79d82ddaa3c3d14b69f239f345946bca255771f3fdf8f5bc644ae69760254d0b852198c17a91d3702e73f2ad1588ffb972a75d35