wxErlang

wxBitmap.erl

  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
%          |¯|   | ¯|¯ |\/|  /\  |¯\ 
%\     W X |¯_\  |  |  |  | /¯¯\ |¯¯ . E R L 
%%                                                                     
%%                                                                     
%%   Copyright Ericsson AB 2008-2013. All Rights Reserved.
%%                                                                     
%%                                                                     
%% Whitespace Beautified by ScriptCulture © 2018
%% Sit Back · Feet Up · Learn wxErlang
%% For use as a reference only
%% www.scriptculture.com
%% Not check-summed 
%% wx 1.8 —————————————————————————————————————— 
%%
%% Licensed under the Apache License, 
%% Version 2.0 (the "License"); you may 
%% not use this file except in compliance 
%% with the License. You may obtain a copy 
%% of the License at:
%%
%%     http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by 
%% applicable law or agreed to in writing, software
%% distributed under the License is distributed 
%% on an "AS IS" BASIS, WITHOUT WARRANTIES 
%% OR CONDITIONS OF ANY KIND, either 
%% express or implied. See the 
%% License for the specific 
%% language governing 
%% permissions and
%% limitations 
%% under the 
%% License.
%%%%%%%
%%%%
%%%%%
%% @doc See external documentation: <a href="http://www.wxwidgets.org/manuals/2.8.12/wx_wxbitmap.html">wxBitmap</a>.
%% @type wxBitmap().  
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%   
%%   OVERVIEW
%%   ––––––––
%%   This class encapsulates the concept of a platform-dependent bitmap, 
%%   either monochrome or colour or colour with alpha channel support.
%%   
%%   
%%   See Also:
%%   —————————
%%    wxBitmap overview, supported bitmap file formats, 
%%    wxDC::Blit, wxIcon, wxCursor, wxBitmap, wxMemoryDC
%%   
%%   
-module(wxBitmap).
-include("wxe.hrl").
-export([

                    new/0 ,
                    new/1 ,
                    new/2 ,
                    new/3 ,
                    new/4 ,
                    create/3 ,
                    create/4 ,
                    destroy/1 ,


                    convertToImage/1 ,


                    copyFromIcon/2 ,


                    getSubBitmap/2 ,

                    loadFile/2 ,
                    loadFile/3 ,

                    ok/1 ,

                    saveFile/3 ,
                    saveFile/4 ,


                    getDepth/1 ,
                    getHeight/1 ,
                    getMask/1 ,
                    getPalette/1 ,
                    getWidth/1 ,

                    setDepth/2 ,
                    setHeight/2 ,
                    setMask/2 ,
                    setPalette/2 ,
                    setWidth/2
            ]).


%% inherited exports
-export([parent_class/1]).

-export_type([wxBitmap/0]).


%% @hidden
parent_class(_Class) -> erlang:error({badtype, ?MODULE}).




-type wxBitmap()  ::  wx:wx_object().






%%
%%
           %·%% NEW / 0 %%·%

%%   
%%    Default constructor.
%%   
%% Return Value:
%% See Also:
%%*%%*%%
          -spec new() -> wxBitmap().
new() ->
           wxe_util:construct(?wxBitmap_new_0,
            <<>>).

           %·%% NEW / 1 %%·%
%%
%%   Loads a bitmap from a file or resource.
%%    
%%   Creates a bitmap from XPM data.
%%
%%   PERTAINS TO ALL BELOW NEW / 1-4
%%   1. The first form constructs a bitmap object with no data; 
%%      an assignment or another member function such as 
%%      Create or LoadFile must be called subsequently.
%%   
%%   2 & 3. The second and third forms provide copy constructors. 
%%      Note that these do not copy the bitmap data, but instead a 
%%      pointer to the data, keeping a reference count. 
%%      They are therefore very efficient operations.
%%   
%%   4. The fourth form constructs a bitmap from data whose type and 
%%      value depends on the value of the type argument.
%%   
%%   5. The fifth form constructs a (usually monochrome) bitmap from 
%%      an array of pixel values, under both X and Windows.
%%   
%%   6. The sixth form constructs a new bitmap.
%%   
%%   7. The seventh form constructs a bitmap from pixmap (XPM) data, 
%%      if wxWidgets has been configured to incorporate this feature.
%%   
%%      To use this constructor, you must first include an XPM file. 
%%      For example, assuming that the file mybitmap.xpm contains an 
%%      XPM array of character pointers called mybitmap:
%%
%%   8. The eighth form constructs a bitmap from a file or resource. 
%%      name can refer to a resource name under MS Windows, or a filename 
%%      under MS Windows and X.
%%   
%%   Under Windows, type defaults to wxBITMAP_TYPE_BMP_RESOURCE. 
%%   Under X, type defaults to wxBITMAP_TYPE_XPM.
%%   
%% Return Value:
%% See Also:
%%*%%*%%
%%<br /> Type = ?wxBITMAP_TYPE_INVALID       | ?wxBITMAP_TYPE_BMP           | ?wxBITMAP_TYPE_BMP_RESOURCE 
%%            | ?wxBITMAP_TYPE_RESOURCE      | ?wxBITMAP_TYPE_ICO           | ?wxBITMAP_TYPE_ICO_RESOURCE 
%%            | ?wxBITMAP_TYPE_CUR           | ?wxBITMAP_TYPE_CUR_RESOURCE  | ?wxBITMAP_TYPE_XBM 
%%            | ?wxBITMAP_TYPE_XBM_DATA      | ?wxBITMAP_TYPE_XPM           | ?wxBITMAP_TYPE_XPM_DATA 
%%            | ?wxBITMAP_TYPE_TIF           | ?wxBITMAP_TYPE_TIF_RESOURCE  | ?wxBITMAP_TYPE_GIF 
%%            | ?wxBITMAP_TYPE_GIF_RESOURCE  | ?wxBITMAP_TYPE_PNG           | ?wxBITMAP_TYPE_PNG_RESOURCE 
%%            | ?wxBITMAP_TYPE_JPEG          | ?wxBITMAP_TYPE_JPEG_RESOURCE | ?wxBITMAP_TYPE_PNM 
%%            | ?wxBITMAP_TYPE_PNM_RESOURCE  | ?wxBITMAP_TYPE_PCX           | ?wxBITMAP_TYPE_PCX_RESOURCE 
%%            | ?wxBITMAP_TYPE_PICT          | ?wxBITMAP_TYPE_PICT_RESOURCE | ?wxBITMAP_TYPE_ICON 
%%            | ?wxBITMAP_TYPE_ICON_RESOURCE | ?wxBITMAP_TYPE_ANI           | ?wxBITMAP_TYPE_IFF 
%%            | ?wxBITMAP_TYPE_TGA           | ?wxBITMAP_TYPE_MACCURSOR     | ?wxBITMAP_TYPE_MACCURSOR_RESOURCE 
%%            | ?wxBITMAP_TYPE_ANY 

          -spec new(Filename)      -> wxBitmap()
           when
           Filename :: unicode:chardata();

                   (Image)         -> wxBitmap()

           when
           Image :: wxImage:wxImage().

new(Filename)
           when 
           is_list(Filename)        -> new(Filename, []);

new(Image)
           when 
           is_record(Image, wx_ref) -> new(Image, []).


           %·%% NEW / 2 %%·%
%%
%%   Creates bitmap object from the image. This has to be done to actually display 
%%   an image as you cannot draw an image directly on a window. The resulting bitmap 
%%   will use the provided colour depth (or that of the current system if depth is -1) 
%%   which entails that a colour reduction has to take place.
%% 
%%   When in 8-bit mode (PseudoColour mode), the GTK port will use a color cube 
%%   created on program start-up to look up colors. This ensures a very fast 
%%   conversion, but the image quality won't be perfect (and could be better 
%%   for photo images using more sophisticated dithering algorithms).
%%
%%   On Windows, if there is a palette present (set with SetPalette), 
%%   it will be used when creating the wxBitmap (most useful in 8-bit display mode). 
%%   On other platforms, the palette is currently ignored.
%%
%%    
%% Return Value:
%% See Also:
%%*%%*%%
%%<br /> Type = ?wxBITMAP_TYPE_INVALID       | ?wxBITMAP_TYPE_BMP           | ?wxBITMAP_TYPE_BMP_RESOURCE 
%%            | ?wxBITMAP_TYPE_RESOURCE      | ?wxBITMAP_TYPE_ICO           | ?wxBITMAP_TYPE_ICO_RESOURCE 
%%            | ?wxBITMAP_TYPE_CUR           | ?wxBITMAP_TYPE_CUR_RESOURCE  | ?wxBITMAP_TYPE_XBM 
%%            | ?wxBITMAP_TYPE_XBM_DATA      | ?wxBITMAP_TYPE_XPM           | ?wxBITMAP_TYPE_XPM_DATA 
%%            | ?wxBITMAP_TYPE_TIF           | ?wxBITMAP_TYPE_TIF_RESOURCE  | ?wxBITMAP_TYPE_GIF 
%%            | ?wxBITMAP_TYPE_GIF_RESOURCE  | ?wxBITMAP_TYPE_PNG           | ?wxBITMAP_TYPE_PNG_RESOURCE 
%%            | ?wxBITMAP_TYPE_JPEG          | ?wxBITMAP_TYPE_JPEG_RESOURCE | ?wxBITMAP_TYPE_PNM 
%%            | ?wxBITMAP_TYPE_PNM_RESOURCE  | ?wxBITMAP_TYPE_PCX           | ?wxBITMAP_TYPE_PCX_RESOURCE 
%%            | ?wxBITMAP_TYPE_PICT          | ?wxBITMAP_TYPE_PICT_RESOURCE | ?wxBITMAP_TYPE_ICON 
%%            | ?wxBITMAP_TYPE_ICON_RESOURCE | ?wxBITMAP_TYPE_ANI           | ?wxBITMAP_TYPE_IFF 
%%            | ?wxBITMAP_TYPE_TGA           | ?wxBITMAP_TYPE_MACCURSOR     | ?wxBITMAP_TYPE_MACCURSOR_RESOURCE 
%%            | ?wxBITMAP_TYPE_ANY           
          
          -spec new(Width, Height)      -> wxBitmap()
           when
           Width  :: integer(), 
           Height :: integer();
                   (Filename, [Option]) -> wxBitmap()

           when
           Filename :: unicode:chardata(),
           Option   :: {type, wx:wx_enum()};
%%
%%   May be one of the following:
%% 
%%   wxBITMAP_TYPE_BMP             Load a Windows bitmap file.
%%   wxBITMAP_TYPE_BMP_RESOURCE    Load a Windows bitmap resource from the executable. Windows only.
%%   wxBITMAP_TYPE_PICT_RESOURCE   Load a PICT image resource from the executable. Mac OS only.
%%   wxBITMAP_TYPE_GIF             Load a GIF bitmap file.
%%   wxBITMAP_TYPE_XBM             Load an X bitmap file.
%%   wxBITMAP_TYPE_XPM             Load an XPM bitmap file.
%%
%%   The validity of these flags depends on the platform and wxWidgets configuration. 
%%   If all possible wxWidgets settings are used, the Windows 
%%   platform supports BMP file, BMP resource, XPM data, and XPM. 
%%   Under wxGTK, the available formats are BMP file, XPM data, XPM file,
%%   and PNG file. Under wxMotif, the available formats are XBM data, 
%%   XBM file, XPM data, XPM file.
%%   
%%   In addition, wxBitmap can read all formats that wxImage can, 
%%   which currently include 
%%            wxBITMAP_TYPE_JPEG, 
%%            wxBITMAP_TYPE_TIF, 
%%            wxBITMAP_TYPE_PNG, 
%%            wxBITMAP_TYPE_GIF, 
%%            wxBITMAP_TYPE_PCX, and 
%%            wxBITMAP_TYPE_PNM. 
%%            Of course, you must have wxImage handlers loaded. 


                   (Image, [Option])    -> wxBitmap()
           when
           Image   :: wxImage:wxImage(),
           Option  :: {depth, integer()}.


new(Width,Height)
           when 
           is_integer(Width),
           is_integer(Height) -> new(Width,Height, []);

new(Filename, Options)
           when 
           is_list(Filename),
           is_list(Options)   ->
                   Filename_UC = unicode:characters_to_binary([Filename,0]),
                   MOpts   = fun({type, Type}, Acc) -> [<<1:32/?UI,Type:32/?UI>>|Acc];
                                        (BadOpt, _) -> erlang:error({badoption, BadOpt})
                             end,
                   BinOpt = list_to_binary(lists:foldl(MOpts, [<<0:32>>], Options)),
                                        wxe_util:construct(?wxBitmap_new_2_0,
                                              <<(byte_size(Filename_UC)):32/?UI,(Filename_UC)/binary, 
                                     0:(((8- ((4+byte_size(Filename_UC)) band 16#7)) band 16#7))/unit:8, BinOpt/binary>>);

new(#wx_ref{type=ImageT,ref=ImageRef}, Options)
           when 
           is_list(Options) ->
                             ?CLASS(ImageT,wxImage),
                   MOpts = fun({depth, Depth}, Acc) -> [<<1:32/?UI,Depth:32/?UI>>|Acc];
                                        (BadOpt, _) -> erlang:error({badoption, BadOpt})
                           end,
                   BinOpt = list_to_binary(lists:foldl(MOpts, [<<0:32>>], Options)),
                                        wxe_util:construct(?wxBitmap_new_2_1,
                                        <<ImageRef:32/?UI, 0:32,BinOpt/binary>>).

              %·%% NEW / 3 %%·%
%%   
%%  Creates a bitmap from the given data which is interpreted in platform-dependent manner.
%%  Also, See below, for more  
%%
%% Return Value:
%% See Also:
%%*%%*%%
          -spec new(Bits, Width, Height)     -> wxBitmap()
           when
           Bits   ::  binary(), 
           Width  :: integer(), 
           Height :: integer();
                   (Width, Height, [Option]) -> wxBitmap()
           when
           Width   ::          integer(), 
           Height  ::          integer(),
           Option  ::  {depth, integer()}.

new(Bits,Width,Height)
           when 
           is_binary(Bits),
           is_integer(Width),
           is_integer(Height)                 -> new(Bits,Width,Height, []);

new(Width,Height, Options)
           when 
           is_integer(Width),
           is_integer(Height),
           is_list(Options) ->
                   MOpts = fun({depth, Depth}, Acc) -> [<<1:32/?UI,Depth:32/?UI>>|Acc];
                                        (BadOpt, _) -> erlang:error({badoption, BadOpt})
                           end,
                   BinOpt = list_to_binary(lists:foldl(MOpts, [<<0:32>>], Options)),
                                        wxe_util:construct(?wxBitmap_new_3,
                                        <<Width:32/?UI,Height:32/?UI, BinOpt/binary>>).

              %·%% NEW / 4 %%·%
%%
%%    Creates a bitmap from an array of bits.
%%   
%%   You should only use this function for monochrome bitmaps (depth 1) 
%%   in portable programs: in this case the bits parameter should 
%%   contain an XBM image.
%%   
%%   For other bit depths, the behaviour is platform dependent: 
%%       under Windows, the data is passed without 
%%       any changes to the  underlying CreateBitmap() API. 
%%       
%%       Under other platforms, 
%%       only monochrome bitmaps may be created using this constructor 
%%       and wxImage should be used for creating colour bitmaps from static data.
%%    
%% Return Value:
%% See Also:
%%*%%*%%
          -spec new(Bits, Width, Height, [Option]) -> wxBitmap()
           when
           Bits    ::           binary(),  %% Specifies an array of pixel values.
           Width   ::          integer(),  %% Specifies the width of the bitmap.
           Height  ::          integer(),  %% Specifies the height of the bitmap.
           Option  ::  {depth, integer()}. %% Specifies the depth of the bitmap. 
                                           %% If this is omitted, the display 
                                           %% depth of the screen is used.
new(Bits,Width,Height, Options)
           when 
           is_binary(Bits),
           is_integer(Width),
           is_integer(Height),
           is_list(Options) ->
                                                           wxe_util:send_bin(Bits),
                       MOpts = fun({depth, Depth}, Acc) -> [<<1:32/?UI,Depth:32/?UI>>|Acc];
                                            (BadOpt, _) -> erlang:error({badoption, BadOpt})
                               end,
                       BinOpt = list_to_binary(lists:foldl(MOpts, [<<0:32>>], Options)),
                                            wxe_util:construct(?wxBitmap_new_4,
                                            <<Width:32/?UI,Height:32/?UI, BinOpt/binary>>).











           %·%% CONVERT TO IMAGE %%·%

%%   
%%   Creates an image from a platform-dependent bitmap. 
%%   This preserves mask information so that bitmaps and images can 
%%   be converted back and forth without loss in that respect.
%%   
%% Return Value:
%% See Also:
%%*%%*%%
          -spec convertToImage(This) -> wxImage:wxImage()
           when
           This :: wxBitmap().

convertToImage(#wx_ref{type=ThisT,ref=ThisRef}) ->
                                                 ?CLASS(ThisT,wxBitmap),
                                   wxe_util:call(?wxBitmap_ConvertToImage,
                                   <<ThisRef:32/?UI>>).





           %·%% COPY FROM ICON %%·%

%%   
%%    Creates the bitmap from an icon.
%%   
%% Return Value:
%% See Also:
%%*%%*%%
          -spec copyFromIcon(This, Icon) -> boolean()
           when
           This ::      wxBitmap(), 
           Icon :: wxIcon:wxIcon().

copyFromIcon(#wx_ref{type=ThisT,ref=ThisRef},
             #wx_ref{type=IconT,ref=IconRef}) ->
                                               ?CLASS(ThisT,wxBitmap),
                                               ?CLASS(IconT,wxIcon),
                                 wxe_util:call(?wxBitmap_CopyFromIcon,
                                 <<ThisRef:32/?UI,IconRef:32/?UI>>).




           %·%% CREATE %%·%

%%   
%%   Creates a fresh bitmap. If the final argument is omitted, 
%%   the display depth of the screen is used.
%%   
%%   The first form works on all platforms. 
%%   The portability of the second form depends on the type of data.   
%%
%% See below...
%% @equiv create(This,Width,Height, [])
          -spec create(This, Width, Height) -> boolean()
           when
           This   :: wxBitmap(), 
           Width  ::  integer(), 
           Height ::  integer().

create(This,Width,Height)
           when 
           is_record(This, wx_ref),
           is_integer(Width),
           is_integer(Height)               -> create(This,Width,Height, []).


%%    
%% Return Value: true if the call succeeded, false otherwise.
%% See Also: wxBitmap::wxBitmap
%%*%%*%%
          -spec create(This, Width, Height, [Option]) -> boolean()
           when
           This    ::         wxBitmap(), 
           Width   ::          integer(),  %% The width of the bitmap in pixels.
           Height  ::          integer(),  %% The height of the bitmap in pixels.
           Option  ::  {depth, integer()}. %% The depth of the bitmap in pixels. If this is -1, the screen depth is used.

create(#wx_ref{type=ThisT,ref=ThisRef}, Width, Height, Options)
           when 
           is_integer(Width),
           is_integer(Height),
           is_list(Options) ->
                             ?CLASS(ThisT,wxBitmap),
                   MOpts = fun({depth, Depth}, Acc) -> [<<1:32/?UI,Depth:32/?UI>>|Acc];
                                        (BadOpt, _) -> erlang:error({badoption, BadOpt})
                           end,
                   BinOpt = list_to_binary(lists:foldl(MOpts, [<<0:32>>], Options)),
                                        wxe_util:call(?wxBitmap_Create,
                                        <<ThisRef:32/?UI,Width:32/?UI,Height:32/?UI, 0:32,BinOpt/binary>>).







           %·%% GET DEPTH %%·%

%%   
%%   Gets the colour depth of the bitmap. 
%%   A value of 1 indicates a monochrome bitmap.
%%   
%% Return Value:
%% See Also:
%%*%%*%%
          -spec getDepth(This) -> integer()
           when
           This :: wxBitmap().

getDepth(#wx_ref{type=ThisT,ref=ThisRef}) ->
                                           ?CLASS(ThisT,wxBitmap),
                             wxe_util:call(?wxBitmap_GetDepth,
                             <<ThisRef:32/?UI>>).







           %·%% GET HEIGHT %%·%

%%   
%%   Gets the height of the bitmap in pixels. 
%%   
%% Return Value:
%% See Also:
%%*%%*%%
          -spec getHeight(This) -> integer()
           when
           This :: wxBitmap().

getHeight(#wx_ref{type=ThisT,ref=ThisRef}) ->
                                            ?CLASS(ThisT,wxBitmap),
                              wxe_util:call(?wxBitmap_GetHeight,
                              <<ThisRef:32/?UI>>).





           %·%% GET PALETTE %%·%

%%   
%%   Gets the associated palette (if any) which may have been loaded 
%%   from a file or set for the bitmap.
%%   
%% Return Value:
%% See Also: wxPalette
%%*%%*%%
          -spec getPalette(This) -> wxPalette:wxPalette()
           when
           This :: wxBitmap().

getPalette(#wx_ref{type=ThisT,ref=ThisRef}) ->
                                             ?CLASS(ThisT,wxBitmap),
                               wxe_util:call(?wxBitmap_GetPalette,
                               <<ThisRef:32/?UI>>).





           %·%% GET MASK %%·%

%%   
%%   Gets the associated mask (if any) which may have been 
%%   loaded from a file or set for the bitmap.
%%   
%% Return Value:
%% See Also:  wxBitmap::SetMask, wxMask
%%*%%*%%
          -spec getMask(This) -> wxMask:wxMask()
           when
           This :: wxBitmap().

getMask(#wx_ref{type=ThisT,ref=ThisRef}) ->
                             ?CLASS(ThisT,wxBitmap),
               wxe_util:call(?wxBitmap_GetMask,
               <<ThisRef:32/?UI>>).





           %·%% GET WIDTH %%·%

%%   
%%    Gets the width of the bitmap in pixels.
%%   
%% Return Value:
%% See Also: wxBitmap::GetHeight
%%*%%*%%
          -spec getWidth(This) -> integer()
           when
           This :: wxBitmap().

getWidth(#wx_ref{type=ThisT,ref=ThisRef}) ->
                                           ?CLASS(ThisT,wxBitmap),
                             wxe_util:call(?wxBitmap_GetWidth,
                             <<ThisRef:32/?UI>>).





           %·%% GET SUB BITMAP %%·%

%%   
%%   Returns a sub bitmap of the current one as long as the rect 
%%   belongs entirely to the bitmap. 
%%   This function preserves bit depth and mask information.
%%   
%% Return Value:
%% See Also:
%%*%%*%%
          -spec getSubBitmap(This, Rect) -> wxBitmap()
           when
           This :: wxBitmap(), 
           Rect :: {X :: integer(), 
                    Y :: integer(), 
                    W :: integer(), 
                    H :: integer()}.

getSubBitmap(#wx_ref{type=ThisT,ref=ThisRef}, {RectX, RectY, RectW, RectH})
           when 
           is_integer(RectX),
           is_integer(RectY),
           is_integer(RectW),
           is_integer(RectH) ->
                              ?CLASS(ThisT,wxBitmap),
                wxe_util:call(?wxBitmap_GetSubBitmap,
                <<ThisRef:32/?UI,RectX:32/?UI,RectY:32/?UI,RectW:32/?UI,RectH:32/?UI>>).






           %·%% LOAD FILE %%·%

%%   
%% See below...
%% @equiv loadFile(This,Name, [])
          -spec loadFile(This, Name) -> boolean()
           when
           This ::         wxBitmap(),
           Name :: unicode:chardata(). 
       %%  Either a filename or a Windows resource name. 
       %%  The meaning of name is determined by the type parameter.

loadFile(This,Name)
           when 
           is_record(This, wx_ref),
           is_list(Name)             -> loadFile(This,Name, []).

%%   
%%   Loads a bitmap from a file or resource.
%%    
%%   A palette may be associated with the bitmap if one exists 
%%   (especially for colour Windows bitmaps), and if the code supports it. 
%%   You can check if one has been created by using the GetPalette member.
%%
%% Return Value: true if the operation succeeded, false otherwise.
%% See Also: wxBitmap::SaveFile
%%*%%*%%
%%<br /> Type = ?wxBITMAP_TYPE_INVALID 
%%            | ?wxBITMAP_TYPE_BMP             | ?wxBITMAP_TYPE_BMP_RESOURCE 
%%            | ?wxBITMAP_TYPE_RESOURCE        | ?wxBITMAP_TYPE_ICO 
%%            | ?wxBITMAP_TYPE_ICO_RESOURCE    | ?wxBITMAP_TYPE_CUR 
%%            | ?wxBITMAP_TYPE_CUR_RESOURCE    | ?wxBITMAP_TYPE_XBM 
%%            | ?wxBITMAP_TYPE_XBM_DATA        | ?wxBITMAP_TYPE_XPM 
%%            | ?wxBITMAP_TYPE_XPM_DATA        | ?wxBITMAP_TYPE_TIF 
%%            | ?wxBITMAP_TYPE_TIF_RESOURCE    | ?wxBITMAP_TYPE_GIF 
%%            | ?wxBITMAP_TYPE_GIF_RESOURCE    | ?wxBITMAP_TYPE_PNG 
%%            | ?wxBITMAP_TYPE_PNG_RESOURCE    | ?wxBITMAP_TYPE_JPEG 
%%            | ?wxBITMAP_TYPE_JPEG_RESOURCE   | ?wxBITMAP_TYPE_PNM 
%%            | ?wxBITMAP_TYPE_PNM_RESOURCE    | ?wxBITMAP_TYPE_PCX 
%%            | ?wxBITMAP_TYPE_PCX_RESOURCE    | ?wxBITMAP_TYPE_PICT 
%%            | ?wxBITMAP_TYPE_PICT_RESOURCE   | ?wxBITMAP_TYPE_ICON 
%%            | ?wxBITMAP_TYPE_ICON_RESOURCE   | ?wxBITMAP_TYPE_ANI 
%%            | ?wxBITMAP_TYPE_IFF             | ?wxBITMAP_TYPE_TGA 
%%            | ?wxBITMAP_TYPE_MACCURSOR       | ?wxBITMAP_TYPE_MACCURSOR_RESOURCE 
%%            | ?wxBITMAP_TYPE_ANY
%%
          -spec loadFile(This, Name, [Option]) -> boolean()
           when
           This    ::           wxBitmap(), 
           Name    ::   unicode:chardata(),
           Option  ::  {type, wx:wx_enum()}.
%%              Type — One of the following values:
%%
%%                     wxBITMAP_TYPE_BMP             Load a Windows bitmap file.
%%                     wxBITMAP_TYPE_BMP_RESOURCE    Load a Windows bitmap resource from the executable.
%%                     wxBITMAP_TYPE_PICT_RESOURCE   Load a PICT image resource from the executable. Mac OS only.
%%                     wxBITMAP_TYPE_GIF             Load a GIF bitmap file.
%%                     wxBITMAP_TYPE_XBM             Load an X bitmap file.
%%                     wxBITMAP_TYPE_XPM             Load an XPM bitmap file.
%%
%%                     The validity of these flags depends on the platform and wxWidgets configuration.
%%
%%                     In addition, wxBitmap can read all formats that wxImage can: 
%%                                                                                    wxBITMAP_TYPE_JPEG, 
%%                                                                                    wxBITMAP_TYPE_PNG, 
%%                                                                                    wxBITMAP_TYPE_GIF, 
%%                                                                                    wxBITMAP_TYPE_PCX, 
%%                                                                                    wxBITMAP_TYPE_PNM). 
%%                     (Of course you must have wxImage handlers loaded.) 



loadFile(#wx_ref{type=ThisT,ref=ThisRef}, Name, Options)
           when 
           is_list(Name),
           is_list(Options) ->
                             ?CLASS(ThisT,wxBitmap),
                   Name_UC = unicode:characters_to_binary([Name,0]),
                   MOpts   = fun({type, Type}, Acc) -> [<<1:32/?UI,Type:32/?UI>>|Acc];
                                        (BadOpt, _) -> erlang:error({badoption, BadOpt})
                             end,
                   BinOpt = list_to_binary(lists:foldl(MOpts, [<<0:32>>], Options)),
                                        wxe_util:call(?wxBitmap_LoadFile,
                               <<ThisRef:32/?UI,(byte_size(Name_UC)):32/?UI,(Name_UC)/binary, 
                                     0:(((8- ((0+byte_size(Name_UC)) band 16#7)) band 16#7))/unit:8, BinOpt/binary>>).








           %·%% OK %%·%

%%   
%%    Returns true if bitmap data is present.
%%   
%% Return Value:
%% See Also:
%%*%%*%%
          -spec ok(This) -> boolean()
           when
           This :: wxBitmap().

ok(#wx_ref{type=ThisT,ref=ThisRef}) ->
                                     ?CLASS(ThisT,wxBitmap),
                       wxe_util:call(?wxBitmap_Ok,
                       <<ThisRef:32/?UI>>).




           %·%% SAVE FILE %%·%

%%   
%% See below...
%% @equiv saveFile(This,Name,Type, [])
          -spec saveFile(This, Name, Type) -> boolean()
           when
           This ::         wxBitmap(), 
           Name :: unicode:chardata(), 
           Type ::       wx:wx_enum().

saveFile(This,Name,Type)
           when 
           is_record(This, wx_ref),
           is_list(Name),
           is_integer(Type) -> saveFile(This, Name, Type, []).


%%    
%%    Saves a bitmap in the named file.
%% 
%%    Depending on how wxWidgets has been configured, not all formats may be available.
%%   
%% Return Value: true if the operation succeeded, false otherwise.
%% See Also: wxBitmap::LoadFile
%%*%%*%%
%%<br /> Type = ?wxBITMAP_TYPE_INVALID 
%%            | ?wxBITMAP_TYPE_BMP             | ?wxBITMAP_TYPE_BMP_RESOURCE 
%%            | ?wxBITMAP_TYPE_RESOURCE        | ?wxBITMAP_TYPE_ICO 
%%            | ?wxBITMAP_TYPE_ICO_RESOURCE    | ?wxBITMAP_TYPE_CUR 
%%            | ?wxBITMAP_TYPE_CUR_RESOURCE    | ?wxBITMAP_TYPE_XBM 
%%            | ?wxBITMAP_TYPE_XBM_DATA        | ?wxBITMAP_TYPE_XPM 
%%            | ?wxBITMAP_TYPE_XPM_DATA        | ?wxBITMAP_TYPE_TIF 
%%            | ?wxBITMAP_TYPE_TIF_RESOURCE    | ?wxBITMAP_TYPE_GIF 
%%            | ?wxBITMAP_TYPE_GIF_RESOURCE    | ?wxBITMAP_TYPE_PNG 
%%            | ?wxBITMAP_TYPE_PNG_RESOURCE    | ?wxBITMAP_TYPE_JPEG 
%%            | ?wxBITMAP_TYPE_JPEG_RESOURCE   | ?wxBITMAP_TYPE_PNM 
%%            | ?wxBITMAP_TYPE_PNM_RESOURCE    | ?wxBITMAP_TYPE_PCX 
%%            | ?wxBITMAP_TYPE_PCX_RESOURCE    | ?wxBITMAP_TYPE_PICT 
%%            | ?wxBITMAP_TYPE_PICT_RESOURCE   | ?wxBITMAP_TYPE_ICON 
%%            | ?wxBITMAP_TYPE_ICON_RESOURCE   | ?wxBITMAP_TYPE_ANI 
%%            | ?wxBITMAP_TYPE_IFF             | ?wxBITMAP_TYPE_TGA 
%%            | ?wxBITMAP_TYPE_MACCURSOR       | ?wxBITMAP_TYPE_MACCURSOR_RESOURCE 
%%            | ?wxBITMAP_TYPE_ANY          -spec saveFile(This, Name, Type, [Option]) -> boolean()
           when
           This    ::                      wxBitmap(), 
           Name    ::              unicode:chardata(), 
           Type    ::                    wx:wx_enum(),
           Option  :: {palette, wxPalette:wxPalette()}. %% An optional palette used for saving the bitmap.
%%
%%         One of the following values:
%% 
%%                          wxBITMAP_TYPE_BMP   Save a Windows bitmap file.
%%                          wxBITMAP_TYPE_GIF   Save a GIF bitmap file.
%%                          wxBITMAP_TYPE_XBM   Save an X bitmap file.
%%                          wxBITMAP_TYPE_XPM   Save an XPM bitmap file.
%%
%%                          The validity of these flags depends on the platform and wxWidgets configuration.
%%
%%                          In addition, wxBitmap can save all formats that wxImage can 
%%                                      (wxBITMAP_TYPE_JPEG, wxBITMAP_TYPE_PNG). 
%%                                      (Of course you must have wxImage handlers loaded.) 
 

saveFile(#wx_ref{type=ThisT,ref=ThisRef}, Name, Type, Options)
           when 
           is_list(Name),
           is_integer(Type),
           is_list(Options) ->
                             ?CLASS(ThisT,wxBitmap),
                     Name_UC = unicode:characters_to_binary([Name,0]),
                       MOpts = fun({palette, #wx_ref{type=PaletteT,ref=PaletteRef}}, Acc) -> ?CLASS(PaletteT,wxPalette),[<<1:32/?UI,PaletteRef:32/?UI>>|Acc];
                                                                              (BadOpt, _) -> erlang:error({badoption, BadOpt})
                               end,
                      BinOpt = list_to_binary(lists:foldl(MOpts, [<<0:32>>], Options)),
                                           wxe_util:call(?wxBitmap_SaveFile,
                                  <<ThisRef:32/?UI,(byte_size(Name_UC)):32/?UI,(Name_UC)/binary,
                                        0:(((8- ((0+byte_size(Name_UC)) band 16#7)) band 16#7))/unit:8,Type:32/?UI, 0:32,BinOpt/binary>>).





           %·%% SET DEPTH %%·%

%%   
%%   Sets the depth member (does not affect the bitmap data).
%%   
%% Return Value:
%% See Also:
%%*%%*%%
          -spec setDepth(This, Depth) -> ok
           when
           This  :: wxBitmap(), 
           Depth ::  integer(). %% Bitmap depth.

setDepth(#wx_ref{type=ThisT,ref=ThisRef}, Depth)
           when 
           is_integer(Depth) ->
                              ?CLASS(ThisT,wxBitmap),
                wxe_util:cast(?wxBitmap_SetDepth,
                <<ThisRef:32/?UI,Depth:32/?UI>>).






           %·%% SET HEIGHT %%·%

%%   
%%    Sets the height member (does not affect the bitmap data).
%%   
%% Return Value:
%% See Also:
%%*%%*%%
          -spec setHeight(This, Height) -> ok
           when
           This   :: wxBitmap(), 
           Height ::  integer(). %% Bitmap height in pixels.

setHeight(#wx_ref{type=ThisT,ref=ThisRef}, Height)
           when 
           is_integer(Height) ->
                               ?CLASS(ThisT,wxBitmap),
                 wxe_util:cast(?wxBitmap_SetHeight,
                 <<ThisRef:32/?UI,Height:32/?UI>>).








           %·%% SET MASK %%·%

%%    
%%    Sets the mask for this bitmap.
%%
%%    The bitmap object owns the mask once this has been called.
%%   
%% Return Value:
%% See Also:  wxBitmap::GetMask, wxMask
%%*%%*%%
          -spec setMask(This, Mask) -> ok
           when
           This ::      wxBitmap(), 
           Mask :: wxMask:wxMask().

setMask(#wx_ref{type=ThisT,ref=ThisRef},
        #wx_ref{type=MaskT,ref=MaskRef}) ->
                                          ?CLASS(ThisT,wxBitmap),
                                          ?CLASS(MaskT,wxMask),
                            wxe_util:cast(?wxBitmap_SetMask,
                            <<ThisRef:32/?UI,MaskRef:32/?UI>>).





           %·%% SET PALETTE %%·%

%%   
%%    Sets the associated palette. (Not implemented under GTK+).
%%   
%% Return Value:
%% See Also: wxPalette
%%*%%*%%
          -spec setPalette(This, Palette) -> ok
           when
           This    ::            wxBitmap(), 
           Palette :: wxPalette:wxPalette(). %% The palette to set.

setPalette(#wx_ref{type=ThisT,ref=ThisRef},
           #wx_ref{type=PaletteT,ref=PaletteRef}) ->
                                                   ?CLASS(ThisT,wxBitmap),
                                                   ?CLASS(PaletteT,wxPalette),
                                     wxe_util:cast(?wxBitmap_SetPalette,
                                     <<ThisRef:32/?UI,PaletteRef:32/?UI>>).






           %·%% SET WIDTH %%·%

%%   
%%    Sets the width member (does not affect the bitmap data).
%%   
%% Return Value:
%% See Also:
%%*%%*%%
          -spec setWidth(This, Width) -> ok
           when
           This  :: wxBitmap(),
           Width ::  integer(). %%  Bitmap width in pixels.

setWidth(#wx_ref{type=ThisT,ref=ThisRef}, Width)
           when 
           is_integer(Width) ->
                              ?CLASS(ThisT,wxBitmap),
                wxe_util:cast(?wxBitmap_SetWidth,
                <<ThisRef:32/?UI,Width:32/?UI>>).





           %·%% DESTROY %%·%

%%   Destructor. See reference-counted object destruction for more info.
%%
%%   If the application omits to delete the bitmap explicitly, 
%%   the bitmap will be destroyed automatically by wxWidgets when 
%%   the application exits.
%%   
%%   Do not delete a bitmap that is selected into a memory device context.
%%   
%% @doc Destroys this object, do not use object again
          -spec destroy(This :: wxBitmap()) -> ok.
          
destroy(Obj=#wx_ref{type=Type}) ->
                                 ?CLASS(Type,wxBitmap),
                wxe_util:destroy(?DESTROY_OBJECT,Obj),
                ok.