Coverage Report

Created: 2025-06-16 07:00

/src/imagemagick/coders/ashlar.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3
%                                                                             %
4
%                                                                             %
5
%                                                                             %
6
%                   AAA   SSSSS  H   H  L       AAA   RRRR                    %
7
%                  A   A  SS     H   H  L      A   A  R   R                   %
8
%                  AAAAA   SSS   HHHHH  L      AAAAA  RRRR                    %
9
%                  A   A     SS  H   H  L      A   A  R  R                    %
10
%                  A   A  SSSSS  H   H  LLLLL  A   A  R   R                   %
11
%                                                                             %
12
%                                                                             %
13
%                           Write Ashlar Images                               %
14
%                                                                             %
15
%                              Software Design                                %
16
%                                   Cristy                                    %
17
%                                 July 2020                                   %
18
%                                                                             %
19
%                                                                             %
20
%  Copyright @ 1999 ImageMagick Studio LLC, a non-profit organization         %
21
%  dedicated to making software imaging solutions freely available.           %
22
%                                                                             %
23
%  You may not use this file except in compliance with the License.  You may  %
24
%  obtain a copy of the License at                                            %
25
%                                                                             %
26
%    https://imagemagick.org/script/license.php                               %
27
%                                                                             %
28
%  Unless required by applicable law or agreed to in writing, software        %
29
%  distributed under the License is distributed on an "AS IS" BASIS,          %
30
%  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   %
31
%  See the License for the specific language governing permissions and        %
32
%  limitations under the License.                                             %
33
%                                                                             %
34
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35
%
36
%
37
*/
38

39
/*
40
  Include declarations.
41
*/
42
#include "MagickCore/studio.h"
43
#include "MagickCore/annotate.h"
44
#include "MagickCore/blob.h"
45
#include "MagickCore/blob-private.h"
46
#include "MagickCore/client.h"
47
#include "MagickCore/constitute.h"
48
#include "MagickCore/display.h"
49
#include "MagickCore/exception.h"
50
#include "MagickCore/exception-private.h"
51
#include "MagickCore/image.h"
52
#include "MagickCore/image-private.h"
53
#include "MagickCore/list.h"
54
#include "MagickCore/magick.h"
55
#include "MagickCore/memory_.h"
56
#include "MagickCore/option.h"
57
#include "MagickCore/property.h"
58
#include "MagickCore/quantum-private.h"
59
#include "MagickCore/static.h"
60
#include "MagickCore/string_.h"
61
#include "MagickCore/string-private.h"
62
#include "MagickCore/module.h"
63
#include "MagickCore/utility.h"
64
#include "MagickCore/xwindow.h"
65
#include "MagickCore/xwindow-private.h"
66

67
/*
68
  Forward declarations.
69
*/
70
static MagickBooleanType
71
  WriteASHLARImage(const ImageInfo *,Image *,ExceptionInfo *);
72

73
/*
74
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75
%                                                                             %
76
%                                                                             %
77
%                                                                             %
78
%   R e g i s t e r A S H L A R I m a g e                                     %
79
%                                                                             %
80
%                                                                             %
81
%                                                                             %
82
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
83
%
84
%  RegisterASHLARImage() adds attributes for the ASHLAR image format to
85
%  the list of supported formats.  The attributes include the image format
86
%  tag, a method to read and/or write the format, whether the format
87
%  supports the saving of more than one frame to the same file or blob,
88
%  whether the format supports native in-memory I/O, and a brief
89
%  description of the format.
90
%
91
%  The format of the RegisterASHLARImage method is:
92
%
93
%      size_t RegisterASHLARImage(void)
94
%
95
*/
96
ModuleExport size_t RegisterASHLARImage(void)
97
7
{
98
7
  MagickInfo
99
7
    *entry;
100
101
7
  entry=AcquireMagickInfo("ASHLAR","ASHLAR",
102
7
   "Image sequence laid out in continuous irregular courses");
103
7
  entry->encoder=(EncodeImageHandler *) WriteASHLARImage;
104
7
  (void) RegisterMagickInfo(entry);
105
7
  return(MagickImageCoderSignature);
106
7
}
107

108
/*
109
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
110
%                                                                             %
111
%                                                                             %
112
%                                                                             %
113
%   U n r e g i s t e r A S H L A R I m a g e                                 %
114
%                                                                             %
115
%                                                                             %
116
%                                                                             %
117
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
118
%
119
%  UnregisterASHLARImage() removes format registrations made by the
120
%  ASHLAR module from the list of supported formats.
121
%
122
%  The format of the UnregisterASHLARImage method is:
123
%
124
%      UnregisterASHLARImage(void)
125
%
126
*/
127
ModuleExport void UnregisterASHLARImage(void)
128
0
{
129
0
  (void) UnregisterMagickInfo("ASHLAR");
130
0
}
131

132
/*
133
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
134
%                                                                             %
135
%                                                                             %
136
%                                                                             %
137
%   W r i t e A S H L A R I m a g e                                           %
138
%                                                                             %
139
%                                                                             %
140
%                                                                             %
141
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
142
%
143
%  WriteASHLARImage() writes an image to a file in ASHLAR format.
144
%
145
%  The format of the WriteASHLARImage method is:
146
%
147
%      MagickBooleanType WriteASHLARImage(const ImageInfo *image_info,
148
%        Image *image,ExceptionInfo *exception)
149
%
150
%  A description of each parameter follows.
151
%
152
%    o image_info: the image info.
153
%
154
%    o image:  The image.
155
%
156
%    o exception: return any errors or warnings in this structure.
157
%
158
*/
159
160
typedef struct _NodeInfo
161
{
162
  ssize_t
163
    x,
164
    y;
165
166
  struct _NodeInfo
167
    *next;
168
} NodeInfo;
169
170
typedef struct _AshlarInfo
171
{
172
  size_t
173
    width,
174
    height;
175
176
  ssize_t
177
    align;
178
179
  size_t
180
    number_nodes;
181
182
  MagickBooleanType
183
    best_fit;
184
185
  NodeInfo
186
    *current,
187
    *free,
188
    head,
189
    sentinel;
190
} AshlarInfo;
191
192
typedef struct _CanvasInfo
193
{
194
  ssize_t
195
    id;
196
197
  size_t
198
    width,
199
    height;
200
201
  ssize_t
202
    x,
203
    y,
204
    order;
205
} CanvasInfo;
206
207
typedef struct _TileInfo
208
{
209
  ssize_t
210
    x,
211
    y;
212
213
  NodeInfo
214
    **previous;
215
} TileInfo;
216
217
static inline ssize_t FindMinimumTileLocation(NodeInfo *first,const ssize_t x,
218
  const size_t width,ssize_t *excess)
219
0
{
220
0
  NodeInfo
221
0
    *node;
222
223
0
  ssize_t
224
0
    extent,
225
0
    y;
226
227
  /*
228
    Find minimum y location if it starts at x.
229
  */
230
0
  *excess=0;
231
0
  y=0;
232
0
  extent=0;
233
0
  node=first;
234
0
  while (node->x < (x+(ssize_t) width))
235
0
  {
236
0
    if (node->y > y)
237
0
      {
238
0
        *excess+=extent*(node->y-y);
239
0
        y=node->y;
240
0
        if (node->x < x)
241
0
          extent+=node->next->x-x;
242
0
        else
243
0
          extent+=node->next->x-node->x;
244
0
      }
245
0
    else
246
0
      {
247
0
        size_t delta = (size_t) (node->next->x-node->x);
248
0
        if ((delta+(size_t) extent) > width)
249
0
          delta=width-(size_t) extent;
250
0
        *excess+=(ssize_t) delta*(y-node->y);
251
0
        extent+=(ssize_t) delta;
252
0
      }
253
0
    node=node->next;
254
0
  }
255
0
  return(y);
256
0
}
257
258
static inline TileInfo AssignBestTileLocation(AshlarInfo *ashlar_info,
259
  const size_t width,size_t const height)
260
0
{
261
0
  NodeInfo
262
0
    *node,
263
0
    **previous,
264
0
    *tail;
265
266
0
  ssize_t
267
0
    min_excess;
268
269
0
  size_t
270
0
    ashlar_width;
271
272
0
  TileInfo
273
0
    tile;
274
275
  /*
276
    Align along left edge.
277
  */
278
0
  tile.previous=(NodeInfo **) NULL;
279
0
  ashlar_width=(size_t) ((ssize_t) width+ashlar_info->align-1);
280
0
  ashlar_width-=(size_t) ((ssize_t) ashlar_width % ashlar_info->align);
281
0
  if ((ashlar_width > ashlar_info->width) || (height > ashlar_info->height))
282
0
    {
283
      /*
284
        Tile can't fit, bail.
285
      */
286
0
      tile.x=0;
287
0
      tile.y=0;
288
0
      return(tile);
289
0
    }
290
0
  tile.x=(ssize_t) MAGICK_SSIZE_MAX;
291
0
  tile.y=(ssize_t) MAGICK_SSIZE_MAX;
292
0
  min_excess=(ssize_t) MAGICK_SSIZE_MAX;
293
0
  node=ashlar_info->current;
294
0
  previous=(&ashlar_info->current);
295
0
  while (((ssize_t) ashlar_width+node->x) <= (ssize_t) ashlar_info->width)
296
0
  {
297
0
    ssize_t
298
0
      excess,
299
0
      y;
300
301
0
    y=FindMinimumTileLocation(node,node->x,ashlar_width,&excess);
302
0
    if (ashlar_info->best_fit == MagickFalse)
303
0
      {
304
0
        if (y < tile.y)
305
0
          {
306
0
            tile.y=y;
307
0
            tile.previous=previous;
308
0
          }
309
0
      }
310
0
    else
311
0
      {
312
0
        if (((ssize_t) height+y) <= (ssize_t) ashlar_info->height)
313
0
          if ((y < tile.y) || ((y == tile.y) && (excess < min_excess)))
314
0
            {
315
0
              tile.y=y;
316
0
              tile.previous=previous;
317
0
              min_excess=excess;
318
0
            }
319
0
      }
320
0
    previous=(&node->next);
321
0
    node=node->next;
322
0
  }
323
0
  tile.x=(tile.previous == (NodeInfo **) NULL) ? 0 : (*tile.previous)->x;
324
0
  if (ashlar_info->best_fit != MagickFalse)
325
0
    {
326
      /*
327
        Align along both left and right edges.
328
      */
329
0
      tail=ashlar_info->current;
330
0
      node=ashlar_info->current;
331
0
      previous=(&ashlar_info->current);
332
0
      while (tail->x < (ssize_t) ashlar_width)
333
0
        tail=tail->next;
334
0
      while (tail != (NodeInfo *) NULL)
335
0
      {
336
0
        ssize_t
337
0
          excess,
338
0
          x,
339
0
          y;
340
341
0
        x=tail->x-(ssize_t) ashlar_width;
342
0
        while (node->next->x <= x)
343
0
        {
344
0
          previous=(&node->next);
345
0
          node=node->next;
346
0
        }
347
0
        y=FindMinimumTileLocation(node,x,ashlar_width,&excess);
348
0
        if (((ssize_t) height+y) <= (ssize_t) ashlar_info->height)
349
0
          {
350
0
            if (y <= tile.y)
351
0
              if ((y < tile.y) || (excess < min_excess) ||
352
0
                  ((excess == min_excess) && (x < tile.x)))
353
0
                {
354
0
                  tile.x=x;
355
0
                  tile.y=y;
356
0
                  min_excess=excess;
357
0
                  tile.previous=previous;
358
0
               }
359
0
         }
360
0
       tail=tail->next;
361
0
    }
362
0
  }
363
0
  return(tile);
364
0
}
365
366
static inline TileInfo AssignTileLocation(AshlarInfo *ashlar_info,
367
  const size_t width,const size_t height)
368
0
{
369
0
  NodeInfo
370
0
    *current,
371
0
    *node;
372
373
0
  TileInfo
374
0
    tile;
375
376
  /*
377
    Find the best location in the canvas for this tile.
378
  */
379
0
  tile=AssignBestTileLocation(ashlar_info,width,height);
380
0
  if ((tile.previous == (NodeInfo **) NULL) ||
381
0
      ((tile.y+(ssize_t) height) > (ssize_t) ashlar_info->height) ||
382
0
      (ashlar_info->free == (NodeInfo *) NULL))
383
0
    {
384
0
      tile.previous=(NodeInfo **) NULL;
385
0
      return(tile);
386
0
    }
387
   /*
388
     Create a new node.
389
   */
390
0
   node=ashlar_info->free;
391
0
   node->x=(ssize_t) tile.x;
392
0
   node->y=tile.y+(ssize_t) height;
393
0
   ashlar_info->free=node->next;
394
   /*
395
     Insert node.
396
   */
397
0
   current=(*tile.previous);
398
0
   if (current->x >= tile.x)
399
0
     *tile.previous=node;
400
0
   else
401
0
     {
402
0
       NodeInfo *next = current->next;
403
0
       current->next=node;
404
0
       current=next;
405
0
     }
406
0
   while ((current->next != (NodeInfo *) NULL) &&
407
0
          (current->next->x <= (tile.x+(ssize_t) width)))
408
0
   {
409
     /*
410
       Push current node to free list.
411
     */
412
0
     NodeInfo *next = current->next;
413
0
     current->next=ashlar_info->free;
414
0
     ashlar_info->free=current;
415
0
     current=next;
416
0
   }
417
0
   node->next=current;
418
0
   if (current->x < (tile.x+(ssize_t) width))
419
0
     current->x=tile.x+(ssize_t) width;
420
0
   return(tile);
421
0
}
422
423
static inline int CompareTileHeight(const void *p_tile,const void *q_tile)
424
0
{
425
0
  const CanvasInfo
426
0
    *p,
427
0
    *q;
428
429
0
  p=(const CanvasInfo *) p_tile;
430
0
  q=(const CanvasInfo *) q_tile;
431
0
  if (p->height > q->height)
432
0
    return(-1);
433
0
  if (p->height < q->height)
434
0
    return(1);
435
0
  return((p->width > q->width) ? -1 : (p->width < q->width) ? 1 : 0);
436
0
}
437
438
static inline int RestoreTileOrder(const void *p_tile,const void *q_tile)
439
0
{
440
0
  const CanvasInfo
441
0
    *p,
442
0
    *q;
443
444
0
  p=(const CanvasInfo *) p_tile;
445
0
  q=(const CanvasInfo *) q_tile;
446
0
  return((p->order < q->order) ? -1 : (p->order > q->order) ? 1 : 0);
447
0
}
448
449
static inline MagickBooleanType PackAshlarTiles(AshlarInfo *ashlar_info,
450
  const size_t number_tiles,CanvasInfo *tiles)
451
0
{
452
0
  MagickBooleanType
453
0
    status;
454
455
0
  ssize_t
456
0
    i;
457
458
  /*
459
    Pack tiles so they fit the canvas with minimum excess.
460
  */
461
0
  for (i=0; i < (ssize_t) number_tiles; i++)
462
0
    tiles[i].order=(i);
463
0
  qsort((void *) tiles,number_tiles,sizeof(*tiles),CompareTileHeight);
464
0
  for (i=0; i < (ssize_t) number_tiles; i++)
465
0
  {
466
0
    tiles[i].x=0;
467
0
    tiles[i].y=0;
468
0
    if ((tiles[i].width != 0) && (tiles[i].height != 0))
469
0
      {
470
0
        TileInfo
471
0
          tile_info;
472
473
0
        tile_info=AssignTileLocation(ashlar_info,tiles[i].width,
474
0
          tiles[i].height);
475
0
        tiles[i].x=(ssize_t) tile_info.x;
476
0
        tiles[i].y=(ssize_t) tile_info.y;
477
0
        if (tile_info.previous == (NodeInfo **) NULL)
478
0
          {
479
0
            tiles[i].x=(ssize_t) MAGICK_SSIZE_MAX;
480
0
            tiles[i].y=(ssize_t) MAGICK_SSIZE_MAX;
481
0
          }
482
0
      }
483
0
  }
484
0
  qsort((void *) tiles,number_tiles,sizeof(*tiles),RestoreTileOrder);
485
0
  status=MagickTrue;
486
0
  for (i=0; i < (ssize_t) number_tiles; i++)
487
0
  {
488
0
    tiles[i].order=(ssize_t) ((tiles[i].x != (ssize_t) MAGICK_SSIZE_MAX) ||
489
0
      (tiles[i].y != (ssize_t) MAGICK_SSIZE_MAX) ? 1 : 0);
490
0
    if (tiles[i].order == 0)
491
0
      status=MagickFalse;
492
0
  }
493
0
  return(status);  /* return true if room is found for all tiles */
494
0
}
495
496
static Image *ASHLARImage(ImageInfo *image_info,Image *image,
497
  ExceptionInfo *exception)
498
0
{
499
0
  AshlarInfo
500
0
    ashlar_info;
501
502
0
  CanvasInfo
503
0
    *tiles;
504
505
0
  const char
506
0
    *value;
507
508
0
  Image
509
0
    *ashlar_image,
510
0
    *next;
511
512
0
  MagickBooleanType
513
0
    status;
514
515
0
  NodeInfo
516
0
    *nodes;
517
518
0
  RectangleInfo
519
0
    extent,
520
0
    geometry;
521
522
0
  ssize_t
523
0
    i,
524
0
    n;
525
526
  /*
527
    Convert image sequence laid out in continuous irregular courses.
528
  */
529
0
  if (image_info->extract != (char *) NULL)
530
0
    (void) ParseAbsoluteGeometry(image_info->extract,&geometry);
531
0
  else
532
0
    {
533
      /*
534
        Determine a sane canvas size and border width.
535
      */
536
0
      (void) ParseAbsoluteGeometry("0x0+0+0",&geometry);
537
0
      for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
538
0
      {
539
0
        geometry.width+=next->columns;
540
0
        geometry.height+=next->rows;
541
0
      }
542
0
      geometry.width=(size_t) geometry.width/7;
543
0
      geometry.height=(size_t) geometry.height/7;
544
0
      geometry.x=(ssize_t) pow((double) geometry.width,0.25);
545
0
      geometry.y=(ssize_t) pow((double) geometry.height,0.25);
546
0
      image_info->extract=AcquireString("");
547
0
      if (image_info->extract != (char *) NULL)
548
0
        (void) FormatLocaleString(image_info->extract,MagickPathExtent,
549
0
          "%gx%g%+g%+g",(double) geometry.width,(double) geometry.height,
550
0
          (double) geometry.x,(double) geometry.y);
551
0
    }
552
  /*
553
    Initialize image tiles.
554
  */
555
0
  ashlar_image=AcquireImage(image_info,exception);
556
0
  status=SetImageExtent(ashlar_image,geometry.width,geometry.height,exception);
557
0
  if (status == MagickFalse)
558
0
    {
559
0
      ashlar_image=DestroyImageList(ashlar_image);
560
0
      return((Image *) NULL);
561
0
    }
562
0
  (void) SetImageBackgroundColor(ashlar_image,exception);
563
0
  tiles=(CanvasInfo *) AcquireQuantumMemory(GetImageListLength(image),
564
0
    sizeof(*tiles));
565
0
  ashlar_info.number_nodes=2*geometry.width;
566
0
  nodes=(NodeInfo *) AcquireQuantumMemory(ashlar_info.number_nodes,
567
0
    sizeof(*nodes));
568
0
  if ((tiles == (CanvasInfo *) NULL) || (nodes == (NodeInfo *) NULL))
569
0
    {
570
0
      if (tiles != (CanvasInfo *) NULL)
571
0
        tiles=(CanvasInfo *) RelinquishMagickMemory(tiles);
572
0
      if (nodes != (NodeInfo *) NULL)
573
0
        nodes=(NodeInfo *) RelinquishMagickMemory(tiles);
574
0
      ashlar_image=DestroyImageList(ashlar_image);
575
0
      ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
576
0
    }
577
  /*
578
    Iterate until we find a tile size that fits the canvas.
579
  */
580
0
  value=GetImageOption(image_info,"ashlar:best-fit");
581
0
  for (i=20; i > 0; i--)
582
0
  {
583
0
    ssize_t
584
0
      j;
585
586
0
    n=0;
587
0
    for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
588
0
    {
589
0
      tiles[n].id=n;
590
0
      tiles[n].width=(size_t) (0.05*i*next->columns+2*geometry.x);
591
0
      tiles[n].height=(size_t) (0.05*i*next->rows+2*geometry.y);
592
0
      n++;
593
0
    }
594
0
    for (j=0; j < (ssize_t) ashlar_info.number_nodes-1; j++)
595
0
      nodes[j].next=nodes+j+1;
596
0
    nodes[j].next=(NodeInfo *) NULL;
597
0
    ashlar_info.best_fit=IsStringTrue(value) != MagickFalse ? MagickTrue :
598
0
      MagickFalse;
599
0
    ashlar_info.free=nodes;
600
0
    ashlar_info.current=(&ashlar_info.head);
601
0
    ashlar_info.width=geometry.width;
602
0
    ashlar_info.height=geometry.height;
603
0
    ashlar_info.align=(ssize_t) ((ashlar_info.width+ashlar_info.number_nodes-1)/
604
0
      ashlar_info.number_nodes);
605
0
    ashlar_info.head.x=0;
606
0
    ashlar_info.head.y=0;
607
0
    ashlar_info.head.next=(&ashlar_info.sentinel);
608
0
    ashlar_info.sentinel.x=(ssize_t) geometry.width;
609
0
    ashlar_info.sentinel.y=(ssize_t) MAGICK_SSIZE_MAX;
610
0
    ashlar_info.sentinel.next=(NodeInfo *) NULL;
611
0
    status=PackAshlarTiles(&ashlar_info,(size_t) n,tiles);
612
0
    if (status != MagickFalse)
613
0
      break;
614
0
  }
615
  /*
616
    Determine layout of images tiles on the canvas.
617
  */
618
0
  value=GetImageOption(image_info,"label");
619
0
  extent.width=0;
620
0
  extent.height=0;
621
0
  for (i=0; i < n; i++)
622
0
  {
623
0
    Image
624
0
      *tile_image;
625
626
0
    if ((tiles[i].x == (ssize_t) MAGICK_SSIZE_MAX) ||
627
0
        (tiles[i].y == (ssize_t) MAGICK_SSIZE_MAX))
628
0
      continue;
629
0
    tile_image=ResizeImage(GetImageFromList(image,tiles[i].id),(size_t)
630
0
      ((ssize_t) tiles[i].width-2*geometry.x),(size_t)
631
0
      ((ssize_t) tiles[i].height-2*geometry.y),image->filter,exception);
632
0
    if (tile_image == (Image *) NULL)
633
0
      continue;
634
0
    (void) CompositeImage(ashlar_image,tile_image,image->compose,MagickTrue,
635
0
      tiles[i].x+geometry.x,tiles[i].y+geometry.y,exception);
636
0
    if (value != (const char *) NULL)
637
0
      {
638
0
        char
639
0
          *label,
640
0
          offset[MagickPathExtent];
641
642
0
        DrawInfo
643
0
          *draw_info = CloneDrawInfo(image_info,(DrawInfo *) NULL);
644
645
0
        label=InterpretImageProperties((ImageInfo *) image_info,tile_image,
646
0
          value,exception);
647
0
        if (label != (const char *) NULL)
648
0
          {
649
0
            (void) CloneString(&draw_info->text,label);
650
0
            draw_info->pointsize=1.8*geometry.y;
651
0
            (void) FormatLocaleString(offset,MagickPathExtent,"%+g%+g",(double)
652
0
              tiles[i].x+geometry.x,(double) tiles[i].height+tiles[i].y+
653
0
              geometry.y/2.0);
654
0
            (void) CloneString(&draw_info->geometry,offset);
655
0
            (void) AnnotateImage(ashlar_image,draw_info,exception);
656
0
          }
657
0
      }
658
0
    if (((ssize_t) tiles[i].width+tiles[i].x) > (ssize_t) extent.width)
659
0
      extent.width=(size_t) ((ssize_t) tiles[i].width+tiles[i].x);
660
0
    if (((ssize_t) tiles[i].height+tiles[i].y+geometry.y+2) > (ssize_t) extent.height)
661
0
      extent.height=(size_t) ((ssize_t) tiles[i].height+tiles[i].y+
662
0
        geometry.y+2);
663
0
    tile_image=DestroyImage(tile_image);
664
0
  }
665
0
  (void) SetImageExtent(ashlar_image,extent.width,extent.height,exception);
666
0
  nodes=(NodeInfo *) RelinquishMagickMemory(nodes);
667
0
  tiles=(CanvasInfo *) RelinquishMagickMemory(tiles);
668
0
  return(ashlar_image);
669
0
}
670
671
static MagickBooleanType WriteASHLARImage(const ImageInfo *image_info,
672
  Image *image,ExceptionInfo *exception)
673
0
{
674
0
  const char
675
0
    *value;
676
677
0
  const MagickInfo
678
0
    *magick_info;
679
680
0
  Image
681
0
    *ashlar_images;
682
683
0
  ImageInfo
684
0
    *write_info;
685
686
0
  MagickBooleanType
687
0
    status;
688
689
0
  size_t
690
0
    tiles_per_page;
691
692
0
  ssize_t
693
0
    i;
694
695
  /*
696
    Write ASHLAR canvas.
697
  */
698
0
  assert(image_info != (const ImageInfo *) NULL);
699
0
  assert(image_info->signature == MagickCoreSignature);
700
0
  assert(image != (Image *) NULL);
701
0
  assert(image->signature == MagickCoreSignature);
702
0
  if (IsEventLogging() != MagickFalse)
703
0
    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
704
0
  tiles_per_page=GetImageListLength(image);
705
0
  value=GetImageOption(image_info,"ashlar:tiles");
706
0
  if (value != (const char *) NULL)
707
0
    tiles_per_page=(size_t) MagickMax(StringToInteger(value),1);
708
0
  ashlar_images=NewImageList();
709
0
  write_info=CloneImageInfo(image_info);
710
0
  for (i=0; i < (ssize_t) GetImageListLength(image); i+=(ssize_t) tiles_per_page)
711
0
  {
712
0
    char
713
0
      scenes[MagickPathExtent];
714
715
0
    Image
716
0
      *ashlar_image,
717
0
      *clone_images;
718
719
0
    (void) FormatLocaleString(scenes,MagickPathExtent,"%g-%g",(double) i,
720
0
      (double) (i+(ssize_t) tiles_per_page-1));
721
0
    clone_images=CloneImages(image,scenes,exception);
722
0
    if (clone_images == (Image *) NULL)
723
0
      {
724
0
        if (ashlar_images != (Image *) NULL)
725
0
          ashlar_images=DestroyImageList(ashlar_images);
726
0
        break;
727
0
      }
728
0
    ashlar_image=ASHLARImage(write_info,clone_images,exception);
729
0
    clone_images=DestroyImageList(clone_images);
730
0
    if (ashlar_image == (Image *) NULL)
731
0
      {
732
0
        if (ashlar_images != (Image *) NULL)
733
0
          ashlar_images=DestroyImageList(ashlar_images);
734
0
        break;
735
0
      }
736
0
    AppendImageToList(&ashlar_images,ashlar_image);
737
0
  }
738
0
  if (ashlar_images == (Image *) NULL)
739
0
    return(MagickFalse);
740
0
  ashlar_images=GetFirstImageInList(ashlar_images);
741
0
  (void) CopyMagickString(ashlar_images->filename,image_info->filename,
742
0
    MagickPathExtent);
743
0
  *write_info->magick='\0';
744
0
  (void) SetImageInfo(write_info,(unsigned int)
745
0
    GetImageListLength(ashlar_images),exception);
746
0
  magick_info=GetMagickInfo(write_info->magick,exception);
747
0
  if ((magick_info == (const MagickInfo*) NULL) ||
748
0
      (LocaleCompare(magick_info->magick_module,"ASHLAR") == 0))
749
0
    (void) FormatLocaleString(ashlar_images->filename,MagickPathExtent,
750
0
      "miff:%s",write_info->filename);
751
0
  status=WriteImages(write_info,ashlar_images,ashlar_images->filename,
752
0
    exception);
753
0
  ashlar_images=DestroyImageList(ashlar_images);
754
0
  write_info=DestroyImageInfo(write_info);
755
0
  return(status);
756
0
}