w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

gd.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <math.h>
3 #include <string.h>
4 #include <stdlib.h>
5 #include <stdarg.h>
6 
7 #ifdef HAVE_CONFIG_H
8 #include "config.h"
9 #endif
10 
11 #include "gd_intern.h"
12 
13 /* 2.03: don't include zlib here or we can't build without PNG */
14 #include "gd.h"
15 #include "gdhelpers.h"
16 #include "gd_color.h"
17 #include "gd_errors.h"
18 
19 /* 2.0.12: this now checks the clipping rectangle */
20 #define gdImageBoundsSafeMacro(im, x, y) (!((((y) < (im)->cy1) || ((y) > (im)->cy2)) || (((x) < (im)->cx1) || ((x) > (im)->cx2))))
21 
22 #ifdef _OSD_POSIX /* BS2000 uses the EBCDIC char set instead of ASCII */
23 #define CHARSET_EBCDIC
24 #define __attribute__(any) /*nothing */
25 #endif
26 /*_OSD_POSIX*/
27 
28 #ifndef CHARSET_EBCDIC
29 #define ASC(ch) ch
30 #else /*CHARSET_EBCDIC */
31 #define ASC(ch) gd_toascii[(unsigned char)ch]
32 static const unsigned char gd_toascii[256] = {
33  /*00 */ 0x00, 0x01, 0x02, 0x03, 0x85, 0x09, 0x86, 0x7f,
34  0x87, 0x8d, 0x8e, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /*................ */
35  /*10 */ 0x10, 0x11, 0x12, 0x13, 0x8f, 0x0a, 0x08, 0x97,
36  0x18, 0x19, 0x9c, 0x9d, 0x1c, 0x1d, 0x1e, 0x1f, /*................ */
37  /*20 */ 0x80, 0x81, 0x82, 0x83, 0x84, 0x92, 0x17, 0x1b,
38  0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x05, 0x06, 0x07, /*................ */
39  /*30 */ 0x90, 0x91, 0x16, 0x93, 0x94, 0x95, 0x96, 0x04,
40  0x98, 0x99, 0x9a, 0x9b, 0x14, 0x15, 0x9e, 0x1a, /*................ */
41  /*40 */ 0x20, 0xa0, 0xe2, 0xe4, 0xe0, 0xe1, 0xe3, 0xe5,
42  0xe7, 0xf1, 0x60, 0x2e, 0x3c, 0x28, 0x2b, 0x7c, /* .........`.<(+| */
43  /*50 */ 0x26, 0xe9, 0xea, 0xeb, 0xe8, 0xed, 0xee, 0xef,
44  0xec, 0xdf, 0x21, 0x24, 0x2a, 0x29, 0x3b, 0x9f, /*&.........!$*);. */
45  /*60 */ 0x2d, 0x2f, 0xc2, 0xc4, 0xc0, 0xc1, 0xc3, 0xc5,
46  0xc7, 0xd1, 0x5e, 0x2c, 0x25, 0x5f, 0x3e, 0x3f,
47  /*-/........^,%_>?*/
48  /*70 */ 0xf8, 0xc9, 0xca, 0xcb, 0xc8, 0xcd, 0xce, 0xcf,
49  0xcc, 0xa8, 0x3a, 0x23, 0x40, 0x27, 0x3d, 0x22, /*..........:#@'=" */
50  /*80 */ 0xd8, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
51  0x68, 0x69, 0xab, 0xbb, 0xf0, 0xfd, 0xfe, 0xb1, /*.abcdefghi...... */
52  /*90 */ 0xb0, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70,
53  0x71, 0x72, 0xaa, 0xba, 0xe6, 0xb8, 0xc6, 0xa4, /*.jklmnopqr...... */
54  /*a0 */ 0xb5, 0xaf, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
55  0x79, 0x7a, 0xa1, 0xbf, 0xd0, 0xdd, 0xde, 0xae, /*..stuvwxyz...... */
56  /*b0 */ 0xa2, 0xa3, 0xa5, 0xb7, 0xa9, 0xa7, 0xb6, 0xbc,
57  0xbd, 0xbe, 0xac, 0x5b, 0x5c, 0x5d, 0xb4, 0xd7, /*...........[\].. */
58  /*c0 */ 0xf9, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
59  0x48, 0x49, 0xad, 0xf4, 0xf6, 0xf2, 0xf3, 0xf5, /*.ABCDEFGHI...... */
60  /*d0 */ 0xa6, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
61  0x51, 0x52, 0xb9, 0xfb, 0xfc, 0xdb, 0xfa, 0xff, /*.JKLMNOPQR...... */
62  /*e0 */ 0xd9, 0xf7, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
63  0x59, 0x5a, 0xb2, 0xd4, 0xd6, 0xd2, 0xd3, 0xd5, /*..STUVWXYZ...... */
64  /*f0 */ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
65  0x38, 0x39, 0xb3, 0x7b, 0xdc, 0x7d, 0xda, 0x7e /*0123456789.{.}.~ */
66 };
67 #endif /*CHARSET_EBCDIC */
68 
69 extern const int gdCosT[];
70 extern const int gdSinT[];
71 
72 /**
73  * Group: Error Handling
74  */
75 
76 void gd_stderr_error(int priority, const char *format, va_list args)
77 {
78  switch (priority) {
79  case GD_ERROR:
80  fputs("GD Error: ", stderr);
81  break;
82  case GD_WARNING:
83  fputs("GD Warning: ", stderr);
84  break;
85  case GD_NOTICE:
86  fputs("GD Notice: ", stderr);
87  break;
88  case GD_INFO:
89  fputs("GD Info: ", stderr);
90  break;
91  case GD_DEBUG:
92  fputs("GD Debug: ", stderr);
93  break;
94  }
95  vfprintf(stderr, format, args);
96  fflush(stderr);
97 }
98 
100 
101 static void _gd_error_ex(int priority, const char *format, va_list args)
102 {
103  if (gd_error_method) {
105  }
106 }
107 
108 void gd_error(const char *format, ...)
109 {
110  va_list args;
111 
112  va_start(args, format);
114  va_end(args);
115 }
116 void gd_error_ex(int priority, const char *format, ...)
117 {
118  va_list args;
119 
120  va_start(args, format);
122  va_end(args);
123 }
124 
125 /*
126  Function: gdSetErrorMethod
127 */
129 {
130  gd_error_method = error_method;
131 }
132 
133 /*
134  Function: gdClearErrorMethod
135 */
137 {
139 }
140 
141 static void gdImageBrushApply (gdImagePtr im, int x, int y);
142 static void gdImageTileApply (gdImagePtr im, int x, int y);
143 
145 
146 /**
147  * Group: Creation and Destruction
148  */
149 
150 /*
151  Function: gdImageCreate
152 
153  gdImageCreate is called to create palette-based images, with no
154  more than 256 colors. The image must eventually be destroyed using
155  gdImageDestroy().
156 
157  Parameters:
158 
159  sx - The image width.
160  sy - The image height.
161 
162  Returns:
163 
164  A pointer to the new image or NULL if an error occurred.
165 
166  Example:
167  (start code)
168 
169  gdImagePtr im;
170  im = gdImageCreate(64, 64);
171  // ... Use the image ...
172  gdImageDestroy(im);
173 
174  (end code)
175 
176  See Also:
177 
178  <gdImageCreateTrueColor>
179 
180  */
182 {
183  int i;
184  gdImagePtr im;
185 
186  if (overflow2(sx, sy)) {
187  return NULL;
188  }
189 
190  if (overflow2(sizeof (unsigned char *), sy)) {
191  return NULL;
192  }
193  if (overflow2(sizeof (unsigned char), sx)) {
194  return NULL;
195  }
196 
197  im = (gdImage *) gdCalloc(1, sizeof(gdImage));
198  if (!im) {
199  return NULL;
200  }
201 
202  /* Row-major ever since gd 1.3 */
203  im->pixels = (unsigned char **) gdMalloc (sizeof (unsigned char *) * sy);
204  if (!im->pixels) {
205  gdFree(im);
206  return NULL;
207  }
208 
209  im->polyInts = 0;
210  im->polyAllocated = 0;
211  im->brush = 0;
212  im->tile = 0;
213  im->style = 0;
214  for (i = 0; (i < sy); i++) {
215  /* Row-major ever since gd 1.3 */
216  im->pixels[i] = (unsigned char *) gdCalloc (sx, sizeof (unsigned char));
217  if (!im->pixels[i]) {
218  for (--i ; i >= 0; i--) {
219  gdFree(im->pixels[i]);
220  }
221  gdFree(im->pixels);
222  gdFree(im);
223  return NULL;
224  }
225 
226  }
227  im->sx = sx;
228  im->sy = sy;
229  im->colorsTotal = 0;
230  im->transparent = (-1);
231  im->interlace = 0;
232  im->thick = 1;
233  im->AA = 0;
234  for (i = 0; (i < gdMaxColors); i++) {
235  im->open[i] = 1;
236  };
237  im->trueColor = 0;
238  im->tpixels = 0;
239  im->cx1 = 0;
240  im->cy1 = 0;
241  im->cx2 = im->sx - 1;
242  im->cy2 = im->sy - 1;
243  im->res_x = GD_RESOLUTION;
244  im->res_y = GD_RESOLUTION;
245  im->interpolation = NULL;
247  return im;
248 }
249 
250 
251 
252 /*
253  Function: gdImageCreateTrueColor
254 
255  <gdImageCreateTrueColor> is called to create truecolor images,
256  with an essentially unlimited number of colors. Invoke
257  <gdImageCreateTrueColor> with the x and y dimensions of the
258  desired image. <gdImageCreateTrueColor> returns a <gdImagePtr>
259  to the new image, or NULL if unable to allocate the image. The
260  image must eventually be destroyed using <gdImageDestroy>().
261 
262  Truecolor images are always filled with black at creation
263  time. There is no concept of a "background" color index.
264 
265  Parameters:
266 
267  sx - The image width.
268  sy - The image height.
269 
270  Returns:
271 
272  A pointer to the new image or NULL if an error occurred.
273 
274  Example:
275  (start code)
276 
277  gdImagePtr im;
278  im = gdImageCreateTrueColor(64, 64);
279  // ... Use the image ...
280  gdImageDestroy(im);
281 
282  (end code)
283 
284  See Also:
285 
286  <gdImageCreateTrueColor>
287 
288 */
290 {
291  int i;
292  gdImagePtr im;
293 
294  if (overflow2(sx, sy)) {
295  return NULL;
296  }
297  if (overflow2(sizeof (int *), sy)) {
298  return 0;
299  }
300  if (overflow2(sizeof(int), sx)) {
301  return NULL;
302  }
303 
304  im = (gdImage *) gdMalloc (sizeof (gdImage));
305  if (!im) {
306  return 0;
307  }
308  memset (im, 0, sizeof (gdImage));
309 
310  im->tpixels = (int **) gdMalloc (sizeof (int *) * sy);
311  if (!im->tpixels) {
312  gdFree(im);
313  return 0;
314  }
315  im->polyInts = 0;
316  im->polyAllocated = 0;
317  im->brush = 0;
318  im->tile = 0;
319  im->style = 0;
320  for (i = 0; (i < sy); i++) {
321  im->tpixels[i] = (int *) gdCalloc (sx, sizeof (int));
322  if (!im->tpixels[i]) {
323  /* 2.0.34 */
324  i--;
325  while (i >= 0) {
326  gdFree(im->tpixels[i]);
327  i--;
328  }
329  gdFree(im->tpixels);
330  gdFree(im);
331  return 0;
332  }
333  }
334  im->sx = sx;
335  im->sy = sy;
336  im->transparent = (-1);
337  im->interlace = 0;
338  im->trueColor = 1;
339  /* 2.0.2: alpha blending is now on by default, and saving of alpha is
340  off by default. This allows font antialiasing to work as expected
341  on the first try in JPEGs -- quite important -- and also allows
342  for smaller PNGs when saving of alpha channel is not really
343  desired, which it usually isn't! */
344  im->saveAlphaFlag = 0;
345  im->alphaBlendingFlag = 1;
346  im->thick = 1;
347  im->AA = 0;
348  im->cx1 = 0;
349  im->cy1 = 0;
350  im->cx2 = im->sx - 1;
351  im->cy2 = im->sy - 1;
352  im->res_x = GD_RESOLUTION;
353  im->res_y = GD_RESOLUTION;
354  im->interpolation = NULL;
356  return im;
357 }
358 
359 /*
360  Function: gdImageDestroy
361 
362  <gdImageDestroy> is used to free the memory associated with an
363  image. It is important to invoke <gdImageDestroy> before exiting
364  your program or assigning a new image to a <gdImagePtr> variable.
365 
366  Parameters:
367 
368  im - Pointer to the gdImage to delete.
369 
370  Returns:
371 
372  Nothing.
373 
374  Example:
375  (start code)
376 
377  gdImagePtr im;
378  im = gdImageCreate(10, 10);
379  // ... Use the image ...
380  // Now destroy it
381  gdImageDestroy(im);
382 
383  (end code)
384 
385 */
386 
388 {
389  int i;
390  if (im->pixels) {
391  for (i = 0; (i < im->sy); i++) {
392  gdFree (im->pixels[i]);
393  }
394  gdFree (im->pixels);
395  }
396  if (im->tpixels) {
397  for (i = 0; (i < im->sy); i++) {
398  gdFree (im->tpixels[i]);
399  }
400  gdFree (im->tpixels);
401  }
402  if (im->polyInts) {
403  gdFree (im->polyInts);
404  }
405  if (im->style) {
406  gdFree (im->style);
407  }
408  gdFree (im);
409 }
410 
411 /**
412  * Group: Color
413  */
414 
415 /**
416  * Function: gdImageColorClosest
417  *
418  * Gets the closest color of the image
419  *
420  * This is a simplified variant of <gdImageColorClosestAlpha> where the alpha
421  * channel is always opaque.
422  *
423  * Parameters:
424  * im - The image.
425  * r - The value of the red component.
426  * g - The value of the green component.
427  * b - The value of the blue component.
428  *
429  * Returns:
430  * The closest color already available in the palette for palette images;
431  * the color value of the given components for truecolor images.
432  *
433  * See also:
434  * - <gdImageColorExact>
435  */
436 BGD_DECLARE(int) gdImageColorClosest (gdImagePtr im, int r, int g, int b)
437 {
438  return gdImageColorClosestAlpha (im, r, g, b, gdAlphaOpaque);
439 }
440 
441 /**
442  * Function: gdImageColorClosestAlpha
443  *
444  * Gets the closest color of the image
445  *
446  * Parameters:
447  * im - The image.
448  * r - The value of the red component.
449  * g - The value of the green component.
450  * b - The value of the blue component.
451  * a - The value of the alpha component.
452  *
453  * Returns:
454  * The closest color already available in the palette for palette images;
455  * the color value of the given components for truecolor images.
456  *
457  * See also:
458  * - <gdImageColorExactAlpha>
459  */
460 BGD_DECLARE(int) gdImageColorClosestAlpha (gdImagePtr im, int r, int g, int b, int a)
461 {
462  int i;
463  long rd, gd, bd, ad;
464  int ct = (-1);
465  int first = 1;
466  long mindist = 0;
467  if (im->trueColor) {
468  return gdTrueColorAlpha (r, g, b, a);
469  }
470  for (i = 0; (i < (im->colorsTotal)); i++) {
471  long dist;
472  if (im->open[i]) {
473  continue;
474  }
475  rd = (im->red[i] - r);
476  gd = (im->green[i] - g);
477  bd = (im->blue[i] - b);
478  /* gd 2.02: whoops, was - b (thanks to David Marwood) */
479  /* gd 2.16: was blue rather than alpha! Geez! Thanks to
480  Artur Jakub Jerzak */
481  ad = (im->alpha[i] - a);
482  dist = rd * rd + gd * gd + bd * bd + ad * ad;
483  if (first || (dist < mindist)) {
484  mindist = dist;
485  ct = i;
486  first = 0;
487  }
488  }
489  return ct;
490 }
491 
492 /* This code is taken from http://www.acm.org/jgt/papers/SmithLyons96/hwb_rgb.html, an article
493  * on colour conversion to/from RBG and HWB colour systems.
494  * It has been modified to return the converted value as a * parameter.
495  */
496 
497 #define RETURN_HWB(h, w, b) {HWB->H = h; HWB->W = w; HWB->B = b; return HWB;}
498 #define RETURN_RGB(r, g, b) {RGB->R = r; RGB->G = g; RGB->B = b; return RGB;}
499 #define HWB_UNDEFINED -1
500 #define SETUP_RGB(s, r, g, b) {s.R = r/255.0; s.G = g/255.0; s.B = b/255.0;}
501 
502 #define MIN(a,b) ((a)<(b)?(a):(b))
503 #define MIN3(a,b,c) ((a)<(b)?(MIN(a,c)):(MIN(b,c)))
504 #define MAX(a,b) ((a)<(b)?(b):(a))
505 #define MAX3(a,b,c) ((a)<(b)?(MAX(b,c)):(MAX(a,c)))
506 
507 
508 /*
509  * Theoretically, hue 0 (pure red) is identical to hue 6 in these transforms. Pure
510  * red always maps to 6 in this implementation. Therefore UNDEFINED can be
511  * defined as 0 in situations where only unsigned numbers are desired.
512  */
513 typedef struct {
514  float R, G, B;
515 }
516 RGBType;
517 typedef struct {
518  float H, W, B;
519 }
520 HWBType;
521 
522 static HWBType *
524 {
525 
526  /*
527  * RGB are each on [0, 1]. W and B are returned on [0, 1] and H is
528  * returned on [0, 6]. Exception: H is returned UNDEFINED if W == 1 - B.
529  */
530 
531  float R = RGB.R, G = RGB.G, B = RGB.B, w, v, b, f;
532  int i;
533 
534  w = MIN3 (R, G, B);
535  v = MAX3 (R, G, B);
536  b = 1 - v;
537  if (v == w)
539  f = (R == w) ? G - B : ((G == w) ? B - R : R - G);
540  i = (R == w) ? 3 : ((G == w) ? 5 : 1);
541  RETURN_HWB (i - f / (v - w), w, b);
542 
543 }
544 
545 static float
546 HWB_Diff (int r1, int g1, int b1, int r2, int g2, int b2)
547 {
548  RGBType RGB1, RGB2;
549  HWBType HWB1, HWB2;
550  float diff;
551 
552  SETUP_RGB (RGB1, r1, g1, b1);
553  SETUP_RGB (RGB2, r2, g2, b2);
554 
555  RGB_to_HWB (RGB1, &HWB1);
556  RGB_to_HWB (RGB2, &HWB2);
557 
558  /*
559  * I made this bit up; it seems to produce OK results, and it is certainly
560  * more visually correct than the current RGB metric. (PJW)
561  */
562 
563  if ((HWB1.H == HWB_UNDEFINED) || (HWB2.H == HWB_UNDEFINED)) {
564  diff = 0; /* Undefined hues always match... */
565  } else {
566  diff = fabs (HWB1.H - HWB2.H);
567  if (diff > 3) {
568  diff = 6 - diff; /* Remember, it's a colour circle */
569  }
570  }
571 
572  diff =
573  diff * diff + (HWB1.W - HWB2.W) * (HWB1.W - HWB2.W) + (HWB1.B -
574  HWB2.B) * (HWB1.B -
575  HWB2.B);
576 
577  return diff;
578 }
579 
580 
581 #if 0
582 /*
583  * This is not actually used, but is here for completeness, in case someone wants to
584  * use the HWB stuff for anything else...
585  */
586 static RGBType *
587 HWB_to_RGB (HWBType HWB, RGBType * RGB)
588 {
589 
590  /*
591  * H is given on [0, 6] or UNDEFINED. W and B are given on [0, 1].
592  * RGB are each returned on [0, 1].
593  */
594 
595  float h = HWB.H, w = HWB.W, b = HWB.B, v, n, f;
596  int i;
597 
598  v = 1 - b;
599  if (h == HWB_UNDEFINED)
600  RETURN_RGB (v, v, v);
601  i = floor (h);
602  f = h - i;
603  if (i & 1)
604  f = 1 - f; /* if i is odd */
605  n = w + f * (v - w); /* linear interpolation between w and v */
606  switch (i) {
607  case 6:
608  case 0:
609  RETURN_RGB (v, n, w);
610  case 1:
611  RETURN_RGB (n, v, w);
612  case 2:
613  RETURN_RGB (w, v, n);
614  case 3:
615  RETURN_RGB (w, n, v);
616  case 4:
617  RETURN_RGB (n, w, v);
618  case 5:
619  RETURN_RGB (v, w, n);
620  }
621 
622  return RGB;
623 
624 }
625 #endif
626 
627 /*
628  Function: gdImageColorClosestHWB
629 */
631 {
632  int i;
633  /* long rd, gd, bd; */
634  int ct = (-1);
635  int first = 1;
636  float mindist = 0;
637  if (im->trueColor) {
638  return gdTrueColor (r, g, b);
639  }
640  for (i = 0; (i < (im->colorsTotal)); i++) {
641  float dist;
642  if (im->open[i]) {
643  continue;
644  }
645  dist = HWB_Diff (im->red[i], im->green[i], im->blue[i], r, g, b);
646  if (first || (dist < mindist)) {
647  mindist = dist;
648  ct = i;
649  first = 0;
650  }
651  }
652  return ct;
653 }
654 
655 /**
656  * Function: gdImageColorExact
657  *
658  * Gets the exact color of the image
659  *
660  * This is a simplified variant of <gdImageColorExactAlpha> where the alpha
661  * channel is always opaque.
662  *
663  * Parameters:
664  * im - The image.
665  * r - The value of the red component.
666  * g - The value of the green component.
667  * b - The value of the blue component.
668  *
669  * Returns:
670  * The exact color already available in the palette for palette images; if
671  * there is no exact color, -1 is returned.
672  * For truecolor images the color value of the given components is returned.
673  *
674  * See also:
675  * - <gdImageColorClosest>
676  */
677 BGD_DECLARE(int) gdImageColorExact (gdImagePtr im, int r, int g, int b)
678 {
679  return gdImageColorExactAlpha (im, r, g, b, gdAlphaOpaque);
680 }
681 
682 /**
683  * Function: gdImageColorExactAlpha
684  *
685  * Gets the exact color of the image
686  *
687  * Parameters:
688  * im - The image.
689  * r - The value of the red component.
690  * g - The value of the green component.
691  * b - The value of the blue component.
692  * a - The value of the alpha component.
693  *
694  * Returns:
695  * The exact color already available in the palette for palette images; if
696  * there is no exact color, -1 is returned.
697  * For truecolor images the color value of the given components is returned.
698  *
699  * See also:
700  * - <gdImageColorClosestAlpha>
701  * - <gdTrueColorAlpha>
702  */
703 BGD_DECLARE(int) gdImageColorExactAlpha (gdImagePtr im, int r, int g, int b, int a)
704 {
705  int i;
706  if (im->trueColor) {
707  return gdTrueColorAlpha (r, g, b, a);
708  }
709  for (i = 0; (i < (im->colorsTotal)); i++) {
710  if (im->open[i]) {
711  continue;
712  }
713  if ((im->red[i] == r) &&
714  (im->green[i] == g) && (im->blue[i] == b) && (im->alpha[i] == a)) {
715  return i;
716  }
717  }
718  return -1;
719 }
720 
721 /**
722  * Function: gdImageColorAllocate
723  *
724  * Allocates a color
725  *
726  * This is a simplified variant of <gdImageColorAllocateAlpha> where the alpha
727  * channel is always opaque.
728  *
729  * Parameters:
730  * im - The image.
731  * r - The value of the red component.
732  * g - The value of the green component.
733  * b - The value of the blue component.
734  *
735  * Returns:
736  * The color value.
737  *
738  * See also:
739  * - <gdImageColorDeallocate>
740  */
741 BGD_DECLARE(int) gdImageColorAllocate (gdImagePtr im, int r, int g, int b)
742 {
743  return gdImageColorAllocateAlpha (im, r, g, b, gdAlphaOpaque);
744 }
745 
746 /**
747  * Function: gdImageColorAllocateAlpha
748  *
749  * Allocates a color
750  *
751  * This is typically used for palette images, but can be used for truecolor
752  * images as well.
753  *
754  * Parameters:
755  * im - The image.
756  * r - The value of the red component.
757  * g - The value of the green component.
758  * b - The value of the blue component.
759  *
760  * Returns:
761  * The color value.
762  *
763  * See also:
764  * - <gdImageColorDeallocate>
765  */
766 BGD_DECLARE(int) gdImageColorAllocateAlpha (gdImagePtr im, int r, int g, int b, int a)
767 {
768  int i;
769  int ct = (-1);
770  if (im->trueColor) {
771  return gdTrueColorAlpha (r, g, b, a);
772  }
773  for (i = 0; (i < (im->colorsTotal)); i++) {
774  if (im->open[i]) {
775  ct = i;
776  break;
777  }
778  }
779  if (ct == (-1)) {
780  ct = im->colorsTotal;
781  if (ct == gdMaxColors) {
782  return -1;
783  }
784  im->colorsTotal++;
785  }
786  im->red[ct] = r;
787  im->green[ct] = g;
788  im->blue[ct] = b;
789  im->alpha[ct] = a;
790  im->open[ct] = 0;
791  return ct;
792 }
793 
794 /*
795  Function: gdImageColorResolve
796 
797  gdImageColorResolve is an alternative for the code fragment
798  (start code)
799  if ((color=gdImageColorExact(im,R,G,B)) < 0)
800  if ((color=gdImageColorAllocate(im,R,G,B)) < 0)
801  color=gdImageColorClosest(im,R,G,B);
802  (end code)
803  in a single function. Its advantage is that it is guaranteed to
804  return a color index in one search over the color table.
805 */
806 
807 BGD_DECLARE(int) gdImageColorResolve (gdImagePtr im, int r, int g, int b)
808 {
809  return gdImageColorResolveAlpha (im, r, g, b, gdAlphaOpaque);
810 }
811 
812 /*
813  Function: gdImageColorResolveAlpha
814 */
815 BGD_DECLARE(int) gdImageColorResolveAlpha (gdImagePtr im, int r, int g, int b, int a)
816 {
817  int c;
818  int ct = -1;
819  int op = -1;
820  long rd, gd, bd, ad, dist;
821  long mindist = 4 * 255 * 255; /* init to max poss dist */
822  if (im->trueColor) {
823  return gdTrueColorAlpha (r, g, b, a);
824  }
825 
826  for (c = 0; c < im->colorsTotal; c++) {
827  if (im->open[c]) {
828  op = c; /* Save open slot */
829  continue; /* Color not in use */
830  }
831  if (c == im->transparent) {
832  /* don't ever resolve to the color that has
833  * been designated as the transparent color */
834  continue;
835  }
836  rd = (long) (im->red[c] - r);
837  gd = (long) (im->green[c] - g);
838  bd = (long) (im->blue[c] - b);
839  ad = (long) (im->alpha[c] - a);
840  dist = rd * rd + gd * gd + bd * bd + ad * ad;
841  if (dist < mindist) {
842  if (dist == 0) {
843  return c; /* Return exact match color */
844  }
845  mindist = dist;
846  ct = c;
847  }
848  }
849  /* no exact match. We now know closest, but first try to allocate exact */
850  if (op == -1) {
851  op = im->colorsTotal;
852  if (op == gdMaxColors) {
853  /* No room for more colors */
854  return ct; /* Return closest available color */
855  }
856  im->colorsTotal++;
857  }
858  im->red[op] = r;
859  im->green[op] = g;
860  im->blue[op] = b;
861  im->alpha[op] = a;
862  im->open[op] = 0;
863  return op; /* Return newly allocated color */
864 }
865 
866 /**
867  * Function: gdImageColorDeallocate
868  *
869  * Removes a palette entry
870  *
871  * This is a no-op for truecolor images.
872  *
873  * Parameters:
874  * im - The image.
875  * color - The palette index.
876  *
877  * See also:
878  * - <gdImageColorAllocate>
879  * - <gdImageColorAllocateAlpha>
880  */
882 {
883  if (im->trueColor || (color >= gdMaxColors) || (color < 0)) {
884  return;
885  }
886  /* Mark it open. */
887  im->open[color] = 1;
888 }
889 
890 /**
891  * Function: gdImageColorTransparent
892  *
893  * Sets the transparent color of the image
894  *
895  * Parameter:
896  * im - The image.
897  * color - The color.
898  *
899  * See also:
900  * - <gdImageGetTransparent>
901  */
903 {
904  if (color < 0) {
905  return;
906  }
907 
908  if (!im->trueColor) {
909  if (color >= gdMaxColors) {
910  return;
911  }
912  if (im->transparent != -1) {
913  im->alpha[im->transparent] = gdAlphaOpaque;
914  }
916  }
917  im->transparent = color;
918 }
919 
920 /*
921  Function: gdImagePaletteCopy
922 */
924 {
925  int i;
926  int x, y, p;
927  int xlate[256];
928  if (to->trueColor) {
929  return;
930  }
931  if (from->trueColor) {
932  return;
933  }
934 
935  for (i = 0; i < 256; i++) {
936  xlate[i] = -1;
937  };
938 
939  for (y = 0; y < (to->sy); y++) {
940  for (x = 0; x < (to->sx); x++) {
941  /* Optimization: no gdImageGetPixel */
942  p = to->pixels[y][x];
943  if (xlate[p] == -1) {
944  /* This ought to use HWB, but we don't have an alpha-aware
945  version of that yet. */
946  xlate[p] =
947  gdImageColorClosestAlpha (from, to->red[p], to->green[p],
948  to->blue[p], to->alpha[p]);
949  /*printf("Mapping %d (%d, %d, %d, %d) to %d (%d, %d, %d, %d)\n", */
950  /* p, to->red[p], to->green[p], to->blue[p], to->alpha[p], */
951  /* xlate[p], from->red[xlate[p]], from->green[xlate[p]], from->blue[xlate[p]], from->alpha[xlate[p]]); */
952  };
953  /* Optimization: no gdImageSetPixel */
954  to->pixels[y][x] = xlate[p];
955  };
956  };
957 
958  for (i = 0; (i < (from->colorsTotal)); i++) {
959  /*printf("Copying color %d (%d, %d, %d, %d)\n", i, from->red[i], from->blue[i], from->green[i], from->alpha[i]); */
960  to->red[i] = from->red[i];
961  to->blue[i] = from->blue[i];
962  to->green[i] = from->green[i];
963  to->alpha[i] = from->alpha[i];
964  to->open[i] = 0;
965  };
966 
967  for (i = from->colorsTotal; (i < to->colorsTotal); i++) {
968  to->open[i] = 1;
969  };
970 
971  to->colorsTotal = from->colorsTotal;
972 
973 }
974 
975 /*
976  Function: gdImageColorReplace
977 */
979 {
980  register int x, y;
981  int n = 0;
982 
983  if (src == dst) {
984  return 0;
985  }
986 
987 #define REPLACING_LOOP(pixel) do { \
988  for (y = im->cy1; y <= im->cy2; y++) { \
989  for (x = im->cx1; x <= im->cx2; x++) { \
990  if (pixel(im, x, y) == src) { \
991  gdImageSetPixel(im, x, y, dst); \
992  n++; \
993  } \
994  } \
995  } \
996  } while (0)
997 
998  if (im->trueColor) {
1000  } else {
1002  }
1003 
1004 #undef REPLACING_LOOP
1005 
1006  return n;
1007 }
1008 
1009 /*
1010  Function: gdImageColorReplaceThreshold
1011 */
1013 {
1014  register int x, y;
1015  int n = 0;
1016 
1017  if (src == dst) {
1018  return 0;
1019  }
1020 
1021 #define REPLACING_LOOP(pixel) do { \
1022  for (y = im->cy1; y <= im->cy2; y++) { \
1023  for (x = im->cx1; x <= im->cx2; x++) { \
1024  if (gdColorMatch(im, src, pixel(im, x, y), threshold)) { \
1025  gdImageSetPixel(im, x, y, dst); \
1026  n++; \
1027  } \
1028  } \
1029  } \
1030  } while (0)
1031 
1032  if (im->trueColor) {
1034  } else {
1036  }
1037 
1038 #undef REPLACING_LOOP
1039 
1040  return n;
1041 }
1042 
1043 static int colorCmp (const void *x, const void *y)
1044 {
1045  int a = *(int const *)x;
1046  int b = *(int const *)y;
1047  return (a > b) - (a < b);
1048 }
1049 
1050 /*
1051  Function: gdImageColorReplaceArray
1052 */
1054 {
1055  register int x, y;
1056  int c, *d, *base;
1057  int i, n = 0;
1058 
1059  if (len <= 0 || src == dst) {
1060  return 0;
1061  }
1062  if (len == 1) {
1063  return gdImageColorReplace(im, src[0], dst[0]);
1064  }
1065  if (overflow2(len, sizeof(int)<<1)) {
1066  return -1;
1067  }
1068  base = (int *)gdMalloc(len * (sizeof(int)<<1));
1069  if (!base) {
1070  return -1;
1071  }
1072  for (i = 0; i < len; i++) {
1073  base[(i<<1)] = src[i];
1074  base[(i<<1)+1] = dst[i];
1075  }
1076  qsort(base, len, sizeof(int)<<1, colorCmp);
1077 
1078 #define REPLACING_LOOP(pixel) do { \
1079  for (y = im->cy1; y <= im->cy2; y++) { \
1080  for (x = im->cx1; x <= im->cx2; x++) { \
1081  c = pixel(im, x, y); \
1082  if ( (d = (int *)bsearch(&c, base, len, sizeof(int)<<1, colorCmp)) ) { \
1083  gdImageSetPixel(im, x, y, d[1]); \
1084  n++; \
1085  } \
1086  } \
1087  } \
1088  } while (0)
1089 
1090  if (im->trueColor) {
1092  } else {
1094  }
1095 
1096 #undef REPLACING_LOOP
1097 
1098  gdFree(base);
1099  return n;
1100 }
1101 
1102 /*
1103  Function: gdImageColorReplaceCallback
1104 */
1106 {
1107  int c, d, n = 0;
1108 
1109  if (!callback) {
1110  return 0;
1111  }
1112  if (im->trueColor) {
1113  register int x, y;
1114 
1115  for (y = im->cy1; y <= im->cy2; y++) {
1116  for (x = im->cx1; x <= im->cx2; x++) {
1117  c = gdImageTrueColorPixel(im, x, y);
1118  if ( (d = callback(im, c)) != c) {
1119  gdImageSetPixel(im, x, y, d);
1120  n++;
1121  }
1122  }
1123  }
1124  } else { /* palette */
1125  int *sarr, *darr;
1126  int k, len = 0;
1127 
1128  sarr = (int *)gdCalloc(im->colorsTotal, sizeof(int));
1129  if (!sarr) {
1130  return -1;
1131  }
1132  for (c = 0; c < im->colorsTotal; c++) {
1133  if (!im->open[c]) {
1134  sarr[len++] = c;
1135  }
1136  }
1137  darr = (int *)gdCalloc(len, sizeof(int));
1138  if (!darr) {
1139  gdFree(sarr);
1140  return -1;
1141  }
1142  for (k = 0; k < len; k++) {
1143  darr[k] = callback(im, sarr[k]);
1144  }
1145  n = gdImageColorReplaceArray(im, k, sarr, darr);
1146  gdFree(darr);
1147  gdFree(sarr);
1148  }
1149  return n;
1150 }
1151 
1152 /* 2.0.10: before the drawing routines, some code to clip points that are
1153  * outside the drawing window. Nick Atty (nick@canalplan.org.uk)
1154  *
1155  * This is the Sutherland Hodgman Algorithm, as implemented by
1156  * Duvanenko, Robbins and Gyurcsik - SH(DRG) for short. See Dr Dobb's
1157  * Journal, January 1996, pp107-110 and 116-117
1158  *
1159  * Given the end points of a line, and a bounding rectangle (which we
1160  * know to be from (0,0) to (SX,SY)), adjust the endpoints to be on
1161  * the edges of the rectangle if the line should be drawn at all,
1162  * otherwise return a failure code */
1163 
1164 /* this does "one-dimensional" clipping: note that the second time it
1165  is called, all the x parameters refer to height and the y to width
1166  - the comments ignore this (if you can understand it when it's
1167  looking at the X parameters, it should become clear what happens on
1168  the second call!) The code is simplified from that in the article,
1169  as we know that gd images always start at (0,0) */
1170 
1171 /* 2.0.26, TBB: we now have to respect a clipping rectangle, it won't
1172  necessarily start at 0. */
1173 
1174 static int
1175 clip_1d (int *x0, int *y0, int *x1, int *y1, int mindim, int maxdim)
1176 {
1177  double m; /* gradient of line */
1178  if (*x0 < mindim) {
1179  /* start of line is left of window */
1180  if (*x1 < mindim) /* as is the end, so the line never cuts the window */
1181  return 0;
1182  m = (*y1 - *y0) / (double) (*x1 - *x0); /* calculate the slope of the line */
1183  /* adjust x0 to be on the left boundary (ie to be zero), and y0 to match */
1184  *y0 -= (int)(m * (*x0 - mindim));
1185  *x0 = mindim;
1186  /* now, perhaps, adjust the far end of the line as well */
1187  if (*x1 > maxdim) {
1188  *y1 += m * (maxdim - *x1);
1189  *x1 = maxdim;
1190  }
1191  return 1;
1192  }
1193  if (*x0 > maxdim) {
1194  /* start of line is right of window -
1195  complement of above */
1196  if (*x1 > maxdim) /* as is the end, so the line misses the window */
1197  return 0;
1198  m = (*y1 - *y0) / (double) (*x1 - *x0); /* calculate the slope of the line */
1199  *y0 += (int)(m * (maxdim - *x0)); /* adjust so point is on the right
1200  boundary */
1201  *x0 = maxdim;
1202  /* now, perhaps, adjust the end of the line */
1203  if (*x1 < mindim) {
1204  *y1 -= (int)(m * (*x1 - mindim));
1205  *x1 = mindim;
1206  }
1207  return 1;
1208  }
1209  /* the final case - the start of the line is inside the window */
1210  if (*x1 > maxdim) {
1211  /* other end is outside to the right */
1212  m = (*y1 - *y0) / (double) (*x1 - *x0); /* calculate the slope of the line */
1213  *y1 += (int)(m * (maxdim - *x1));
1214  *x1 = maxdim;
1215  return 1;
1216  }
1217  if (*x1 < mindim) {
1218  /* other end is outside to the left */
1219  m = (*y1 - *y0) / (double) (*x1 - *x0); /* calculate the slope of the line */
1220  *y1 -= (int)(m * (*x1 - mindim));
1221  *x1 = mindim;
1222  return 1;
1223  }
1224  /* only get here if both points are inside the window */
1225  return 1;
1226 }
1227 
1228 /* end of line clipping code */
1229 
1230 /**
1231  * Group: Pixels
1232  */
1233 
1234 /*
1235  Function: gdImageSetPixel
1236 */
1237 BGD_DECLARE(void) gdImageSetPixel (gdImagePtr im, int x, int y, int color)
1238 {
1239  int p;
1240  switch (color) {
1241  case gdStyled:
1242  if (!im->style) {
1243  /* Refuse to draw if no style is set. */
1244  return;
1245  } else {
1246  p = im->style[im->stylePos++];
1247  }
1248  if (p != (gdTransparent)) {
1249  gdImageSetPixel (im, x, y, p);
1250  }
1251  im->stylePos = im->stylePos % im->styleLength;
1252  break;
1253  case gdStyledBrushed:
1254  if (!im->style) {
1255  /* Refuse to draw if no style is set. */
1256  return;
1257  }
1258  p = im->style[im->stylePos++];
1259  if ((p != gdTransparent) && (p != 0)) {
1260  gdImageSetPixel (im, x, y, gdBrushed);
1261  }
1262  im->stylePos = im->stylePos % im->styleLength;
1263  break;
1264  case gdBrushed:
1265  gdImageBrushApply (im, x, y);
1266  break;
1267  case gdTiled:
1268  gdImageTileApply (im, x, y);
1269  break;
1270  case gdAntiAliased:
1271  /* This shouldn't happen (2.0.26) because we just call
1272  gdImageAALine now, but do something sane. */
1273  gdImageSetPixel(im, x, y, im->AA_color);
1274  break;
1275  default:
1276  if (gdImageBoundsSafeMacro (im, x, y)) {
1277  if (im->trueColor) {
1278  switch (im->alphaBlendingFlag) {
1279  default:
1280  case gdEffectReplace:
1281  im->tpixels[y][x] = color;
1282  break;
1283  case gdEffectAlphaBlend:
1284  case gdEffectNormal:
1285  im->tpixels[y][x] = gdAlphaBlend(im->tpixels[y][x], color);
1286  break;
1287  case gdEffectOverlay :
1288  im->tpixels[y][x] = gdLayerOverlay(im->tpixels[y][x], color);
1289  break;
1290  case gdEffectMultiply :
1291  im->tpixels[y][x] = gdLayerMultiply(im->tpixels[y][x], color);
1292  break;
1293  }
1294  } else {
1295  im->pixels[y][x] = color;
1296  }
1297  }
1298  break;
1299  }
1300 }
1301 
1302 static void
1304 {
1305  int lx, ly;
1306  int hy;
1307  int hx;
1308  int x1, y1, x2, y2;
1309  int srcx, srcy;
1310  if (!im->brush) {
1311  return;
1312  }
1313  hy = gdImageSY (im->brush) / 2;
1314  y1 = y - hy;
1315  y2 = y1 + gdImageSY (im->brush);
1316  hx = gdImageSX (im->brush) / 2;
1317  x1 = x - hx;
1318  x2 = x1 + gdImageSX (im->brush);
1319  srcy = 0;
1320  if (im->trueColor) {
1321  if (im->brush->trueColor) {
1322  for (ly = y1; (ly < y2); ly++) {
1323  srcx = 0;
1324  for (lx = x1; (lx < x2); lx++) {
1325  int p;
1326  p = gdImageGetTrueColorPixel (im->brush, srcx, srcy);
1327  /* 2.0.9, Thomas Winzig: apply simple full transparency */
1328  if (p != gdImageGetTransparent (im->brush)) {
1329  gdImageSetPixel (im, lx, ly, p);
1330  }
1331  srcx++;
1332  }
1333  srcy++;
1334  }
1335  } else {
1336  /* 2.0.12: Brush palette, image truecolor (thanks to Thorben Kundinger
1337  for pointing out the issue) */
1338  for (ly = y1; (ly < y2); ly++) {
1339  srcx = 0;
1340  for (lx = x1; (lx < x2); lx++) {
1341  int p, tc;
1342  p = gdImageGetPixel (im->brush, srcx, srcy);
1343  tc = gdImageGetTrueColorPixel (im->brush, srcx, srcy);
1344  /* 2.0.9, Thomas Winzig: apply simple full transparency */
1345  if (p != gdImageGetTransparent (im->brush)) {
1346  gdImageSetPixel (im, lx, ly, tc);
1347  }
1348  srcx++;
1349  }
1350  srcy++;
1351  }
1352  }
1353  } else {
1354  for (ly = y1; (ly < y2); ly++) {
1355  srcx = 0;
1356  for (lx = x1; (lx < x2); lx++) {
1357  int p;
1358  p = gdImageGetPixel (im->brush, srcx, srcy);
1359  /* Allow for non-square brushes! */
1360  if (p != gdImageGetTransparent (im->brush)) {
1361  /* Truecolor brush. Very slow
1362  on a palette destination. */
1363  if (im->brush->trueColor) {
1364  gdImageSetPixel (im, lx, ly,
1367  (p),
1369  (p),
1371  (p),
1373  (p)));
1374  } else {
1375  gdImageSetPixel (im, lx, ly, im->brushColorMap[p]);
1376  }
1377  }
1378  srcx++;
1379  }
1380  srcy++;
1381  }
1382  }
1383 }
1384 
1385 static void
1387 {
1388  gdImagePtr tile = im->tile;
1389  int srcx, srcy;
1390  int p;
1391  if (!tile) {
1392  return;
1393  }
1394  srcx = x % gdImageSX (tile);
1395  srcy = y % gdImageSY (tile);
1396  if (im->trueColor) {
1397  p = gdImageGetPixel (tile, srcx, srcy);
1398  if (p != gdImageGetTransparent (tile)) {
1399  if (!tile->trueColor) {
1400  p = gdTrueColorAlpha(tile->red[p], tile->green[p], tile->blue[p], tile->alpha[p]);
1401  }
1402  gdImageSetPixel (im, x, y, p);
1403  }
1404  } else {
1405  p = gdImageGetPixel (tile, srcx, srcy);
1406  /* Allow for transparency */
1407  if (p != gdImageGetTransparent (tile)) {
1408  if (tile->trueColor) {
1409  /* Truecolor tile. Very slow
1410  on a palette destination. */
1411  gdImageSetPixel (im, x, y,
1414  (p),
1416  (p),
1418  (p),
1420  (p)));
1421  } else {
1422  gdImageSetPixel (im, x, y, im->tileColorMap[p]);
1423  }
1424  }
1425  }
1426 }
1427 
1428 /**
1429  * Function: gdImageGetPixel
1430  *
1431  * Gets a pixel color as stored in the image.
1432  *
1433  * Parameters:
1434  * im - The image.
1435  * x - The x-coordinate.
1436  * y - The y-coordinate.
1437  *
1438  * See also:
1439  * - <gdImageGetTrueColorPixel>
1440  * - <gdImagePalettePixel>
1441  * - <gdImageTrueColorPixel>
1442  */
1444 {
1445  if (gdImageBoundsSafeMacro (im, x, y)) {
1446  if (im->trueColor) {
1447  return im->tpixels[y][x];
1448  } else {
1449  return im->pixels[y][x];
1450  }
1451  } else {
1452  return 0;
1453  }
1454 }
1455 
1456 /**
1457  * Function: gdImageGetTrueColorPixel
1458  *
1459  * Gets a pixel color always as truecolor value.
1460  *
1461  * Parameters:
1462  * im - The image.
1463  * x - The x-coordinate.
1464  * y - The y-coordinate.
1465  *
1466  * See also:
1467  * - <gdImageGetPixel>
1468  * - <gdImageTrueColorPixel>
1469  */
1471 {
1472  int p = gdImageGetPixel (im, x, y);
1473  if (!im->trueColor) {
1474  return gdTrueColorAlpha (im->red[p], im->green[p], im->blue[p],
1475  (im->transparent == p) ? gdAlphaTransparent :
1476  im->alpha[p]);
1477  } else {
1478  return p;
1479  }
1480 }
1481 
1482 /**
1483  * Group: Primitives
1484  */
1485 
1486 /*
1487  Function: gdImageAABlend
1488 
1489  NO-OP, kept for library compatibility.
1490 */
1492 {
1493  (void)im;
1494 }
1495 
1496 static void gdImageAALine (gdImagePtr im, int x1, int y1, int x2, int y2, int col);
1497 
1498 static void _gdImageFilledHRectangle (gdImagePtr im, int x1, int y1, int x2, int y2,
1499  int color);
1500 
1501 static void gdImageHLine(gdImagePtr im, int y, int x1, int x2, int col)
1502 {
1503  if (im->thick > 1) {
1504  int thickhalf = im->thick >> 1;
1505  _gdImageFilledHRectangle(im, x1, y - thickhalf, x2, y + im->thick - thickhalf - 1, col);
1506  } else {
1507  if (x2 < x1) {
1508  int t = x2;
1509  x2 = x1;
1510  x1 = t;
1511  }
1512 
1513  for (; x1 <= x2; x1++) {
1514  gdImageSetPixel(im, x1, y, col);
1515  }
1516  }
1517  return;
1518 }
1519 
1520 static void gdImageVLine(gdImagePtr im, int x, int y1, int y2, int col)
1521 {
1522  if (im->thick > 1) {
1523  int thickhalf = im->thick >> 1;
1524  gdImageFilledRectangle(im, x - thickhalf, y1, x + im->thick - thickhalf - 1, y2, col);
1525  } else {
1526  if (y2 < y1) {
1527  int t = y1;
1528  y1 = y2;
1529  y2 = t;
1530  }
1531 
1532  for (; y1 <= y2; y1++) {
1533  gdImageSetPixel(im, x, y1, col);
1534  }
1535  }
1536  return;
1537 }
1538 
1539 /*
1540  Function: gdImageLine
1541 
1542  Bresenham as presented in Foley & Van Dam.
1543 */
1544 BGD_DECLARE(void) gdImageLine (gdImagePtr im, int x1, int y1, int x2, int y2, int color)
1545 {
1546  int dx, dy, incr1, incr2, d, x, y, xend, yend, xdirflag, ydirflag;
1547  int wid;
1548  int w, wstart;
1549  int thick;
1550 
1551  if (color == gdAntiAliased) {
1552  /*
1553  gdAntiAliased passed as color: use the much faster, much cheaper
1554  and equally attractive gdImageAALine implementation. That
1555  clips too, so don't clip twice.
1556  */
1557  gdImageAALine(im, x1, y1, x2, y2, im->AA_color);
1558  return;
1559  }
1560  /* 2.0.10: Nick Atty: clip to edges of drawing rectangle, return if no
1561  points need to be drawn. 2.0.26, TBB: clip to edges of clipping
1562  rectangle. We were getting away with this because gdImageSetPixel
1563  is used for actual drawing, but this is still more efficient and opens
1564  the way to skip per-pixel bounds checking in the future. */
1565 
1566  if (clip_1d (&x1, &y1, &x2, &y2, im->cx1, im->cx2) == 0)
1567  return;
1568  if (clip_1d (&y1, &x1, &y2, &x2, im->cy1, im->cy2) == 0)
1569  return;
1570  thick = im->thick;
1571 
1572  dx = abs (x2 - x1);
1573  dy = abs (y2 - y1);
1574 
1575  if (dx == 0) {
1576  gdImageVLine(im, x1, y1, y2, color);
1577  return;
1578  } else if (dy == 0) {
1579  gdImageHLine(im, y1, x1, x2, color);
1580  return;
1581  }
1582 
1583  if (dy <= dx) {
1584  /* More-or-less horizontal. use wid for vertical stroke */
1585  /* Doug Claar: watch out for NaN in atan2 (2.0.5) */
1586 
1587  /* 2.0.12: Michael Schwartz: divide rather than multiply;
1588  TBB: but watch out for /0! */
1589  double ac = cos (atan2 (dy, dx));
1590  if (ac != 0) {
1591  wid = thick / ac;
1592  } else {
1593  wid = 1;
1594  }
1595  if (wid == 0) {
1596  wid = 1;
1597  }
1598  d = 2 * dy - dx;
1599  incr1 = 2 * dy;
1600  incr2 = 2 * (dy - dx);
1601  if (x1 > x2) {
1602  x = x2;
1603  y = y2;
1604  ydirflag = (-1);
1605  xend = x1;
1606  } else {
1607  x = x1;
1608  y = y1;
1609  ydirflag = 1;
1610  xend = x2;
1611  }
1612 
1613  /* Set up line thickness */
1614  wstart = y - wid / 2;
1615  for (w = wstart; w < wstart + wid; w++)
1616  gdImageSetPixel (im, x, w, color);
1617 
1618  if (((y2 - y1) * ydirflag) > 0) {
1619  while (x < xend) {
1620  x++;
1621  if (d < 0) {
1622  d += incr1;
1623  } else {
1624  y++;
1625  d += incr2;
1626  }
1627  wstart = y - wid / 2;
1628  for (w = wstart; w < wstart + wid; w++)
1629  gdImageSetPixel (im, x, w, color);
1630  }
1631  } else {
1632  while (x < xend) {
1633  x++;
1634  if (d < 0) {
1635  d += incr1;
1636  } else {
1637  y--;
1638  d += incr2;
1639  }
1640  wstart = y - wid / 2;
1641  for (w = wstart; w < wstart + wid; w++)
1642  gdImageSetPixel (im, x, w, color);
1643  }
1644  }
1645  } else {
1646  /* More-or-less vertical. use wid for horizontal stroke */
1647  /* 2.0.12: Michael Schwartz: divide rather than multiply;
1648  TBB: but watch out for /0! */
1649  double as = sin (atan2 (dy, dx));
1650  if (as != 0) {
1651  wid = thick / as;
1652  } else {
1653  wid = 1;
1654  }
1655  if (wid == 0)
1656  wid = 1;
1657 
1658  d = 2 * dx - dy;
1659  incr1 = 2 * dx;
1660  incr2 = 2 * (dx - dy);
1661  if (y1 > y2) {
1662  y = y2;
1663  x = x2;
1664  yend = y1;
1665  xdirflag = (-1);
1666  } else {
1667  y = y1;
1668  x = x1;
1669  yend = y2;
1670  xdirflag = 1;
1671  }
1672 
1673  /* Set up line thickness */
1674  wstart = x - wid / 2;
1675  for (w = wstart; w < wstart + wid; w++)
1676  gdImageSetPixel (im, w, y, color);
1677 
1678  if (((x2 - x1) * xdirflag) > 0) {
1679  while (y < yend) {
1680  y++;
1681  if (d < 0) {
1682  d += incr1;
1683  } else {
1684  x++;
1685  d += incr2;
1686  }
1687  wstart = x - wid / 2;
1688  for (w = wstart; w < wstart + wid; w++)
1689  gdImageSetPixel (im, w, y, color);
1690  }
1691  } else {
1692  while (y < yend) {
1693  y++;
1694  if (d < 0) {
1695  d += incr1;
1696  } else {
1697  x--;
1698  d += incr2;
1699  }
1700  wstart = x - wid / 2;
1701  for (w = wstart; w < wstart + wid; w++)
1702  gdImageSetPixel (im, w, y, color);
1703  }
1704  }
1705  }
1706 
1707 }
1708 static void dashedSet (gdImagePtr im, int x, int y, int color,
1709  int *onP, int *dashStepP, int wid, int vert);
1710 
1711 /*
1712  Function: gdImageDashedLine
1713 */
1714 BGD_DECLARE(void) gdImageDashedLine (gdImagePtr im, int x1, int y1, int x2, int y2, int color)
1715 {
1716  int dx, dy, incr1, incr2, d, x, y, xend, yend, xdirflag, ydirflag;
1717  int dashStep = 0;
1718  int on = 1;
1719  int wid;
1720  int vert;
1721  int thick = im->thick;
1722 
1723  dx = abs (x2 - x1);
1724  dy = abs (y2 - y1);
1725  if (dy <= dx) {
1726  /* More-or-less horizontal. use wid for vertical stroke */
1727  /* 2.0.12: Michael Schwartz: divide rather than multiply;
1728  TBB: but watch out for /0! */
1729  double as = sin (atan2 (dy, dx));
1730  if (as != 0) {
1731  wid = thick / as;
1732  } else {
1733  wid = 1;
1734  }
1735  vert = 1;
1736 
1737  d = 2 * dy - dx;
1738  incr1 = 2 * dy;
1739  incr2 = 2 * (dy - dx);
1740  if (x1 > x2) {
1741  x = x2;
1742  y = y2;
1743  ydirflag = (-1);
1744  xend = x1;
1745  } else {
1746  x = x1;
1747  y = y1;
1748  ydirflag = 1;
1749  xend = x2;
1750  }
1751  dashedSet (im, x, y, color, &on, &dashStep, wid, vert);
1752  if (((y2 - y1) * ydirflag) > 0) {
1753  while (x < xend) {
1754  x++;
1755  if (d < 0) {
1756  d += incr1;
1757  } else {
1758  y++;
1759  d += incr2;
1760  }
1761  dashedSet (im, x, y, color, &on, &dashStep, wid, vert);
1762  }
1763  } else {
1764  while (x < xend) {
1765  x++;
1766  if (d < 0) {
1767  d += incr1;
1768  } else {
1769  y--;
1770  d += incr2;
1771  }
1772  dashedSet (im, x, y, color, &on, &dashStep, wid, vert);
1773  }
1774  }
1775  } else {
1776  /* 2.0.12: Michael Schwartz: divide rather than multiply;
1777  TBB: but watch out for /0! */
1778  double as = sin (atan2 (dy, dx));
1779  if (as != 0) {
1780  wid = thick / as;
1781  } else {
1782  wid = 1;
1783  }
1784  vert = 0;
1785 
1786  d = 2 * dx - dy;
1787  incr1 = 2 * dx;
1788  incr2 = 2 * (dx - dy);
1789  if (y1 > y2) {
1790  y = y2;
1791  x = x2;
1792  yend = y1;
1793  xdirflag = (-1);
1794  } else {
1795  y = y1;
1796  x = x1;
1797  yend = y2;
1798  xdirflag = 1;
1799  }
1800  dashedSet (im, x, y, color, &on, &dashStep, wid, vert);
1801  if (((x2 - x1) * xdirflag) > 0) {
1802  while (y < yend) {
1803  y++;
1804  if (d < 0) {
1805  d += incr1;
1806  } else {
1807  x++;
1808  d += incr2;
1809  }
1810  dashedSet (im, x, y, color, &on, &dashStep, wid, vert);
1811  }
1812  } else {
1813  while (y < yend) {
1814  y++;
1815  if (d < 0) {
1816  d += incr1;
1817  } else {
1818  x--;
1819  d += incr2;
1820  }
1821  dashedSet (im, x, y, color, &on, &dashStep, wid, vert);
1822  }
1823  }
1824  }
1825 }
1826 
1827 static void
1828 dashedSet (gdImagePtr im, int x, int y, int color,
1829  int *onP, int *dashStepP, int wid, int vert)
1830 {
1831  int dashStep = *dashStepP;
1832  int on = *onP;
1833  int w, wstart;
1834 
1835  dashStep++;
1836  if (dashStep == gdDashSize) {
1837  dashStep = 0;
1838  on = !on;
1839  }
1840  if (on) {
1841  if (vert) {
1842  wstart = y - wid / 2;
1843  for (w = wstart; w < wstart + wid; w++)
1844  gdImageSetPixel (im, x, w, color);
1845  } else {
1846  wstart = x - wid / 2;
1847  for (w = wstart; w < wstart + wid; w++)
1848  gdImageSetPixel (im, w, y, color);
1849  }
1850  }
1851  *dashStepP = dashStep;
1852  *onP = on;
1853 }
1854 
1855 /*
1856  Function: gdImageBoundsSafe
1857 */
1859 {
1860  return gdImageBoundsSafeMacro (im, x, y);
1861 }
1862 
1863 /**
1864  * Function: gdImageChar
1865  *
1866  * Draws a single character.
1867  *
1868  * Parameters:
1869  * im - The image to draw onto.
1870  * f - The raster font.
1871  * x - The x coordinate of the upper left pixel.
1872  * y - The y coordinate of the upper left pixel.
1873  * c - The character.
1874  * color - The color.
1875  *
1876  * Variants:
1877  * - <gdImageCharUp>
1878  *
1879  * See also:
1880  * - <gdFontPtr>
1881  */
1882 BGD_DECLARE(void) gdImageChar (gdImagePtr im, gdFontPtr f, int x, int y, int c, int color)
1883 {
1884  int cx, cy;
1885  int px, py;
1886  int fline;
1887  const int xuppper = (x > INT_MAX - f->w) ? INT_MAX : x + f->w;
1888  const int yuppper = (y > INT_MAX - f->h) ? INT_MAX : y + f->h;
1889  cx = 0;
1890  cy = 0;
1891 #ifdef CHARSET_EBCDIC
1892  c = ASC (c);
1893 #endif /*CHARSET_EBCDIC */
1894  if ((c < f->offset) || (c >= (f->offset + f->nchars))) {
1895  return;
1896  }
1897  fline = (c - f->offset) * f->h * f->w;
1898  for (py = y; py < yuppper; py++) {
1899  for (px = x; px < xuppper; px++) {
1900  if (f->data[fline + cy * f->w + cx]) {
1901  gdImageSetPixel (im, px, py, color);
1902  }
1903  cx++;
1904  }
1905  cx = 0;
1906  cy++;
1907  }
1908 }
1909 
1910 /**
1911  * Function: gdImageCharUp
1912  */
1913 BGD_DECLARE(void) gdImageCharUp (gdImagePtr im, gdFontPtr f, int x, int y, int c, int color)
1914 {
1915  int cx, cy;
1916  int px, py;
1917  int fline;
1918  const int xuppper = (x > INT_MAX - f->h) ? INT_MAX : x + f->h;
1919  const int ylower = (y < INT_MIN + f->w) ? INT_MIN : y - f->w;
1920  cx = 0;
1921  cy = 0;
1922 #ifdef CHARSET_EBCDIC
1923  c = ASC (c);
1924 #endif /*CHARSET_EBCDIC */
1925  if ((c < f->offset) || (c >= (f->offset + f->nchars))) {
1926  return;
1927  }
1928  fline = (c - f->offset) * f->h * f->w;
1929  for (py = y; py > ylower; py--) {
1930  for (px = x; px < xuppper; px++) {
1931  if (f->data[fline + cy * f->w + cx]) {
1932  gdImageSetPixel (im, px, py, color);
1933  }
1934  cy++;
1935  }
1936  cy = 0;
1937  cx++;
1938  }
1939 }
1940 
1941 /**
1942  * Function: gdImageString
1943  *
1944  * Draws a character string.
1945  *
1946  * Parameters:
1947  * im - The image to draw onto.
1948  * f - The raster font.
1949  * x - The x coordinate of the upper left pixel.
1950  * y - The y coordinate of the upper left pixel.
1951  * c - The character string.
1952  * color - The color.
1953  *
1954  * Variants:
1955  * - <gdImageStringUp>
1956  * - <gdImageString16>
1957  * - <gdImageStringUp16>
1958  *
1959  * See also:
1960  * - <gdFontPtr>
1961  * - <gdImageStringTTF>
1962  */
1964  int x, int y, unsigned char *s, int color)
1965 {
1966  int i;
1967  int l;
1968  l = strlen ((char *) s);
1969  for (i = 0; (i < l); i++) {
1970  gdImageChar (im, f, x, y, s[i], color);
1971  x += f->w;
1972  }
1973 }
1974 
1975 /**
1976  * Function: gdImageStringUp
1977  */
1979  int x, int y, unsigned char *s, int color)
1980 {
1981  int i;
1982  int l;
1983  l = strlen ((char *) s);
1984  for (i = 0; (i < l); i++) {
1985  gdImageCharUp (im, f, x, y, s[i], color);
1986  y -= f->w;
1987  }
1988 }
1989 
1990 static int strlen16 (unsigned short *s);
1991 
1992 /**
1993  * Function: gdImageString16
1994  */
1996  int x, int y, unsigned short *s, int color)
1997 {
1998  int i;
1999  int l;
2000  l = strlen16 (s);
2001  for (i = 0; (i < l); i++) {
2002  gdImageChar (im, f, x, y, s[i], color);
2003  x += f->w;
2004  }
2005 }
2006 
2007 /**
2008  * Function: gdImageStringUp16
2009  */
2011  int x, int y, unsigned short *s, int color)
2012 {
2013  int i;
2014  int l;
2015  l = strlen16 (s);
2016  for (i = 0; (i < l); i++) {
2017  gdImageCharUp (im, f, x, y, s[i], color);
2018  y -= f->w;
2019  }
2020 }
2021 
2022 static int
2023 strlen16 (unsigned short *s)
2024 {
2025  int len = 0;
2026  while (*s) {
2027  s++;
2028  len++;
2029  }
2030  return len;
2031 }
2032 
2033 #ifndef HAVE_LSQRT
2034 /* If you don't have a nice square root function for longs, you can use
2035  ** this hack
2036  */
2037 long
2038 lsqrt (long n)
2039 {
2040  long result = (long) sqrt ((double) n);
2041  return result;
2042 }
2043 #endif
2044 
2045 /* s and e are integers modulo 360 (degrees), with 0 degrees
2046  being the rightmost extreme and degrees changing clockwise.
2047  cx and cy are the center in pixels; w and h are the horizontal
2048  and vertical diameter in pixels. */
2049 
2050 /*
2051  Function: gdImageArc
2052 */
2053 BGD_DECLARE(void) gdImageArc (gdImagePtr im, int cx, int cy, int w, int h, int s, int e,
2054  int color)
2055 {
2056  gdImageFilledArc (im, cx, cy, w, h, s, e, color, gdNoFill);
2057 }
2058 
2059 /*
2060  Function: gdImageFilledArc
2061 */
2062 BGD_DECLARE(void) gdImageFilledArc (gdImagePtr im, int cx, int cy, int w, int h, int s, int e,
2063  int color, int style)
2064 {
2065  gdPoint pts[363];
2066  int i, pti;
2067  int lx = 0, ly = 0;
2068  int fx = 0, fy = 0;
2069  int startx = -1, starty = -1, endx = -1, endy = -1;
2070 
2071  if ((s % 360) == (e % 360)) {
2072  s = 0;
2073  e = 360;
2074  } else {
2075  if (s > 360) {
2076  s = s % 360;
2077  }
2078 
2079  if (e > 360) {
2080  e = e % 360;
2081  }
2082 
2083  while (s < 0) {
2084  s += 360;
2085  }
2086 
2087  while (e < s) {
2088  e += 360;
2089  }
2090 
2091  if (s == e) {
2092  s = 0;
2093  e = 360;
2094  }
2095  }
2096 
2097  for (i = s, pti = 1; (i <= e); i++, pti++) {
2098  int x, y;
2099  x = endx = ((long) gdCosT[i % 360] * (long) w / (2 * 1024)) + cx;
2100  y = endy = ((long) gdSinT[i % 360] * (long) h / (2 * 1024)) + cy;
2101  if (i != s) {
2102  if (!(style & gdChord)) {
2103  if (style & gdNoFill) {
2104  gdImageLine (im, lx, ly, x, y, color);
2105  } else {
2106  if (y == ly) {
2107  pti--; /* don't add this point */
2108  if (((i > 270 || i < 90) && x > lx) || ((i > 90 && i < 270) && x < lx)) {
2109  /* replace the old x coord, if increasing on the
2110  right side or decreasing on the left side */
2111  pts[pti].x = x;
2112  }
2113  } else {
2114  pts[pti].x = x;
2115  pts[pti].y = y;
2116  }
2117  }
2118  }
2119  } else {
2120  fx = x;
2121  fy = y;
2122 
2123  if (!(style & (gdChord | gdNoFill))) {
2124  pts[0].x = cx;
2125  pts[0].y = cy;
2126  pts[pti].x = startx = x;
2127  pts[pti].y = starty = y;
2128  }
2129  }
2130  lx = x;
2131  ly = y;
2132  }
2133  if (style & gdChord) {
2134  if (style & gdNoFill) {
2135  if (style & gdEdged) {
2136  gdImageLine (im, cx, cy, lx, ly, color);
2137  gdImageLine (im, cx, cy, fx, fy, color);
2138  }
2139  gdImageLine (im, fx, fy, lx, ly, color);
2140  } else {
2141  pts[0].x = fx;
2142  pts[0].y = fy;
2143  pts[1].x = lx;
2144  pts[1].y = ly;
2145  pts[2].x = cx;
2146  pts[2].y = cy;
2147  gdImageFilledPolygon (im, pts, 3, color);
2148  }
2149  } else {
2150  if (style & gdNoFill) {
2151  if (style & gdEdged) {
2152  gdImageLine (im, cx, cy, lx, ly, color);
2153  gdImageLine (im, cx, cy, fx, fy, color);
2154  }
2155  } else {
2156  if (e - s < 360) {
2157  if (pts[1].x != startx && pts[1].y == starty) {
2158  /* start point has been removed due to y-coord fix => insert it */
2159  for (i = pti; i > 1; i--) {
2160  pts[i].x = pts[i-1].x;
2161  pts[i].y = pts[i-1].y;
2162  }
2163  pts[1].x = startx;
2164  pts[1].y = starty;
2165  pti++;
2166  }
2167  if (pts[pti-1].x != endx && pts[pti-1].y == endy) {
2168  /* end point has been removed due to y-coord fix => insert it */
2169  pts[pti].x = endx;
2170  pts[pti].y = endy;
2171  pti++;
2172  }
2173  }
2174  pts[pti].x = cx;
2175  pts[pti].y = cy;
2176  gdImageFilledPolygon(im, pts, pti+1, color);
2177  }
2178  }
2179 }
2180 
2181 /*
2182  Function: gdImageEllipse
2183 */
2184 BGD_DECLARE(void) gdImageEllipse(gdImagePtr im, int mx, int my, int w, int h, int c)
2185 {
2186  int x=0,mx1=0,mx2=0,my1=0,my2=0;
2187  int64_t aq,bq,dx,dy,r,rx,ry,a,b;
2188 
2189  a=w>>1;
2190  b=h>>1;
2191  gdImageSetPixel(im,mx+a, my, c);
2192  gdImageSetPixel(im,mx-a, my, c);
2193  mx1 = mx-a;
2194  my1 = my;
2195  mx2 = mx+a;
2196  my2 = my;
2197 
2198  aq = a * a;
2199  bq = b * b;
2200  dx = aq << 1;
2201  dy = bq << 1;
2202  r = a * bq;
2203  rx = r << 1;
2204  ry = 0;
2205  x = a;
2206  while (x > 0) {
2207  if (r > 0) {
2208  my1++;
2209  my2--;
2210  ry +=dx;
2211  r -=ry;
2212  }
2213  if (r <= 0) {
2214  x--;
2215  mx1++;
2216  mx2--;
2217  rx -=dy;
2218  r +=rx;
2219  }
2220  gdImageSetPixel(im,mx1, my1, c);
2221  gdImageSetPixel(im,mx1, my2, c);
2222  gdImageSetPixel(im,mx2, my1, c);
2223  gdImageSetPixel(im,mx2, my2, c);
2224  }
2225 }
2226 
2227 
2228 /*
2229  Function: gdImageFilledEllipse
2230 */
2231 BGD_DECLARE(void) gdImageFilledEllipse (gdImagePtr im, int mx, int my, int w, int h, int c)
2232 {
2233  int x=0,mx1=0,mx2=0,my1=0,my2=0;
2234  int64_t aq,bq,dx,dy,r,rx,ry,a,b;
2235  int i;
2236  int old_y2;
2237 
2238  a=w>>1;
2239  b=h>>1;
2240 
2241  for (x = mx-a; x <= mx+a; x++) {
2242  gdImageSetPixel(im, x, my, c);
2243  }
2244 
2245  mx1 = mx-a;
2246  my1 = my;
2247  mx2 = mx+a;
2248  my2 = my;
2249 
2250  aq = a * a;
2251  bq = b * b;
2252  dx = aq << 1;
2253  dy = bq << 1;
2254  r = a * bq;
2255  rx = r << 1;
2256  ry = 0;
2257  x = a;
2258  old_y2=-2;
2259  while (x > 0) {
2260  if (r > 0) {
2261  my1++;
2262  my2--;
2263  ry +=dx;
2264  r -=ry;
2265  }
2266  if (r <= 0) {
2267  x--;
2268  mx1++;
2269  mx2--;
2270  rx -=dy;
2271  r +=rx;
2272  }
2273 
2274  if(old_y2!=my2) {
2275  for(i=mx1; i<=mx2; i++) {
2276  gdImageSetPixel(im,i,my2,c);
2277  gdImageSetPixel(im,i,my1,c);
2278  }
2279  }
2280  old_y2 = my2;
2281  }
2282 }
2283 
2284 /*
2285  Function: gdImageFillToBorder
2286 */
2287 BGD_DECLARE(void) gdImageFillToBorder (gdImagePtr im, int x, int y, int border, int color)
2288 {
2289  int lastBorder;
2290  /* Seek left */
2291  int leftLimit, rightLimit;
2292  int i;
2293  int restoreAlphaBleding;
2294 
2295  if (border < 0 || color < 0) {
2296  /* Refuse to fill to a non-solid border */
2297  return;
2298  }
2299 
2300  if (!im->trueColor) {
2301  if (color > (im->colorsTotal - 1) || border > (im->colorsTotal - 1)) {
2302  return;
2303  }
2304  }
2305 
2306  leftLimit = (-1);
2307 
2308  restoreAlphaBleding = im->alphaBlendingFlag;
2309  im->alphaBlendingFlag = 0;
2310 
2311  if (x >= im->sx) {
2312  x = im->sx - 1;
2313  } else if (x < 0) {
2314  x = 0;
2315  }
2316  if (y >= im->sy) {
2317  y = im->sy - 1;
2318  } else if (y < 0) {
2319  y = 0;
2320  }
2321 
2322  for (i = x; (i >= 0); i--) {
2323  if (gdImageGetPixel (im, i, y) == border) {
2324  break;
2325  }
2326  gdImageSetPixel (im, i, y, color);
2327  leftLimit = i;
2328  }
2329  if (leftLimit == (-1)) {
2330  im->alphaBlendingFlag = restoreAlphaBleding;
2331  return;
2332  }
2333  /* Seek right */
2334  rightLimit = x;
2335  for (i = (x + 1); (i < im->sx); i++) {
2336  if (gdImageGetPixel (im, i, y) == border) {
2337  break;
2338  }
2339  gdImageSetPixel (im, i, y, color);
2340  rightLimit = i;
2341  }
2342  /* Look at lines above and below and start paints */
2343  /* Above */
2344  if (y > 0) {
2345  lastBorder = 1;
2346  for (i = leftLimit; (i <= rightLimit); i++) {
2347  int c;
2348  c = gdImageGetPixel (im, i, y - 1);
2349  if (lastBorder) {
2350  if ((c != border) && (c != color)) {
2351  gdImageFillToBorder (im, i, y - 1, border, color);
2352  lastBorder = 0;
2353  }
2354  } else if ((c == border) || (c == color)) {
2355  lastBorder = 1;
2356  }
2357  }
2358  }
2359  /* Below */
2360  if (y < ((im->sy) - 1)) {
2361  lastBorder = 1;
2362  for (i = leftLimit; (i <= rightLimit); i++) {
2363  int c = gdImageGetPixel (im, i, y + 1);
2364  if (lastBorder) {
2365  if ((c != border) && (c != color)) {
2366  gdImageFillToBorder (im, i, y + 1, border, color);
2367  lastBorder = 0;
2368  }
2369  } else if ((c == border) || (c == color)) {
2370  lastBorder = 1;
2371  }
2372  }
2373  }
2374  im->alphaBlendingFlag = restoreAlphaBleding;
2375 }
2376 
2377 /*
2378  * set the pixel at (x,y) and its 4-connected neighbors
2379  * with the same pixel value to the new pixel value nc (new color).
2380  * A 4-connected neighbor: pixel above, below, left, or right of a pixel.
2381  * ideas from comp.graphics discussions.
2382  * For tiled fill, the use of a flag buffer is mandatory. As the tile image can
2383  * contain the same color as the color to fill. To do not bloat normal filling
2384  * code I added a 2nd private function.
2385  */
2386 
2387 static int gdImageTileGet (gdImagePtr im, int x, int y)
2388 {
2389  int srcx, srcy;
2390  int tileColor,p;
2391  if (!im->tile) {
2392  return -1;
2393  }
2394  srcx = x % gdImageSX(im->tile);
2395  srcy = y % gdImageSY(im->tile);
2396  p = gdImageGetPixel(im->tile, srcx, srcy);
2397  if (p == im->tile->transparent) {
2398  tileColor = im->transparent;
2399  } else if (im->trueColor) {
2400  if (im->tile->trueColor) {
2401  tileColor = p;
2402  } else {
2403  tileColor = gdTrueColorAlpha( gdImageRed(im->tile,p), gdImageGreen(im->tile,p), gdImageBlue (im->tile,p), gdImageAlpha (im->tile,p));
2404  }
2405  } else {
2406  if (im->tile->trueColor) {
2408  } else {
2409  tileColor = gdImageColorResolveAlpha(im, gdImageRed (im->tile,p), gdImageGreen (im->tile,p), gdImageBlue (im->tile,p), gdImageAlpha (im->tile,p));
2410  }
2411  }
2412  return tileColor;
2413 }
2414 
2415 
2416 
2417 /* horizontal segment of scan line y */
2418 struct seg {
2419  int y, xl, xr, dy;
2420 };
2421 
2422 /* max depth of stack */
2423 #define FILL_MAX ((int)(im->sy*im->sx)/4)
2424 #define FILL_PUSH(Y, XL, XR, DY) \
2425  if (sp<stack+FILL_MAX && Y+(DY)>=0 && Y+(DY)<wy2) \
2426  {sp->y = Y; sp->xl = XL; sp->xr = XR; sp->dy = DY; sp++;}
2427 
2428 #define FILL_POP(Y, XL, XR, DY) \
2429  {sp--; Y = sp->y+(DY = sp->dy); XL = sp->xl; XR = sp->xr;}
2430 
2431 static void _gdImageFillTiled(gdImagePtr im, int x, int y, int nc);
2432 
2433 /*
2434  Function: gdImageFill
2435 */
2436 BGD_DECLARE(void) gdImageFill(gdImagePtr im, int x, int y, int nc)
2437 {
2438  int l, x1, x2, dy;
2439  int oc; /* old pixel value */
2440  int wx2,wy2;
2441 
2442  int alphablending_bak;
2443 
2444  /* stack of filled segments */
2445  /* struct seg stack[FILL_MAX],*sp = stack; */
2446  struct seg *stack;
2447  struct seg *sp;
2448 
2449  if (!im->trueColor && nc > (im->colorsTotal - 1)) {
2450  return;
2451  }
2452 
2453  alphablending_bak = im->alphaBlendingFlag;
2454  im->alphaBlendingFlag = 0;
2455 
2456  if (nc==gdTiled) {
2457  _gdImageFillTiled(im,x,y,nc);
2458  im->alphaBlendingFlag = alphablending_bak;
2459  return;
2460  }
2461 
2462  wx2=im->sx;
2463  wy2=im->sy;
2464  oc = gdImageGetPixel(im, x, y);
2465  if (oc==nc || x<0 || x>wx2 || y<0 || y>wy2) {
2466  im->alphaBlendingFlag = alphablending_bak;
2467  return;
2468  }
2469 
2470  /* Do not use the 4 neighbors implementation with
2471  * small images
2472  */
2473  if (im->sx < 4) {
2474  int ix = x, iy = y, c;
2475  do {
2476  do {
2477  c = gdImageGetPixel(im, ix, iy);
2478  if (c != oc) {
2479  goto done;
2480  }
2481  gdImageSetPixel(im, ix, iy, nc);
2482  } while(ix++ < (im->sx -1));
2483  ix = x;
2484  } while(iy++ < (im->sy -1));
2485  goto done;
2486  }
2487 
2488  if(overflow2(im->sy, im->sx)) {
2489  return;
2490  }
2491 
2492  if(overflow2(sizeof(struct seg), ((im->sy * im->sx) / 4))) {
2493  return;
2494  }
2495 
2496  stack = (struct seg *)gdMalloc(sizeof(struct seg) * ((int)(im->sy*im->sx)/4));
2497  if (!stack) {
2498  return;
2499  }
2500  sp = stack;
2501 
2502  /* required! */
2503  FILL_PUSH(y,x,x,1);
2504  /* seed segment (popped 1st) */
2505  FILL_PUSH(y+1, x, x, -1);
2506  while (sp>stack) {
2507  FILL_POP(y, x1, x2, dy);
2508 
2509  for (x=x1; x>=0 && gdImageGetPixel(im,x, y)==oc; x--) {
2510  gdImageSetPixel(im,x, y, nc);
2511  }
2512  if (x>=x1) {
2513  goto skip;
2514  }
2515  l = x+1;
2516 
2517  /* leak on left? */
2518  if (l<x1) {
2519  FILL_PUSH(y, l, x1-1, -dy);
2520  }
2521  x = x1+1;
2522  do {
2523  for (; x<=wx2 && gdImageGetPixel(im,x, y)==oc; x++) {
2524  gdImageSetPixel(im, x, y, nc);
2525  }
2526  FILL_PUSH(y, l, x-1, dy);
2527  /* leak on right? */
2528  if (x>x2+1) {
2529  FILL_PUSH(y, x2+1, x-1, -dy);
2530  }
2531 skip:
2532  for (x++; x<=x2 && (gdImageGetPixel(im, x, y)!=oc); x++);
2533 
2534  l = x;
2535  } while (x<=x2);
2536  }
2537 
2538  gdFree(stack);
2539 
2540 done:
2541  im->alphaBlendingFlag = alphablending_bak;
2542 }
2543 
2544 static void _gdImageFillTiled(gdImagePtr im, int x, int y, int nc)
2545 {
2546  int l, x1, x2, dy;
2547  int oc; /* old pixel value */
2548  int wx2,wy2;
2549  /* stack of filled segments */
2550  struct seg *stack;
2551  struct seg *sp;
2552  char *pts;
2553 
2554  if (!im->tile) {
2555  return;
2556  }
2557 
2558  wx2=im->sx;
2559  wy2=im->sy;
2560 
2561  if(overflow2(im->sy, im->sx)) {
2562  return;
2563  }
2564 
2565  if(overflow2(sizeof(struct seg), ((im->sy * im->sx) / 4))) {
2566  return;
2567  }
2568 
2569  pts = (char *) gdCalloc(im->sy * im->sx, sizeof(char));
2570  if (!pts) {
2571  return;
2572  }
2573 
2574  stack = (struct seg *)gdMalloc(sizeof(struct seg) * ((int)(im->sy*im->sx)/4));
2575  if (!stack) {
2576  gdFree(pts);
2577  return;
2578  }
2579  sp = stack;
2580 
2581  oc = gdImageGetPixel(im, x, y);
2582 
2583  /* required! */
2584  FILL_PUSH(y,x,x,1);
2585  /* seed segment (popped 1st) */
2586  FILL_PUSH(y+1, x, x, -1);
2587  while (sp>stack) {
2588  FILL_POP(y, x1, x2, dy);
2589  for (x=x1; x>=0 && (!pts[y + x*wy2] && gdImageGetPixel(im,x,y)==oc); x--) {
2590  nc = gdImageTileGet(im,x,y);
2591  pts[y + x*wy2]=1;
2592  gdImageSetPixel(im,x, y, nc);
2593  }
2594  if (x>=x1) {
2595  goto skip;
2596  }
2597  l = x+1;
2598 
2599  /* leak on left? */
2600  if (l<x1) {
2601  FILL_PUSH(y, l, x1-1, -dy);
2602  }
2603  x = x1+1;
2604  do {
2605  for (; x<wx2 && (!pts[y + x*wy2] && gdImageGetPixel(im,x, y)==oc) ; x++) {
2606  if (pts[y + x*wy2]) {
2607  /* we should never be here */
2608  break;
2609  }
2610  nc = gdImageTileGet(im,x,y);
2611  pts[y + x*wy2]=1;
2612  gdImageSetPixel(im, x, y, nc);
2613  }
2614  FILL_PUSH(y, l, x-1, dy);
2615  /* leak on right? */
2616  if (x>x2+1) {
2617  FILL_PUSH(y, x2+1, x-1, -dy);
2618  }
2619 skip:
2620  for (x++; x<=x2 && (pts[y + x*wy2] || gdImageGetPixel(im,x, y)!=oc); x++);
2621  l = x;
2622  } while (x<=x2);
2623  }
2624 
2625  gdFree(pts);
2626  gdFree(stack);
2627 }
2628 
2629 /**
2630  * Function: gdImageRectangle
2631  *
2632  * Draws a rectangle.
2633  *
2634  * Parameters:
2635  * im - The image.
2636  * x1 - The x-coordinate of one of the corners.
2637  * y1 - The y-coordinate of one of the corners.
2638  * x2 - The x-coordinate of another corner.
2639  * y2 - The y-coordinate of another corner.
2640  * color - The color.
2641  *
2642  * See also:
2643  * - <gdImageFilledRectangle>
2644  */
2645 BGD_DECLARE(void) gdImageRectangle (gdImagePtr im, int x1, int y1, int x2, int y2, int color)
2646 {
2647  int thick = im->thick;
2648 
2649  if (x1 == x2 && y1 == y2 && thick == 1) {
2650  gdImageSetPixel(im, x1, y1, color);
2651  return;
2652  }
2653 
2654  if (y2 < y1) {
2655  int t = y1;
2656  y1 = y2;
2657  y2 = t;
2658  }
2659 
2660  if (x2 < x1) {
2661  int t = x1;
2662  x1 = x2;
2663  x2 = t;
2664  }
2665 
2666  if (thick > 1) {
2667  int cx, cy, x1ul, y1ul, x2lr, y2lr;
2668  int half = thick >> 1;
2669  x1ul = x1 - half;
2670  y1ul = y1 - half;
2671 
2672  x2lr = x2 + half;
2673  y2lr = y2 + half;
2674 
2675  cy = y1ul + thick;
2676  while (cy-- > y1ul) {
2677  cx = x1ul - 1;
2678  while (cx++ < x2lr) {
2679  gdImageSetPixel(im, cx, cy, color);
2680  }
2681  }
2682 
2683  cy = y2lr - thick;
2684  while (cy++ < y2lr) {
2685  cx = x1ul - 1;
2686  while (cx++ < x2lr) {
2687  gdImageSetPixel(im, cx, cy, color);
2688  }
2689  }
2690 
2691  cy = y1ul + thick - 1;
2692  while (cy++ < y2lr -thick) {
2693  cx = x1ul - 1;
2694  while (cx++ < x1ul + thick) {
2695  gdImageSetPixel(im, cx, cy, color);
2696  }
2697  }
2698 
2699  cy = y1ul + thick - 1;
2700  while (cy++ < y2lr -thick) {
2701  cx = x2lr - thick - 1;
2702  while (cx++ < x2lr) {
2703  gdImageSetPixel(im, cx, cy, color);
2704  }
2705  }
2706 
2707  return;
2708  } else {
2709  if (x1 == x2 || y1 == y2) {
2710  gdImageLine(im, x1, y1, x2, y2, color);
2711  } else {
2712  gdImageLine(im, x1, y1, x2, y1, color);
2713  gdImageLine(im, x1, y2, x2, y2, color);
2714  gdImageLine(im, x1, y1 + 1, x1, y2 - 1, color);
2715  gdImageLine(im, x2, y1 + 1, x2, y2 - 1, color);
2716  }
2717  }
2718 }
2719 
2720 static void _gdImageFilledHRectangle (gdImagePtr im, int x1, int y1, int x2, int y2,
2721  int color)
2722 {
2723  int x, y;
2724 
2725  if (x1 == x2 && y1 == y2) {
2726  gdImageSetPixel(im, x1, y1, color);
2727  return;
2728  }
2729 
2730  if (x1 > x2) {
2731  x = x1;
2732  x1 = x2;
2733  x2 = x;
2734  }
2735 
2736  if (y1 > y2) {
2737  y = y1;
2738  y1 = y2;
2739  y2 = y;
2740  }
2741 
2742  if (x1 < 0) {
2743  x1 = 0;
2744  }
2745 
2746  if (x2 >= gdImageSX(im)) {
2747  x2 = gdImageSX(im) - 1;
2748  }
2749 
2750  if (y1 < 0) {
2751  y1 = 0;
2752  }
2753 
2754  if (y2 >= gdImageSY(im)) {
2755  y2 = gdImageSY(im) - 1;
2756  }
2757 
2758  for (x = x1; (x <= x2); x++) {
2759  for (y = y1; (y <= y2); y++) {
2760  gdImageSetPixel (im, x, y, color);
2761  }
2762  }
2763 }
2764 
2765 static void _gdImageFilledVRectangle (gdImagePtr im, int x1, int y1, int x2, int y2,
2766  int color)
2767 {
2768  int x, y;
2769 
2770  if (x1 == x2 && y1 == y2) {
2771  gdImageSetPixel(im, x1, y1, color);
2772  return;
2773  }
2774 
2775  if (x1 > x2) {
2776  x = x1;
2777  x1 = x2;
2778  x2 = x;
2779  }
2780 
2781  if (y1 > y2) {
2782  y = y1;
2783  y1 = y2;
2784  y2 = y;
2785  }
2786 
2787  if (x1 < 0) {
2788  x1 = 0;
2789  }
2790 
2791  if (x2 >= gdImageSX(im)) {
2792  x2 = gdImageSX(im) - 1;
2793  }
2794 
2795  if (y1 < 0) {
2796  y1 = 0;
2797  }
2798 
2799  if (y2 >= gdImageSY(im)) {
2800  y2 = gdImageSY(im) - 1;
2801  }
2802 
2803  for (y = y1; (y <= y2); y++) {
2804  for (x = x1; (x <= x2); x++) {
2805  gdImageSetPixel (im, x, y, color);
2806  }
2807  }
2808 }
2809 
2810 /*
2811  Function: gdImageFilledRectangle
2812 */
2813 BGD_DECLARE(void) gdImageFilledRectangle (gdImagePtr im, int x1, int y1, int x2, int y2,
2814  int color)
2815 {
2817 }
2818 
2819 /**
2820  * Group: Cloning and Copying
2821  */
2822 
2823 /**
2824  * Function: gdImageClone
2825  *
2826  * Clones an image
2827  *
2828  * Creates an exact duplicate of the given image.
2829  *
2830  * Parameters:
2831  * src - The source image.
2832  *
2833  * Returns:
2834  * The cloned image on success, NULL on failure.
2835  */
2837  gdImagePtr dst;
2838  register int i, x;
2839 
2840  if (src->trueColor) {
2841  dst = gdImageCreateTrueColor(src->sx , src->sy);
2842  } else {
2843  dst = gdImageCreate(src->sx , src->sy);
2844  }
2845 
2846  if (dst == NULL) {
2847  return NULL;
2848  }
2849 
2850  if (src->trueColor == 0) {
2851  dst->colorsTotal = src->colorsTotal;
2852  for (i = 0; i < gdMaxColors; i++) {
2853  dst->red[i] = src->red[i];
2854  dst->green[i] = src->green[i];
2855  dst->blue[i] = src->blue[i];
2856  dst->alpha[i] = src->alpha[i];
2857  dst->open[i] = src->open[i];
2858  }
2859  for (i = 0; i < src->sy; i++) {
2860  for (x = 0; x < src->sx; x++) {
2861  dst->pixels[i][x] = src->pixels[i][x];
2862  }
2863  }
2864  } else {
2865  for (i = 0; i < src->sy; i++) {
2866  for (x = 0; x < src->sx; x++) {
2867  dst->tpixels[i][x] = src->tpixels[i][x];
2868  }
2869  }
2870  }
2871 
2872  dst->interlace = src->interlace;
2873 
2874  dst->alphaBlendingFlag = src->alphaBlendingFlag;
2875  dst->saveAlphaFlag = src->saveAlphaFlag;
2876  dst->AA = src->AA;
2877  dst->AA_color = src->AA_color;
2878  dst->AA_dont_blend = src->AA_dont_blend;
2879 
2880  dst->cx1 = src->cx1;
2881  dst->cy1 = src->cy1;
2882  dst->cx2 = src->cx2;
2883  dst->cy2 = src->cy2;
2884 
2885  dst->res_x = src->res_x;
2886  dst->res_y = src->res_y;
2887 
2888  dst->paletteQuantizationMethod = src->paletteQuantizationMethod;
2889  dst->paletteQuantizationSpeed = src->paletteQuantizationSpeed;
2890  dst->paletteQuantizationMinQuality = src->paletteQuantizationMinQuality;
2891  dst->paletteQuantizationMinQuality = src->paletteQuantizationMinQuality;
2892 
2893  dst->interpolation_id = src->interpolation_id;
2894  dst->interpolation = src->interpolation;
2895 
2896  if (src->brush) {
2897  dst->brush = gdImageClone(src->brush);
2898  }
2899 
2900  if (src->tile) {
2901  dst->tile = gdImageClone(src->tile);
2902  }
2903 
2904  if (src->style) {
2905  gdImageSetStyle(dst, src->style, src->styleLength);
2906  dst->stylePos = src->stylePos;
2907  }
2908 
2909  for (i = 0; i < gdMaxColors; i++) {
2910  dst->brushColorMap[i] = src->brushColorMap[i];
2911  dst->tileColorMap[i] = src->tileColorMap[i];
2912  }
2913 
2914  if (src->polyAllocated > 0) {
2915  dst->polyAllocated = src->polyAllocated;
2916  for (i = 0; i < src->polyAllocated; i++) {
2917  dst->polyInts[i] = src->polyInts[i];
2918  }
2919  }
2920 
2921  return dst;
2922 }
2923 
2924 /**
2925  * Function: gdImageCopy
2926  *
2927  * Copy an area of an image to another image
2928  *
2929  * Parameters:
2930  * dst - The destination image.
2931  * src - The source image.
2932  * dstX - The x-coordinate of the upper left corner to copy to.
2933  * dstY - The y-coordinate of the upper left corner to copy to.
2934  * srcX - The x-coordinate of the upper left corner to copy from.
2935  * srcY - The y-coordinate of the upper left corner to copy from.
2936  * w - The width of the area to copy.
2937  * h - The height of the area to copy.
2938  *
2939  * See also:
2940  * - <gdImageCopyMerge>
2941  * - <gdImageCopyMergeGray>
2942  */
2943 BGD_DECLARE(void) gdImageCopy (gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX,
2944  int srcY, int w, int h)
2945 {
2946  int c;
2947  int x, y;
2948  int tox, toy;
2949  int i;
2950  int colorMap[gdMaxColors];
2951 
2952  if (dst->trueColor) {
2953  /* 2.0: much easier when the destination is truecolor. */
2954  /* 2.0.10: needs a transparent-index check that is still valid if
2955  * * the source is not truecolor. Thanks to Frank Warmerdam.
2956  */
2957 
2958  if (src->trueColor) {
2959  for (y = 0; (y < h); y++) {
2960  for (x = 0; (x < w); x++) {
2961  int c = gdImageGetTrueColorPixel (src, srcX + x, srcY + y);
2962  if (c != src->transparent) {
2963  gdImageSetPixel (dst, dstX + x, dstY + y, c);
2964  }
2965  }
2966  }
2967  } else {
2968  /* source is palette based */
2969  for (y = 0; (y < h); y++) {
2970  for (x = 0; (x < w); x++) {
2971  int c = gdImageGetPixel (src, srcX + x, srcY + y);
2972  if (c != src->transparent) {
2973  gdImageSetPixel(dst, dstX + x, dstY + y, gdTrueColorAlpha(src->red[c], src->green[c], src->blue[c], src->alpha[c]));
2974  }
2975  }
2976  }
2977  }
2978  return;
2979  }
2980 
2981  for (i = 0; (i < gdMaxColors); i++) {
2982  colorMap[i] = (-1);
2983  }
2984  toy = dstY;
2985  for (y = srcY; (y < (srcY + h)); y++) {
2986  tox = dstX;
2987  for (x = srcX; (x < (srcX + w)); x++) {
2988  int nc;
2989  int mapTo;
2990  c = gdImageGetPixel (src, x, y);
2991  /* Added 7/24/95: support transparent copies */
2992  if (gdImageGetTransparent (src) == c) {
2993  tox++;
2994  continue;
2995  }
2996  /* Have we established a mapping for this color? */
2997  if (src->trueColor) {
2998  /* 2.05: remap to the palette available in the
2999  destination image. This is slow and
3000  works badly, but it beats crashing! Thanks
3001  to Padhrig McCarthy. */
3002  mapTo = gdImageColorResolveAlpha (dst,
3003  gdTrueColorGetRed (c),
3007  } else if (colorMap[c] == (-1)) {
3008  /* If it's the same image, mapping is trivial */
3009  if (dst == src) {
3010  nc = c;
3011  } else {
3012  /* Get best match possible. This
3013  function never returns error. */
3015  src->red[c], src->green[c],
3016  src->blue[c], src->alpha[c]);
3017  }
3018  colorMap[c] = nc;
3019  mapTo = colorMap[c];
3020  } else {
3021  mapTo = colorMap[c];
3022  }
3023  gdImageSetPixel (dst, tox, toy, mapTo);
3024  tox++;
3025  }
3026  toy++;
3027  }
3028 }
3029 
3030 /**
3031  * Function: gdImageCopyMerge
3032  *
3033  * Copy an area of an image to another image ignoring alpha
3034  *
3035  * The source area will be copied to the destination are by merging the pixels.
3036  *
3037  * Note:
3038  * This function is a substitute for real alpha channel operations,
3039  * so it doesn't pay attention to the alpha channel.
3040  *
3041  * Parameters:
3042  * dst - The destination image.
3043  * src - The source image.
3044  * dstX - The x-coordinate of the upper left corner to copy to.
3045  * dstY - The y-coordinate of the upper left corner to copy to.
3046  * srcX - The x-coordinate of the upper left corner to copy from.
3047  * srcY - The y-coordinate of the upper left corner to copy from.
3048  * w - The width of the area to copy.
3049  * h - The height of the area to copy.
3050  * pct - The percentage in range 0..100.
3051  *
3052  * See also:
3053  * - <gdImageCopy>
3054  * - <gdImageCopyMergeGray>
3055  */
3057  int srcX, int srcY, int w, int h, int pct)
3058 {
3059 
3060  int c, dc;
3061  int x, y;
3062  int tox, toy;
3063  int ncR, ncG, ncB;
3064  toy = dstY;
3065  for (y = srcY; (y < (srcY + h)); y++) {
3066  tox = dstX;
3067  for (x = srcX; (x < (srcX + w)); x++) {
3068  int nc;
3069  c = gdImageGetPixel (src, x, y);
3070  /* Added 7/24/95: support transparent copies */
3071  if (gdImageGetTransparent (src) == c) {
3072  tox++;
3073  continue;
3074  }
3075  /* If it's the same image, mapping is trivial */
3076  if (dst == src) {
3077  nc = c;
3078  } else {
3079  dc = gdImageGetPixel (dst, tox, toy);
3080 
3081  ncR = gdImageRed (src, c) * (pct / 100.0)
3082  + gdImageRed (dst, dc) * ((100 - pct) / 100.0);
3083  ncG = gdImageGreen (src, c) * (pct / 100.0)
3084  + gdImageGreen (dst, dc) * ((100 - pct) / 100.0);
3085  ncB = gdImageBlue (src, c) * (pct / 100.0)
3086  + gdImageBlue (dst, dc) * ((100 - pct) / 100.0);
3087 
3088  /* Find a reasonable color */
3089  nc = gdImageColorResolve (dst, ncR, ncG, ncB);
3090  }
3091  gdImageSetPixel (dst, tox, toy, nc);
3092  tox++;
3093  }
3094  toy++;
3095  }
3096 }
3097 
3098 /**
3099  * Function: gdImageCopyMergeGray
3100  *
3101  * Copy an area of an image to another image ignoring alpha
3102  *
3103  * The source area will be copied to the grayscaled destination area by merging
3104  * the pixels.
3105  *
3106  * Note:
3107  * This function is a substitute for real alpha channel operations,
3108  * so it doesn't pay attention to the alpha channel.
3109  *
3110  * Parameters:
3111  * dst - The destination image.
3112  * src - The source image.
3113  * dstX - The x-coordinate of the upper left corner to copy to.
3114  * dstY - The y-coordinate of the upper left corner to copy to.
3115  * srcX - The x-coordinate of the upper left corner to copy from.
3116  * srcY - The y-coordinate of the upper left corner to copy from.
3117  * w - The width of the area to copy.
3118  * h - The height of the area to copy.
3119  * pct - The percentage of the source color intensity in range 0..100.
3120  *
3121  * See also:
3122  * - <gdImageCopy>
3123  * - <gdImageCopyMerge>
3124  */
3126  int srcX, int srcY, int w, int h, int pct)
3127 {
3128 
3129  int c, dc;
3130  int x, y;
3131  int tox, toy;
3132  int ncR, ncG, ncB;
3133  float g;
3134  toy = dstY;
3135  for (y = srcY; (y < (srcY + h)); y++) {
3136  tox = dstX;
3137  for (x = srcX; (x < (srcX + w)); x++) {
3138  int nc;
3139  c = gdImageGetPixel (src, x, y);
3140  /* Added 7/24/95: support transparent copies */
3141  if (gdImageGetTransparent (src) == c) {
3142  tox++;
3143  continue;
3144  }
3145  /*
3146  * If it's the same image, mapping is NOT trivial since we
3147  * merge with greyscale target, but if pct is 100, the grey
3148  * value is not used, so it becomes trivial. pjw 2.0.12.
3149  */
3150  if (dst == src && pct == 100) {
3151  nc = c;
3152  } else {
3153  dc = gdImageGetPixel (dst, tox, toy);
3154  g = 0.29900 * gdImageRed(dst, dc)
3155  + 0.58700 * gdImageGreen(dst, dc) + 0.11400 * gdImageBlue(dst, dc);
3156 
3157  ncR = gdImageRed (src, c) * (pct / 100.0)
3158  + g * ((100 - pct) / 100.0);
3159  ncG = gdImageGreen (src, c) * (pct / 100.0)
3160  + g * ((100 - pct) / 100.0);
3161  ncB = gdImageBlue (src, c) * (pct / 100.0)
3162  + g * ((100 - pct) / 100.0);
3163 
3164  /* First look for an exact match */
3165  nc = gdImageColorExact (dst, ncR, ncG, ncB);
3166  if (nc == (-1)) {
3167  /* No, so try to allocate it */
3168  nc = gdImageColorAllocate (dst, ncR, ncG, ncB);
3169  /* If we're out of colors, go for the
3170  closest color */
3171  if (nc == (-1)) {
3172  nc = gdImageColorClosest (dst, ncR, ncG, ncB);
3173  }
3174  }
3175  }
3176  gdImageSetPixel (dst, tox, toy, nc);
3177  tox++;
3178  }
3179  toy++;
3180  }
3181 }
3182 
3183 /**
3184  * Function: gdImageCopyResized
3185  *
3186  * Copy a resized area from an image to another image
3187  *
3188  * If the source and destination area differ in size, the area will be resized
3189  * using nearest-neighbor interpolation.
3190  *
3191  * Parameters:
3192  * dst - The destination image.
3193  * src - The source image.
3194  * dstX - The x-coordinate of the upper left corner to copy to.
3195  * dstY - The y-coordinate of the upper left corner to copy to.
3196  * srcX - The x-coordinate of the upper left corner to copy from.
3197  * srcY - The y-coordinate of the upper left corner to copy from.
3198  * dstW - The width of the area to copy to.
3199  * dstH - The height of the area to copy to.
3200  * srcW - The width of the area to copy from.
3201  * srcH - The height of the area to copy from.
3202  *
3203  * See also:
3204  * - <gdImageCopyResampled>
3205  * - <gdImageScale>
3206  */
3208  int srcX, int srcY, int dstW, int dstH, int srcW,
3209  int srcH)
3210 {
3211  int c;
3212  int x, y;
3213  int tox, toy;
3214  int ydest;
3215  int i;
3216  int colorMap[gdMaxColors];
3217  /* Stretch vectors */
3218  int *stx;
3219  int *sty;
3220  /* We only need to use floating point to determine the correct
3221  stretch vector for one line's worth. */
3222  if (overflow2(sizeof (int), srcW)) {
3223  return;
3224  }
3225  if (overflow2(sizeof (int), srcH)) {
3226  return;
3227  }
3228  stx = (int *) gdMalloc (sizeof (int) * srcW);
3229  if (!stx) {
3230  return;
3231  }
3232 
3233  sty = (int *) gdMalloc (sizeof (int) * srcH);
3234  if (!sty) {
3235  gdFree(stx);
3236  return;
3237  }
3238 
3239  /* Fixed by Mao Morimoto 2.0.16 */
3240  for (i = 0; (i < srcW); i++) {
3241  stx[i] = dstW * (i + 1) / srcW - dstW * i / srcW;
3242  }
3243  for (i = 0; (i < srcH); i++) {
3244  sty[i] = dstH * (i + 1) / srcH - dstH * i / srcH;
3245  }
3246  for (i = 0; (i < gdMaxColors); i++) {
3247  colorMap[i] = (-1);
3248  }
3249  toy = dstY;
3250  for (y = srcY; (y < (srcY + srcH)); y++) {
3251  for (ydest = 0; (ydest < sty[y - srcY]); ydest++) {
3252  tox = dstX;
3253  for (x = srcX; (x < (srcX + srcW)); x++) {
3254  int nc = 0;
3255  int mapTo;
3256  if (!stx[x - srcX]) {
3257  continue;
3258  }
3259  if (dst->trueColor) {
3260  /* 2.0.9: Thorben Kundinger: Maybe the source image is not
3261  a truecolor image */
3262  if (!src->trueColor) {
3263  int tmp = gdImageGetPixel (src, x, y);
3264  mapTo = gdImageGetTrueColorPixel (src, x, y);
3265  if (gdImageGetTransparent (src) == tmp) {
3266  /* 2.0.21, TK: not tox++ */
3267  tox += stx[x - srcX];
3268  continue;
3269  }
3270  } else {
3271  /* TK: old code follows */
3272  mapTo = gdImageGetTrueColorPixel (src, x, y);
3273  /* Added 7/24/95: support transparent copies */
3274  if (gdImageGetTransparent (src) == mapTo) {
3275  /* 2.0.21, TK: not tox++ */
3276  tox += stx[x - srcX];
3277  continue;
3278  }
3279  }
3280  } else {
3281  c = gdImageGetPixel (src, x, y);
3282  /* Added 7/24/95: support transparent copies */
3283  if (gdImageGetTransparent (src) == c) {
3284  tox += stx[x - srcX];
3285  continue;
3286  }
3287  if (src->trueColor) {
3288  /* Remap to the palette available in the
3289  destination image. This is slow and
3290  works badly. */
3291  mapTo = gdImageColorResolveAlpha (dst,
3292  gdTrueColorGetRed (c),
3294  (c),
3296  (c),
3298  (c));
3299  } else {
3300  /* Have we established a mapping for this color? */
3301  if (colorMap[c] == (-1)) {
3302  /* If it's the same image, mapping is trivial */
3303  if (dst == src) {
3304  nc = c;
3305  } else {
3306  /* Find or create the best match */
3307  /* 2.0.5: can't use gdTrueColorGetRed, etc with palette */
3309  gdImageRed (src,
3310  c),
3311  gdImageGreen
3312  (src, c),
3313  gdImageBlue (src,
3314  c),
3315  gdImageAlpha
3316  (src, c));
3317  }
3318  colorMap[c] = nc;
3319  }
3320  mapTo = colorMap[c];
3321  }
3322  }
3323  for (i = 0; (i < stx[x - srcX]); i++) {
3324  gdImageSetPixel (dst, tox, toy, mapTo);
3325  tox++;
3326  }
3327  }
3328  toy++;
3329  }
3330  }
3331  gdFree (stx);
3332  gdFree (sty);
3333 }
3334 
3335 /**
3336  * Function: gdImageCopyRotated
3337  *
3338  * Copy a rotated area from an image to another image
3339  *
3340  * The area is counter-clockwise rotated using nearest-neighbor interpolation.
3341  *
3342  * Parameters:
3343  * dst - The destination image.
3344  * src - The source image.
3345  * dstX - The x-coordinate of the center of the area to copy to.
3346  * dstY - The y-coordinate of the center of the area to copy to.
3347  * srcX - The x-coordinate of the upper left corner to copy from.
3348  * srcY - The y-coordinate of the upper left corner to copy from.
3349  * srcW - The width of the area to copy from.
3350  * srcH - The height of the area to copy from.
3351  * angle - The angle in degrees.
3352  *
3353  * See also:
3354  * - <gdImageRotateInterpolated>
3355  */
3357  gdImagePtr src,
3358  double dstX, double dstY,
3359  int srcX, int srcY,
3360  int srcWidth, int srcHeight, int angle)
3361 {
3362  double dx, dy;
3363  double radius = sqrt (srcWidth * srcWidth + srcHeight * srcHeight);
3364  double aCos = cos (angle * .0174532925);
3365  double aSin = sin (angle * .0174532925);
3366  double scX = srcX + ((double) srcWidth) / 2;
3367  double scY = srcY + ((double) srcHeight) / 2;
3368  int cmap[gdMaxColors];
3369  int i;
3370 
3371  /*
3372  2.0.34: transparency preservation. The transparentness of
3373  the transparent color is more important than its hue.
3374  */
3375  if (src->transparent != -1) {
3376  if (dst->transparent == -1) {
3377  dst->transparent = src->transparent;
3378  }
3379  }
3380 
3381  for (i = 0; (i < gdMaxColors); i++) {
3382  cmap[i] = (-1);
3383  }
3384  for (dy = dstY - radius; (dy <= dstY + radius); dy++) {
3385  for (dx = dstX - radius; (dx <= dstX + radius); dx++) {
3386  double sxd = (dx - dstX) * aCos - (dy - dstY) * aSin;
3387  double syd = (dy - dstY) * aCos + (dx - dstX) * aSin;
3388  int sx = sxd + scX;
3389  int sy = syd + scY;
3390  if ((sx >= srcX) && (sx < srcX + srcWidth) &&
3391  (sy >= srcY) && (sy < srcY + srcHeight)) {
3392  int c = gdImageGetPixel (src, sx, sy);
3393  /* 2.0.34: transparency wins */
3394  if (c == src->transparent) {
3395  gdImageSetPixel (dst, dx, dy, dst->transparent);
3396  } else if (!src->trueColor) {
3397  /* Use a table to avoid an expensive
3398  lookup on every single pixel */
3399  if (cmap[c] == -1) {
3401  gdImageRed (src, c),
3402  gdImageGreen (src,
3403  c),
3404  gdImageBlue (src,
3405  c),
3406  gdImageAlpha (src,
3407  c));
3408  }
3409  gdImageSetPixel (dst, dx, dy, cmap[c]);
3410  } else {
3412  dx, dy,
3414  gdImageRed (src,
3415  c),
3416  gdImageGreen
3417  (src, c),
3418  gdImageBlue (src,
3419  c),
3420  gdImageAlpha
3421  (src, c)));
3422  }
3423  }
3424  }
3425  }
3426 }
3427 
3428 /* When gd 1.x was first created, floating point was to be avoided.
3429  These days it is often faster than table lookups or integer
3430  arithmetic. The routine below is shamelessly, gloriously
3431  floating point. TBB */
3432 
3433 /* 2.0.10: cast instead of floor() yields 35% performance improvement.
3434  Thanks to John Buckman. */
3435 
3436 #define floor2(exp) ((long) exp)
3437 /*#define floor2(exp) floor(exp)*/
3438 
3439 /**
3440  * Function: gdImageCopyResampled
3441  *
3442  * Copy a resampled area from an image to another image
3443  *
3444  * If the source and destination area differ in size, the area will be resized
3445  * using bilinear interpolation for truecolor images, and nearest-neighbor
3446  * interpolation for palette images.
3447  *
3448  * Parameters:
3449  * dst - The destination image.
3450  * src - The source image.
3451  * dstX - The x-coordinate of the upper left corner to copy to.
3452  * dstY - The y-coordinate of the upper left corner to copy to.
3453  * srcX - The x-coordinate of the upper left corner to copy from.
3454  * srcY - The y-coordinate of the upper left corner to copy from.
3455  * dstW - The width of the area to copy to.
3456  * dstH - The height of the area to copy to.
3457  * srcW - The width of the area to copy from.
3458  * srcH - The height of the area to copy from.
3459  *
3460  * See also:
3461  * - <gdImageCopyResized>
3462  * - <gdImageScale>
3463  */
3465  gdImagePtr src,
3466  int dstX, int dstY,
3467  int srcX, int srcY,
3468  int dstW, int dstH, int srcW, int srcH)
3469 {
3470  int x, y;
3471  if (!dst->trueColor) {
3472  gdImageCopyResized (dst, src, dstX, dstY, srcX, srcY, dstW, dstH, srcW, srcH);
3473  return;
3474  }
3475  for (y = dstY; (y < dstY + dstH); y++) {
3476  for (x = dstX; (x < dstX + dstW); x++) {
3477  float sy1, sy2, sx1, sx2;
3478  float sx, sy;
3479  float spixels = 0.0;
3480  float red = 0.0, green = 0.0, blue = 0.0, alpha = 0.0;
3481  float alpha_factor, alpha_sum = 0.0, contrib_sum = 0.0;
3482  sy1 = ((float)(y - dstY)) * (float)srcH / (float)dstH;
3483  sy2 = ((float)(y + 1 - dstY)) * (float) srcH / (float) dstH;
3484  sy = sy1;
3485  do {
3486  float yportion;
3487  if (floorf(sy) == floorf(sy1)) {
3488  yportion = 1.0 - (sy - floorf(sy));
3489  if (yportion > sy2 - sy1) {
3490  yportion = sy2 - sy1;
3491  }
3492  sy = floorf(sy);
3493  } else if (sy == floorf(sy2)) {
3494  yportion = sy2 - floorf(sy2);
3495  } else {
3496  yportion = 1.0;
3497  }
3498  sx1 = ((float)(x - dstX)) * (float) srcW / dstW;
3499  sx2 = ((float)(x + 1 - dstX)) * (float) srcW / dstW;
3500  sx = sx1;
3501  do {
3502  float xportion;
3503  float pcontribution;
3504  int p;
3505  if (floorf(sx) == floorf(sx1)) {
3506  xportion = 1.0 - (sx - floorf(sx));
3507  if (xportion > sx2 - sx1) {
3508  xportion = sx2 - sx1;
3509  }
3510  sx = floorf(sx);
3511  } else if (sx == floorf(sx2)) {
3512  xportion = sx2 - floorf(sx2);
3513  } else {
3514  xportion = 1.0;
3515  }
3516  pcontribution = xportion * yportion;
3517  p = gdImageGetTrueColorPixel(src, (int) sx + srcX, (int) sy + srcY);
3518 
3519  alpha_factor = ((gdAlphaMax - gdTrueColorGetAlpha(p))) * pcontribution;
3520  red += gdTrueColorGetRed (p) * alpha_factor;
3521  green += gdTrueColorGetGreen (p) * alpha_factor;
3522  blue += gdTrueColorGetBlue (p) * alpha_factor;
3523  alpha += gdTrueColorGetAlpha (p) * pcontribution;
3524  alpha_sum += alpha_factor;
3525  contrib_sum += pcontribution;
3526  spixels += xportion * yportion;
3527  sx += 1.0;
3528  }
3529  while (sx < sx2);
3530  sy += 1.0f;
3531  }
3532  while (sy < sy2);
3533 
3534  if (spixels != 0.0) {
3535  red /= spixels;
3536  green /= spixels;
3537  blue /= spixels;
3538  alpha /= spixels;
3539  }
3540  if ( alpha_sum != 0.0) {
3541  if( contrib_sum != 0.0) {
3542  alpha_sum /= contrib_sum;
3543  }
3544  red /= alpha_sum;
3545  green /= alpha_sum;
3546  blue /= alpha_sum;
3547  }
3548  /* Clamping to allow for rounding errors above */
3549  if (red > 255.0) {
3550  red = 255.0;
3551  }
3552  if (green > 255.0) {
3553  green = 255.0;
3554  }
3555  if (blue > 255.0f) {
3556  blue = 255.0;
3557  }
3558  if (alpha > gdAlphaMax) {
3559  alpha = gdAlphaMax;
3560  }
3561  gdImageSetPixel(dst, x, y, gdTrueColorAlpha ((int) red, (int) green, (int) blue, (int) alpha));
3562  }
3563  }
3564 }
3565 
3566 /**
3567  * Group: Polygons
3568  */
3569 
3570 /**
3571  * Function: gdImagePolygon
3572  *
3573  * Draws a closed polygon
3574  *
3575  * Parameters:
3576  * im - The image.
3577  * p - The vertices as array of <gdPoint>s.
3578  * n - The number of vertices.
3579  * c - The color.
3580  *
3581  * See also:
3582  * - <gdImageOpenPolygon>
3583  * - <gdImageFilledPolygon>
3584  */
3586 {
3587  if (n <= 0) {
3588  return;
3589  }
3590 
3591 
3592  gdImageLine (im, p->x, p->y, p[n - 1].x, p[n - 1].y, c);
3593  gdImageOpenPolygon (im, p, n, c);
3594 }
3595 
3596 /**
3597  * Function: gdImageOpenPolygon
3598  *
3599  * Draws an open polygon
3600  *
3601  * Parameters:
3602  * im - The image.
3603  * p - The vertices as array of <gdPoint>s.
3604  * n - The number of vertices.
3605  * c - The color
3606  *
3607  * See also:
3608  * - <gdImagePolygon>
3609  */
3611 {
3612  int i;
3613  int lx, ly;
3614  if (n <= 0) {
3615  return;
3616  }
3617 
3618 
3619  lx = p->x;
3620  ly = p->y;
3621  for (i = 1; (i < n); i++) {
3622  p++;
3623  gdImageLine (im, lx, ly, p->x, p->y, c);
3624  lx = p->x;
3625  ly = p->y;
3626  }
3627 
3628 }
3629 
3630 /* THANKS to Kirsten Schulz for the polygon fixes! */
3631 
3632 /* The intersection finding technique of this code could be improved */
3633 /* by remembering the previous intertersection, and by using the slope. */
3634 /* That could help to adjust intersections to produce a nice */
3635 /* interior_extrema. */
3636 
3637 /**
3638  * Function: gdImageFilledPolygon
3639  *
3640  * Draws a filled polygon
3641  *
3642  * The polygon is filled using the even-odd fillrule what can leave unfilled
3643  * regions inside of self-intersecting polygons. This behavior might change in
3644  * a future version.
3645  *
3646  * Parameters:
3647  * im - The image.
3648  * p - The vertices as array of <gdPoint>s.
3649  * n - The number of vertices.
3650  * c - The color
3651  *
3652  * See also:
3653  * - <gdImagePolygon>
3654  */
3656 {
3657  int i;
3658  int j;
3659  int index;
3660  int y;
3661  int miny, maxy, pmaxy;
3662  int x1, y1;
3663  int x2, y2;
3664  int ind1, ind2;
3665  int ints;
3666  int fill_color;
3667  if (n <= 0) {
3668  return;
3669  }
3670 
3671  if (c == gdAntiAliased) {
3672  fill_color = im->AA_color;
3673  } else {
3674  fill_color = c;
3675  }
3676  if (!im->polyAllocated) {
3677  if (overflow2(sizeof (int), n)) {
3678  return;
3679  }
3680  im->polyInts = (int *) gdMalloc (sizeof (int) * n);
3681  if (!im->polyInts) {
3682  return;
3683  }
3684  im->polyAllocated = n;
3685  }
3686  if (im->polyAllocated < n) {
3687  while (im->polyAllocated < n) {
3688  im->polyAllocated *= 2;
3689  }
3690  if (overflow2(sizeof (int), im->polyAllocated)) {
3691  return;
3692  }
3693  im->polyInts = (int *) gdReallocEx (im->polyInts,
3694  sizeof (int) * im->polyAllocated);
3695  if (!im->polyInts) {
3696  return;
3697  }
3698  }
3699  miny = p[0].y;
3700  maxy = p[0].y;
3701  for (i = 1; (i < n); i++) {
3702  if (p[i].y < miny) {
3703  miny = p[i].y;
3704  }
3705  if (p[i].y > maxy) {
3706  maxy = p[i].y;
3707  }
3708  }
3709  /* necessary special case: horizontal line */
3710  if (n > 1 && miny == maxy) {
3711  x1 = x2 = p[0].x;
3712  for (i = 1; (i < n); i++) {
3713  if (p[i].x < x1) {
3714  x1 = p[i].x;
3715  } else if (p[i].x > x2) {
3716  x2 = p[i].x;
3717  }
3718  }
3719  gdImageLine(im, x1, miny, x2, miny, c);
3720  return;
3721  }
3722  pmaxy = maxy;
3723  /* 2.0.16: Optimization by Ilia Chipitsine -- don't waste time offscreen */
3724  /* 2.0.26: clipping rectangle is even better */
3725  if (miny < im->cy1) {
3726  miny = im->cy1;
3727  }
3728  if (maxy > im->cy2) {
3729  maxy = im->cy2;
3730  }
3731  /* Fix in 1.3: count a vertex only once */
3732  for (y = miny; (y <= maxy); y++) {
3733  ints = 0;
3734  for (i = 0; (i < n); i++) {
3735  if (!i) {
3736  ind1 = n - 1;
3737  ind2 = 0;
3738  } else {
3739  ind1 = i - 1;
3740  ind2 = i;
3741  }
3742  y1 = p[ind1].y;
3743  y2 = p[ind2].y;
3744  if (y1 < y2) {
3745  x1 = p[ind1].x;
3746  x2 = p[ind2].x;
3747  } else if (y1 > y2) {
3748  y2 = p[ind1].y;
3749  y1 = p[ind2].y;
3750  x2 = p[ind1].x;
3751  x1 = p[ind2].x;
3752  } else {
3753  continue;
3754  }
3755 
3756  /* Do the following math as float intermediately, and round to ensure
3757  * that Polygon and FilledPolygon for the same set of points have the
3758  * same footprint. */
3759 
3760  if ((y >= y1) && (y < y2)) {
3761  im->polyInts[ints++] = (int) ((float) ((y - y1) * (x2 - x1)) /
3762  (float) (y2 - y1) + 0.5 + x1);
3763  } else if ((y == pmaxy) && (y == y2)) {
3764  im->polyInts[ints++] = x2;
3765  }
3766  }
3767  /*
3768  2.0.26: polygons pretty much always have less than 100 points,
3769  and most of the time they have considerably less. For such trivial
3770  cases, insertion sort is a good choice. Also a good choice for
3771  future implementations that may wish to indirect through a table.
3772  */
3773  for (i = 1; (i < ints); i++) {
3774  index = im->polyInts[i];
3775  j = i;
3776  while ((j > 0) && (im->polyInts[j - 1] > index)) {
3777  im->polyInts[j] = im->polyInts[j - 1];
3778  j--;
3779  }
3780  im->polyInts[j] = index;
3781  }
3782  for (i = 0; (i < (ints-1)); i += 2) {
3783  /* 2.0.29: back to gdImageLine to prevent segfaults when
3784  performing a pattern fill */
3785  gdImageLine (im, im->polyInts[i], y, im->polyInts[i + 1], y,
3786  fill_color);
3787  }
3788  }
3789  /* If we are drawing this AA, then redraw the border with AA lines. */
3790  /* This doesn't work as well as I'd like, but it doesn't clash either. */
3791  if (c == gdAntiAliased) {
3792  gdImagePolygon (im, p, n, c);
3793  }
3794 }
3795 
3796 /**
3797  * Group: other
3798  */
3799 
3800 static void gdImageSetAAPixelColor(gdImagePtr im, int x, int y, int color, int t);
3801 
3802 /**
3803  * Function: gdImageSetStyle
3804  *
3805  * Sets the style for following drawing operations
3806  *
3807  * Parameters:
3808  * im - The image.
3809  * style - An array of color values.
3810  * noOfPixel - The number of color values.
3811  */
3812 BGD_DECLARE(void) gdImageSetStyle (gdImagePtr im, int *style, int noOfPixels)
3813 {
3814  if (im->style) {
3815  gdFree (im->style);
3816  }
3817  if (overflow2(sizeof (int), noOfPixels)) {
3818  return;
3819  }
3820  im->style = (int *) gdMalloc (sizeof (int) * noOfPixels);
3821  if (!im->style) {
3822  return;
3823  }
3824  memcpy (im->style, style, sizeof (int) * noOfPixels);
3825  im->styleLength = noOfPixels;
3826  im->stylePos = 0;
3827 }
3828 
3829 /**
3830  * Function: gdImageSetThickness
3831  *
3832  * Sets the thickness for following drawing operations
3833  *
3834  * Parameters:
3835  * im - The image.
3836  * thickness - The thickness in pixels.
3837  */
3839 {
3840  im->thick = thickness;
3841 }
3842 
3843 /**
3844  * Function: gdImageSetBrush
3845  *
3846  * Sets the brush for following drawing operations
3847  *
3848  * Parameters:
3849  * im - The image.
3850  * brush - The brush image.
3851  */
3853 {
3854  int i;
3855  im->brush = brush;
3856  if ((!im->trueColor) && (!im->brush->trueColor)) {
3857  for (i = 0; (i < gdImageColorsTotal (brush)); i++) {
3858  int index;
3860  gdImageRed (brush, i),
3861  gdImageGreen (brush, i),
3862  gdImageBlue (brush, i),
3863  gdImageAlpha (brush, i));
3864  im->brushColorMap[i] = index;
3865  }
3866  }
3867 }
3868 
3869 /*
3870  Function: gdImageSetTile
3871 */
3873 {
3874  int i;
3875  im->tile = tile;
3876  if ((!im->trueColor) && (!im->tile->trueColor)) {
3877  for (i = 0; (i < gdImageColorsTotal (tile)); i++) {
3878  int index;
3880  gdImageRed (tile, i),
3881  gdImageGreen (tile, i),
3882  gdImageBlue (tile, i),
3883  gdImageAlpha (tile, i));
3884  im->tileColorMap[i] = index;
3885  }
3886  }
3887 }
3888 
3889 /**
3890  * Function: gdImageSetAntiAliased
3891  *
3892  * Set the color for subsequent anti-aliased drawing
3893  *
3894  * If <gdAntiAliased> is passed as color to drawing operations that support
3895  * anti-aliased drawing (such as <gdImageLine> and <gdImagePolygon>), the actual
3896  * color to be used can be set with this function.
3897  *
3898  * Example: draw an anti-aliased blue line:
3899  * | gdImageSetAntiAliased(im, gdTrueColorAlpha(0, 0, gdBlueMax, gdAlphaOpaque));
3900  * | gdImageLine(im, 10,10, 20,20, gdAntiAliased);
3901  *
3902  * Parameters:
3903  * im - The image.
3904  * c - The color.
3905  *
3906  * See also:
3907  * - <gdImageSetAntiAliasedDontBlend>
3908  */
3910 {
3911  im->AA = 1;
3912  im->AA_color = c;
3913  im->AA_dont_blend = -1;
3914 }
3915 
3916 /**
3917  * Function: gdImageSetAntiAliasedDontBlend
3918  *
3919  * Set the color and "dont_blend" color for subsequent anti-aliased drawing
3920  *
3921  * This extended variant of <gdImageSetAntiAliased> allows to also specify a
3922  * (background) color that will not be blended in anti-aliased drawing
3923  * operations.
3924  *
3925  * Parameters:
3926  * im - The image.
3927  * c - The color.
3928  * dont_blend - Whether to blend.
3929  */
3931 {
3932  im->AA = 1;
3933  im->AA_color = c;
3934  im->AA_dont_blend = dont_blend;
3935 }
3936 
3937 /**
3938  * Function: gdImageInterlace
3939  *
3940  * Sets whether an image is interlaced
3941  *
3942  * This is relevant only when saving the image in a format that supports
3943  * interlacing.
3944  *
3945  * Parameters:
3946  * im - The image.
3947  * interlaceArg - Whether the image is interlaced.
3948  *
3949  * See also:
3950  * - <gdImageGetInterlaced>
3951 */
3952 BGD_DECLARE(void) gdImageInterlace (gdImagePtr im, int interlaceArg)
3953 {
3954  im->interlace = interlaceArg;
3955 }
3956 
3957 /**
3958  * Function: gdImageCompare
3959  *
3960  * Compare two images
3961  *
3962  * Parameters:
3963  * im1 - An image.
3964  * im2 - Another image.
3965  *
3966  * Returns:
3967  * A bitmask of <Image Comparison> flags where each set flag signals
3968  * which attributes of the images are different.
3969  */
3971 {
3972  int x, y;
3973  int p1, p2;
3974  int cmpStatus = 0;
3975  int sx, sy;
3976 
3977  if (im1->interlace != im2->interlace) {
3978  cmpStatus |= GD_CMP_INTERLACE;
3979  }
3980 
3981  if (im1->transparent != im2->transparent) {
3982  cmpStatus |= GD_CMP_TRANSPARENT;
3983  }
3984 
3985  if (im1->trueColor != im2->trueColor) {
3986  cmpStatus |= GD_CMP_TRUECOLOR;
3987  }
3988 
3989  sx = im1->sx;
3990  if (im1->sx != im2->sx) {
3991  cmpStatus |= GD_CMP_SIZE_X + GD_CMP_IMAGE;
3992  if (im2->sx < im1->sx) {
3993  sx = im2->sx;
3994  }
3995  }
3996 
3997  sy = im1->sy;
3998  if (im1->sy != im2->sy) {
3999  cmpStatus |= GD_CMP_SIZE_Y + GD_CMP_IMAGE;
4000  if (im2->sy < im1->sy) {
4001  sy = im2->sy;
4002  }
4003  }
4004 
4005  if (im1->colorsTotal != im2->colorsTotal) {
4006  cmpStatus |= GD_CMP_NUM_COLORS;
4007  }
4008 
4009  for (y = 0; (y < sy); y++) {
4010  for (x = 0; (x < sx); x++) {
4011  p1 =
4012  im1->trueColor ? gdImageTrueColorPixel (im1, x,
4013  y) :
4014  gdImagePalettePixel (im1, x, y);
4015  p2 =
4016  im2->trueColor ? gdImageTrueColorPixel (im2, x,
4017  y) :
4018  gdImagePalettePixel (im2, x, y);
4019  if (gdImageRed (im1, p1) != gdImageRed (im2, p2)) {
4020  cmpStatus |= GD_CMP_COLOR + GD_CMP_IMAGE;
4021  break;
4022  }
4023  if (gdImageGreen (im1, p1) != gdImageGreen (im2, p2)) {
4024  cmpStatus |= GD_CMP_COLOR + GD_CMP_IMAGE;
4025  break;
4026  }
4027  if (gdImageBlue (im1, p1) != gdImageBlue (im2, p2)) {
4028  cmpStatus |= GD_CMP_COLOR + GD_CMP_IMAGE;
4029  break;
4030  }
4031 #if 0
4032  /* Soon we'll add alpha channel to palettes */
4033  if (gdImageAlpha (im1, p1) != gdImageAlpha (im2, p2)) {
4034  cmpStatus |= GD_CMP_COLOR + GD_CMP_IMAGE;
4035  break;
4036  }
4037 #endif
4038  }
4039  if (cmpStatus & GD_CMP_COLOR) {
4040  break;
4041  };
4042  }
4043 
4044  return cmpStatus;
4045 }
4046 
4047 
4048 /* Thanks to Frank Warmerdam for this superior implementation
4049  of gdAlphaBlend(), which merges alpha in the
4050  destination color much better. */
4051 
4052 /**
4053  * Function: gdAlphaBlend
4054  *
4055  * Blend two colors
4056  *
4057  * Parameters:
4058  * dst - The color to blend onto.
4059  * src - The color to blend.
4060  *
4061  * See also:
4062  * - <gdImageAlphaBlending>
4063  * - <gdLayerOverlay>
4064  * - <gdLayerMultiply>
4065  */
4067 {
4068  int src_alpha = gdTrueColorGetAlpha(src);
4069  int dst_alpha, alpha, red, green, blue;
4070  int src_weight, dst_weight, tot_weight;
4071 
4072  /* -------------------------------------------------------------------- */
4073  /* Simple cases we want to handle fast. */
4074  /* -------------------------------------------------------------------- */
4075  if( src_alpha == gdAlphaOpaque )
4076  return src;
4077 
4078  dst_alpha = gdTrueColorGetAlpha(dst);
4079  if( src_alpha == gdAlphaTransparent )
4080  return dst;
4081  if( dst_alpha == gdAlphaTransparent )
4082  return src;
4083 
4084  /* -------------------------------------------------------------------- */
4085  /* What will the source and destination alphas be? Note that */
4086  /* the destination weighting is substantially reduced as the */
4087  /* overlay becomes quite opaque. */
4088  /* -------------------------------------------------------------------- */
4089  src_weight = gdAlphaTransparent - src_alpha;
4090  dst_weight = (gdAlphaTransparent - dst_alpha) * src_alpha / gdAlphaMax;
4091  tot_weight = src_weight + dst_weight;
4092 
4093  /* -------------------------------------------------------------------- */
4094  /* What red, green and blue result values will we use? */
4095  /* -------------------------------------------------------------------- */
4096  alpha = src_alpha * dst_alpha / gdAlphaMax;
4097 
4098  red = (gdTrueColorGetRed(src) * src_weight
4099  + gdTrueColorGetRed(dst) * dst_weight) / tot_weight;
4100  green = (gdTrueColorGetGreen(src) * src_weight
4101  + gdTrueColorGetGreen(dst) * dst_weight) / tot_weight;
4102  blue = (gdTrueColorGetBlue(src) * src_weight
4103  + gdTrueColorGetBlue(dst) * dst_weight) / tot_weight;
4104 
4105  /* -------------------------------------------------------------------- */
4106  /* Return merged result. */
4107  /* -------------------------------------------------------------------- */
4108  return ((alpha << 24) + (red << 16) + (green << 8) + blue);
4109 }
4110 
4111 static int gdAlphaOverlayColor (int src, int dst, int max );
4112 
4113 /**
4114  * Function: gdLayerOverlay
4115  *
4116  * Overlay two colors
4117  *
4118  * Parameters:
4119  * dst - The color to overlay onto.
4120  * src - The color to overlay.
4121  *
4122  * See also:
4123  * - <gdImageAlphaBlending>
4124  * - <gdAlphaBlend>
4125  * - <gdLayerMultiply>
4126  */
4128 {
4129  int a1, a2;
4132  return ( ((gdAlphaMax - a1*a2/gdAlphaMax) << 24) +
4136  );
4137 }
4138 
4139 /* Apply 'overlay' effect - background pixels are colourised by the foreground colour */
4140 static int gdAlphaOverlayColor (int src, int dst, int max )
4141 {
4142  dst = dst << 1;
4143  if( dst > max ) {
4144  /* in the "light" zone */
4145  return dst + (src << 1) - (dst * src / max) - max;
4146  } else {
4147  /* in the "dark" zone */
4148  return dst * src / max;
4149  }
4150 }
4151 
4152 /**
4153  * Function: gdLayerMultiply
4154  *
4155  * Overlay two colors with multiply effect
4156  *
4157  * Parameters:
4158  * dst - The color to overlay onto.
4159  * src - The color to overlay.
4160  *
4161  * See also:
4162  * - <gdImageAlphaBlending>
4163  * - <gdAlphaBlend>
4164  * - <gdLayerOverlay>
4165  */
4167 {
4168  int a1, a2, r1, r2, g1, g2, b1, b2;
4171 
4178 
4179  a1 = gdAlphaMax - a1;
4180  a2 = gdAlphaMax - a2;
4181  return ( ((a1*a2/gdAlphaMax) << 24) +
4182  ((r1*r2/gdRedMax) << 16) +
4183  ((g1*g2/gdGreenMax) << 8) +
4184  ((b1*b2/gdBlueMax))
4185  );
4186 }
4187 
4188 /**
4189  * Function: gdImageAlphaBlending
4190  *
4191  * Set the effect for subsequent drawing operations
4192  *
4193  * Note that the effect is used for truecolor images only.
4194  *
4195  * Parameters:
4196  * im - The image.
4197  * alphaBlendingArg - The effect.
4198  *
4199  * See also:
4200  * - <Effects>
4201  */
4202 BGD_DECLARE(void) gdImageAlphaBlending (gdImagePtr im, int alphaBlendingArg)
4203 {
4204  im->alphaBlendingFlag = alphaBlendingArg;
4205 }
4206 
4207 /**
4208  * Function: gdImageSaveAlpha
4209  *
4210  * Sets the save alpha flag
4211  *
4212  * The save alpha flag specifies whether the alpha channel of the pixels should
4213  * be saved. This is supported only for image formats that support full alpha
4214  * transparency, e.g. PNG.
4215  */
4216 BGD_DECLARE(void) gdImageSaveAlpha (gdImagePtr im, int saveAlphaArg)
4217 {
4218  im->saveAlphaFlag = saveAlphaArg;
4219 }
4220 
4221 /**
4222  * Function: gdImageSetClip
4223  *
4224  * Sets the clipping rectangle
4225  *
4226  * The clipping rectangle restricts the drawing area for following drawing
4227  * operations.
4228  *
4229  * Parameters:
4230  * im - The image.
4231  * x1 - The x-coordinate of the upper left corner.
4232  * y1 - The y-coordinate of the upper left corner.
4233  * x2 - The x-coordinate of the lower right corner.
4234  * y2 - The y-coordinate of the lower right corner.
4235  *
4236  * See also:
4237  * - <gdImageGetClip>
4238  */
4239 BGD_DECLARE(void) gdImageSetClip (gdImagePtr im, int x1, int y1, int x2, int y2)
4240 {
4241  if (x1 < 0) {
4242  x1 = 0;
4243  }
4244  if (x1 >= im->sx) {
4245  x1 = im->sx - 1;
4246  }
4247  if (x2 < 0) {
4248  x2 = 0;
4249  }
4250  if (x2 >= im->sx) {
4251  x2 = im->sx - 1;
4252  }
4253  if (y1 < 0) {
4254  y1 = 0;
4255  }
4256  if (y1 >= im->sy) {
4257  y1 = im->sy - 1;
4258  }
4259  if (y2 < 0) {
4260  y2 = 0;
4261  }
4262  if (y2 >= im->sy) {
4263  y2 = im->sy - 1;
4264  }
4265  im->cx1 = x1;
4266  im->cy1 = y1;
4267  im->cx2 = x2;
4268  im->cy2 = y2;
4269 }
4270 
4271 /**
4272  * Function: gdImageGetClip
4273  *
4274  * Gets the current clipping rectangle
4275  *
4276  * Parameters:
4277  * im - The image.
4278  * x1P - (out) The x-coordinate of the upper left corner.
4279  * y1P - (out) The y-coordinate of the upper left corner.
4280  * x2P - (out) The x-coordinate of the lower right corner.
4281  * y2P - (out) The y-coordinate of the lower right corner.
4282  *
4283  * See also:
4284  * - <gdImageSetClip>
4285  */
4286 BGD_DECLARE(void) gdImageGetClip (gdImagePtr im, int *x1P, int *y1P, int *x2P, int *y2P)
4287 {
4288  *x1P = im->cx1;
4289  *y1P = im->cy1;
4290  *x2P = im->cx2;
4291  *y2P = im->cy2;
4292 }
4293 
4294 /**
4295  * Function: gdImageSetResolution
4296  *
4297  * Sets the resolution of an image.
4298  *
4299  * Parameters:
4300  * im - The image.
4301  * res_x - The horizontal resolution in DPI.
4302  * res_y - The vertical resolution in DPI.
4303  *
4304  * See also:
4305  * - <gdImageResolutionX>
4306  * - <gdImageResolutionY>
4307  */
4308 BGD_DECLARE(void) gdImageSetResolution(gdImagePtr im, const unsigned int res_x, const unsigned int res_y)
4309 {
4310  if (res_x > 0) im->res_x = res_x;
4311  if (res_y > 0) im->res_y = res_y;
4312 }
4313 
4314 /*
4315  * Added on 2003/12 by Pierre-Alain Joye (pajoye@pearfr.org)
4316  * */
4317 #define BLEND_COLOR(a, nc, c, cc) \
4318 nc = (cc) + (((((c) - (cc)) * (a)) + ((((c) - (cc)) * (a)) >> 8) + 0x80) >> 8);
4319 
4320 static void gdImageSetAAPixelColor(gdImagePtr im, int x, int y, int color, int t)
4321 {
4322  int dr,dg,db,p,r,g,b;
4323 
4324  /* 2.0.34: watch out for out of range calls */
4325  if (!gdImageBoundsSafeMacro(im, x, y)) {
4326  return;
4327  }
4328  p = gdImageGetPixel(im,x,y);
4329  /* TBB: we have to implement the dont_blend stuff to provide
4330  the full feature set of the old implementation */
4331  if ((p == color)
4332  || ((p == im->AA_dont_blend)
4333  && (t != 0x00))) {
4334  return;
4335  }
4339 
4340  r = gdTrueColorGetRed(p);
4341  g = gdTrueColorGetGreen(p);
4342  b = gdTrueColorGetBlue(p);
4343 
4344  BLEND_COLOR(t, dr, r, dr);
4345  BLEND_COLOR(t, dg, g, dg);
4346  BLEND_COLOR(t, db, b, db);
4348 }
4349 
4350 static void gdImageAALine (gdImagePtr im, int x1, int y1, int x2, int y2, int col)
4351 {
4352  /* keep them as 32bits */
4353  long x, y, inc, frac;
4354  long dx, dy,tmp;
4355  int w, wid, wstart;
4356  int thick = im->thick;
4357 
4358  if (!im->trueColor) {
4359  /* TBB: don't crash when the image is of the wrong type */
4360  gdImageLine(im, x1, y1, x2, y2, col);
4361  return;
4362  }
4363 
4364  /* TBB: use the clipping rectangle */
4365  if (clip_1d (&x1, &y1, &x2, &y2, im->cx1, im->cx2) == 0)
4366  return;
4367  if (clip_1d (&y1, &x1, &y2, &x2, im->cy1, im->cy2) == 0)
4368  return;
4369 
4370  dx = x2 - x1;
4371  dy = y2 - y1;
4372 
4373  if (dx == 0 && dy == 0) {
4374  /* TBB: allow setting points */
4375  gdImageSetPixel(im, x1, y1, col);
4376  return;
4377  } else {
4378  double ag;
4379  /* Cast the long to an int to avoid compiler warnings about truncation.
4380  * This isn't a problem as computed dy/dx values came from ints above. */
4381  ag = fabs(abs((int)dy) < abs((int)dx) ? cos(atan2(dy, dx)) : sin(atan2(dy, dx)));
4382  if (ag != 0) {
4383  wid = thick / ag;
4384  } else {
4385  wid = 1;
4386  }
4387  if (wid == 0) {
4388  wid = 1;
4389  }
4390  }
4391 
4392  /* Axis aligned lines */
4393  if (dx == 0) {
4394  gdImageVLine(im, x1, y1, y2, col);
4395  return;
4396  } else if (dy == 0) {
4397  gdImageHLine(im, y1, x1, x2, col);
4398  return;
4399  }
4400 
4401  if (abs((int)dx) > abs((int)dy)) {
4402  if (dx < 0) {
4403  tmp = x1;
4404  x1 = x2;
4405  x2 = tmp;
4406  tmp = y1;
4407  y1 = y2;
4408  y2 = tmp;
4409  dx = x2 - x1;
4410  dy = y2 - y1;
4411  }
4412  y = y1;
4413  inc = (dy * 65536) / dx;
4414  frac = 0;
4415  /* TBB: set the last pixel for consistency (<=) */
4416  for (x = x1 ; x <= x2 ; x++) {
4417  wstart = y - wid / 2;
4418  for (w = wstart; w < wstart + wid; w++) {
4419  gdImageSetAAPixelColor(im, x , w , col , (frac >> 8) & 0xFF);
4420  gdImageSetAAPixelColor(im, x , w + 1 , col, (~frac >> 8) & 0xFF);
4421  }
4422  frac += inc;
4423  if (frac >= 65536) {
4424  frac -= 65536;
4425  y++;
4426  } else if (frac < 0) {
4427  frac += 65536;
4428  y--;
4429  }
4430  }
4431  } else {
4432  if (dy < 0) {
4433  tmp = x1;
4434  x1 = x2;
4435  x2 = tmp;
4436  tmp = y1;
4437  y1 = y2;
4438  y2 = tmp;
4439  dx = x2 - x1;
4440  dy = y2 - y1;
4441  }
4442  x = x1;
4443  inc = (dx * 65536) / dy;
4444  frac = 0;
4445  /* TBB: set the last pixel for consistency (<=) */
4446  for (y = y1 ; y <= y2 ; y++) {
4447  wstart = x - wid / 2;
4448  for (w = wstart; w < wstart + wid; w++) {
4449  gdImageSetAAPixelColor(im, w , y , col, (frac >> 8) & 0xFF);
4450  gdImageSetAAPixelColor(im, w + 1, y, col, (~frac >> 8) & 0xFF);
4451  }
4452  frac += inc;
4453  if (frac >= 65536) {
4454  frac -= 65536;
4455  x++;
4456  } else if (frac < 0) {
4457  frac += 65536;
4458  x--;
4459  }
4460  }
4461  }
4462 }
4463 
4464 
4465 /**
4466  * Function: gdImagePaletteToTrueColor
4467  *
4468  * Convert a palette image to true color
4469  *
4470  * Parameters:
4471  * src - The image.
4472  *
4473  * Returns:
4474  * Non-zero if the conversion succeeded, zero otherwise.
4475  *
4476  * See also:
4477  * - <gdImageTrueColorToPalette>
4478  */
4480 {
4481  unsigned int y;
4482  unsigned int yy;
4483 
4484  if (src == NULL) {
4485  return 0;
4486  }
4487 
4488  if (src->trueColor == 1) {
4489  return 1;
4490  } else {
4491  unsigned int x;
4492  const unsigned int sy = gdImageSY(src);
4493  const unsigned int sx = gdImageSX(src);
4494 
4495  src->tpixels = (int **) gdMalloc(sizeof(int *) * sy);
4496  if (src->tpixels == NULL) {
4497  return 0;
4498  }
4499 
4500  for (y = 0; y < sy; y++) {
4501  const unsigned char *src_row = src->pixels[y];
4502  int * dst_row;
4503 
4504  /* no need to calloc it, we overwrite all pxl anyway */
4505  src->tpixels[y] = (int *) gdMalloc(sx * sizeof(int));
4506  if (src->tpixels[y] == NULL) {
4507  goto clean_on_error;
4508  }
4509 
4510  dst_row = src->tpixels[y];
4511  for (x = 0; x < sx; x++) {
4512  const unsigned char c = *(src_row + x);
4513  if (c == src->transparent) {
4514  *(dst_row + x) = gdTrueColorAlpha(0, 0, 0, 127);
4515  } else {
4516  *(dst_row + x) = gdTrueColorAlpha(src->red[c], src->green[c], src->blue[c], src->alpha[c]);
4517  }
4518  }
4519  }
4520  }
4521 
4522  /* free old palette buffer (y is sy) */
4523  for (yy = 0; yy < y; yy++) {
4524  gdFree(src->pixels[yy]);
4525  }
4526  gdFree(src->pixels);
4527  src->trueColor = 1;
4528  src->pixels = NULL;
4529  src->alphaBlendingFlag = 0;
4530  src->saveAlphaFlag = 1;
4531 
4532  if (src->transparent >= 0) {
4533  const unsigned char c = src->transparent;
4534  src->transparent = gdTrueColorAlpha(src->red[c], src->green[c], src->blue[c], src->alpha[c]);
4535  }
4536 
4537  return 1;
4538 
4539 clean_on_error:
4540  /* free new true color buffer (y is not allocated, have failed) */
4541  for (yy = 0; yy < y; yy++) {
4542  gdFree(src->tpixels[yy]);
4543  }
4544  gdFree(src->tpixels);
4545  return 0;
4546 }
double __cdecl atan2(double _Y, double _X)
__inline float __cdecl floorf(float _X)
Definition: CPAL.d:18965
return _Result< 0 ? -1 :_Result;} #line 1069 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __inline int __cdecl _vsnwprintf_s_l(wchar_t *const _Buffer, size_t const _BufferCount, size_t const _MaxCount, wchar_t const *const _Format, _locale_t const _Locale, va_list _ArgList) { int const _Result=__stdio_common_vsnwprintf_s((*__local_stdio_printf_options()), _Buffer, _BufferCount, _MaxCount, _Format, _Locale, _ArgList);return _Result< 0 ? -1 :_Result;} #line 1091 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __inline int __cdecl _vsnwprintf_s(wchar_t *const _Buffer, size_t const _BufferCount, size_t const _MaxCount, wchar_t const *const _Format, va_list _ArgList) { return _vsnwprintf_s_l(_Buffer, _BufferCount, _MaxCount, _Format,((void *) 0), _ArgList);} #line 1108 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __declspec(deprecated("This function or variable may be unsafe. Consider using " "_snwprintf_s" " instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. " "See online help for details.")) __inline int __cdecl _snwprintf(wchar_t *_Buffer, size_t _BufferCount, wchar_t const *_Format,...);__declspec(deprecated("This function or variable may be unsafe. Consider using " "_vsnwprintf_s" " instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. " "See online help for details.")) __inline int __cdecl _vsnwprintf(wchar_t *_Buffer, size_t _BufferCount, wchar_t const *_Format, va_list _Args);__declspec(deprecated("This function or variable may be unsafe. Consider using " "_vsnwprintf_s" " instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. " "See online help for details.")) __inline int __cdecl _vsnwprintf(wchar_t *_Buffer, size_t _BufferCount, wchar_t const *_Format, va_list _ArgList) { return _vsnwprintf_l(_Buffer, _BufferCount, _Format,((void *) 0), _ArgList);} #line 1133 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __inline int __cdecl _vswprintf_c_l(wchar_t *const _Buffer, size_t const _BufferCount, wchar_t const *const _Format, _locale_t const _Locale, va_list _ArgList) { int const _Result=__stdio_common_vswprintf((*__local_stdio_printf_options()), _Buffer, _BufferCount, _Format, _Locale, _ArgList);return _Result< 0 ? -1 :_Result;} #line 1163 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __inline int __cdecl _vswprintf_c(wchar_t *const _Buffer, size_t const _BufferCount, wchar_t const *const _Format, va_list _ArgList) { return _vswprintf_c_l(_Buffer, _BufferCount, _Format,((void *) 0), _ArgList);} #line 1179 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __inline int __cdecl _vswprintf_l(wchar_t *const _Buffer, size_t const _BufferCount, wchar_t const *const _Format, _locale_t const _Locale, va_list _ArgList) { return _vswprintf_c_l(_Buffer, _BufferCount, _Format, _Locale, _ArgList);} #line 1196 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __inline int __cdecl __vswprintf_l(wchar_t *const _Buffer, wchar_t const *const _Format, _locale_t const _Locale, va_list _ArgList) { return _vswprintf_l(_Buffer,(size_t) -1, _Format, _Locale, _ArgList);} #line 1212 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __inline int __cdecl _vswprintf(wchar_t *const _Buffer, wchar_t const *const _Format, va_list _ArgList) { return _vswprintf_l(_Buffer,(size_t) -1, _Format,((void *) 0), _ArgList);} #line 1227 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __inline int __cdecl vswprintf(wchar_t *const _Buffer, size_t const _BufferCount, wchar_t const *const _Format, va_list _ArgList) { return _vswprintf_c_l(_Buffer, _BufferCount, _Format,((void *) 0), _ArgList);} #line 1243 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __inline int __cdecl _vswprintf_s_l(wchar_t *const _Buffer, size_t const _BufferCount, wchar_t const *const _Format, _locale_t const _Locale, va_list _ArgList) { int const _Result=__stdio_common_vswprintf_s((*__local_stdio_printf_options()), _Buffer, _BufferCount, _Format, _Locale, _ArgList);return _Result< 0 ? -1 :_Result;} #line 1264 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __inline int __cdecl vswprintf_s(wchar_t *const _Buffer, size_t const _BufferCount, wchar_t const *const _Format, va_list _ArgList) { return _vswprintf_s_l(_Buffer, _BufferCount, _Format,((void *) 0), _ArgList);} #line 1281 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" #line 1283 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __inline int __cdecl _vswprintf_p_l(wchar_t *const _Buffer, size_t const _BufferCount, wchar_t const *const _Format, _locale_t const _Locale, va_list _ArgList) { int const _Result=__stdio_common_vswprintf_p((*__local_stdio_printf_options()), _Buffer, _BufferCount, _Format, _Locale, _ArgList);return _Result< 0 ? -1 :_Result;} #line 1312 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __inline int __cdecl _vswprintf_p(wchar_t *const _Buffer, size_t const _BufferCount, wchar_t const *const _Format, va_list _ArgList) { return _vswprintf_p_l(_Buffer, _BufferCount, _Format,((void *) 0), _ArgList);} #line 1328 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __inline int __cdecl _vscwprintf_l(wchar_t const *const _Format, _locale_t const _Locale, va_list _ArgList) { int const _Result=__stdio_common_vswprintf((*__local_stdio_printf_options())|(1ULL<< 1),((void *) 0), 0, _Format, _Locale, _ArgList);return _Result< 0 ? -1 :_Result;} #line 1347 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __inline int __cdecl _vscwprintf(wchar_t const *const _Format, va_list _ArgList) { return _vscwprintf_l(_Format,((void *) 0), _ArgList);} #line 1361 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __inline int __cdecl _vscwprintf_p_l(wchar_t const *const _Format, _locale_t const _Locale, va_list _ArgList) { int const _Result=__stdio_common_vswprintf_p((*__local_stdio_printf_options())|(1ULL<< 1),((void *) 0), 0, _Format, _Locale, _ArgList);return _Result< 0 ? -1 :_Result;} #line 1380 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __inline int __cdecl _vscwprintf_p(wchar_t const *const _Format, va_list _ArgList) { return _vscwprintf_p_l(_Format,((void *) 0), _ArgList);} #line 1394 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __inline int __cdecl __swprintf_l(wchar_t *const _Buffer, wchar_t const *const _Format, _locale_t const _Locale,...) { int _Result;va_list _ArgList;((void)(_ArgList=(va_list)(&(_Locale))+((sizeof(_Locale)+sizeof(int) - 1) &~(sizeof(int) - 1)))) ;_Result=__vswprintf_l(_Buffer, _Format, _Locale, _ArgList);((void)(_ArgList=(va_list) 0)) ;return _Result;} #line 1414 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __inline int __cdecl _swprintf_l(wchar_t *const _Buffer, size_t const _BufferCount, wchar_t const *const _Format, _locale_t const _Locale,...) { int _Result;va_list _ArgList;((void)(_ArgList=(va_list)(&(_Locale))+((sizeof(_Locale)+sizeof(int) - 1) &~(sizeof(int) - 1)))) ;_Result=_vswprintf_c_l(_Buffer, _BufferCount, _Format, _Locale, _ArgList);((void)(_ArgList=(va_list) 0)) ;return _Result;} #line 1435 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __inline int __cdecl _swprintf(wchar_t *const _Buffer, wchar_t const *const _Format,...) { int _Result;va_list _ArgList;((void)(_ArgList=(va_list)(&(_Format))+((sizeof(_Format)+sizeof(int) - 1) &~(sizeof(int) - 1)))) ;_Result=__vswprintf_l(_Buffer, _Format,((void *) 0), _ArgList);((void)(_ArgList=(va_list) 0)) ;return _Result;} #line 1454 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __inline int __cdecl swprintf(wchar_t *const _Buffer, size_t const _BufferCount, wchar_t const *const _Format,...) { int _Result;va_list _ArgList;((void)(_ArgList=(va_list)(&(_Format))+((sizeof(_Format)+sizeof(int) - 1) &~(sizeof(int) - 1)))) ;_Result=_vswprintf_c_l(_Buffer, _BufferCount, _Format,((void *) 0), _ArgList);((void)(_ArgList=(va_list) 0)) ;return _Result;} #line 1474 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __declspec(deprecated("This function or variable may be unsafe. Consider using " "__swprintf_l_s" " instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. " "See online help for details.")) __inline int __cdecl __swprintf_l(wchar_t *_Buffer, wchar_t const *_Format, _locale_t _Locale,...);__declspec(deprecated("This function or variable may be unsafe. Consider using " "_vswprintf_s_l" " instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. " "See online help for details.")) __inline int __cdecl __vswprintf_l(wchar_t *_Buffer, wchar_t const *_Format, _locale_t _Locale, va_list _Args);__declspec(deprecated("This function or variable may be unsafe. Consider using " "swprintf_s" " instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. " "See online help for details.")) __inline int __cdecl _swprintf(wchar_t *_Buffer, wchar_t const *_Format,...);__declspec(deprecated("This function or variable may be unsafe. Consider using " "vswprintf_s" " instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. " "See online help for details.")) __inline int __cdecl _vswprintf(wchar_t *_Buffer, wchar_t const *_Format, va_list _Args);__inline int __cdecl _swprintf_s_l(wchar_t *const _Buffer, size_t const _BufferCount, wchar_t const *const _Format, _locale_t const _Locale,...) { int _Result;va_list _ArgList;((void)(_ArgList=(va_list)(&(_Locale))+((sizeof(_Locale)+sizeof(int) - 1) &~(sizeof(int) - 1)))) ;_Result=_vswprintf_s_l(_Buffer, _BufferCount, _Format, _Locale, _ArgList);((void)(_ArgList=(va_list) 0)) ;return _Result;} #line 1511 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __inline int __cdecl swprintf_s(wchar_t *const _Buffer, size_t const _BufferCount, wchar_t const *const _Format,...) { int _Result;va_list _ArgList;((void)(_ArgList=(va_list)(&(_Format))+((sizeof(_Format)+sizeof(int) - 1) &~(sizeof(int) - 1)))) ;_Result=_vswprintf_s_l(_Buffer, _BufferCount, _Format,((void *) 0), _ArgList);((void)(_ArgList=(va_list) 0)) ;return _Result;} #line 1532 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" #line 1534 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __inline int __cdecl _swprintf_p_l(wchar_t *const _Buffer, size_t const _BufferCount, wchar_t const *const _Format, _locale_t const _Locale,...) { int _Result;va_list _ArgList;((void)(_ArgList=(va_list)(&(_Locale))+((sizeof(_Locale)+sizeof(int) - 1) &~(sizeof(int) - 1)))) ;_Result=_vswprintf_p_l(_Buffer, _BufferCount, _Format, _Locale, _ArgList);((void)(_ArgList=(va_list) 0)) ;return _Result;} #line 1562 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __inline int __cdecl _swprintf_p(wchar_t *const _Buffer, size_t const _BufferCount, wchar_t const *const _Format,...) { int _Result;va_list _ArgList;((void)(_ArgList=(va_list)(&(_Format))+((sizeof(_Format)+sizeof(int) - 1) &~(sizeof(int) - 1)))) ;_Result=_vswprintf_p_l(_Buffer, _BufferCount, _Format,((void *) 0), _ArgList);((void)(_ArgList=(va_list) 0)) ;return _Result;} #line 1582 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __inline int __cdecl _swprintf_c_l(wchar_t *const _Buffer, size_t const _BufferCount, wchar_t const *const _Format, _locale_t const _Locale,...) { int _Result;va_list _ArgList;((void)(_ArgList=(va_list)(&(_Locale))+((sizeof(_Locale)+sizeof(int) - 1) &~(sizeof(int) - 1)))) ;_Result=_vswprintf_c_l(_Buffer, _BufferCount, _Format, _Locale, _ArgList);((void)(_ArgList=(va_list) 0)) ;return _Result;} #line 1603 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __inline int __cdecl _swprintf_c(wchar_t *const _Buffer, size_t const _BufferCount, wchar_t const *const _Format,...) { int _Result;va_list _ArgList;((void)(_ArgList=(va_list)(&(_Format))+((sizeof(_Format)+sizeof(int) - 1) &~(sizeof(int) - 1)))) ;_Result=_vswprintf_c_l(_Buffer, _BufferCount, _Format,((void *) 0), _ArgList);((void)(_ArgList=(va_list) 0)) ;return _Result;} #line 1623 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __declspec(deprecated("This function or variable may be unsafe. Consider using " "_snwprintf_s_l" " instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. " "See online help for details.")) __inline int __cdecl _snwprintf_l(wchar_t *const _Buffer, size_t const _BufferCount, wchar_t const *const _Format, _locale_t const _Locale,...) { int _Result;va_list _ArgList;((void)(_ArgList=(va_list)(&(_Locale))+((sizeof(_Locale)+sizeof(int) - 1) &~(sizeof(int) - 1)))) ;_Result=_vsnwprintf_l(_Buffer, _BufferCount, _Format, _Locale, _ArgList);((void)(_ArgList=(va_list) 0)) ;return _Result;} #line 1646 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __inline int __cdecl _snwprintf(wchar_t *_Buffer, size_t _BufferCount, wchar_t const *_Format,...) { int _Result;va_list _ArgList;((void)(_ArgList=(va_list)(&(_Format))+((sizeof(_Format)+sizeof(int) - 1) &~(sizeof(int) - 1)))) ;_Result=_vsnwprintf_l(_Buffer, _BufferCount, _Format,((void *) 0), _ArgList);((void)(_ArgList=(va_list) 0)) ;return _Result;} #line 1668 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __inline int __cdecl _snwprintf_s_l(wchar_t *const _Buffer, size_t const _BufferCount, size_t const _MaxCount, wchar_t const *const _Format, _locale_t const _Locale,...) { int _Result;va_list _ArgList;((void)(_ArgList=(va_list)(&(_Locale))+((sizeof(_Locale)+sizeof(int) - 1) &~(sizeof(int) - 1)))) ;_Result=_vsnwprintf_s_l(_Buffer, _BufferCount, _MaxCount, _Format, _Locale, _ArgList);((void)(_ArgList=(va_list) 0)) ;return _Result;} #line 1690 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __inline int __cdecl _snwprintf_s(wchar_t *const _Buffer, size_t const _BufferCount, size_t const _MaxCount, wchar_t const *const _Format,...) { int _Result;va_list _ArgList;((void)(_ArgList=(va_list)(&(_Format))+((sizeof(_Format)+sizeof(int) - 1) &~(sizeof(int) - 1)))) ;_Result=_vsnwprintf_s_l(_Buffer, _BufferCount, _MaxCount, _Format,((void *) 0), _ArgList);((void)(_ArgList=(va_list) 0)) ;return _Result;} #line 1711 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __inline int __cdecl _scwprintf_l(wchar_t const *const _Format, _locale_t const _Locale,...) { int _Result;va_list _ArgList;((void)(_ArgList=(va_list)(&(_Locale))+((sizeof(_Locale)+sizeof(int) - 1) &~(sizeof(int) - 1)))) ;_Result=_vscwprintf_l(_Format, _Locale, _ArgList);((void)(_ArgList=(va_list) 0)) ;return _Result;} #line 1737 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __inline int __cdecl _scwprintf(wchar_t const *const _Format,...) { int _Result;va_list _ArgList;((void)(_ArgList=(va_list)(&(_Format))+((sizeof(_Format)+sizeof(int) - 1) &~(sizeof(int) - 1)))) ;_Result=_vscwprintf_l(_Format,((void *) 0), _ArgList);((void)(_ArgList=(va_list) 0)) ;return _Result;} #line 1755 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __inline int __cdecl _scwprintf_p_l(wchar_t const *const _Format, _locale_t const _Locale,...) { int _Result;va_list _ArgList;((void)(_ArgList=(va_list)(&(_Locale))+((sizeof(_Locale)+sizeof(int) - 1) &~(sizeof(int) - 1)))) ;_Result=_vscwprintf_p_l(_Format, _Locale, _ArgList);((void)(_ArgList=(va_list) 0)) ;return _Result;} #line 1774 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __inline int __cdecl _scwprintf_p(wchar_t const *const _Format,...) { int _Result;va_list _ArgList;((void)(_ArgList=(va_list)(&(_Format))+((sizeof(_Format)+sizeof(int) - 1) &~(sizeof(int) - 1)))) ;_Result=_vscwprintf_p_l(_Format,((void *) 0), _ArgList);((void)(_ArgList=(va_list) 0)) ;return _Result;} #line 1792 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" #pragma warning(push) #pragma warning(disable:4141 6054) #pragma warning(pop) #line 1856 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" int __cdecl __stdio_common_vswscanf(unsigned __int64 _Options, wchar_t const *_Buffer, size_t _BufferCount, wchar_t const *_Format, _locale_t _Locale, va_list _ArgList);__inline int __cdecl _vswscanf_l(wchar_t const *const _Buffer, wchar_t const *const _Format, _locale_t const _Locale, va_list _ArgList) { return __stdio_common_vswscanf((*__local_stdio_scanf_options()), _Buffer,(size_t) -1, _Format, _Locale, _ArgList);} #line 1897 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __inline int __cdecl vswscanf(wchar_t const *_Buffer, wchar_t const *_Format, va_list _ArgList) { return _vswscanf_l(_Buffer, _Format,((void *) 0), _ArgList);} #line 1912 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __inline int __cdecl _vswscanf_s_l(wchar_t const *const _Buffer, wchar_t const *const _Format, _locale_t const _Locale, va_list _ArgList) { return __stdio_common_vswscanf((*__local_stdio_scanf_options())|(1ULL<< 0), _Buffer,(size_t) -1, _Format, _Locale, _ArgList);} #line 1930 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __inline int __cdecl vswscanf_s(wchar_t const *const _Buffer, wchar_t const *const _Format, va_list _ArgList) { return _vswscanf_s_l(_Buffer, _Format,((void *) 0), _ArgList);} #line 1947 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" #line 1949 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __declspec(deprecated("This function or variable may be unsafe. Consider using " "_vsnwscanf_s_l" " instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. " "See online help for details.")) __inline int __cdecl _vsnwscanf_l(wchar_t const *const _Buffer, size_t const _BufferCount, wchar_t const *const _Format, _locale_t const _Locale, va_list _ArgList) { return __stdio_common_vswscanf((*__local_stdio_scanf_options()), _Buffer, _BufferCount, _Format, _Locale, _ArgList);} #line 1976 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __inline int __cdecl _vsnwscanf_s_l(wchar_t const *const _Buffer, size_t const _BufferCount, wchar_t const *const _Format, _locale_t const _Locale, va_list _ArgList) { return __stdio_common_vswscanf((*__local_stdio_scanf_options())|(1ULL<< 0), _Buffer, _BufferCount, _Format, _Locale, _ArgList);} #line 1995 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __declspec(deprecated("This function or variable may be unsafe. Consider using " "_swscanf_s_l" " instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. " "See online help for details.")) __inline int __cdecl _swscanf_l(wchar_t const *const _Buffer, wchar_t const *const _Format, _locale_t _Locale,...) { int _Result;va_list _ArgList;((void)(_ArgList=(va_list)(&(_Locale))+((sizeof(_Locale)+sizeof(int) - 1) &~(sizeof(int) - 1)))) ;_Result=_vswscanf_l(_Buffer, _Format, _Locale, _ArgList);((void)(_ArgList=(va_list) 0)) ;return _Result;} #line 2015 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __declspec(deprecated("This function or variable may be unsafe. Consider using " "swscanf_s" " instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. " "See online help for details.")) __inline int __cdecl swscanf(wchar_t const *const _Buffer, wchar_t const *const _Format,...) { int _Result;va_list _ArgList;((void)(_ArgList=(va_list)(&(_Format))+((sizeof(_Format)+sizeof(int) - 1) &~(sizeof(int) - 1)))) ;_Result=_vswscanf_l(_Buffer, _Format,((void *) 0), _ArgList);((void)(_ArgList=(va_list) 0)) ;return _Result;} #line 2034 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __inline int __cdecl _swscanf_s_l(wchar_t const *const _Buffer, wchar_t const *const _Format, _locale_t const _Locale,...) { int _Result;va_list _ArgList;((void)(_ArgList=(va_list)(&(_Locale))+((sizeof(_Locale)+sizeof(int) - 1) &~(sizeof(int) - 1)))) ;_Result=_vswscanf_s_l(_Buffer, _Format, _Locale, _ArgList);((void)(_ArgList=(va_list) 0)) ;return _Result;} #line 2054 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __inline int __cdecl swscanf_s(wchar_t const *const _Buffer, wchar_t const *const _Format,...) { int _Result;va_list _ArgList;((void)(_ArgList=(va_list)(&(_Format))+((sizeof(_Format)+sizeof(int) - 1) &~(sizeof(int) - 1)))) ;_Result=_vswscanf_s_l(_Buffer, _Format,((void *) 0), _ArgList);((void)(_ArgList=(va_list) 0)) ;return _Result;} #line 2075 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" #line 2077 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __declspec(deprecated("This function or variable may be unsafe. Consider using " "_snwscanf_s_l" " instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. " "See online help for details.")) __inline int __cdecl _snwscanf_l(wchar_t const *const _Buffer, size_t const _BufferCount, wchar_t const *const _Format, _locale_t const _Locale,...) { int _Result;va_list _ArgList;((void)(_ArgList=(va_list)(&(_Locale))+((sizeof(_Locale)+sizeof(int) - 1) &~(sizeof(int) - 1)))) ;_Result=_vsnwscanf_l(_Buffer, _BufferCount, _Format, _Locale, _ArgList);((void)(_ArgList=(va_list) 0)) ;return _Result;} #line 2100 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __declspec(deprecated("This function or variable may be unsafe. Consider using " "_snwscanf_s" " instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. " "See online help for details.")) __inline int __cdecl _snwscanf(wchar_t const *const _Buffer, size_t const _BufferCount, wchar_t const *const _Format,...) { int _Result;va_list _ArgList;((void)(_ArgList=(va_list)(&(_Format))+((sizeof(_Format)+sizeof(int) - 1) &~(sizeof(int) - 1)))) ;_Result=_vsnwscanf_l(_Buffer, _BufferCount, _Format,((void *) 0), _ArgList);((void)(_ArgList=(va_list) 0)) ;return _Result;} #line 2122 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __inline int __cdecl _snwscanf_s_l(wchar_t const *const _Buffer, size_t const _BufferCount, wchar_t const *const _Format, _locale_t const _Locale,...) { int _Result;va_list _ArgList;((void)(_ArgList=(va_list)(&(_Locale))+((sizeof(_Locale)+sizeof(int) - 1) &~(sizeof(int) - 1)))) ;_Result=_vsnwscanf_s_l(_Buffer, _BufferCount, _Format, _Locale, _ArgList);((void)(_ArgList=(va_list) 0)) ;return _Result;} #line 2143 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __inline int __cdecl _snwscanf_s(wchar_t const *const _Buffer, size_t const _BufferCount, wchar_t const *const _Format,...) { int _Result;va_list _ArgList;((void)(_ArgList=(va_list)(&(_Format))+((sizeof(_Format)+sizeof(int) - 1) &~(sizeof(int) - 1)))) ;_Result=_vsnwscanf_s_l(_Buffer, _BufferCount, _Format,((void *) 0), _ArgList);((void)(_ArgList=(va_list) 0)) ;return _Result;} #line 2163 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\corecrt_wstdio.h" __pragma(pack(pop))#pragma warning(pop) #pragma warning(push)#pragma warning(disable:4324 4514 4574 4710 4793 4820 4995 4996 28719 28726 28727) __pragma(pack(push, 8)) typedef __int64 fpos_t;errno_t __cdecl _get_stream_buffer_pointers(FILE *_Stream, char ***_Base, char ***_Pointer, int **_Count);errno_t __cdecl clearerr_s(FILE *_Stream);errno_t __cdecl fopen_s(FILE **_Stream, char const *_FileName, char const *_Mode);size_t __cdecl fread_s(void *_Buffer, size_t _BufferSize, size_t _ElementSize, size_t _ElementCount, FILE *_Stream);errno_t __cdecl freopen_s(FILE **_Stream, char const *_FileName, char const *_Mode, FILE *_OldStream);char *__cdecl gets_s(char *_Buffer, rsize_t _Size);errno_t __cdecl tmpfile_s(FILE **_Stream);errno_t __cdecl tmpnam_s(char *_Buffer, rsize_t _Size);#line 145 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" void __cdecl clearerr(FILE *_Stream);int __cdecl fclose(FILE *_Stream);int __cdecl _fcloseall(void);FILE *__cdecl _fdopen(int _FileHandle, char const *_Mode);int __cdecl feof(FILE *_Stream);int __cdecl ferror(FILE *_Stream);int __cdecl fflush(FILE *_Stream);int __cdecl fgetc(FILE *_Stream);int __cdecl _fgetchar(void);int __cdecl fgetpos(FILE *_Stream, fpos_t *_Position);char *__cdecl fgets(char *_Buffer, int _MaxCount, FILE *_Stream);int __cdecl _fileno(FILE *_Stream);int __cdecl _flushall(void);__declspec(deprecated("This function or variable may be unsafe. Consider using " "fopen_s" " instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. " "See online help for details.")) FILE *__cdecl fopen(char const *_FileName, char const *_Mode);int __cdecl fputc(int _Character, FILE *_Stream);int __cdecl _fputchar(int _Character);int __cdecl fputs(char const *_Buffer, FILE *_Stream);size_t __cdecl fread(void *_Buffer, size_t _ElementSize, size_t _ElementCount, FILE *_Stream);__declspec(deprecated("This function or variable may be unsafe. Consider using " "freopen_s" " instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. " "See online help for details.")) FILE *__cdecl freopen(char const *_FileName, char const *_Mode, FILE *_Stream);FILE *__cdecl _fsopen(char const *_FileName, char const *_Mode, int _ShFlag);int __cdecl fsetpos(FILE *_Stream, fpos_t const *_Position);int __cdecl fseek(FILE *_Stream, long _Offset, int _Origin);int __cdecl _fseeki64(FILE *_Stream, __int64 _Offset, int _Origin);long __cdecl ftell(FILE *_Stream);__int64 __cdecl _ftelli64(FILE *_Stream);size_t __cdecl fwrite(void const *_Buffer, size_t _ElementSize, size_t _ElementCount, FILE *_Stream);int __cdecl getc(FILE *_Stream);int __cdecl getchar(void);int __cdecl _getmaxstdio(void);int __cdecl _getw(FILE *_Stream);void __cdecl perror(char const *_ErrorMessage);int __cdecl _pclose(FILE *_Stream);FILE *__cdecl _popen(char const *_Command, char const *_Mode);#line 344 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" int __cdecl putc(int _Character, FILE *_Stream);int __cdecl putchar(int _Character);int __cdecl puts(char const *_Buffer);int __cdecl _putw(int _Word, FILE *_Stream);int __cdecl remove(char const *_FileName);int __cdecl rename(char const *_OldFileName, char const *_NewFileName);int __cdecl _unlink(char const *_FileName);__declspec(deprecated("The POSIX name for this item is deprecated. Instead, use the ISO C " "and C++ conformant name: " "_unlink" ". See online help for details.")) int __cdecl unlink(char const *_FileName);#line 391 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" void __cdecl rewind(FILE *_Stream);int __cdecl _rmtmp(void);__declspec(deprecated("This function or variable may be unsafe. Consider using " "setvbuf" " instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. " "See online help for details.")) void __cdecl setbuf(FILE *_Stream, char *_Buffer);int __cdecl _setmaxstdio(int _Maximum);int __cdecl setvbuf(FILE *_Stream, char *_Buffer, int _Mode, size_t _Size);__declspec(allocator) char *__cdecl _tempnam(char const *_DirectoryName, char const *_FilePrefix);__declspec(deprecated("This function or variable may be unsafe. Consider using " "tmpfile_s" " instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. " "See online help for details.")) FILE *__cdecl tmpfile(void);__declspec(deprecated("This function or variable may be unsafe. Consider using " "tmpnam_s" " instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. " "See online help for details.")) char *__cdecl tmpnam(char *_Buffer);int __cdecl ungetc(int _Character, FILE *_Stream);void __cdecl _lock_file(FILE *_Stream);void __cdecl _unlock_file(FILE *_Stream);int __cdecl _fclose_nolock(FILE *_Stream);int __cdecl _fflush_nolock(FILE *_Stream);int __cdecl _fgetc_nolock(FILE *_Stream);int __cdecl _fputc_nolock(int _Character, FILE *_Stream);size_t __cdecl _fread_nolock(void *_Buffer, size_t _ElementSize, size_t _ElementCount, FILE *_Stream);size_t __cdecl _fread_nolock_s(void *_Buffer, size_t _BufferSize, size_t _ElementSize, size_t _ElementCount, FILE *_Stream);int __cdecl _fseek_nolock(FILE *_Stream, long _Offset, int _Origin);int __cdecl _fseeki64_nolock(FILE *_Stream, __int64 _Offset, int _Origin);long __cdecl _ftell_nolock(FILE *_Stream);__int64 __cdecl _ftelli64_nolock(FILE *_Stream);size_t __cdecl _fwrite_nolock(void const *_Buffer, size_t _ElementSize, size_t _ElementCount, FILE *_Stream);int __cdecl _getc_nolock(FILE *_Stream);int __cdecl _putc_nolock(int _Character, FILE *_Stream);int __cdecl _ungetc_nolock(int _Character, FILE *_Stream);int *__cdecl __p__commode(void);#line 596 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" int __cdecl __stdio_common_vfprintf(unsigned __int64 _Options, FILE *_Stream, char const *_Format, _locale_t _Locale, va_list _ArgList);int __cdecl __stdio_common_vfprintf_s(unsigned __int64 _Options, FILE *_Stream, char const *_Format, _locale_t _Locale, va_list _ArgList);int __cdecl __stdio_common_vfprintf_p(unsigned __int64 _Options, FILE *_Stream, char const *_Format, _locale_t _Locale, va_list _ArgList);__inline int __cdecl _vfprintf_l(FILE *const _Stream, char const *const _Format, _locale_t const _Locale, va_list _ArgList) { return __stdio_common_vfprintf((*__local_stdio_printf_options()), _Stream, _Format, _Locale, _ArgList);} #line 648 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" __inline int __cdecl vfprintf(FILE *const _Stream, char const *const _Format, va_list _ArgList) { return _vfprintf_l(_Stream, _Format,((void *) 0), _ArgList);} #line 662 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" __inline int __cdecl _vfprintf_s_l(FILE *const _Stream, char const *const _Format, _locale_t const _Locale, va_list _ArgList) { return __stdio_common_vfprintf_s((*__local_stdio_printf_options()), _Stream, _Format, _Locale, _ArgList);} #line 677 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" __inline int __cdecl vfprintf_s(FILE *const _Stream, char const *const _Format, va_list _ArgList) { return _vfprintf_s_l(_Stream, _Format,((void *) 0), _ArgList);} #line 693 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" #line 695 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" __inline int __cdecl _vfprintf_p_l(FILE *const _Stream, char const *const _Format, _locale_t const _Locale, va_list _ArgList) { return __stdio_common_vfprintf_p((*__local_stdio_printf_options()), _Stream, _Format, _Locale, _ArgList);} #line 710 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" __inline int __cdecl _vfprintf_p(FILE *const _Stream, char const *const _Format, va_list _ArgList) { return _vfprintf_p_l(_Stream, _Format,((void *) 0), _ArgList);} #line 724 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" __inline int __cdecl _vprintf_l(char const *const _Format, _locale_t const _Locale, va_list _ArgList) { return _vfprintf_l((__acrt_iob_func(1)), _Format, _Locale, _ArgList);} #line 738 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" __inline int __cdecl vprintf(char const *const _Format, va_list _ArgList) { return _vfprintf_l((__acrt_iob_func(1)), _Format,((void *) 0), _ArgList);} #line 751 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" __inline int __cdecl _vprintf_s_l(char const *const _Format, _locale_t const _Locale, va_list _ArgList) { return _vfprintf_s_l((__acrt_iob_func(1)), _Format, _Locale, _ArgList);} #line 765 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" __inline int __cdecl vprintf_s(char const *const _Format, va_list _ArgList) { return _vfprintf_s_l((__acrt_iob_func(1)), _Format,((void *) 0), _ArgList);} #line 780 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" #line 782 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" __inline int __cdecl _vprintf_p_l(char const *const _Format, _locale_t const _Locale, va_list _ArgList) { return _vfprintf_p_l((__acrt_iob_func(1)), _Format, _Locale, _ArgList);} #line 796 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" __inline int __cdecl _vprintf_p(char const *const _Format, va_list _ArgList) { return _vfprintf_p_l((__acrt_iob_func(1)), _Format,((void *) 0), _ArgList);} #line 809 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" __inline int __cdecl _fprintf_l(FILE *const _Stream, char const *const _Format, _locale_t const _Locale,...) { int _Result;va_list _ArgList;((void)(_ArgList=(va_list)(&(_Locale))+((sizeof(_Locale)+sizeof(int) - 1) &~(sizeof(int) - 1)))) ;_Result=_vfprintf_l(_Stream, _Format, _Locale, _ArgList);((void)(_ArgList=(va_list) 0)) ;return _Result;} #line 828 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" __inline int __cdecl fprintf(FILE *const _Stream, char const *const _Format,...) { int _Result;va_list _ArgList;((void)(_ArgList=(va_list)(&(_Format))+((sizeof(_Format)+sizeof(int) - 1) &~(sizeof(int) - 1)))) ;_Result=_vfprintf_l(_Stream, _Format,((void *) 0), _ArgList);((void)(_ArgList=(va_list) 0)) ;return _Result;} #line 846 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" int __cdecl _set_printf_count_output(int _Value);int __cdecl _get_printf_count_output(void);__inline int __cdecl _fprintf_s_l(FILE *const _Stream, char const *const _Format, _locale_t const _Locale,...) { int _Result;va_list _ArgList;((void)(_ArgList=(va_list)(&(_Locale))+((sizeof(_Locale)+sizeof(int) - 1) &~(sizeof(int) - 1)))) ;_Result=_vfprintf_s_l(_Stream, _Format, _Locale, _ArgList);((void)(_ArgList=(va_list) 0)) ;return _Result;} #line 871 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" __inline int __cdecl fprintf_s(FILE *const _Stream, char const *const _Format,...) { int _Result;va_list _ArgList;((void)(_ArgList=(va_list)(&(_Format))+((sizeof(_Format)+sizeof(int) - 1) &~(sizeof(int) - 1)))) ;_Result=_vfprintf_s_l(_Stream, _Format,((void *) 0), _ArgList);((void)(_ArgList=(va_list) 0)) ;return _Result;} #line 891 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" #line 893 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" __inline int __cdecl _fprintf_p_l(FILE *const _Stream, char const *const _Format, _locale_t const _Locale,...) { int _Result;va_list _ArgList;((void)(_ArgList=(va_list)(&(_Locale))+((sizeof(_Locale)+sizeof(int) - 1) &~(sizeof(int) - 1)))) ;_Result=_vfprintf_p_l(_Stream, _Format, _Locale, _ArgList);((void)(_ArgList=(va_list) 0)) ;return _Result;} #line 912 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" __inline int __cdecl _fprintf_p(FILE *const _Stream, char const *const _Format,...) { int _Result;va_list _ArgList;((void)(_ArgList=(va_list)(&(_Format))+((sizeof(_Format)+sizeof(int) - 1) &~(sizeof(int) - 1)))) ;_Result=_vfprintf_p_l(_Stream, _Format,((void *) 0), _ArgList);((void)(_ArgList=(va_list) 0)) ;return _Result;} #line 930 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" __inline int __cdecl _printf_l(char const *const _Format, _locale_t const _Locale,...) { int _Result;va_list _ArgList;((void)(_ArgList=(va_list)(&(_Locale))+((sizeof(_Locale)+sizeof(int) - 1) &~(sizeof(int) - 1)))) ;_Result=_vfprintf_l((__acrt_iob_func(1)), _Format, _Locale, _ArgList);((void)(_ArgList=(va_list) 0)) ;return _Result;} #line 948 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" __inline int __cdecl printf(char const *const _Format,...) { int _Result;va_list _ArgList;((void)(_ArgList=(va_list)(&(_Format))+((sizeof(_Format)+sizeof(int) - 1) &~(sizeof(int) - 1)))) ;_Result=_vfprintf_l((__acrt_iob_func(1)), _Format,((void *) 0), _ArgList);((void)(_ArgList=(va_list) 0)) ;return _Result;} #line 965 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" __inline int __cdecl _printf_s_l(char const *const _Format, _locale_t const _Locale,...) { int _Result;va_list _ArgList;((void)(_ArgList=(va_list)(&(_Locale))+((sizeof(_Locale)+sizeof(int) - 1) &~(sizeof(int) - 1)))) ;_Result=_vfprintf_s_l((__acrt_iob_func(1)), _Format, _Locale, _ArgList);((void)(_ArgList=(va_list) 0)) ;return _Result;} #line 983 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" __inline int __cdecl printf_s(char const *const _Format,...) { int _Result;va_list _ArgList;((void)(_ArgList=(va_list)(&(_Format))+((sizeof(_Format)+sizeof(int) - 1) &~(sizeof(int) - 1)))) ;_Result=_vfprintf_s_l((__acrt_iob_func(1)), _Format,((void *) 0), _ArgList);((void)(_ArgList=(va_list) 0)) ;return _Result;} #line 1002 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" #line 1004 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" __inline int __cdecl _printf_p_l(char const *const _Format, _locale_t const _Locale,...) { int _Result;va_list _ArgList;((void)(_ArgList=(va_list)(&(_Locale))+((sizeof(_Locale)+sizeof(int) - 1) &~(sizeof(int) - 1)))) ;_Result=_vfprintf_p_l((__acrt_iob_func(1)), _Format, _Locale, _ArgList);((void)(_ArgList=(va_list) 0)) ;return _Result;} #line 1022 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" __inline int __cdecl _printf_p(char const *const _Format,...) { int _Result;va_list _ArgList;((void)(_ArgList=(va_list)(&(_Format))+((sizeof(_Format)+sizeof(int) - 1) &~(sizeof(int) - 1)))) ;_Result=_vfprintf_p_l((__acrt_iob_func(1)), _Format,((void *) 0), _ArgList);((void)(_ArgList=(va_list) 0)) ;return _Result;} #line 1039 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" int __cdecl __stdio_common_vfscanf(unsigned __int64 _Options, FILE *_Stream, char const *_Format, _locale_t _Locale, va_list _Arglist);__inline int __cdecl _vfscanf_l(FILE *const _Stream, char const *const _Format, _locale_t const _Locale, va_list _ArgList) { return __stdio_common_vfscanf((*__local_stdio_scanf_options()), _Stream, _Format, _Locale, _ArgList);} #line 1070 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" __inline int __cdecl vfscanf(FILE *const _Stream, char const *const _Format, va_list _ArgList) { return _vfscanf_l(_Stream, _Format,((void *) 0), _ArgList);} #line 1084 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" __inline int __cdecl _vfscanf_s_l(FILE *const _Stream, char const *const _Format, _locale_t const _Locale, va_list _ArgList) { return __stdio_common_vfscanf((*__local_stdio_scanf_options())|(1ULL<< 0), _Stream, _Format, _Locale, _ArgList);} #line 1101 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" __inline int __cdecl vfscanf_s(FILE *const _Stream, char const *const _Format, va_list _ArgList) { return _vfscanf_s_l(_Stream, _Format,((void *) 0), _ArgList);} #line 1118 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" #line 1120 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" __inline int __cdecl _vscanf_l(char const *const _Format, _locale_t const _Locale, va_list _ArgList) { return _vfscanf_l((__acrt_iob_func(0)), _Format, _Locale, _ArgList);} #line 1134 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" __inline int __cdecl vscanf(char const *const _Format, va_list _ArgList) { return _vfscanf_l((__acrt_iob_func(0)), _Format,((void *) 0), _ArgList);} #line 1147 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" __inline int __cdecl _vscanf_s_l(char const *const _Format, _locale_t const _Locale, va_list _ArgList) { return _vfscanf_s_l((__acrt_iob_func(0)), _Format, _Locale, _ArgList);} #line 1161 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" __inline int __cdecl vscanf_s(char const *const _Format, va_list _ArgList) { return _vfscanf_s_l((__acrt_iob_func(0)), _Format,((void *) 0), _ArgList);} #line 1176 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" #line 1178 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" __declspec(deprecated("This function or variable may be unsafe. Consider using " "_fscanf_s_l" " instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. " "See online help for details.")) __inline int __cdecl _fscanf_l(FILE *const _Stream, char const *const _Format, _locale_t const _Locale,...) { int _Result;va_list _ArgList;((void)(_ArgList=(va_list)(&(_Locale))+((sizeof(_Locale)+sizeof(int) - 1) &~(sizeof(int) - 1)))) ;_Result=_vfscanf_l(_Stream, _Format, _Locale, _ArgList);((void)(_ArgList=(va_list) 0)) ;return _Result;} #line 1197 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" __declspec(deprecated("This function or variable may be unsafe. Consider using " "fscanf_s" " instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. " "See online help for details.")) __inline int __cdecl fscanf(FILE *const _Stream, char const *const _Format,...) { int _Result;va_list _ArgList;((void)(_ArgList=(va_list)(&(_Format))+((sizeof(_Format)+sizeof(int) - 1) &~(sizeof(int) - 1)))) ;_Result=_vfscanf_l(_Stream, _Format,((void *) 0), _ArgList);((void)(_ArgList=(va_list) 0)) ;return _Result;} #line 1215 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" __inline int __cdecl _fscanf_s_l(FILE *const _Stream, char const *const _Format, _locale_t const _Locale,...) { int _Result;va_list _ArgList;((void)(_ArgList=(va_list)(&(_Locale))+((sizeof(_Locale)+sizeof(int) - 1) &~(sizeof(int) - 1)))) ;_Result=_vfscanf_s_l(_Stream, _Format, _Locale, _ArgList);((void)(_ArgList=(va_list) 0)) ;return _Result;} #line 1234 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" __inline int __cdecl fscanf_s(FILE *const _Stream, char const *const _Format,...) { int _Result;va_list _ArgList;((void)(_ArgList=(va_list)(&(_Format))+((sizeof(_Format)+sizeof(int) - 1) &~(sizeof(int) - 1)))) ;_Result=_vfscanf_s_l(_Stream, _Format,((void *) 0), _ArgList);((void)(_ArgList=(va_list) 0)) ;return _Result;} #line 1254 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" #line 1256 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" __declspec(deprecated("This function or variable may be unsafe. Consider using " "_scanf_s_l" " instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. " "See online help for details.")) __inline int __cdecl _scanf_l(char const *const _Format, _locale_t const _Locale,...) { int _Result;va_list _ArgList;((void)(_ArgList=(va_list)(&(_Locale))+((sizeof(_Locale)+sizeof(int) - 1) &~(sizeof(int) - 1)))) ;_Result=_vfscanf_l((__acrt_iob_func(0)), _Format, _Locale, _ArgList);((void)(_ArgList=(va_list) 0)) ;return _Result;} #line 1274 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" __declspec(deprecated("This function or variable may be unsafe. Consider using " "scanf_s" " instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. " "See online help for details.")) __inline int __cdecl scanf(char const *const _Format,...) { int _Result;va_list _ArgList;((void)(_ArgList=(va_list)(&(_Format))+((sizeof(_Format)+sizeof(int) - 1) &~(sizeof(int) - 1)))) ;_Result=_vfscanf_l((__acrt_iob_func(0)), _Format,((void *) 0), _ArgList);((void)(_ArgList=(va_list) 0)) ;return _Result;} #line 1291 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" __inline int __cdecl _scanf_s_l(char const *const _Format, _locale_t const _Locale,...) { int _Result;va_list _ArgList;((void)(_ArgList=(va_list)(&(_Locale))+((sizeof(_Locale)+sizeof(int) - 1) &~(sizeof(int) - 1)))) ;_Result=_vfscanf_s_l((__acrt_iob_func(0)), _Format, _Locale, _ArgList);((void)(_ArgList=(va_list) 0)) ;return _Result;} #line 1309 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" __inline int __cdecl scanf_s(char const *const _Format,...) { int _Result;va_list _ArgList;((void)(_ArgList=(va_list)(&(_Format))+((sizeof(_Format)+sizeof(int) - 1) &~(sizeof(int) - 1)))) ;_Result=_vfscanf_s_l((__acrt_iob_func(0)), _Format,((void *) 0), _ArgList);((void)(_ArgList=(va_list) 0)) ;return _Result;} #line 1328 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" #line 1330 "C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt\\stdio.h" int __cdecl __stdio_common_vsprintf(unsigned __int64 _Options, char *_Buffer, size_t _BufferCount, char const *_Format, _locale_t _Locale, va_list _ArgList);int __cdecl __stdio_common_vsprintf_s(unsigned __int64 _Options, char *_Buffer, size_t _BufferCount, char const *_Format, _locale_t _Locale, va_list _ArgList);int __cdecl __stdio_common_vsnprintf_s(unsigned _