rfreeimage 0.2.1 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/rfreeimage/rfi_main.c +187 -0
- data/lib/rfreeimage/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9c9e8cdd384482e5a8231dcbf76f2eef0c5abb0
|
4
|
+
data.tar.gz: 3a007f7207ac6b4ab4bc70cf165e67426883e541
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6511c5393c22018e14436d651a5b8d310eb82450553515d60e53ce5b9e0aa97123131a3a3df5c38235dcdebdbb56f5683dc5d2d7ecb746284b2d52cba1535e0
|
7
|
+
data.tar.gz: a6664341d28ffb484e1922376d79592801e912b25e88c0ec8842301d37c445150ca300a80a37d30eb418e11d1891455f30c21ba0e02edfc62ac6b6c086734d45
|
data/ext/rfreeimage/rfi_main.c
CHANGED
@@ -25,6 +25,24 @@ static void try_sort(int *x, int *y)
|
|
25
25
|
}
|
26
26
|
}
|
27
27
|
|
28
|
+
static int min_of_arrary(int x1, int x2, int x3, int x4)
|
29
|
+
{
|
30
|
+
int m = x1;
|
31
|
+
if(x2 < m) m = x2;
|
32
|
+
if(x3 < m) m = x3;
|
33
|
+
if(x4 < m) m = x4;
|
34
|
+
return m;
|
35
|
+
}
|
36
|
+
|
37
|
+
static int max_of_arrary(int x1, int x2, int x3, int x4)
|
38
|
+
{
|
39
|
+
int m = x1;
|
40
|
+
if(x2 > m) m = x2;
|
41
|
+
if(x3 > m) m = x3;
|
42
|
+
if(x4 > m) m = x4;
|
43
|
+
return m;
|
44
|
+
}
|
45
|
+
|
28
46
|
static VALUE rb_rfi_version(VALUE self)
|
29
47
|
{
|
30
48
|
return rb_ary_new3(3, INT2NUM(FREEIMAGE_MAJOR_VERSION),
|
@@ -48,6 +66,67 @@ struct native_image {
|
|
48
66
|
FIBITMAP *handle;
|
49
67
|
};
|
50
68
|
|
69
|
+
static void dd_line(struct native_image* img, int x0, int y0,
|
70
|
+
int x1,int y1,
|
71
|
+
unsigned int bgra, int size)
|
72
|
+
{
|
73
|
+
float x, dx, dy, y, k, deta, threshold=0.0001;
|
74
|
+
int hs = size / 2, i;
|
75
|
+
|
76
|
+
dx = x1-x0;
|
77
|
+
dy = y1-y0;
|
78
|
+
|
79
|
+
if(dx < threshold && dx > -threshold){
|
80
|
+
k = 0.0;
|
81
|
+
}
|
82
|
+
else
|
83
|
+
{
|
84
|
+
k=dy * 1.0 / dx;
|
85
|
+
}
|
86
|
+
|
87
|
+
if(dx > threshold)
|
88
|
+
{
|
89
|
+
deta = k > 1 ? 1.0 / k : 1;
|
90
|
+
for(i = -hs; i <= hs; i++) {
|
91
|
+
y = y0;
|
92
|
+
for (x = x0; x <= x1; x += deta){
|
93
|
+
FreeImage_SetPixelColor(img->handle, x + i, img->h - (y + i) - 1 , (RGBQUAD*)&bgra);
|
94
|
+
y = y + k * deta;
|
95
|
+
}
|
96
|
+
}
|
97
|
+
}
|
98
|
+
else if(dx < -threshold)
|
99
|
+
{
|
100
|
+
deta = k > 1 ? 1.0 / k : 1;
|
101
|
+
for(i = -hs; i <= hs; i++) {
|
102
|
+
y = y0;
|
103
|
+
for (x = x0; x >= x1; x -= deta){
|
104
|
+
FreeImage_SetPixelColor(img->handle, x + i, img->h - (y + i) - 1, (RGBQUAD*)&bgra);
|
105
|
+
y = y - k * deta;
|
106
|
+
}
|
107
|
+
}
|
108
|
+
}
|
109
|
+
else
|
110
|
+
{
|
111
|
+
if(dy >= 0)
|
112
|
+
{
|
113
|
+
for(i = -hs; i <= hs; i++) {
|
114
|
+
for (y = y0; y <= y1; y++){
|
115
|
+
FreeImage_SetPixelColor(img->handle, x0 + i, img->h - (y + i) - 1, (RGBQUAD*)&bgra);
|
116
|
+
}
|
117
|
+
}
|
118
|
+
}
|
119
|
+
else
|
120
|
+
{
|
121
|
+
for(i = -hs; i <= hs; i++) {
|
122
|
+
for (y = y0; y >= y1; y--){
|
123
|
+
FreeImage_SetPixelColor(img->handle, x0 + i, img->h - (y + i) - 1, (RGBQUAD*)&bgra);
|
124
|
+
}
|
125
|
+
}
|
126
|
+
}
|
127
|
+
}
|
128
|
+
}
|
129
|
+
|
51
130
|
static void Image_free(struct native_image* img)
|
52
131
|
{
|
53
132
|
if(!img)
|
@@ -673,6 +752,27 @@ static VALUE Image_draw_point(VALUE self, VALUE _x, VALUE _y, VALUE color, VALUE
|
|
673
752
|
return self;
|
674
753
|
}
|
675
754
|
|
755
|
+
static VALUE Image_draw_line(VALUE self, VALUE _x1, VALUE _y1,
|
756
|
+
VALUE _x2, VALUE _y2,
|
757
|
+
VALUE color, VALUE _size)
|
758
|
+
{
|
759
|
+
struct native_image* img;
|
760
|
+
int x1 = NUM2INT(_x1);
|
761
|
+
int y1 = NUM2INT(_y1);
|
762
|
+
int x2 = NUM2INT(_x2);
|
763
|
+
int y2 = NUM2INT(_y2);
|
764
|
+
int size = NUM2INT(_size);
|
765
|
+
unsigned int bgra = NUM2UINT(color);
|
766
|
+
if (size < 0)
|
767
|
+
rb_raise(rb_eArgError, "Invalid point size: %d", size);
|
768
|
+
Data_Get_Struct(self, struct native_image, img);
|
769
|
+
RFI_CHECK_IMG(img);
|
770
|
+
|
771
|
+
dd_line(img, x1, y1, x2, y2, bgra, size);
|
772
|
+
|
773
|
+
return self;
|
774
|
+
}
|
775
|
+
|
676
776
|
static VALUE Image_draw_rectangle(VALUE self, VALUE _x1, VALUE _y1,
|
677
777
|
VALUE _x2, VALUE _y2,
|
678
778
|
VALUE color, VALUE _width)
|
@@ -710,6 +810,40 @@ static VALUE Image_draw_rectangle(VALUE self, VALUE _x1, VALUE _y1,
|
|
710
810
|
return self;
|
711
811
|
}
|
712
812
|
|
813
|
+
/*
|
814
|
+
daw arbitrari quadrangle
|
815
|
+
four point is given clockwise ordered
|
816
|
+
*/
|
817
|
+
static VALUE Image_draw_quadrangle(VALUE self, VALUE _x1, VALUE _y1,
|
818
|
+
VALUE _x2, VALUE _y2,
|
819
|
+
VALUE _x3, VALUE _y3,
|
820
|
+
VALUE _x4, VALUE _y4,
|
821
|
+
VALUE color, VALUE _width)
|
822
|
+
{
|
823
|
+
struct native_image* img;
|
824
|
+
int x1 = NUM2INT(_x1);
|
825
|
+
int y1 = NUM2INT(_y1);
|
826
|
+
int x2 = NUM2INT(_x2);
|
827
|
+
int y2 = NUM2INT(_y2);
|
828
|
+
int x3 = NUM2INT(_x3);
|
829
|
+
int y3 = NUM2INT(_y3);
|
830
|
+
int x4 = NUM2INT(_x4);
|
831
|
+
int y4 = NUM2INT(_y4);
|
832
|
+
int size = NUM2INT(_width);
|
833
|
+
unsigned int bgra = NUM2UINT(color);
|
834
|
+
if (size < 0)
|
835
|
+
rb_raise(rb_eArgError, "Invalid line width: %d", size);
|
836
|
+
Data_Get_Struct(self, struct native_image, img);
|
837
|
+
RFI_CHECK_IMG(img);
|
838
|
+
|
839
|
+
dd_line(img, x1, y1, x2, y2, bgra, size);
|
840
|
+
dd_line(img, x2, y2, x3, y3, bgra, size);
|
841
|
+
dd_line(img, x3, y3, x4, y4, bgra, size);
|
842
|
+
dd_line(img, x4, y4, x1, y1, bgra, size);
|
843
|
+
|
844
|
+
return self;
|
845
|
+
}
|
846
|
+
|
713
847
|
static VALUE Image_fill_rectangle(VALUE self, VALUE _x1, VALUE _y1,
|
714
848
|
VALUE _x2, VALUE _y2,
|
715
849
|
VALUE color)
|
@@ -737,6 +871,56 @@ static VALUE Image_fill_rectangle(VALUE self, VALUE _x1, VALUE _y1,
|
|
737
871
|
return self;
|
738
872
|
}
|
739
873
|
|
874
|
+
/*
|
875
|
+
daw arbitrari quadrangle
|
876
|
+
four point is given clockwise ordered
|
877
|
+
*/
|
878
|
+
static VALUE Image_fill_quadrangle(VALUE self, VALUE _x1, VALUE _y1,
|
879
|
+
VALUE _x2, VALUE _y2,
|
880
|
+
VALUE _x3, VALUE _y3,
|
881
|
+
VALUE _x4, VALUE _y4,
|
882
|
+
VALUE color)
|
883
|
+
{
|
884
|
+
struct native_image* img;
|
885
|
+
int x1 = NUM2INT(_x1);
|
886
|
+
int y1 = NUM2INT(_y1);
|
887
|
+
int x2 = NUM2INT(_x2);
|
888
|
+
int y2 = NUM2INT(_y2);
|
889
|
+
int x3 = NUM2INT(_x3);
|
890
|
+
int y3 = NUM2INT(_y3);
|
891
|
+
int x4 = NUM2INT(_x4);
|
892
|
+
int y4 = NUM2INT(_y4);
|
893
|
+
unsigned int bgra = NUM2UINT(color);
|
894
|
+
|
895
|
+
int d1, d2, d3, d4;
|
896
|
+
int x,y;
|
897
|
+
int minx, miny, maxx, maxy;
|
898
|
+
|
899
|
+
Data_Get_Struct(self, struct native_image, img);
|
900
|
+
RFI_CHECK_IMG(img);
|
901
|
+
|
902
|
+
minx = min_of_arrary(x1,x2,x3,x4);
|
903
|
+
maxx = max_of_arrary(x1,x2,x3,x4);
|
904
|
+
miny = min_of_arrary(y1,y2,y3,y4);
|
905
|
+
maxy = max_of_arrary(y1,y2,y3,y4);
|
906
|
+
|
907
|
+
for(x = minx; x <= maxx; x++) {
|
908
|
+
for(y = miny; y <= maxy; y++) {
|
909
|
+
//if inner
|
910
|
+
d1 = (x2 - x1) * (y - y1) - (y2 - y1) * (x - x1);
|
911
|
+
d2 = (x3 - x2) * (y - y2) - (y3 - y2) * (x - x2);
|
912
|
+
d3 = (x4 - x3) * (y - y3) - (y4 - y3) * (x - x3);
|
913
|
+
d4 = (x1 - x4) * (y - y4) - (y1 - y4) * (x - x4);
|
914
|
+
|
915
|
+
if((d1 > 0 && d2 > 0 && d3 >0 && d4 >0) || (d1 < 0 && d2 < 0 && d3 < 0 && d4 <0))
|
916
|
+
{
|
917
|
+
FreeImage_SetPixelColor(img->handle, x, img->h - y, (RGBQUAD*)&bgra);
|
918
|
+
}
|
919
|
+
}
|
920
|
+
}
|
921
|
+
|
922
|
+
return self;
|
923
|
+
}
|
740
924
|
|
741
925
|
void Init_rfreeimage(void)
|
742
926
|
{
|
@@ -772,8 +956,11 @@ void Init_rfreeimage(void)
|
|
772
956
|
|
773
957
|
/* draw */
|
774
958
|
rb_define_method(Class_Image, "draw_point", Image_draw_point, 4);
|
959
|
+
rb_define_method(Class_Image, "draw_line", Image_draw_line, 4 + 2);
|
775
960
|
rb_define_method(Class_Image, "draw_rectangle", Image_draw_rectangle, 4 + 2);
|
961
|
+
rb_define_method(Class_Image, "draw_quadrangle", Image_draw_quadrangle, 8 + 2);
|
776
962
|
rb_define_method(Class_Image, "fill_rectangle", Image_fill_rectangle, 4 + 1);
|
963
|
+
rb_define_method(Class_Image, "fill_quadrangle", Image_fill_quadrangle, 8 + 1);
|
777
964
|
|
778
965
|
rb_define_singleton_method(Class_Image, "ping", Image_ping, 1);
|
779
966
|
rb_define_singleton_method(Class_Image, "from_blob", Image_from_blob, -1);
|
data/lib/rfreeimage/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rfreeimage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuheng Chen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-04-
|
11
|
+
date: 2018-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|