forked from ImageMagick/ImageMagick
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimate.c
3043 lines (2911 loc) · 103 KB
/
animate.c
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
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% AAA N N IIIII M M AAA TTTTT EEEEE %
% A A NN N I MM MM A A T E %
% AAAAA N N N I M M M AAAAA T EEE %
% A A N NN I M M A A T E %
% A A N N IIIII M M A A T EEEEE %
% %
% %
% Methods to Interactively Animate an Image Sequence %
% %
% Software Design %
% Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2016 ImageMagick Studio LLC, a non-profit organization %
% dedicated to making software imaging solutions freely available. %
% %
% You may not use this file except in compliance with the License. You may %
% obtain a copy of the License at %
% %
% http://www.imagemagick.org/script/license.php %
% %
% 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. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "MagickCore/studio.h"
#include "MagickCore/animate.h"
#include "MagickCore/animate-private.h"
#include "MagickCore/attribute.h"
#include "MagickCore/client.h"
#include "MagickCore/color.h"
#include "MagickCore/color-private.h"
#include "MagickCore/colorspace.h"
#include "MagickCore/colorspace-private.h"
#include "MagickCore/constitute.h"
#include "MagickCore/delegate.h"
#include "MagickCore/exception.h"
#include "MagickCore/exception-private.h"
#include "MagickCore/geometry.h"
#include "MagickCore/image-private.h"
#include "MagickCore/layer.h"
#include "MagickCore/list.h"
#include "MagickCore/log.h"
#include "MagickCore/image.h"
#include "MagickCore/memory_.h"
#include "MagickCore/monitor.h"
#include "MagickCore/monitor-private.h"
#include "MagickCore/option.h"
#include "MagickCore/pixel-accessor.h"
#include "MagickCore/property.h"
#include "MagickCore/resource_.h"
#include "MagickCore/string_.h"
#include "MagickCore/string-private.h"
#include "MagickCore/transform.h"
#include "MagickCore/utility.h"
#include "MagickCore/utility-private.h"
#include "MagickCore/version.h"
#include "MagickCore/widget.h"
#include "MagickCore/widget-private.h"
#include "MagickCore/xwindow.h"
#include "MagickCore/xwindow-private.h"
#if defined(MAGICKCORE_X11_DELEGATE)
/*
Animate state declarations.
*/
#define AutoReverseAnimationState 0x0004
#define ForwardAnimationState 0x0008
#define HighlightState 0x0010
#define PlayAnimationState 0x0020
#define RepeatAnimationState 0x0040
#define StepAnimationState 0x0080
/*
Static declarations.
*/
static const char
*AnimateHelp[]=
{
"BUTTONS",
"",
" Press any button to map or unmap the Command widget.",
"",
"COMMAND WIDGET",
" The Command widget lists a number of sub-menus and commands.",
" They are",
"",
" Animate",
" Open...",
" Save...",
" Play",
" Step",
" Repeat",
" Auto Reverse",
" Speed",
" Slower",
" Faster",
" Direction",
" Forward",
" Reverse",
" Help",
" Overview",
" Browse Documentation",
" About Animate",
" Image Info",
" Quit",
"",
" Menu items with a indented triangle have a sub-menu. They",
" are represented above as the indented items. To access a",
" sub-menu item, move the pointer to the appropriate menu and",
" press a button and drag. When you find the desired sub-menu",
" item, release the button and the command is executed. Move",
" the pointer away from the sub-menu if you decide not to",
" execute a particular command.",
"",
"KEYBOARD ACCELERATORS",
" Accelerators are one or two key presses that effect a",
" particular command. The keyboard accelerators that",
" animate(1) understands is:",
"",
" Ctl+O Press to open an image from a file.",
"",
" space Press to display the next image in the sequence.",
"",
" < Press to speed-up the display of the images. Refer to",
" -delay for more information.",
"",
" > Press to slow the display of the images. Refer to",
" -delay for more information.",
"",
" F1 Press to display helpful information about animate(1).",
"",
" Find Press to browse documentation about ImageMagick.",
"",
" ? Press to display information about the image. Press",
" any key or button to erase the information.",
"",
" This information is printed: image name; image size;",
" and the total number of unique colors in the image.",
"",
" Ctl-q Press to discard all images and exit program.",
(char *) NULL
};
/*
Constant declarations.
*/
static const char
*PageSizes[]=
{
"Letter",
"Tabloid",
"Ledger",
"Legal",
"Statement",
"Executive",
"A3",
"A4",
"A5",
"B4",
"B5",
"Folio",
"Quarto",
"10x14",
(char *) NULL
};
static const unsigned char
HighlightBitmap[8] =
{
(unsigned char) 0xaa,
(unsigned char) 0x55,
(unsigned char) 0xaa,
(unsigned char) 0x55,
(unsigned char) 0xaa,
(unsigned char) 0x55,
(unsigned char) 0xaa,
(unsigned char) 0x55
},
ShadowBitmap[8] =
{
(unsigned char) 0x00,
(unsigned char) 0x00,
(unsigned char) 0x00,
(unsigned char) 0x00,
(unsigned char) 0x00,
(unsigned char) 0x00,
(unsigned char) 0x00,
(unsigned char) 0x00
};
/*
Enumeration declarations.
*/
typedef enum
{
OpenCommand,
SaveCommand,
PlayCommand,
StepCommand,
RepeatCommand,
AutoReverseCommand,
SlowerCommand,
FasterCommand,
ForwardCommand,
ReverseCommand,
HelpCommand,
BrowseDocumentationCommand,
VersionCommand,
InfoCommand,
QuitCommand,
StepBackwardCommand,
StepForwardCommand,
NullCommand
} CommandType;
/*
Stipples.
*/
#define HighlightWidth 8
#define HighlightHeight 8
#define ShadowWidth 8
#define ShadowHeight 8
/*
Forward declarations.
*/
static Image
*XMagickCommand(Display *,XResourceInfo *,XWindows *,const CommandType,
Image **,MagickStatusType *,ExceptionInfo *);
static MagickBooleanType
XSaveImage(Display *,XResourceInfo *,XWindows *,Image *,ExceptionInfo *);
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% A n i m a t e I m a g e s %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% AnimateImages() repeatedly displays an image sequence to any X window
% screen. It returns a value other than 0 if successful. Check the
% exception member of image to determine the reason for any failure.
%
% The format of the AnimateImages method is:
%
% MagickBooleanType AnimateImages(const ImageInfo *image_info,
% Image *images,ExceptionInfo *exception)
%
% A description of each parameter follows:
%
% o image_info: the image info.
%
% o image: the image.
%
% o exception: return any errors or warnings in this structure.
%
*/
MagickExport MagickBooleanType AnimateImages(const ImageInfo *image_info,
Image *images,ExceptionInfo *exception)
{
char
*argv[1];
Display
*display;
MagickStatusType
status;
XrmDatabase
resource_database;
XResourceInfo
resource_info;
assert(image_info != (const ImageInfo *) NULL);
assert(image_info->signature == MagickCoreSignature);
assert(images != (Image *) NULL);
assert(images->signature == MagickCoreSignature);
if (images->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
display=XOpenDisplay(image_info->server_name);
if (display == (Display *) NULL)
{
(void) ThrowMagickException(exception,GetMagickModule(),XServerError,
"UnableToOpenXServer","`%s'",XDisplayName(image_info->server_name));
return(MagickFalse);
}
if (exception->severity != UndefinedException)
CatchException(exception);
(void) XSetErrorHandler(XError);
resource_database=XGetResourceDatabase(display,GetClientName());
(void) ResetMagickMemory(&resource_info,0,sizeof(XResourceInfo));
XGetResourceInfo(image_info,resource_database,GetClientName(),&resource_info);
if (image_info->page != (char *) NULL)
resource_info.image_geometry=AcquireString(image_info->page);
resource_info.immutable=MagickTrue;
argv[0]=AcquireString(GetClientName());
(void) XAnimateImages(display,&resource_info,argv,1,images,exception);
(void) SetErrorHandler((ErrorHandler) NULL);
(void) SetWarningHandler((WarningHandler) NULL);
argv[0]=DestroyString(argv[0]);
(void) XCloseDisplay(display);
XDestroyResourceInfo(&resource_info);
status=exception->severity == UndefinedException ? MagickTrue : MagickFalse;
return(status != 0 ? MagickTrue : MagickFalse);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
+ X M a g i c k C o m m a n d %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% XMagickCommand() makes a transform to the image or Image window as specified
% by a user menu button or keyboard command.
%
% The format of the XMagickCommand method is:
%
% Image *XMagickCommand(Display *display,XResourceInfo *resource_info,
% XWindows *windows,const CommandType command_type,Image **image,
% MagickStatusType *state,ExceptionInfo *exception)
%
% A description of each parameter follows:
%
% o display: Specifies a connection to an X server; returned from
% XOpenDisplay.
%
% o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
%
% o windows: Specifies a pointer to a XWindows structure.
%
% o image: the image; XMagickCommand
% may transform the image and return a new image pointer.
%
% o state: Specifies a MagickStatusType; XMagickCommand may return a
% modified state.
%
% o exception: return any errors or warnings in this structure.
%
%
*/
static Image *XMagickCommand(Display *display,XResourceInfo *resource_info,
XWindows *windows,const CommandType command_type,Image **image,
MagickStatusType *state,ExceptionInfo *exception)
{
Image
*nexus;
MagickBooleanType
proceed;
MagickStatusType
status;
XTextProperty
window_name;
/*
Process user command.
*/
nexus=NewImageList();
switch (command_type)
{
case OpenCommand:
{
char
**filelist;
Image
*images,
*next;
ImageInfo
*read_info;
int
number_files;
register int
i;
static char
filenames[MagickPathExtent] = "*";
if (resource_info->immutable != MagickFalse)
break;
/*
Request file name from user.
*/
XFileBrowserWidget(display,windows,"Animate",filenames);
if (*filenames == '\0')
return((Image *) NULL);
/*
Expand the filenames.
*/
filelist=(char **) AcquireMagickMemory(sizeof(char *));
if (filelist == (char **) NULL)
{
ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed",
filenames);
return((Image *) NULL);
}
number_files=1;
filelist[0]=filenames;
status=ExpandFilenames(&number_files,&filelist);
if ((status == MagickFalse) || (number_files == 0))
{
if (number_files == 0)
{
ThrowXWindowException(ImageError,"NoImagesWereLoaded",filenames);
return((Image *) NULL);
}
ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed",
filenames);
return((Image *) NULL);
}
read_info=CloneImageInfo(resource_info->image_info);
images=NewImageList();
XSetCursorState(display,windows,MagickTrue);
XCheckRefreshWindows(display,windows);
for (i=0; i < number_files; i++)
{
(void) CopyMagickString(read_info->filename,filelist[i],MagickPathExtent);
filelist[i]=DestroyString(filelist[i]);
*read_info->magick='\0';
next=ReadImage(read_info,exception);
CatchException(exception);
if (next != (Image *) NULL)
AppendImageToList(&images,next);
if (number_files <= 5)
continue;
proceed=SetImageProgress(images,LoadImageTag,i,(MagickSizeType)
number_files);
if (proceed == MagickFalse)
break;
}
filelist=(char **) RelinquishMagickMemory(filelist);
read_info=DestroyImageInfo(read_info);
if (images == (Image *) NULL)
{
XSetCursorState(display,windows,MagickFalse);
ThrowXWindowException(ImageError,"NoImagesWereLoaded",filenames);
return((Image *) NULL);
}
nexus=GetFirstImageInList(images);
*state|=ExitState;
break;
}
case PlayCommand:
{
char
basename[MagickPathExtent];
int
status;
/*
Window name is the base of the filename.
*/
*state|=PlayAnimationState;
*state&=(~AutoReverseAnimationState);
GetPathComponent((*image)->magick_filename,BasePath,basename);
(void) FormatLocaleString(windows->image.name,MagickPathExtent,
"%s: %s",MagickPackageName,basename);
if (resource_info->title != (char *) NULL)
{
char
*title;
title=InterpretImageProperties(resource_info->image_info,*image,
resource_info->title,exception);
(void) CopyMagickString(windows->image.name,title,MagickPathExtent);
title=DestroyString(title);
}
status=XStringListToTextProperty(&windows->image.name,1,&window_name);
if (status == 0)
break;
XSetWMName(display,windows->image.id,&window_name);
(void) XFree((void *) window_name.value);
break;
}
case StepCommand:
case StepBackwardCommand:
case StepForwardCommand:
{
*state|=StepAnimationState;
*state&=(~PlayAnimationState);
if (command_type == StepBackwardCommand)
*state&=(~ForwardAnimationState);
if (command_type == StepForwardCommand)
*state|=ForwardAnimationState;
if (resource_info->title != (char *) NULL)
break;
break;
}
case RepeatCommand:
{
*state|=RepeatAnimationState;
*state&=(~AutoReverseAnimationState);
*state|=PlayAnimationState;
break;
}
case AutoReverseCommand:
{
*state|=AutoReverseAnimationState;
*state&=(~RepeatAnimationState);
*state|=PlayAnimationState;
break;
}
case SaveCommand:
{
/*
Save image.
*/
status=XSaveImage(display,resource_info,windows,*image,exception);
if (status == MagickFalse)
{
char
message[MagickPathExtent];
(void) FormatLocaleString(message,MagickPathExtent,"%s:%s",
exception->reason != (char *) NULL ? exception->reason : "",
exception->description != (char *) NULL ? exception->description :
"");
XNoticeWidget(display,windows,"Unable to save file:",message);
break;
}
break;
}
case SlowerCommand:
{
resource_info->delay++;
break;
}
case FasterCommand:
{
if (resource_info->delay == 0)
break;
resource_info->delay--;
break;
}
case ForwardCommand:
{
*state=ForwardAnimationState;
*state&=(~AutoReverseAnimationState);
break;
}
case ReverseCommand:
{
*state&=(~ForwardAnimationState);
*state&=(~AutoReverseAnimationState);
break;
}
case InfoCommand:
{
XDisplayImageInfo(display,resource_info,windows,(Image *) NULL,*image,
exception);
break;
}
case HelpCommand:
{
/*
User requested help.
*/
XTextViewWidget(display,resource_info,windows,MagickFalse,
"Help Viewer - Animate",AnimateHelp);
break;
}
case BrowseDocumentationCommand:
{
Atom
mozilla_atom;
Window
mozilla_window,
root_window;
/*
Browse the ImageMagick documentation.
*/
root_window=XRootWindow(display,XDefaultScreen(display));
mozilla_atom=XInternAtom(display,"_MOZILLA_VERSION",MagickFalse);
mozilla_window=XWindowByProperty(display,root_window,mozilla_atom);
if (mozilla_window != (Window) NULL)
{
char
command[MagickPathExtent],
*url;
/*
Display documentation using Netscape remote control.
*/
url=GetMagickHomeURL();
(void) FormatLocaleString(command,MagickPathExtent,
"openurl(%s,new-tab)",url);
url=DestroyString(url);
mozilla_atom=XInternAtom(display,"_MOZILLA_COMMAND",MagickFalse);
(void) XChangeProperty(display,mozilla_window,mozilla_atom,
XA_STRING,8,PropModeReplace,(unsigned char *) command,
(int) strlen(command));
XSetCursorState(display,windows,MagickFalse);
break;
}
XSetCursorState(display,windows,MagickTrue);
XCheckRefreshWindows(display,windows);
status=InvokeDelegate(resource_info->image_info,*image,"browse",
(char *) NULL,exception);
if (status == MagickFalse)
XNoticeWidget(display,windows,"Unable to browse documentation",
(char *) NULL);
XDelay(display,1500);
XSetCursorState(display,windows,MagickFalse);
break;
}
case VersionCommand:
{
XNoticeWidget(display,windows,GetMagickVersion((size_t *) NULL),
GetMagickCopyright());
break;
}
case QuitCommand:
{
/*
exit program
*/
if (resource_info->confirm_exit == MagickFalse)
XClientMessage(display,windows->image.id,windows->im_protocols,
windows->im_exit,CurrentTime);
else
{
int
status;
/*
Confirm program exit.
*/
status=XConfirmWidget(display,windows,"Do you really want to exit",
resource_info->client_name);
if (status != 0)
XClientMessage(display,windows->image.id,windows->im_protocols,
windows->im_exit,CurrentTime);
}
break;
}
default:
break;
}
return(nexus);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
+ X A n i m a t e B a c k g r o u n d I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% XAnimateBackgroundImage() animates an image sequence in the background of
% a window.
%
% The format of the XAnimateBackgroundImage method is:
%
% void XAnimateBackgroundImage(Display *display,
% XResourceInfo *resource_info,Image *images,ExceptionInfo *exception)
%
% A description of each parameter follows:
%
% o display: Specifies a connection to an X server; returned from
% XOpenDisplay.
%
% o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
%
% o images: the image list.
%
% o exception: return any errors or warnings in this structure.
%
*/
#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
#endif
static int SceneCompare(const void *x,const void *y)
{
const Image
**image_1,
**image_2;
image_1=(const Image **) x;
image_2=(const Image **) y;
return((int) ((*image_1)->scene-(*image_2)->scene));
}
#if defined(__cplusplus) || defined(c_plusplus)
}
#endif
MagickExport void XAnimateBackgroundImage(Display *display,
XResourceInfo *resource_info,Image *images,ExceptionInfo *exception)
{
char
geometry[MagickPathExtent],
visual_type[MagickPathExtent];
Image
*coalesce_image,
*display_image,
**image_list;
int
scene;
MagickStatusType
status;
RectangleInfo
geometry_info;
register ssize_t
i;
size_t
number_scenes;
static XPixelInfo
pixel;
static XStandardColormap
*map_info;
static XVisualInfo
*visual_info = (XVisualInfo *) NULL;
static XWindowInfo
window_info;
unsigned int
height,
width;
size_t
delay;
Window
root_window;
XEvent
event;
XGCValues
context_values;
XResourceInfo
resources;
XWindowAttributes
window_attributes;
/*
Determine target window.
*/
assert(images != (Image *) NULL);
assert(images->signature == MagickCoreSignature);
if (images->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
resources=(*resource_info);
window_info.id=(Window) NULL;
root_window=XRootWindow(display,XDefaultScreen(display));
if (LocaleCompare(resources.window_id,"root") == 0)
window_info.id=root_window;
else
{
if (isdigit((int) ((unsigned char) *resources.window_id)) != 0)
window_info.id=XWindowByID(display,root_window,
(Window) strtol((char *) resources.window_id,(char **) NULL,0));
if (window_info.id == (Window) NULL)
window_info.id=
XWindowByName(display,root_window,resources.window_id);
}
if (window_info.id == (Window) NULL)
{
ThrowXWindowException(XServerError,"NoWindowWithSpecifiedIDExists",
resources.window_id);
return;
}
/*
Determine window visual id.
*/
window_attributes.width=XDisplayWidth(display,XDefaultScreen(display));
window_attributes.height=XDisplayHeight(display,XDefaultScreen(display));
(void) CopyMagickString(visual_type,"default",MagickPathExtent);
status=XGetWindowAttributes(display,window_info.id,&window_attributes) != 0 ?
MagickTrue : MagickFalse;
if (status != MagickFalse)
(void) FormatLocaleString(visual_type,MagickPathExtent,"0x%lx",
XVisualIDFromVisual(window_attributes.visual));
if (visual_info == (XVisualInfo *) NULL)
{
/*
Allocate standard colormap.
*/
map_info=XAllocStandardColormap();
if (map_info == (XStandardColormap *) NULL)
ThrowXWindowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed",images->filename);
map_info->colormap=(Colormap) NULL;
pixel.pixels=(unsigned long *) NULL;
/*
Initialize visual info.
*/
resources.map_type=(char *) NULL;
resources.visual_type=visual_type;
visual_info=XBestVisualInfo(display,map_info,&resources);
if (visual_info == (XVisualInfo *) NULL)
ThrowXWindowFatalException(XServerFatalError,"UnableToGetVisual",
images->filename);
/*
Initialize window info.
*/
window_info.ximage=(XImage *) NULL;
window_info.matte_image=(XImage *) NULL;
window_info.pixmap=(Pixmap) NULL;
window_info.matte_pixmap=(Pixmap) NULL;
}
/*
Free previous root colors.
*/
if (window_info.id == root_window)
XDestroyWindowColors(display,root_window);
coalesce_image=CoalesceImages(images,exception);
if (coalesce_image == (Image *) NULL)
ThrowXWindowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
images->filename);
images=coalesce_image;
if (resources.map_type == (char *) NULL)
if ((visual_info->klass != TrueColor) &&
(visual_info->klass != DirectColor))
{
Image
*next;
/*
Determine if the sequence of images has the identical colormap.
*/
for (next=images; next != (Image *) NULL; )
{
next->alpha_trait=UndefinedPixelTrait;
if ((next->storage_class == DirectClass) ||
(next->colors != images->colors) ||
(next->colors > (size_t) visual_info->colormap_size))
break;
for (i=0; i < (ssize_t) images->colors; i++)
if (IsPixelInfoEquivalent(next->colormap+i,images->colormap+i) == MagickFalse)
break;
if (i < (ssize_t) images->colors)
break;
next=GetNextImageInList(next);
}
if (next != (Image *) NULL)
(void) RemapImages(resources.quantize_info,images,(Image *) NULL,
exception);
}
/*
Sort images by increasing scene number.
*/
number_scenes=GetImageListLength(images);
image_list=ImageListToArray(images,exception);
if (image_list == (Image **) NULL)
ThrowXWindowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed",images->filename);
for (i=0; i < (ssize_t) number_scenes; i++)
if (image_list[i]->scene == 0)
break;
if (i == (ssize_t) number_scenes)
qsort((void *) image_list,number_scenes,sizeof(Image *),SceneCompare);
/*
Initialize Standard Colormap.
*/
resources.colormap=SharedColormap;
display_image=image_list[0];
for (scene=0; scene < (int) number_scenes; scene++)
{
if ((resource_info->map_type != (char *) NULL) ||
(visual_info->klass == TrueColor) ||
(visual_info->klass == DirectColor))
(void) SetImageType(image_list[scene],image_list[scene]->alpha_trait ==
BlendPixelTrait ? TrueColorType : TrueColorAlphaType,exception);
if ((display_image->columns < image_list[scene]->columns) &&
(display_image->rows < image_list[scene]->rows))
display_image=image_list[scene];
}
if ((resource_info->map_type != (char *) NULL) ||
(visual_info->klass == TrueColor) || (visual_info->klass == DirectColor))
(void) SetImageType(display_image,display_image->alpha_trait !=
BlendPixelTrait ? TrueColorType : TrueColorAlphaType,exception);
XMakeStandardColormap(display,visual_info,&resources,display_image,map_info,
&pixel,exception);
/*
Graphic context superclass.
*/
context_values.background=pixel.background_color.pixel;
context_values.foreground=pixel.foreground_color.pixel;
pixel.annotate_context=XCreateGC(display,window_info.id,(unsigned long)
(GCBackground | GCForeground),&context_values);
if (pixel.annotate_context == (GC) NULL)
ThrowXWindowFatalException(XServerFatalError,"UnableToCreateGraphicContext",
images->filename);
/*
Initialize Image window attributes.
*/
XGetWindowInfo(display,visual_info,map_info,&pixel,(XFontStruct *) NULL,
&resources,&window_info);
/*
Create the X image.
*/
window_info.width=(unsigned int) image_list[0]->columns;
window_info.height=(unsigned int) image_list[0]->rows;
if ((image_list[0]->columns != window_info.width) ||
(image_list[0]->rows != window_info.height))
ThrowXWindowFatalException(XServerFatalError,"UnableToCreateXImage",
image_list[0]->filename);
(void) FormatLocaleString(geometry,MagickPathExtent,"%ux%u+0+0>",
window_attributes.width,window_attributes.height);
geometry_info.width=window_info.width;
geometry_info.height=window_info.height;
geometry_info.x=(ssize_t) window_info.x;
geometry_info.y=(ssize_t) window_info.y;
(void) ParseMetaGeometry(geometry,&geometry_info.x,&geometry_info.y,
&geometry_info.width,&geometry_info.height);
window_info.width=(unsigned int) geometry_info.width;
window_info.height=(unsigned int) geometry_info.height;
window_info.x=(int) geometry_info.x;
window_info.y=(int) geometry_info.y;
status=XMakeImage(display,&resources,&window_info,image_list[0],
window_info.width,window_info.height,exception);
if (status == MagickFalse)
ThrowXWindowFatalException(XServerFatalError,"UnableToCreateXImage",
images->filename);
window_info.x=0;
window_info.y=0;
if (display_image->debug != MagickFalse)
{
(void) LogMagickEvent(X11Event,GetMagickModule(),
"Image: %s[%.20g] %.20gx%.20g ",image_list[0]->filename,(double)
image_list[0]->scene,(double) image_list[0]->columns,(double)
image_list[0]->rows);
if (image_list[0]->colors != 0)
(void) LogMagickEvent(X11Event,GetMagickModule(),"%.20gc ",(double)
image_list[0]->colors);
(void) LogMagickEvent(X11Event,GetMagickModule(),"%s",
image_list[0]->magick);
}
/*
Adjust image dimensions as specified by backdrop or geometry options.
*/
width=window_info.width;
height=window_info.height;
if (resources.backdrop != MagickFalse)
{
/*
Center image on window.
*/
window_info.x=(int) (window_attributes.width/2)-
(window_info.ximage->width/2);
window_info.y=(int) (window_attributes.height/2)-
(window_info.ximage->height/2);
width=(unsigned int) window_attributes.width;
height=(unsigned int) window_attributes.height;