1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
#![allow(unused_variables)]
use crate::prelude::*;
use crate::{platform::core::{Handle, Material}, Actor, HandlerId, ImageScaleMode, Timeline, Widget};
use std::{cell::RefCell, fmt};
#[derive(Clone, Debug)]
pub struct ImageAsyncData {
// pub parent: Image,
// pub mutex: GMutex,
pub complete: bool,
pub cancelled: bool,
pub upscale: bool,
pub idle_handler: i32,
pub filename: String,
pub buffer: Vec<u8>,
pub count: usize,
// pub free_func: GDestroyNotify,
pub width: i32,
pub height: i32,
pub width_threshold: u32,
pub height_threshold: u32,
// pub pixbuf: GdkPixbuf,
// pub error: GError,
}
#[derive(Debug)]
pub struct ImageProps {
pub mode: ImageScaleMode,
pub previous_mode: ImageScaleMode,
pub load_async: bool,
pub upscale: bool,
pub width_threshold: u32,
pub height_threshold: u32,
pub texture: Handle,
pub old_texture: Handle,
pub blank_texture: Handle,
pub rotation: f32,
pub old_rotation: f32,
pub old_mode: ImageScaleMode,
pub template_material: dx::core::Material,
pub material: dx::core::Material,
pub timeline: Timeline,
pub redraw_timeline: Timeline,
pub transition_duration: u32,
pub async_load_data: Option<ImageAsyncData>,
}
#[derive(Debug)]
pub struct Image {
props: RefCell<ImageProps>,
}
impl Image {
pub fn new() -> Image {
// assert_initialized_main_thread!();
// unsafe { Actor::from_glib_none(ffi::image_new()).unsafe_cast() }
unimplemented!()
}
}
impl Default for Image {
fn default() -> Self {
Self::new()
}
}
impl Object for Image {}
impl Is<Image> for Image {}
impl AsRef<Image> for Image {
fn as_ref(&self) -> &Image {
self
}
}
impl Is<Widget> for Image {}
impl AsRef<Widget> for Image {
fn as_ref(&self) -> &Widget {
// &self.widget
unimplemented!()
}
}
impl Is<Actor> for Image {}
impl AsRef<Actor> for Image {
fn as_ref(&self) -> &Actor {
// &self.widget
unimplemented!()
}
}
pub trait ImageExt: 'static {
/// animate_scale_mode:
/// @image: An #Image
/// @mode: a #AnimationMode
/// @duration: duration of the animation in milliseconds
/// @scale_mode: The #ImageScaleMode to set
///
/// Sets the value of #Image:scale-mode to @scale_mode and animates the
/// scale factor of the image between the previous value and the new value.
///
fn animate_scale_mode(&self, mode: u64, duration: u32, scale_mode: ImageScaleMode);
/// clear:
/// @image: A #Image
///
/// Clear the current image and set a blank, transparent image.
///
/// Returns: static void
///
fn clear(&self);
/// get_allow_upscale:
/// @image: A #Image
///
/// Determines whether image up-scaling is allowed.
///
/// Returns: %true if upscaling is allowed, %false otherwise
///
fn get_allow_upscale(&self) -> bool;
/// get_image_rotation:
/// @image: A #Image
///
/// Get the value of the Image:image-rotation property.
///
/// Returns: The value of the image-rotation property.
///
fn get_image_rotation(&self) -> f32;
/// get_load_async:
/// @image: A #Image
///
/// Determines whether asynchronous image loading is in use.
///
/// Returns: %true if images are set to load asynchronously, %false otherwise
///
fn get_load_async(&self) -> bool;
/// get_scale_height_threshold:
/// @image: A #Image
///
/// Retrieves the height scaling threshold.
///
/// Returns: The height scaling threshold, in pixels
///
fn get_scale_height_threshold(&self) -> u32;
/// get_scale_mode:
/// @image: An #Image
///
/// Get the current scale mode of @Image.
///
/// Returns: The current ImageScaleMode
///
fn get_scale_mode(&self) -> ImageScaleMode;
/// get_scale_width_threshold:
/// @image: A #Image
///
/// Retrieves the width scaling threshold.
///
/// Returns: The width scaling threshold, in pixels
///
fn get_scale_width_threshold(&self) -> u32;
/// get_transition_duration:
/// @image: A #Image
///
/// Get the value of the Image:transition-duration property.
///
/// Returns: The value of the transition-duration property.
///
fn get_transition_duration(&self) -> u32;
/// set_allow_upscale:
/// @image: A #Image
/// @allow: %true to allow upscaling, %false otherwise
///
/// Sets whether up-scaling of images is allowed. If set to %true and a size
/// larger than the image is requested, the image will be up-scaled in
/// software.
///
/// The advantage of this is that software up-scaling is potentially higher
/// quality, but it comes at the expense of video memory.
///
fn set_allow_upscale(&self, allow: bool);
/// set_from_buffer:
/// @image: An #Image
/// @buffer: (array length=buffer_size) (transfer full): A buffer
/// pointing to encoded image data
/// @buffer_size: The size of @buffer, in bytes
/// @buffer_free_func: (allow-none): A function to free @buffer, or %None
/// @error: Return location for a #GError, or #None
///
/// Set the image data from unencoded image data, stored in memory. In case of
/// failure, #false is returned and @error is set. It is expected that @buffer
/// will remain accessible for the duration of the load. Once it is finished
/// with, @buffer_free_func will be called.
///
/// Returns: #true if the image was successfully updated
///
// fn set_from_buffer(&self, buffer: &[u8]) -> Result<(), glib::Error>;
/// set_from_buffer_at_size:
/// @image: An #Image
/// @buffer: (array length=buffer_size) (transfer full): A buffer
/// pointing to encoded image data
/// @buffer_size: The size of @buffer, in bytes
/// @buffer_free_func: (allow-none): A function to free @buffer, or %None
/// @width: Width to scale the image to, or -1
/// @height: Height to scale the image to, or -1
/// @error: Return location for a #GError, or #None
///
/// Set the image data from unencoded image data, stored in memory, and scales
/// it while loading. In case of failure, #false is returned and @error is set.
/// It is expected that @buffer will remain accessible for the duration of the
/// load. Once it is finished with, @buffer_free_func will be called. The aspect
/// ratio will always be maintained.
///
/// Returns: #true if the image was successfully updated
///
// fn set_from_buffer_at_size(
// &self,
// buffer: &[u8],
// width: i32,
// height: i32,
// ) -> Result<(), glib::Error>;
/// set_from_cogl_texture:
/// @image: A #Image
/// @texture: A #CoglHandle to a texture
///
/// Sets the contents of the image from the given Cogl texture.
///
/// Returns: %true on success, %false on failure
///
fn set_from_cogl_texture(&self, texture: Handle) -> bool;
/// set_from_data:
/// @image: An #Image
/// @data: (array): Image data
/// @pixel_format: The #CoglPixelFormat of the buffer
/// @width: Width in pixels of image data.
/// @height: Height in pixels of image data
/// @rowstride: Distance in bytes between row starts.
/// @error: Return location for a #GError, or #None
///
/// Set the image data from a buffer. In case of failure, #false is returned
/// and @error is set.
///
/// Returns: #true if the image was successfully updated
///
// fn set_from_data(
// &self,
// data: &[u8],
// pixel_format: dx::PixelFormat,
// width: i32,
// height: i32,
// rowstride: i32,
// ) -> Result<(), glib::Error>;
/// set_from_file:
/// @image: An #Image
/// @filename: Filename to read the file from
/// @error: Return location for a #GError, or #None
///
/// Set the image data from an image file. In case of failure, #false is returned
/// and @error is set.
///
/// Returns: #true if the image was successfully updated
///
// fn set_from_file(&self, filename: &str) -> Result<(), glib::Error>;
/// set_from_file_at_size:
/// @image: An #Image
/// @filename: Filename to read the file from
/// @width: Width to scale the image to, or -1
/// @height: Height to scale the image to, or -1
/// @error: Return location for a #GError, or #None
///
/// Set the image data from an image file, and scale the image during loading.
/// In case of failure, #false is returned and @error is set. The aspect ratio
/// will always be maintained.
///
/// Returns: #true if the image was successfully updated
///
// fn set_from_file_at_size(
// &self,
// filename: &str,
// width: i32,
// height: i32,
// ) -> Result<(), glib::Error>;
/// set_image_rotation:
/// @image: A #Image
/// @rotation: Rotation angle in degrees
///
/// Set the Image:image-rotation property.
///
fn set_image_rotation(&self, rotation: f32);
/// set_load_async:
/// @image: A #Image
/// @load_async: %true to load images asynchronously
///
/// Sets whether to load images asynchronously. Asynchronous image loading
/// requires thread support (see g_thread_init()).
///
/// When using asynchronous image loading, all image-loading functions will
/// return immediately as successful. The #Image::image-loaded and
/// #Image::image-load-error signals are used to signal success or failure
/// of asynchronous image loading.
///
fn set_load_async(&self, load_async: bool);
/// set_scale_height_threshold:
/// @image: A #Image
/// @pixels: Number of pixels
///
/// Sets the threshold used to determine whether to scale the height of the
/// image. If a specific height is requested, the image height is allowed to
/// differ by this amount before scaling is employed.
///
/// This can be useful to avoid excessive CPU usage when the image differs
/// only slightly to the desired size.
///
fn set_scale_height_threshold(&self, pixels: u32);
/// set_scale_mode:
/// @image: An #Image
/// @mode: The #ImageScaleMode to set
///
/// Set the scale mode on @Image
///
fn set_scale_mode(&self, mode: ImageScaleMode);
/// set_scale_width_threshold:
/// @image: A #Image
/// @pixels: Number of pixels
///
/// Sets the threshold used to determine whether to scale the width of the
/// image. If a specific width is requested, the image width is allowed to
/// differ by this amount before scaling is employed.
///
/// This can be useful to avoid excessive CPU usage when the image differs
/// only slightly to the desired size.
///
fn set_scale_width_threshold(&self, pixels: u32);
/// set_transition_duration:
/// @image: A #Image
/// @duration: Transition duration in milliseconds
///
/// Set the Image:transition-duration property.
///
fn set_transition_duration(&self, duration: u32);
fn set_property_filename(&self, filename: Option<&str>);
// fn connect_image_load_error<F: Fn(&Self, &glib::Error) + 'static>(&self, f: F) -> HandlerId;
fn connect_image_loaded<F: Fn(&Self) + 'static>(&self, f: F) -> HandlerId;
fn connect_property_allow_upscale_notify<F: Fn(&Self) + 'static>(&self, f: F) -> HandlerId;
fn connect_property_filename_notify<F: Fn(&Self) + 'static>(&self, f: F) -> HandlerId;
fn connect_property_image_rotation_notify<F: Fn(&Self) + 'static>(&self, f: F) -> HandlerId;
fn connect_property_load_async_notify<F: Fn(&Self) + 'static>(&self, f: F) -> HandlerId;
fn connect_property_scale_height_threshold_notify<F: Fn(&Self) + 'static>(
&self,
f: F,
) -> HandlerId;
fn connect_property_scale_mode_notify<F: Fn(&Self) + 'static>(&self, f: F) -> HandlerId;
fn connect_property_scale_width_threshold_notify<F: Fn(&Self) + 'static>(
&self,
f: F,
) -> HandlerId;
fn connect_property_transition_duration_notify<F: Fn(&Self) + 'static>(
&self,
f: F,
) -> HandlerId;
}
impl<O: Is<Image>> ImageExt for O {
/// animate_scale_mode:
/// @image: An #Image
/// @mode: a #AnimationMode
/// @duration: duration of the animation in milliseconds
/// @scale_mode: The #ImageScaleMode to set
///
/// Sets the value of #Image:scale-mode to @scale_mode and animates the
/// scale factor of the image between the previous value and the new value.
///
fn animate_scale_mode(&self, mode: u64, duration: u32, scale_mode: ImageScaleMode) {
let image = self.as_ref();
// if image.mode != mode {
// image.previous_mode = image.mode;
// image.mode = scale_mode;
// timeline_stop(image.redraw_timeline);
// timeline_set_duration(image.redraw_timeline, duration);
// timeline_set_progress_mode(image.redraw_timeline, mode);
// timeline_start(image.redraw_timeline);
// g_object_notify(G_OBJECT(image), "scale-mode");
// }
}
/// clear:
/// @image: A #Image
///
/// Clear the current image and set a blank, transparent image.
///
/// Returns: static void
///
fn clear(&self) {
let image = self.as_ref();
// image_cancel_in_progress (image);
// if image.texture {
// cogl_object_unref(image.texture);
// }
// image.texture = cogl_object_ref(image.blank_texture);
// if image.old_texture {
// cogl_object_unref(image.old_texture);
// }
// image.old_texture = cogl_object_ref(image.blank_texture);
// image.old_rotation = image.rotation;
// image.old_mode = image.mode;
// if image.material {
// cogl_object_unref(image.material);
// }
// image.material = cogl_object_ref(image.template_material);
// // the image has changed size, so update the preferred width/height
// actor_queue_relayout(CLUTTER_ACTOR(image));
}
/// get_allow_upscale:
/// @image: A #Image
///
/// Determines whether image up-scaling is allowed.
///
/// Returns: %true if upscaling is allowed, %false otherwise
///
fn get_allow_upscale(&self) -> bool {
let image = self.as_ref();
let props = image.props.borrow();
props.upscale
}
/// get_image_rotation:
/// @image: A #Image
///
/// Get the value of the Image:image-rotation property.
///
/// Returns: The value of the image-rotation property.
///
fn get_image_rotation(&self) -> f32 {
let image = self.as_ref();
let props = image.props.borrow();
props.rotation
}
/// get_load_async:
/// @image: A #Image
///
/// Determines whether asynchronous image loading is in use.
///
/// Returns: %true if images are set to load asynchronously, %false otherwise
///
fn get_load_async(&self) -> bool {
let image = self.as_ref();
let props = image.props.borrow();
props.load_async
}
/// get_scale_height_threshold:
/// @image: A #Image
///
/// Retrieves the height scaling threshold.
///
/// Returns: The height scaling threshold, in pixels
///
fn get_scale_height_threshold(&self) -> u32 {
let image = self.as_ref();
let props = image.props.borrow();
props.height_threshold
}
/// get_scale_mode:
/// @image: An #Image
///
/// Get the current scale mode of @Image.
///
/// Returns: The current ImageScaleMode
///
fn get_scale_mode(&self) -> ImageScaleMode {
let image = self.as_ref();
let props = image.props.borrow();
props.mode
}
/// get_scale_width_threshold:
/// @image: A #Image
///
/// Retrieves the width scaling threshold.
///
/// Returns: The width scaling threshold, in pixels
///
fn get_scale_width_threshold(&self) -> u32 {
let image = self.as_ref();
let props = image.props.borrow();
props.width_threshold
}
/// get_transition_duration:
/// @image: A #Image
///
/// Get the value of the Image:transition-duration property.
///
/// Returns: The value of the transition-duration property.
///
fn get_transition_duration(&self) -> u32 {
let image = self.as_ref();
let props = image.props.borrow();
props.transition_duration
}
/// set_allow_upscale:
/// @image: A #Image
/// @allow: %true to allow upscaling, %false otherwise
///
/// Sets whether up-scaling of images is allowed. If set to %true and a size
/// larger than the image is requested, the image will be up-scaled in
/// software.
///
/// The advantage of this is that software up-scaling is potentially higher
/// quality, but it comes at the expense of video memory.
///
fn set_allow_upscale(&self, allow: bool) {
let image = self.as_ref();
let mut props = image.props.borrow_mut();
if props.upscale != allow {
props.upscale = allow;
// g_object_notify(G_OBJECT(image), "allow-upscale");
}
}
/// set_from_buffer:
/// @image: An #Image
/// @buffer: (array length=buffer_size) (transfer full): A buffer
/// pointing to encoded image data
/// @buffer_size: The size of @buffer, in bytes
/// @buffer_free_func: (allow-none): A function to free @buffer, or %None
/// @error: Return location for a #GError, or #None
///
/// Set the image data from unencoded image data, stored in memory. In case of
/// failure, #false is returned and @error is set. It is expected that @buffer
/// will remain accessible for the duration of the load. Once it is finished
/// with, @buffer_free_func will be called.
///
/// Returns: #true if the image was successfully updated
///
// fn set_from_buffer(&self, buffer: &[u8]) -> Result<(), glib::Error> {
// self.set_from_buffer_at_size(buffer, -1, -1)
// }
/// set_from_buffer_at_size:
/// @image: An #Image
/// @buffer: (array length=buffer_size) (transfer full): A buffer
/// pointing to encoded image data
/// @buffer_size: The size of @buffer, in bytes
/// @buffer_free_func: (allow-none): A function to free @buffer, or %None
/// @width: Width to scale the image to, or -1
/// @height: Height to scale the image to, or -1
/// @error: Return location for a #GError, or #None
///
/// Set the image data from unencoded image data, stored in memory, and scales
/// it while loading. In case of failure, #false is returned and @error is set.
/// It is expected that @buffer will remain accessible for the duration of the
/// load. Once it is finished with, @buffer_free_func will be called. The aspect
/// ratio will always be maintained.
///
/// Returns: #true if the image was successfully updated
///
// fn set_from_buffer_at_size(
// &self,
// buffer: &[u8],
// width: i32,
// height: i32,
// ) -> Result<(), glib::Error> {
// let image = self.as_ref();
// let props = image.props.borrow();
// if props.load_async {
// // return image.set_async(None, buffer, buffer_size,
// // buffer_free_func, width, height, error);
// }
// // let pixbuf: GdkPixbuf = Image::pixbuf_new(None, buffer, buffer_size, width, height,
// // image.width_threshold, image.height_threshold,
// // image.upscale, None, error);
// // if !pixbuf {
// // return false;
// // }
// // let retval = image.set_from_pixbuf(pixbuf, None, error);
// // g_object_unref(pixbuf);
// // if buffer_free_func {
// // buffer_free_func((gpointer)buffer);
// // }
// // retval
// unimplemented!()
// }
/// set_from_cogl_texture:
/// @image: A #Image
/// @texture: A #CoglHandle to a texture
///
/// Sets the contents of the image from the given Cogl texture.
///
/// Returns: %true on success, %false on failure
///
fn set_from_cogl_texture(&self, texture: Handle) -> bool {
// let image = self.as_ref();
// gint width, height;
// g_return_val_if_fail(IS_IMAGE (image), false);
// g_return_val_if_fail(cogl_is_texture (texture), false);
// image_cancel_in_progress(image);
// width = cogl_texture_get_width(texture);
// height = cogl_texture_get_height(texture);
// // If we have offscreen buffers, use those to add the 1-pixel border
// // around the image on the GPU - if not, fallback to copying the image
// // data into memory and use set_from_data.
// if feature_available(CLUTTER_FEATURE_OFFSCREEN) {
// CoglColor transparent;
// CoglMaterial *clear_material;
// CoglHandle new_texture =
// cogl_texture_new_with_size(width + 2, height + 2,
// COGL_TEXTURE_NO_ATLAS,
// COGL_PIXEL_FORMAT_RGBA_8888);
// CoglHandle fbo = cogl_offscreen_new_to_texture(new_texture);
// CoglMaterial *tex_material = cogl_material_new();
// /* Set the blending equation to directly copy the bits of the old
// * texture without blending the destination pixels.
// */
// cogl_material_set_blend(tex_material, "RGBA=ADD(SRC_COLOR, 0)", None);
// clear_material = cogl_material_copy(tex_material);
// cogl_color_set_from_4ub(&transparent, 0, 0, 0, 0);
// cogl_material_set_layer(tex_material, 0, texture);
// /* Push the off-screen buffer and setup an orthographic projection */
// cogl_push_framebuffer(fbo);
// cogl_ortho(0, width + 2, height +2, 0, -1, 1);
// /* Draw the texture into the middle */
// cogl_push_source(tex_material);
// cogl_rectangle(1, 1, width +1, height + 1);
// /* Clear the 1-pixel border around the texture */
// cogl_set_source(clear_material);
// cogl_rectangle(0, 0, width + 2, 1);
// cogl_rectangle(0, height + 1, width + 2, height + 2);
// cogl_rectangle(0, 1, 1, height + 1);
// cogl_rectangle(width + 1, 1, width + 2, height + 1);
// cogl_pop_source();
// cogl_pop_framebuffer();
// /* Free unneeded data */
// cogl_object_unref(clear_material);
// cogl_object_unref(tex_material);
// cogl_handle_unref(fbo);
// /* Replace the old texture */
// if (priv->old_texture)
// cogl_object_unref(priv->old_texture);
// priv->old_texture = priv->texture;
// priv->old_rotation = priv->rotation;
// priv->old_mode = priv->mode;
// priv->texture = new_texture;
// image_prepare_texture(image);
// return true;
// } else {
// guint8 *data;
// gint rowstride;
// CoglPixelFormat format;
// rowstride = cogl_texture_get_rowstride(texture);
// format = cogl_texture_get_format(texture);
// data = g_malloc(height * rowstride);
// cogl_texture_get_data(texture, format, rowstride, data);
// return image_set_from_data(image, data, format,
// width, height, rowstride, None);
// }
unimplemented!()
}
/// set_from_data:
/// @image: An #Image
/// @data: (array): Image data
/// @pixel_format: The #CoglPixelFormat of the buffer
/// @width: Width in pixels of image data.
/// @height: Height in pixels of image data
/// @rowstride: Distance in bytes between row starts.
/// @error: Return location for a #GError, or #None
///
/// Set the image data from a buffer. In case of failure, #false is returned
/// and @error is set.
///
/// Returns: #true if the image was successfully updated
///
// fn set_from_data(
// &self,
// data: &[u8],
// pixel_format: dx::PixelFormat,
// width: i32,
// height: i32,
// rowstride: i32,
// ) -> Result<(), glib::Error> {
// let image = self.as_ref();
// // image.set_from_data_internal(image, data, None, false,
// // pixel_format, width, height,
// // rowstride, error);
// unimplemented!()
// }
/// set_from_file:
/// @image: An #Image
/// @filename: Filename to read the file from
/// @error: Return location for a #GError, or #None
///
/// Set the image data from an image file. In case of failure, #false is returned
/// and @error is set.
///
/// Returns: #true if the image was successfully updated
///
// fn set_from_file(&self, filename: &str) -> Result<(), glib::Error> {
// let image = self.as_ref();
// image.set_from_file_at_size(filename, -1, -1)
// }
/// set_from_file_at_size:
/// @image: An #Image
/// @filename: Filename to read the file from
/// @width: Width to scale the image to, or -1
/// @height: Height to scale the image to, or -1
/// @error: Return location for a #GError, or #None
///
/// Set the image data from an image file, and scale the image during loading.
/// In case of failure, #false is returned and @error is set. The aspect ratio
/// will always be maintained.
///
/// Returns: #true if the image was successfully updated
///
// fn set_from_file_at_size(
// &self,
// filename: &str,
// width: i32,
// height: i32,
// ) -> Result<(), glib::Error> {
// let image = self.as_ref();
// // GdkPixbuf *pixbuf;
// // ImagePrivate *priv;
// // TextureCache *cache;
// // gboolean retval, use_cache;
// // pixbuf = None;
// // // Check if the processed image is in the cache - we don't use the cache
// // // if we're loading at a particular size.
// // cache = texture_cache_get_default();
// // use_cache = true;
// // if (width != -1) || (height != -1) ||
// // !texture_cache_contains_meta(cache, filename,
// // GINT_TO_POINTER(image_cache_quark)) {
// // // Check if the unprocessed image is in the cache, and if so, skip
// // // loading it and set it from the Cogl texture handle.
// // if (width == -1) && (height == -1) &&
// // texture_cache_contains(cache, filename) {
// // if image_set_from_cogl_texture(image,
// // texture_cache_get_cogl_texture(cache, filename)) {
// // // Add the processed image to the cache
// // texture_cache_insert_meta (cache, filename,
// // GINT_TO_POINTER (image_cache_quark),
// // image.texture, None);
// // return true;
// // } else {
// // g_set_error (error, IMAGE_ERROR, IMAGE_ERROR_INTERNAL,
// // "Setting image '%s' from CoglTexture failed",
// // filename);
// // return false;
// // }
// // }
// // // Load the pixbuf in a thread, then later on upload it to the GPU
// // if image.load_async {
// // return image.set_async(filename, None, 0, None,
// // width, height, error);
// // }
// // // Synchronously load the pixbuf and set it
// // pixbuf = image_pixbuf_new(filename, None, 0, width, height,
// // image.width_threshold,
// // image.height_threshold,
// // image.upscale, &use_cache, error);
// // if !pixbuf {
// // return false;
// // }
// // }
// // retval = image.set_from_pixbuf(pixbuf, use_cache ? filename : None, error);
// // if pixbuf {
// // g_object_unref (pixbuf);
// // }
// // return retval;
// unimplemented!()
// }
/// set_image_rotation:
/// @image: A #Image
/// @rotation: Rotation angle in degrees
///
/// Set the Image:image-rotation property.
///
fn set_image_rotation(&self, rotation: f32) {
let image = self.as_ref();
let mut props = image.props.borrow_mut();
if props.rotation != rotation {
props.rotation = rotation;
// actor_queue_redraw(CLUTTER_ACTOR(image));
// g_object_notify(G_OBJECT(image), "image-rotation");
}
}
/// set_load_async:
/// @image: A #Image
/// @load_async: %true to load images asynchronously
///
/// Sets whether to load images asynchronously. Asynchronous image loading
/// requires thread support (see g_thread_init()).
///
/// When using asynchronous image loading, all image-loading functions will
/// return immediately as successful. The #Image::image-loaded and
/// #Image::image-load-error signals are used to signal success or failure
/// of asynchronous image loading.
///
fn set_load_async(&self, load_async: bool) {
let image = self.as_ref();
let mut props = image.props.borrow_mut();
if props.load_async != load_async {
props.load_async = load_async;
// g_object_notify(G_OBJECT(image), "load-async");
// Cancel the old transfer if we're turning async off
if !load_async && props.async_load_data.is_some() {
// props.async_load_data.cancelled = true;
props.async_load_data = None;
}
}
}
/// set_scale_height_threshold:
/// @image: A #Image
/// @pixels: Number of pixels
///
/// Sets the threshold used to determine whether to scale the height of the
/// image. If a specific height is requested, the image height is allowed to
/// differ by this amount before scaling is employed.
///
/// This can be useful to avoid excessive CPU usage when the image differs
/// only slightly to the desired size.
///
fn set_scale_height_threshold(&self, pixels: u32) {
let image = self.as_ref();
let mut props = image.props.borrow_mut();
if props.height_threshold != pixels {
props.height_threshold = pixels;
// g_object_notify(G_OBJECT (image), "scale-height-threshold");
}
}
/// set_scale_mode:
/// @image: An #Image
/// @mode: The #ImageScaleMode to set
///
/// Set the scale mode on @Image
///
fn set_scale_mode(&self, mode: ImageScaleMode) {
let image = self.as_ref();
let mut props = image.props.borrow_mut();
if props.mode != mode {
props.previous_mode = mode;
props.mode = mode;
// g_object_notify(G_OBJECT(image), "scale-mode");
}
// actor_queue_redraw(CLUTTER_ACTOR (image));
}
/// set_scale_width_threshold:
/// @image: A #Image
/// @pixels: Number of pixels
///
/// Sets the threshold used to determine whether to scale the width of the
/// image. If a specific width is requested, the image width is allowed to
/// differ by this amount before scaling is employed.
///
/// This can be useful to avoid excessive CPU usage when the image differs
/// only slightly to the desired size.
///
fn set_scale_width_threshold(&self, pixels: u32) {
let image = self.as_ref();
let mut props = image.props.borrow_mut();
if props.width_threshold != pixels {
props.width_threshold = pixels;
// g_object_notify(G_OBJECT(image), "scale-width-threshold");
}
}
/// set_transition_duration:
/// @image: A #Image
/// @duration: Transition duration in milliseconds
///
/// Set the Image:transition-duration property.
///
fn set_transition_duration(&self, duration: u32) {
let image = self.as_ref();
let mut props = image.props.borrow_mut();
if props.transition_duration != duration {
props.transition_duration = duration;
if duration != 0 {
// timeline_set_duration(image.timeline, duration);
}
// g_object_notify(G_OBJECT (image), "transition-duration");
}
}
fn set_property_filename(&self, filename: Option<&str>) {
let image = self.as_ref();
// unsafe {
// gobject_sys::g_object_set_property(
// self.to_glib_none().0 as *mut gobject_sys::GObject,
// b"filename\0".as_ptr() as *const _,
// Value::from(filename).to_glib_none().0,
// );
// }
unimplemented!()
}
// fn connect_image_load_error<F: Fn(&Self, &glib::Error) + 'static>(&self, f: F) -> HandlerId {
// // unsafe extern "C" fn image_load_error_trampoline<P, F: Fn(&P, &glib::Error) + 'static>(
// // this: *mut ffi::Image,
// // object: *mut glib_sys::GError,
// // f: glib_sys::gpointer,
// // ) where
// // P: Is<Image>,
// // {
// // let f: &F = &*(f as *const F);
// // f(
// // &Image::from_glib_borrow(this).unsafe_cast_ref(),
// // &from_glib_borrow(object),
// // )
// // }
// // unsafe {
// // let f: Box<F> = Box::new(f);
// // connect_raw(
// // self.as_ptr() as *mut _,
// // b"image-load-error\0".as_ptr() as *const _,
// // Some(transmute::<_, unsafe extern "C" fn()>(
// // image_load_error_trampoline::<Self, F> as *const (),
// // )),
// // Box::into_raw(f),
// // )
// // }
// unimplemented!()
// }
fn connect_image_loaded<F: Fn(&Self) + 'static>(&self, f: F) -> HandlerId {
// unsafe extern "C" fn image_loaded_trampoline<P, F: Fn(&P) + 'static>(
// this: *mut ffi::Image,
// f: glib_sys::gpointer,
// ) where
// P: Is<Image>,
// {
// let f: &F = &*(f as *const F);
// f(&Image::from_glib_borrow(this).unsafe_cast_ref())
// }
// unsafe {
// let f: Box<F> = Box::new(f);
// connect_raw(
// self.as_ptr() as *mut _,
// b"image-loaded\0".as_ptr() as *const _,
// Some(transmute::<_, unsafe extern "C" fn()>(
// image_loaded_trampoline::<Self, F> as *const (),
// )),
// Box::into_raw(f),
// )
// }
unimplemented!()
}
fn connect_property_allow_upscale_notify<F: Fn(&Self) + 'static>(&self, f: F) -> HandlerId {
// unsafe extern "C" fn notify_allow_upscale_trampoline<P, F: Fn(&P) + 'static>(
// this: *mut ffi::Image,
// _param_spec: glib_sys::gpointer,
// f: glib_sys::gpointer,
// ) where
// P: Is<Image>,
// {
// let f: &F = &*(f as *const F);
// f(&Image::from_glib_borrow(this).unsafe_cast_ref())
// }
// unsafe {
// let f: Box<F> = Box::new(f);
// connect_raw(
// self.as_ptr() as *mut _,
// b"notify::allow-upscale\0".as_ptr() as *const _,
// Some(transmute::<_, unsafe extern "C" fn()>(
// notify_allow_upscale_trampoline::<Self, F> as *const (),
// )),
// Box::into_raw(f),
// )
// }
unimplemented!()
}
fn connect_property_filename_notify<F: Fn(&Self) + 'static>(&self, f: F) -> HandlerId {
// unsafe extern "C" fn notify_filename_trampoline<P, F: Fn(&P) + 'static>(
// this: *mut ffi::Image,
// _param_spec: glib_sys::gpointer,
// f: glib_sys::gpointer,
// ) where
// P: Is<Image>,
// {
// let f: &F = &*(f as *const F);
// f(&Image::from_glib_borrow(this).unsafe_cast_ref())
// }
// unsafe {
// let f: Box<F> = Box::new(f);
// connect_raw(
// self.as_ptr() as *mut _,
// b"notify::filename\0".as_ptr() as *const _,
// Some(transmute::<_, unsafe extern "C" fn()>(
// notify_filename_trampoline::<Self, F> as *const (),
// )),
// Box::into_raw(f),
// )
// }
unimplemented!()
}
fn connect_property_image_rotation_notify<F: Fn(&Self) + 'static>(&self, f: F) -> HandlerId {
// unsafe extern "C" fn notify_image_rotation_trampoline<P, F: Fn(&P) + 'static>(
// this: *mut ffi::Image,
// _param_spec: glib_sys::gpointer,
// f: glib_sys::gpointer,
// ) where
// P: Is<Image>,
// {
// let f: &F = &*(f as *const F);
// f(&Image::from_glib_borrow(this).unsafe_cast_ref())
// }
// unsafe {
// let f: Box<F> = Box::new(f);
// connect_raw(
// self.as_ptr() as *mut _,
// b"notify::image-rotation\0".as_ptr() as *const _,
// Some(transmute::<_, unsafe extern "C" fn()>(
// notify_image_rotation_trampoline::<Self, F> as *const (),
// )),
// Box::into_raw(f),
// )
// }
unimplemented!()
}
fn connect_property_load_async_notify<F: Fn(&Self) + 'static>(&self, f: F) -> HandlerId {
// unsafe extern "C" fn notify_load_async_trampoline<P, F: Fn(&P) + 'static>(
// this: *mut ffi::Image,
// _param_spec: glib_sys::gpointer,
// f: glib_sys::gpointer,
// ) where
// P: Is<Image>,
// {
// let f: &F = &*(f as *const F);
// f(&Image::from_glib_borrow(this).unsafe_cast_ref())
// }
// unsafe {
// let f: Box<F> = Box::new(f);
// connect_raw(
// self.as_ptr() as *mut _,
// b"notify::load-async\0".as_ptr() as *const _,
// Some(transmute::<_, unsafe extern "C" fn()>(
// notify_load_async_trampoline::<Self, F> as *const (),
// )),
// Box::into_raw(f),
// )
// }
unimplemented!()
}
fn connect_property_scale_height_threshold_notify<F: Fn(&Self) + 'static>(
&self,
f: F,
) -> HandlerId {
// unsafe extern "C" fn notify_scale_height_threshold_trampoline<P, F: Fn(&P) + 'static>(
// this: *mut ffi::Image,
// _param_spec: glib_sys::gpointer,
// f: glib_sys::gpointer,
// ) where
// P: Is<Image>,
// {
// let f: &F = &*(f as *const F);
// f(&Image::from_glib_borrow(this).unsafe_cast_ref())
// }
// unsafe {
// let f: Box<F> = Box::new(f);
// connect_raw(
// self.as_ptr() as *mut _,
// b"notify::scale-height-threshold\0".as_ptr() as *const _,
// Some(transmute::<_, unsafe extern "C" fn()>(
// notify_scale_height_threshold_trampoline::<Self, F> as *const (),
// )),
// Box::into_raw(f),
// )
// }
unimplemented!()
}
fn connect_property_scale_mode_notify<F: Fn(&Self) + 'static>(&self, f: F) -> HandlerId {
// unsafe extern "C" fn notify_scale_mode_trampoline<P, F: Fn(&P) + 'static>(
// this: *mut ffi::Image,
// _param_spec: glib_sys::gpointer,
// f: glib_sys::gpointer,
// ) where
// P: Is<Image>,
// {
// let f: &F = &*(f as *const F);
// f(&Image::from_glib_borrow(this).unsafe_cast_ref())
// }
// unsafe {
// let f: Box<F> = Box::new(f);
// connect_raw(
// self.as_ptr() as *mut _,
// b"notify::scale-mode\0".as_ptr() as *const _,
// Some(transmute::<_, unsafe extern "C" fn()>(
// notify_scale_mode_trampoline::<Self, F> as *const (),
// )),
// Box::into_raw(f),
// )
// }
unimplemented!()
}
fn connect_property_scale_width_threshold_notify<F: Fn(&Self) + 'static>(
&self,
f: F,
) -> HandlerId {
// unsafe extern "C" fn notify_scale_width_threshold_trampoline<P, F: Fn(&P) + 'static>(
// this: *mut ffi::Image,
// _param_spec: glib_sys::gpointer,
// f: glib_sys::gpointer,
// ) where
// P: Is<Image>,
// {
// let f: &F = &*(f as *const F);
// f(&Image::from_glib_borrow(this).unsafe_cast_ref())
// }
// unsafe {
// let f: Box<F> = Box::new(f);
// connect_raw(
// self.as_ptr() as *mut _,
// b"notify::scale-width-threshold\0".as_ptr() as *const _,
// Some(transmute::<_, unsafe extern "C" fn()>(
// notify_scale_width_threshold_trampoline::<Self, F> as *const (),
// )),
// Box::into_raw(f),
// )
// }
unimplemented!()
}
fn connect_property_transition_duration_notify<F: Fn(&Self) + 'static>(
&self,
f: F,
) -> HandlerId {
// unsafe extern "C" fn notify_transition_duration_trampoline<P, F: Fn(&P) + 'static>(
// this: *mut ffi::Image,
// _param_spec: glib_sys::gpointer,
// f: glib_sys::gpointer,
// ) where
// P: Is<Image>,
// {
// let f: &F = &*(f as *const F);
// f(&Image::from_glib_borrow(this).unsafe_cast_ref())
// }
// unsafe {
// let f: Box<F> = Box::new(f);
// connect_raw(
// self.as_ptr() as *mut _,
// b"notify::transition-duration\0".as_ptr() as *const _,
// Some(transmute::<_, unsafe extern "C" fn()>(
// notify_transition_duration_trampoline::<Self, F> as *const (),
// )),
// Box::into_raw(f),
// )
// }
unimplemented!()
}
}
impl fmt::Display for Image {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Image")
}
}