texplay 0.2.710 → 0.2.722

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,23 @@
1
+ #ifndef GUARD_GRAPHICS_UTILS_H
2
+ #define GUARD_GRAPHICS_UTILS_H
3
+
4
+ void update_lazy_bounds(action_struct * cur, texture_info * tex);
5
+ void update_bounds(action_struct * cur, int xmin, int ymin, int xmax, int ymax);
6
+ void set_local_bounds(action_struct * cur, int xmin, int ymin, int xmax, int ymax, texture_info * tex);
7
+
8
+ void draw_prologue(action_struct * cur, texture_info * tex, int xmin, int ymin, int xmax, int ymax, VALUE * hash_arg,
9
+ sync sync_mode, bool primary, action_struct ** payload_ptr);
10
+ void draw_epilogue(action_struct * cur, texture_info * tex, bool primary);
11
+
12
+ void set_pixel_color_with_style(action_struct * payload, texture_info * tex, int x, int y);
13
+ void set_pixel_color(rgba * pixel_color, texture_info * tex, int x, int y);
14
+
15
+ rgba get_pixel_color_from_chunk(float * chunk, int width, int height, int x, int y);
16
+ rgba get_pixel_color(texture_info * tex, int x, int y);
17
+ float* get_pixel_data(texture_info * tex, int x, int y);
18
+
19
+ /* create a blank gosu image of width and height */
20
+ VALUE create_image(VALUE window, int width, int height);
21
+
22
+
23
+ #endif
data/ext/texplay/utils.c CHANGED
@@ -32,8 +32,8 @@
32
32
  :: "r" (X), "r" (Y)); })
33
33
 
34
34
  */
35
- /* internal linkage with static duration */
36
- static const rgba not_a_color_v = { -1.0, -1.0, -1.0, -1.0 };
35
+ /* external linkage with static duration */
36
+ const rgba not_a_color_v = { -1.0, -1.0, -1.0, -1.0 };
37
37
 
38
38
  /* utility functions */
39
39
  char*
@@ -276,28 +276,7 @@ save_rgba_to_image_local_color(VALUE image, rgba color)
276
276
  return ilc;
277
277
  }
278
278
 
279
- /* if 2nd param is Qnil, then create a blank image with 'width' and 'height
280
- otherwise, try to use the 2nd param (dup) to create a duplicate image
281
- */
282
- VALUE
283
- create_image(VALUE window, int width, int height)
284
- {
285
- VALUE gosu = rb_const_get(rb_cObject, rb_intern("Gosu"));
286
- VALUE image = rb_const_get(gosu, rb_intern("Image"));
287
-
288
- VALUE TP = rb_const_get(rb_cObject, rb_intern("TexPlay"));
289
- VALUE EmptyImageStub = rb_const_get(TP, rb_intern("EmptyImageStub"));
290
-
291
- VALUE rmagick_img;
292
- VALUE new_image;
293
279
 
294
- rmagick_img = rb_funcall(EmptyImageStub, rb_intern("new"), 2, INT2FIX(width), INT2FIX(height));
295
-
296
- new_image = rb_funcall(image, rb_intern("new"), 2, window, rmagick_img);
297
-
298
- return new_image;
299
- }
300
-
301
280
 
302
281
  bool
303
282
  not_a_color(rgba color1)
@@ -332,80 +311,6 @@ zero_color(float * tex)
332
311
  memset(tex, 0, 4 * sizeof(float));
333
312
  }
334
313
 
335
- rgba
336
- get_pixel_color_from_chunk(float * chunk, int width, int height, int x, int y)
337
- {
338
- rgba my_color;
339
-
340
- int offset;
341
-
342
- if(x > (width - 1) || x < 0 || y > (height - 1) || y < 0)
343
- return not_a_color_v;
344
-
345
- offset = 4 * (x + y * width);
346
-
347
- my_color.red = chunk[offset + red];
348
- my_color.green = chunk[offset + green];
349
- my_color.blue = chunk[offset + blue];
350
- my_color.alpha = chunk[offset + alpha];
351
-
352
- return my_color;
353
- }
354
-
355
-
356
- rgba
357
- get_pixel_color(texture_info * tex, int x, int y)
358
- {
359
- rgba my_color;
360
-
361
- int offset;
362
-
363
- /* if pixel location is out of range return not_a_color_v */
364
- if (x > (tex->width - 1) || x < 0 || y > (tex->height - 1) || y < 0)
365
- return not_a_color_v;
366
-
367
- offset = calc_pixel_offset(tex, x, y);
368
-
369
- my_color.red = tex->td_array[offset + red];
370
- my_color.green = tex->td_array[offset + green];
371
- my_color.blue = tex->td_array[offset + blue];
372
- my_color.alpha = tex->td_array[offset + alpha];
373
-
374
- return my_color;
375
- }
376
-
377
- /* return the array where pixel data is stored */
378
- float*
379
- get_pixel_data(texture_info * tex, int x, int y)
380
- {
381
- int offset = calc_pixel_offset(tex, x, y);
382
-
383
- return &tex->td_array[offset];
384
- }
385
-
386
- /* set the pixel color at (x, y) */
387
- void
388
- set_pixel_color(rgba * pixel_color, texture_info * tex, int x, int y)
389
- {
390
- float * tex_data;
391
-
392
- /* should pixel be drawn ? */
393
- if (x > (tex->width - 1) || x < 0 || y > (tex->height - 1) || y < 0)
394
- return;
395
-
396
- /* if not a color then do not draw */
397
- if(not_a_color(*pixel_color))
398
- return;
399
-
400
- tex_data = get_pixel_data(tex, x, y);
401
-
402
- /* set the pixel color */
403
- tex_data[red] = pixel_color->red;
404
- tex_data[green] = pixel_color->green;
405
- tex_data[blue] = pixel_color->blue;
406
- tex_data[alpha] = pixel_color->alpha;
407
- }
408
-
409
314
  rgba
410
315
  find_color_from_string(char * try_color)
411
316
  {
@@ -721,176 +626,50 @@ calc_pixel_offset(texture_info * tex, int x, int y)
721
626
  return offset;
722
627
  }
723
628
 
724
- /* from Texure.cpp in Gosu Graphics folder */
629
+ /* NEWEST version that solves segfault on linux, temporarily
630
+ out of action due to unavailability of MAX_TEXTURE_SIZE constant
631
+ in ruby 1.8 */
632
+ /*
725
633
  unsigned
726
634
  max_quad_size(void)
727
635
  {
728
- #ifdef __APPLE__
729
- return 1024;
730
- #else
731
- static unsigned MIN_SIZE = 256, MAX_SIZE = 1024;
732
636
 
733
637
  static unsigned size = 0;
734
- if (size == 0)
735
- {
736
- GLint width = 1;
737
- size = MIN_SIZE / 2;
738
- do {
739
- size *= 2;
740
- glTexImage2D(GL_PROXY_TEXTURE_2D, 0, 4, size * 2, size * 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
741
- glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
742
- } while (width != 0 && size < MAX_SIZE);
743
- }
744
638
 
745
- return size;
746
- #endif
747
- }
748
-
749
- /* ensure gl_tex_info returns non nil */
750
- VALUE
751
- check_for_texture_info(VALUE image)
752
- {
753
- VALUE info;
639
+ if (size == 0) {
640
+ VALUE gosu = rb_const_get(rb_cObject, rb_intern("Gosu"));
641
+ VALUE rb_size = rb_const_get(gosu, rb_intern("MAX_TEXTURE_SIZE"));
754
642
 
755
- info = rb_funcall(image, rb_intern("gl_tex_info"), 0);
756
-
757
- if(NIL_P(info)) {
758
- VALUE image_name = rb_inspect(image);
759
- int width = FIX2INT(rb_funcall(image, rb_intern("width"), 0));
760
- int height = FIX2INT(rb_funcall(image, rb_intern("height"), 0));
761
-
762
- rb_raise(rb_eException, "Error: gl_tex_info returns nil for %s (%i x %i). Could be caused by "
763
- "very large image or Gosu bug. Try updating Gosu or use a smaller image. Note: TexPlay should"
764
- " be able to work with %i x %i images.",
765
- StringValuePtr(image_name), width, height, max_quad_size() - 2, max_quad_size() - 2);
643
+ size = FIX2INT(rb_size);
766
644
  }
767
-
768
- return info;
769
- }
770
-
771
- float *
772
- allocate_texture(int width, int height)
773
- {
774
- float * new_texture;
775
- int mval;
776
-
777
- mval = 4 * width * height * sizeof(float);
778
- assert(mval > 0);
779
-
780
- new_texture = malloc(mval);
781
-
782
- return (float *)new_texture;
783
- }
784
-
785
- /* responsible for syncing a subimage to gl */
786
- void
787
- sync_to_gl(int tex_name, int x_offset, int y_offset, int width, int height, void * sub)
788
- {
789
- /* set the opengl texture context */
790
- glEnable(GL_TEXTURE_2D);
791
- glBindTexture(GL_TEXTURE_2D, tex_name);
792
-
793
- /* sync subtexture */
794
- glTexSubImage2D(GL_TEXTURE_2D, 0, x_offset, y_offset, width, height,
795
- GL_RGBA, GL_FLOAT, sub);
796
-
797
- glDisable(GL_TEXTURE_2D);
798
- }
799
-
800
- void
801
- create_subtexture_and_sync_to_gl(image_bounds * img_bounds, texture_info * tex)
802
- {
803
- /* image vars */
804
- int xbound, ybound;
805
- float * sub = NULL;
806
-
807
- /* make the current action's boundaries sane; left until this point because we only
808
- know height/width here */
809
- constrain_boundaries(&img_bounds->xmin, &img_bounds->ymin, &img_bounds->xmax, &img_bounds->ymax,
810
- tex->width, tex->height);
811
645
 
812
- /* helper variables */
813
- ybound = img_bounds->ymax - img_bounds->ymin + 1;
814
- xbound = img_bounds->xmax - img_bounds->xmin + 1;
815
-
816
- sub = get_image_chunk(tex, img_bounds->xmin, img_bounds->ymin, img_bounds->xmax, img_bounds->ymax);
817
-
818
- sync_to_gl(tex->tname, tex->x_offset + img_bounds->xmin, tex->y_offset + img_bounds->ymin, xbound,
819
- ybound, (void*)sub);
820
-
821
- free(sub);
822
- }
823
-
824
- float *
825
- get_image_chunk(texture_info * tex, int xmin, int ymin, int xmax, int ymax)
826
- {
827
- int xbound;
828
- int ybound;
829
- int x, y;
830
- float * image_buf = NULL;
831
-
832
- constrain_boundaries(&xmin, &ymin, &xmax, &ymax, tex->width, tex->height);
833
-
834
- xbound = xmax - xmin + 1;
835
- ybound = ymax - ymin + 1;
836
-
837
- image_buf = allocate_texture(xbound, ybound);
838
-
839
- for(y = 0; y < ybound; y++)
840
- for(x = 0; x < xbound; x++) {
841
- int buf_index = 4 * (x + y * xbound);
842
-
843
- int offset = calc_pixel_offset(tex, x + xmin, y + ymin);
844
-
845
- color_copy(tex->td_array + offset, image_buf + buf_index);
846
- }
847
-
848
- return image_buf;
646
+ return size;
849
647
  }
648
+ */
850
649
 
851
- /* get information from texture */
852
- void
853
- get_texture_info(VALUE image, texture_info * tex)
650
+ /* old version for quick update */
651
+ unsigned
652
+ max_quad_size(void)
854
653
  {
855
- VALUE info, gc_state_off;
856
- int toppos, leftpos;
857
- float top, left;
858
- cache_entry * entry;
859
-
860
- /* hack to prevent segfault */
861
- gc_state_off = rb_gc_disable();
862
-
863
- tex->width = FIX2INT(rb_funcall(image, rb_intern("width"), 0));
864
- tex->height = FIX2INT(rb_funcall(image, rb_intern("height"), 0));
865
-
866
- /* ensure gl_tex_info returns non nil */
867
- info = check_for_texture_info(image);
868
-
869
- top = NUM2DBL(rb_funcall(info, rb_intern("top"), 0));
870
- left = NUM2DBL(rb_funcall(info, rb_intern("left"), 0));
871
- tex->tname = FIX2INT(rb_funcall(info ,rb_intern("tex_name"),0));
872
-
873
- /* search for texture in cache (& create if not extant) */
874
- entry = find_or_create_cache_entry(tex->tname);
875
-
876
- tex->td_array = entry->tdata;
877
- tex->yincr = entry->sidelength;
878
-
879
- /* scratch variables */
880
- toppos = ROUND(top * entry->sidelength * entry->sidelength);
881
- leftpos = ROUND(left * entry->sidelength);
882
-
883
- /* find the first pixel for the image */
884
- tex->firstpixel = (int)(toppos + leftpos);
885
-
886
- tex->x_offset = ROUND(left * tex->yincr);
887
- tex->y_offset = ROUND(top * tex->yincr);
888
-
889
- /* save the associated Gosu::Image */
890
- tex->image = image;
654
+ #ifdef __APPLE__
655
+ return 1024;
656
+ #else
657
+ static unsigned MIN_SIZE = 256, MAX_SIZE = 1024;
658
+
659
+ static unsigned size = 0;
660
+ if (size == 0)
661
+ {
662
+ GLint width = 1;
663
+ size = MIN_SIZE / 2;
664
+ do {
665
+ size *= 2;
666
+ glTexImage2D(GL_PROXY_TEXTURE_2D, 0, 4, size * 2, size * 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
667
+ glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
668
+ } while (width != 0 && size < MAX_SIZE);
669
+ }
891
670
 
892
- /* only enable gc if was enabled on function entry */
893
- if(!gc_state_off) rb_gc_enable();
671
+ return size;
672
+ #endif
894
673
  }
895
674
 
896
675
  /* point format utilities */
@@ -930,8 +709,7 @@ power(float base, int exp)
930
709
  }
931
710
  else if(exp == 0) return 1;
932
711
  else {
933
- int k;
934
- for(k = exp; k >= 1; k--) {
712
+ for(int k = exp; k >= 1; k--) {
935
713
  ans = ans * base;
936
714
  }
937
715
  return ans;
@@ -963,8 +741,7 @@ unsigned
963
741
  perm(int n, int r)
964
742
  {
965
743
  int val = 1;
966
- int i;
967
- for(i = n; i > (n - r); i--)
744
+ for(int i = n; i > (n - r); i--)
968
745
  val *= i;
969
746
 
970
747
  return val;
data/ext/texplay/utils.h CHANGED
@@ -8,6 +8,8 @@
8
8
  #define IMAGE_COLOR 2
9
9
  #define USER_DEFAULTS 3
10
10
 
11
+ /* shared global */
12
+ extern const rgba not_a_color_v;
11
13
 
12
14
  /* color and pixel related functions */
13
15
  rgba find_color_from_string(char * try_color);
@@ -85,8 +87,6 @@ void check_image(VALUE image);
85
87
  /* is try_image a Gosu::Image ? */
86
88
  bool is_gosu_image(VALUE try_image);
87
89
 
88
- /* create a blank gosu image of width and height */
89
- VALUE create_image(VALUE window, int width, int height);
90
90
 
91
91
  /* make boundaries sane */
92
92
  void constrain_boundaries(int * x0, int * y0, int * x1, int * y1, int width, int height);
File without changes
data/lib/texplay.rb CHANGED
File without changes
@@ -1,3 +1,3 @@
1
1
  module TexPlay
2
- VERSION = "0.2.710"
2
+ VERSION = "0.2.722"
3
3
  end
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: texplay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.710
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 2
8
+ - 722
9
+ version: 0.2.722
5
10
  platform: ruby
6
11
  authors:
7
12
  - John Mair (banisterfiend)
@@ -9,19 +14,23 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2009-12-08 00:00:00 -05:00
17
+ date: 2010-03-14 00:00:00 +13:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: gosu
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
20
24
  requirements:
21
25
  - - ">="
22
26
  - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 7
30
+ - 14
23
31
  version: 0.7.14
24
- version:
32
+ type: :runtime
33
+ version_requirements: *id001
25
34
  description: TexPlay is a light-weight image manipulation framework for Ruby and Gosu
26
35
  email: jrmair@gmail.com
27
36
  executables: []
@@ -38,57 +47,60 @@ files:
38
47
  - lib/texplay-contrib.rb
39
48
  - lib/texplay/version.rb
40
49
  - ext/texplay/extconf.rb
41
- - ext/texplay/object2module.h
42
- - ext/texplay/bindings.h
43
- - ext/texplay/utils.h
44
50
  - ext/texplay/actions.h
45
- - ext/texplay/compat.h
51
+ - ext/texplay/bindings.h
46
52
  - ext/texplay/cache.h
47
- - ext/texplay/texplay.h
53
+ - ext/texplay/compat.h
48
54
  - ext/texplay/gen_eval.h
49
- - ext/texplay/texplay.c
55
+ - ext/texplay/graphics_utils.h
56
+ - ext/texplay/object2module.h
57
+ - ext/texplay/texplay.h
58
+ - ext/texplay/utils.h
50
59
  - ext/texplay/actions.c
51
- - ext/texplay/object2module.c
52
- - ext/texplay/utils.c
53
60
  - ext/texplay/bindings.c
54
- - ext/texplay/gen_eval.c
55
61
  - ext/texplay/cache.c
56
- - examples/example_dup.rb
57
- - examples/example_turtle.rb
58
- - examples/example_color_control.rb
59
- - examples/example_sine.rb
60
- - examples/example_effect.rb
62
+ - ext/texplay/gen_eval.c
63
+ - ext/texplay/graphics_utils.c
64
+ - ext/texplay/object2module.c
65
+ - ext/texplay/texplay.c
66
+ - ext/texplay/utils.c
61
67
  - examples/common.rb
68
+ - examples/example_alpha_blend.rb
69
+ - examples/example_bezier.rb
70
+ - examples/example_color_control.rb
62
71
  - examples/example_color_transform.rb
63
- - examples/example_fill_test.rb
64
- - examples/example_hash_arguments.rb
65
- - examples/example_gen_eval.rb
66
- - examples/example_polyline.rb
72
+ - examples/example_dup.rb
73
+ - examples/example_each.rb
74
+ - examples/example_effect.rb
67
75
  - examples/example_fill.rb
68
- - examples/example_bezier.rb
69
- - examples/example_simple.rb
70
76
  - examples/example_fill_old.rb
71
- - examples/example_blur.rb
72
- - examples/example_each.rb
73
- - examples/example_modify.rb
74
77
  - examples/example_fluent.rb
75
- - examples/example_sync.rb
76
- - examples/example_splice.rb
77
- - examples/example_alpha_blend.rb
78
- - examples/example_melt.rb
78
+ - examples/example_gen_eval.rb
79
+ - examples/example_hash_arguments.rb
79
80
  - examples/example_lsystem.rb
81
+ - examples/example_melt.rb
82
+ - examples/example_polyline.rb
80
83
  - examples/example_scale.rb
81
- - examples/media/sand1.png
82
- - examples/media/rose.bmp
84
+ - examples/example_simple.rb
85
+ - examples/example_splice.rb
86
+ - examples/example_sync.rb
87
+ - examples/example_turtle.rb
88
+ - examples/example_weird.rb
89
+ - examples/media/bird.png
90
+ - examples/media/empty2.png
91
+ - examples/media/gob.png
92
+ - examples/media/gosu.png
93
+ - examples/media/green.png
94
+ - examples/media/logo.png
83
95
  - examples/media/maria.png
96
+ - examples/media/rose.bmp
97
+ - examples/media/sand1.png
84
98
  - examples/media/sunset.png
85
99
  - examples/media/texplay.png
86
- - examples/media/gosu.png
87
- - examples/media/logo.png
88
- - examples/media/platform.png
89
- - examples/media/empty2.png
90
- has_rdoc: false
100
+ has_rdoc: true
91
101
  homepage: http://banisterfiend.wordpress.com/2008/08/23/texplay-an-image-manipulation-tool-for-ruby-and-gosu/
102
+ licenses: []
103
+
92
104
  post_install_message:
93
105
  rdoc_options: []
94
106
 
@@ -98,20 +110,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
98
110
  requirements:
99
111
  - - ">="
100
112
  - !ruby/object:Gem::Version
113
+ segments:
114
+ - 0
101
115
  version: "0"
102
- version:
103
116
  required_rubygems_version: !ruby/object:Gem::Requirement
104
117
  requirements:
105
118
  - - ">="
106
119
  - !ruby/object:Gem::Version
120
+ segments:
121
+ - 0
107
122
  version: "0"
108
- version:
109
123
  requirements: []
110
124
 
111
125
  rubyforge_project:
112
- rubygems_version: 1.2.0
126
+ rubygems_version: 1.3.6
113
127
  signing_key:
114
- specification_version: 2
128
+ specification_version: 3
115
129
  summary: TexPlay is a light-weight image manipulation framework for Ruby and Gosu
116
130
  test_files: []
117
131