-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpntr.h
5780 lines (5160 loc) · 197 KB
/
pntr.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* pntr: Image manipulation library for C99 and C++, with a focus on ease-of-use.
*
* https://github.com/robloach/pntr
*
* Configuration:
* - PNTR_IMPLEMENTATION: Define this in one of your .c files, before including pntr.h
* - PNTR_PIXELFORMAT_RGBA: Use the RGBA format
* - PNTR_PIXELFORMAT_ARGB: Use the ARGB pixel format
* - PNTR_NO_ALPHABLEND: Skips alpha blending when rendering images
* - PNTR_ENABLE_DEFAULT_FONT: Enables the default font
* - PNTR_ENABLE_JPEG: When available, support JPEG image loading
* - PNTR_ENABLE_MATH: When enabled, will use C's math.h library, rather than internal implementations
* - PNTR_ENABLE_TTF: Enables support for loading TrueType fonts
* - PNTR_ENABLE_UTF8: Enables support for UTF-8 text rendering
* - PNTR_ENABLE_VARGS: Adds support for functions that require variadic arguments.
* - PNTR_LOAD_FILE: Callback used to load a file in pntr_load_file(). By default, will use stdio.h.
* - PNTR_LOAD_IMAGE_FROM_MEMORY: Callback to load an image from memory in pntr_load_image_from_memory(). By default, will use cute_png.
* - PNTR_SAVE_FILE: Callback used to save a file in pntr_save_file(). By default, will use stdio.h.
* - PNTR_SAVE_IMAGE_TO_MEMORY: Callback to save an image to memory in pntr_save_image_to_memory(). By default, will use cute_png.
* - PNTR_NO_STDIO: When enabled, will disable the standard file loading/saving calls for PNTR_LOAD_FILE and PNTR_SAVE_FILE.
* - PNTR_NO_SAVE_IMAGE: Disables the default behaviour of saving images.
* - PNTR_NO_LOAD_IMAGE: Disables the default behavior of loading images.
* - PNTR_NO_CUTE_PNG_IMPLEMENTATION: Skips defining CUTE_PNG_IMPLEMENTATION. Useful if you're using cute_png elsewhere.
* - PNTR_NO_STB_IMAGE_IMPLEMENTATION: Skips defining STB_IMAGE_IMPLEMENTATION. Useful if you're using stb_image elsewhere.
* - PNTR_NO_STB_IMAGE_WRITE_IMPLEMENTATION: Skips defining STB_IMAGE_WRITE_IMPLEMENTATION. Useful if you're using stb_image_write elsewhere.
* - PNTR_NO_STB_TRUETYPE_IMPLEMENTATION: Skips defining STB_TRUETYPE_IMPLEMENTATION. Useful if you're using stb_truetype elsewhere.
*
* @file pntr.h
*
* @copyright 2023 Rob Loach (@RobLoach, https://robloach.net)
*
* @license Zlib
*
* Copyright (c) 2023 Rob Loach (@RobLoach, https://robloach.net)
*
* This software is provided "as-is", without any express or implied warranty. In no event
* will the authors be held liable for any damages arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose, including commercial
* applications, and to alter it and redistribute it freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not claim that you
* wrote the original software. If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be misrepresented
* as being the original software.
*
* 3. This notice may not be removed or altered from any source distribution.
*/
#ifndef PNTR_H__
#define PNTR_H__
#include <stdint.h> // uint32_t
#include <stdbool.h> // bool
#include <stddef.h> // size_t
/**
* @defgroup pntr pntr
* @{
*
* @brief Image manipulation library for C99 or C++, with a focus on ease-of-use.
*
* Make sure to define `PNTR_IMPLEMENTATION` before including in one of your `.c` files.
*
* @code
* #define PNTR_IMPLEMENTATION
* #include "pntr.h"
*
* int main() {
* pntr_image* image = pntr_new_image(200, 200);
* pntr_draw_circle_fill(image, 100, 100, 80, PNTR_RED);
* pntr_save_image(image, "output.png");
* pntr_unload_image(image);
*
* return 0;
* }
* @endcode
*
* @see PNTR_IMPLEMENTATION
*/
#ifdef _DOXYGEN_
/**
* @defgroup config Configuration
* @{
*/
/**
* Define `PNTR_IMPLEMENTATION` in **one** of your `.c` files before including `pntr.h`.
*
* This will let pntr.h know where to implement its functions.
*
* @code
* #define PNTR_IMPLEMENTATION
* #include "pntr.h"
*
* int main() {
* return 0;
* }
* @endcode
*/
#define PNTR_IMPLEMENTATION
/**
* When defined, will use the RGBA format.
*
* @see PNTR_PIXELFORMAT_RGBA8888
*/
#define PNTR_PIXELFORMAT_RGBA
/**
* When defined, will use the ARGB pixel format.
*
* @see PNTR_PIXELFORMAT_ARGB8888
*/
#define PNTR_PIXELFORMAT_ARGB
/**
* Enables support for pntr's default font. It's a small 8x8 font.
*
* @see pntr_load_font_default()
*/
#define PNTR_ENABLE_DEFAULT_FONT
/**
* Enables support for loading TrueType fonts with `stb_truetype.h`.
*
* @see pntr_load_font_ttf()
* @see https://github.com/nothings/stb/blob/master/stb_truetype.h
*/
#define PNTR_ENABLE_TTF
/**
* Enable UTF-8 character set support for font loading, and text rendering, with `utf8.h`.
*
* @note When this is enabled, there is an increase in font memory usage.
*
* @see https://github.com/sheredom/utf8.h
*/
#define PNTR_ENABLE_UTF8
/**
* Callback to use when saving an image to memory. By default, will use stb_image_write.
*
* @see pntr_save_image_to_memory()
* @see PNTR_STB_IMAGE
* @see PNTR_CUTE_PNG
* @see pntr_stb_image_save_image_to_memory()
* @see pntr_cute_png_save_image_to_memory()
*/
#define PNTR_SAVE_IMAGE_TO_MEMORY
/**
* Callback to use when loading an image. By default, will use stb_image.
*
* @see pntr_stb_image_load_image_from_memory()
* @see pntr_cute_png_load_image_from_memory()
* @see pntr_load_image_from_memory()
* @see PNTR_CUTE_PNG
* @see PNTR_STB_IMAGE
*/
#define PNTR_LOAD_IMAGE_FROM_MEMORY
/**
* When enabled, will use C's standard math.h library for math functions, rather than pntr's internally build in methods.
*/
#define PNTR_ENABLE_MATH
/**
* Callback to use when loading a file. Must match the `pntr_load_file()` definition.
*
* @see pntr_load_file()
* @see PNTR_NO_STDIO
*/
#define PNTR_LOAD_FILE
/**
* Callback to use when saving a file. Must match the `pntr_save_file()` definition.
*
* @see pntr_save_file()
* @see PNTR_NO_STDIO
*/
#define PNTR_SAVE_FILE
/**
* When defined, will use `stb_image.h` for loading images, and `stb_image_write.h` for saving.
*
* @details By default, `stb_image` will be used if a custom implementation isn't defined.
*
* @see pntr_load_image()
* @see pntr_save_image()
* @see PNTR_CUTE_PNG
* @see PNTR_SAVE_IMAGE_TO_MEMORY
* @see PNTR_LOAD_IMAGE_FROM_MEMORY
*/
#define PNTR_STB_IMAGE
/**
* When defined, will use `cute_png.h` for loading and saving.
*
* @details While cute_png takes up less memory than stb_image, it doesn't support as many of the features.
*
* @see pntr_load_image()
* @see pntr_save_image()
* @see PNTR_STB_IMAGE
* @see PNTR_SAVE_IMAGE_TO_MEMORY
* @see PNTR_LOAD_IMAGE_FROM_MEMORY
*/
#define PNTR_CUTE_PNG
/**
* Skips alpha blending when rendering images. Defining this will improve performance.
*
* @see pntr_color_alpha_blend()
*/
#define PNTR_NO_ALPHABLEND
/**
* Will disable the default use of `stdio.h` for file saving/loading with `PNTR_LOAD_FILE` and `PNTR_SAVE_FILE`.
*
* @see PNTR_LOAD_FILE
* @see PNTR_SAVE_FILE
*/
#define PNTR_NO_STDIO
/**
* Will disable image loading.
*
* @see PNTR_LOAD_IMAGE_FROM_MEMORY
*/
#define PNTR_NO_LOAD_IMAGE
/**
* Will disable image saving.
*
* @see PNTR_SAVE_IMAGE_TO_MEMORY
*/
#define PNTR_NO_SAVE_IMAGE
/**
* Skips defining `CUTE_PNG_IMPLEMENTATION`. Useful if you're using cute_png elsewhere.
*/
#define PNTR_NO_CUTE_PNG_IMPLEMENTATION
/**
* Skips defining `STB_IMAGE_WRITE_IMPLEMENTATION`. Useful if you're using stb_image_write elsewhere.
*/
#define PNTR_NO_STB_IMAGE_WRITE_IMPLEMENTATION
/**
* Skips defining `STB_IMAGE_IMPLEMENTATION`. Useful if you're using stb_image elsewhere.
*/
#define PNTR_NO_STB_IMAGE_IMPLEMENTATION
/**
* Skips defining `STB_TRUETYPE_IMPLEMENTATION`. Useful if you're using stb_truetype elsewhere.
*/
#define PNTR_NO_STB_TRUETYPE_IMPLEMENTATION
/**
* @}
*/
#endif
#ifndef PNTR_API
/**
* Prefix applied to all pntr methods.
*
* If you're using Emscripten, for instance, you could use the following to export all pntr methods:
*
* #define PNTR_API EMSCRIPTEN_KEEPALIVE
*/
#define PNTR_API
#endif
// Pixel Format. Default to PNTR_PIXELFORMAT_RGBA
#if !defined(PNTR_PIXELFORMAT_RGBA) && !defined(PNTR_PIXELFORMAT_ARGB)
#define PNTR_PIXELFORMAT_RGBA
#endif
#if defined(PNTR_PIXELFORMAT_RGBA) && defined(PNTR_PIXELFORMAT_ARGB)
#undef PNTR_PIXELFORMAT_ARGB
#endif
#ifdef PNTR_PIXELFORMAT
#undef PNTR_PIXELFORMAT
#endif
#ifdef PNTR_PIXELFORMAT_RGBA
/**
* The set pixel format for the application.
*
* Will become either `PNTR_PIXELFORMAT_ARGB8888` or `PNTR_PIXELFORMAT_RGBA8888`, with the default being `PNTR_PIXELFORMAT_RGBA8888`.
*
* @see PNTR_PIXELFORMAT_RGBA8888
* @see PNTR_PIXELFORMAT_ARGB8888
*/
#define PNTR_PIXELFORMAT PNTR_PIXELFORMAT_RGBA8888
#elif defined(PNTR_PIXELFORMAT_ARGB)
#define PNTR_PIXELFORMAT PNTR_PIXELFORMAT_ARGB8888
#endif
#ifndef PNTR_CLITERAL
#if defined(__cplusplus)
#define PNTR_CLITERAL(type) type
#else
/**
* Compound literal to initialize a structure.
*
* @param type The type of the structure to intiailize.
* @return The initialized structure.
* @note MSVC C++ compiler does not support compound literals (C99 feature)
*
* @code
* pntr_color color = PNTR_CLITERAL(pntr_color) { 255, 255, 255, 255 };
* @endif
*/
#define PNTR_CLITERAL(type) (type)
#endif
#endif
/**
* Color, represented by an unsigned 32-bit integer.
*
* Has four components: Red, Green, Blue, and Alpha. Depending on the pixel format, will
* shift the order in which the components are defines.
*
* @see pntr_new_color()
* @see pntr_get_color()
* @see PNTR_PIXELFORMAT_RGBA
* @see PNTR_PIXELFORMAT_ARGB
*/
typedef union pntr_color {
/**
* The color value, represented by an unsigned 32-bit integer.
*/
uint32_t value;
/**
* Union data representing the 32-bit integer, split into four bytes.
*
* The order in which the values are sorted depends on which pixel format you're using.
*
* @see PNTR_PIXELFORMAT_RGBA
* @see PNTR_PIXELFORMAT_ARGB
*/
struct pntr_color_rgba_t {
#if defined(PNTR_PIXELFORMAT_RGBA)
unsigned char r; /** Red channel. */
unsigned char g; /** Green channel. */
unsigned char b; /** Blue channel. */
unsigned char a; /** Alpha channel. */
#elif defined(PNTR_PIXELFORMAT_ARGB)
unsigned char b; /** Blue channel. */
unsigned char g; /** Green channel. */
unsigned char r; /** Red channel. */
unsigned char a; /** Alpha channel. */
#endif
} rgba;
} pntr_color;
/**
* A rectangle.
*/
typedef struct pntr_rectangle {
int x; /** The x position of the rectangle. */
int y; /** The y position of the rectangle. */
int width; /** The width of the rectangle. */
int height; /** The height of the rectangle. */
} pntr_rectangle;
/**
* An image, represented by pixel data.
*
* @see pntr_new_image()
* @see pntr_gen_image_color()
*/
typedef struct pntr_image {
pntr_color* data; /** The pixel data for the image. */
int width; /** The width of the image. */
int height; /** The height of the image. */
int pitch; /** The amount of bytes of one row of the image. */
/**
* Whether or not the image is a portion of another image, sharing the same image data.
*
* @see pntr_image_subimage()
*/
bool subimage;
/**
* A rectangle representing the region of the image that can be changed.
*
* @see pntr_image_set_clip()
* @see pntr_image_reset_clip()
* @see pntr_image_get_clip()
*/
pntr_rectangle clip;
} pntr_image;
/**
* A vector, represented by x and y coordinates.
*/
typedef struct pntr_vector {
int x; /** The X coordinate. */
int y; /** The Y coordinate. */
} pntr_vector;
/**
* Font used to render text.
*
* @see pntr_load_font_tty()
* @see pntr_load_font_ttf()
* @see pntr_load_font_bmf()
* @see PNTR_ENABLE_UTF8
* @see PNTR_ENABLE_TTF
*/
typedef struct pntr_font {
pntr_image* atlas; /** The image used for the character atlas for the font. */
pntr_rectangle* srcRects; /** The glyph source rectangles on the atlas. */
pntr_rectangle* glyphRects; /** How the glyph appears when rendering. */
char* characters; /** An array of characters that are available in the font's atlas. */
int charactersLen; /** The number of characters that the font implements. */
void* user_data; /** General extra user data that can be referenced to by the font. */
} pntr_font;
/**
* Pixel format.
*/
typedef enum pntr_pixelformat {
PNTR_PIXELFORMAT_RGBA8888 = 0, /** RGBA, with 8 bytes for each component. */
PNTR_PIXELFORMAT_ARGB8888, /** ARGB, with 8 bytes for each component. */
PNTR_PIXELFORMAT_GRAYSCALE /** Grayscale, with one byte for each pixel, 0 - 255. 0 being disabled, 255 being enabled. */
} pntr_pixelformat;
/**
* Possible image filters to apply.
*/
typedef enum pntr_filter {
PNTR_FILTER_NEARESTNEIGHBOR = 0, /** Nearest-neighbor interpolation for fast processing. Good for a pixel art look. */
PNTR_FILTER_BILINEAR /** Bilinear interpolation will combine multiple pixels together when processing for smoother scaling. */
} pntr_filter;
/**
* Error states definitions.
*
* @see pntr_set_error()
* @see pntr_get_error()
*/
typedef enum pntr_error {
PNTR_ERROR_NONE = 0, /** No error */
PNTR_ERROR_INVALID_ARGS = -1, /** Invalid arguments */
PNTR_ERROR_NO_MEMORY = -2, /** Not enough memory */
PNTR_ERROR_NOT_SUPPORTED = -3, /** Not supported */
PNTR_ERROR_FAILED_TO_OPEN = -4, /** Failed to open */
PNTR_ERROR_FAILED_TO_WRITE = -5, /** Failed to write */
PNTR_ERROR_UNKNOWN = -6 /** Unknown error occurred */
} pntr_error;
/**
* The associated image format.
*/
typedef enum pntr_image_type {
PNTR_IMAGE_TYPE_UNKNOWN = 0, /** Image type: Unknown. */
PNTR_IMAGE_TYPE_PNG, /** Image type: PNG - Portable Network Graphics */
PNTR_IMAGE_TYPE_JPG, /** Image type: JPEG - Joint Photographic Experts Group */
PNTR_IMAGE_TYPE_BMP /** Image type: BMP - Bitmap */
} pntr_image_type;
#ifdef __cplusplus
extern "C" {
#endif
PNTR_API pntr_image* pntr_new_image(int width, int height);
PNTR_API pntr_image* pntr_gen_image_color(int width, int height, pntr_color color);
PNTR_API pntr_image* pntr_image_copy(pntr_image* image);
PNTR_API pntr_image* pntr_image_from_image(pntr_image* image, int x, int y, int width, int height);
PNTR_API pntr_image* pntr_image_subimage(pntr_image* image, int x, int y, int width, int height);
PNTR_API pntr_rectangle pntr_image_get_clip(pntr_image* image);
PNTR_API void pntr_image_set_clip(pntr_image* image, int x, int y, int width, int height);
PNTR_API void pntr_image_set_clip_rec(pntr_image* image, pntr_rectangle clip);
PNTR_API void pntr_image_reset_clip(pntr_image* image);
PNTR_API void pntr_unload_image(pntr_image* image);
PNTR_API void pntr_clear_background(pntr_image* image, pntr_color color);
PNTR_API void pntr_draw_point(pntr_image* dst, int x, int y, pntr_color color);
PNTR_API void pntr_draw_point_vec(pntr_image* dst, pntr_vector* point, pntr_color color);
PNTR_API void pntr_draw_points(pntr_image* dst, pntr_vector* points, int pointsCount, pntr_color color);
PNTR_API void pntr_draw_line(pntr_image* dst, int startPosX, int startPosY, int endPosX, int endPosY, pntr_color color);
PNTR_API void pntr_draw_line_curve(pntr_image* dst, pntr_vector point1, pntr_vector point2, pntr_vector point3, pntr_vector point4, int segments, pntr_color color);
PNTR_API void pntr_draw_line_vec(pntr_image* dst, pntr_vector start, pntr_vector end, pntr_color color);
PNTR_API void pntr_draw_line_vertical(pntr_image* dst, int posX, int posY, int height, pntr_color color);
PNTR_API void pntr_draw_line_horizontal(pntr_image* dst, int posX, int posY, int width, pntr_color color);
PNTR_API void pntr_draw_rectangle(pntr_image* dst, int posX, int posY, int width, int height, pntr_color color);
PNTR_API void pntr_draw_rectangle_rec(pntr_image* dst, pntr_rectangle rec, pntr_color color);
PNTR_API void pntr_draw_rectangle_fill(pntr_image* dst, int posX, int posY, int width, int height, pntr_color color);
PNTR_API void pntr_draw_rectangle_fill_rec(pntr_image* dst, pntr_rectangle rect, pntr_color color);
PNTR_API void pntr_draw_rectangle_gradient(pntr_image* dst, int x, int y, int width, int height, pntr_color topLeft, pntr_color topRight, pntr_color bottomLeft, pntr_color bottomRight);
PNTR_API void pntr_draw_rectangle_gradient_rec(pntr_image* dst, pntr_rectangle rect, pntr_color topLeft, pntr_color topRight, pntr_color bottomLeft, pntr_color bottomRight);
PNTR_API void pntr_draw_triangle(pntr_image* dst, int x1, int y1, int x2, int y2, int x3, int y3, pntr_color color);
PNTR_API void pntr_draw_triangle_vec(pntr_image* dst, pntr_vector point1, pntr_vector point2, pntr_vector point3, pntr_color color);
PNTR_API void pntr_draw_triangle_fill(pntr_image* dst, int x1, int y1, int x2, int y2, int x3, int y3, pntr_color color);
PNTR_API void pntr_draw_triangle_fill_vec(pntr_image* dst, pntr_vector point1, pntr_vector point2, pntr_vector point3, pntr_color color);
PNTR_API void pntr_draw_ellipse(pntr_image* dst, int centerX, int centerY, int radiusX, int radiusY, pntr_color color);
PNTR_API void pntr_draw_ellipse_fill(pntr_image* dst, int centerX, int centerY, int radiusX, int radiusY, pntr_color color);
PNTR_API void pntr_draw_circle(pntr_image* dst, int centerX, int centerY, int radius, pntr_color color);
PNTR_API void pntr_draw_circle_fill(pntr_image* dst, int centerX, int centerY, int radius, pntr_color color);
PNTR_API void pntr_draw_polygon(pntr_image* dst, pntr_vector* points, int numPoints, pntr_color color);
PNTR_API void pntr_draw_polygon_fill(pntr_image* dst, pntr_vector* points, int numPoints, pntr_color color);
PNTR_API void pntr_draw_polyline(pntr_image* dst, pntr_vector* points, int numPoints, pntr_color color);
PNTR_API void pntr_draw_arc(pntr_image* dst, int centerX, int centerY, float radius, float startAngle, float endAngle, int segments, pntr_color color);
PNTR_API void pntr_draw_arc_fill(pntr_image* dst, int centerX, int centerY, float radius, float startAngle, float endAngle, int segments, pntr_color color);
PNTR_API void pntr_draw_rectangle_rounded(pntr_image* dst, int x, int y, int width, int height, int topLeftRadius, int topRightRadius, int bottomLeftRadius, int bottomRightRadius, pntr_color color);
PNTR_API void pntr_draw_rectangle_rounded_fill(pntr_image* dst, int x, int y, int width, int height, int cornerRadius, pntr_color color);
PNTR_API void pntr_draw_image(pntr_image* dst, pntr_image* src, int posX, int posY);
PNTR_API void pntr_draw_image_rec(pntr_image* dst, pntr_image* src, pntr_rectangle srcRect, int posX, int posY);
PNTR_API void pntr_draw_image_tint(pntr_image* dst, pntr_image* src, int posX, int posY, pntr_color tint);
PNTR_API void pntr_draw_image_tint_rec(pntr_image* dst, pntr_image* src, pntr_rectangle srcRect, int posX, int posY, pntr_color tint);
PNTR_API void pntr_draw_image_rotated(pntr_image* dst, pntr_image* src, int posX, int posY, float degrees, float offsetX, float offsetY, pntr_filter filter);
PNTR_API void pntr_draw_image_rotated_rec(pntr_image* dst, pntr_image* src, pntr_rectangle srcRect, int posX, int posY, float degrees, float offsetX, float offsetY, pntr_filter filter);
PNTR_API void pntr_draw_image_flipped(pntr_image* dst, pntr_image* src, int posX, int posY, bool flipHorizontal, bool flipVertical, bool flipDiagonal);
PNTR_API void pntr_draw_image_flipped_rec(pntr_image* dst, pntr_image* src, pntr_rectangle srcRec, int posX, int posY, bool flipHorizontal, bool flipVertical, bool flipDiagonal);
PNTR_API void pntr_draw_image_scaled(pntr_image* dst, pntr_image* src, int posX, int posY, float scaleX, float scaleY, float offsetX, float offsetY, pntr_filter filter);
PNTR_API void pntr_draw_image_scaled_rec(pntr_image* dst, pntr_image* src, pntr_rectangle srcRect, int posX, int posY, float scaleX, float scaleY, float offsetX, float offsetY, pntr_filter filter);
PNTR_API void pntr_draw_text(pntr_image* dst, pntr_font* font, const char* text, int posX, int posY, pntr_color tint);
PNTR_API void pntr_draw_text_len(pntr_image* dst, pntr_font* font, const char* text, int textLength, int posX, int posY, pntr_color tint);
PNTR_API void pntr_draw_text_wrapped(pntr_image* dst, pntr_font* font, const char* text, int posX, int posY, int maxWidth, pntr_color tint);
#ifdef PNTR_ENABLE_VARGS
PNTR_API void pntr_draw_text_ex(pntr_image* dst, pntr_font* font, int posX, int posY, pntr_color tint, const char* text, ...);
#endif
PNTR_API pntr_color pntr_new_color(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
PNTR_API pntr_color pntr_get_color(unsigned int hexValue);
PNTR_API unsigned char pntr_color_r(pntr_color color);
PNTR_API unsigned char pntr_color_g(pntr_color color);
PNTR_API unsigned char pntr_color_b(pntr_color color);
PNTR_API unsigned char pntr_color_a(pntr_color color);
PNTR_API void pntr_color_set_r(pntr_color* color, unsigned char r);
PNTR_API void pntr_color_set_g(pntr_color* color, unsigned char g);
PNTR_API void pntr_color_set_b(pntr_color* color, unsigned char b);
PNTR_API void pntr_color_set_a(pntr_color* color, unsigned char a);
PNTR_API pntr_color pntr_image_get_color(pntr_image* image, int x, int y);
PNTR_API bool pntr_save_file(const char *fileName, const void *data, unsigned int bytesToWrite);
PNTR_API void* pntr_image_to_pixelformat(pntr_image* image, unsigned int* dataSize, pntr_pixelformat pixelFormat);
PNTR_API bool pntr_save_image(pntr_image* image, const char* fileName);
PNTR_API unsigned char* pntr_save_image_to_memory(pntr_image* image, pntr_image_type type, unsigned int* dataSize);
PNTR_API int pntr_get_pixel_data_size(int width, int height, pntr_pixelformat pixelFormat);
PNTR_API pntr_image* pntr_load_image(const char* fileName);
PNTR_API pntr_image* pntr_load_image_from_memory(pntr_image_type type, const unsigned char* fileData, unsigned int dataSize);
PNTR_API pntr_image* pntr_image_from_pixelformat(const void* data, int width, int height, pntr_pixelformat pixelFormat);
PNTR_API void* pntr_set_error(pntr_error error);
PNTR_API const char* pntr_get_error(void);
PNTR_API pntr_error pntr_get_error_code(void);
PNTR_API pntr_image* pntr_image_resize(pntr_image* image, int newWidth, int newHeight, pntr_filter filter);
PNTR_API pntr_image* pntr_image_scale(pntr_image* image, float scaleX, float scaleY, pntr_filter filter);
PNTR_API void pntr_image_color_replace(pntr_image* image, pntr_color color, pntr_color replace);
PNTR_API pntr_color pntr_color_tint(pntr_color color, pntr_color tint);
PNTR_API void pntr_image_color_tint(pntr_image* image, pntr_color color);
PNTR_API pntr_color pntr_color_fade(pntr_color color, float alpha);
PNTR_API void pntr_image_color_fade(pntr_image* image, float alpha);
PNTR_API pntr_color pntr_color_brightness(pntr_color color, float factor);
PNTR_API pntr_color pntr_get_pixel_color(void* srcPtr, pntr_pixelformat srcPixelFormat);
PNTR_API void pntr_set_pixel_color(void* dstPtr, pntr_pixelformat dstPixelFormat, pntr_color color);
PNTR_API pntr_font* pntr_load_font_default(void);
PNTR_API void pntr_unload_font(pntr_font* font);
PNTR_API pntr_font* pntr_font_copy(pntr_font* font);
PNTR_API pntr_font* pntr_font_scale(pntr_font* font, float scaleX, float scaleY, pntr_filter filter);
PNTR_API pntr_font* pntr_load_font_bmf(const char* fileName, const char* characters);
PNTR_API pntr_font* pntr_load_font_bmf_from_image(pntr_image* image, const char* characters);
PNTR_API pntr_font* pntr_load_font_bmf_from_memory(const unsigned char* fileData, unsigned int dataSize, const char* characters);
PNTR_API int pntr_measure_text(pntr_font* font, const char* text);
PNTR_API pntr_vector pntr_measure_text_ex(pntr_font* font, const char* text, int textLength);
PNTR_API pntr_image* pntr_gen_image_text(pntr_font* font, const char* text, pntr_color tint, pntr_color backgroundColor);
PNTR_API pntr_font* pntr_load_font_tty(const char* fileName, int glyphWidth, int glyphHeight, const char* characters);
PNTR_API pntr_font* pntr_load_font_tty_from_memory(const unsigned char* fileData, unsigned int dataSize, int glyphWidth, int glyphHeight, const char* characters);
PNTR_API pntr_font* pntr_load_font_tty_from_image(pntr_image* image, int glyphWidth, int glyphHeight, const char* characters);
PNTR_API unsigned char* pntr_load_file(const char *fileName, unsigned int *bytesRead);
PNTR_API void pntr_unload_file(unsigned char* fileData);
PNTR_API const char* pntr_load_file_text(const char *fileName);
PNTR_API void pntr_unload_file_text(const char* text);
PNTR_API pntr_font* pntr_load_font_ttf(const char* fileName, int fontSize);
PNTR_API pntr_font* pntr_load_font_ttf_from_memory(const unsigned char* fileData, unsigned int dataSize, int fontSize);
PNTR_API pntr_color pntr_color_invert(pntr_color color);
PNTR_API void pntr_image_color_invert(pntr_image* image);
PNTR_API pntr_color pntr_color_alpha_blend(pntr_color dst, pntr_color src);
PNTR_API pntr_rectangle pntr_image_alpha_border(pntr_image* image, float threshold);
PNTR_API bool pntr_image_crop(pntr_image* image, int x, int y, int width, int height);
PNTR_API void pntr_image_alpha_crop(pntr_image* image, float threshold);
PNTR_API void pntr_image_color_brightness(pntr_image* image, float factor);
PNTR_API void pntr_image_flip(pntr_image* image, bool horizontal, bool vertical);
PNTR_API pntr_color pntr_color_contrast(pntr_color color, float contrast);
PNTR_API void pntr_image_color_contrast(pntr_image* image, float contrast);
PNTR_API void pntr_image_alpha_mask(pntr_image* image, pntr_image* alphaMask, int posX, int posY);
PNTR_API bool pntr_image_resize_canvas(pntr_image* image, int newWidth, int newHeight, int offsetX, int offsetY, pntr_color fill);
PNTR_API pntr_image* pntr_image_rotate(pntr_image* image, float degrees, pntr_filter filter);
PNTR_API pntr_image* pntr_gen_image_gradient(int width, int height, pntr_color topLeft, pntr_color topRight, pntr_color bottomLeft, pntr_color bottomRight);
PNTR_API pntr_color pntr_color_bilinear_interpolate(pntr_color color00, pntr_color color01, pntr_color color10, pntr_color color11, float coordinateX, float coordinateY);
PNTR_API void* pntr_load_memory(size_t size);
PNTR_API void pntr_unload_memory(void* pointer);
PNTR_API void* pntr_memory_copy(void* destination, void* source, size_t size);
PNTR_API pntr_image_type pntr_get_file_image_type(const char* filePath);
PNTR_API void pntr_draw_line_thick(pntr_image* dst, int startPosX, int startPosY, int endPosX, int endPosY, int thickness, pntr_color color);
PNTR_API void pntr_draw_line_thick_vec(pntr_image* dst, pntr_vector start, pntr_vector end, int thickness, pntr_color color);
PNTR_API void pntr_draw_rectangle_thick(pntr_image* dst, int posX, int posY, int width, int height, int thickness, pntr_color color);
PNTR_API void pntr_draw_rectangle_thick_rec(pntr_image* dst, pntr_rectangle rect, int thickness, pntr_color color);
PNTR_API void pntr_draw_triangle_thick(pntr_image* dst, int x1, int y1, int x2, int y2, int x3, int y3, int thickness, pntr_color color);
PNTR_API void pntr_draw_triangle_thick_vec(pntr_image* dst, pntr_vector point1, pntr_vector point2, pntr_vector point3, int thickness, pntr_color color);
PNTR_API void pntr_draw_ellipse_thick(pntr_image* dst, int centerX, int centerY, int radiusX, int radiusY, int thickness, pntr_color color);
PNTR_API void pntr_draw_circle_thick(pntr_image* dst, int centerX, int centerY, int radius, int thickness, pntr_color color);
PNTR_API void pntr_draw_polygon_thick(pntr_image* dst, pntr_vector* points, int numPoints, int thickness, pntr_color color);
PNTR_API void pntr_draw_polyline_thick(pntr_image* dst, pntr_vector* points, int numPoints, int thickness, pntr_color color);
PNTR_API void pntr_draw_arc_thick(pntr_image* dst, int centerX, int centerY, float radius, float startAngle, float endAngle, int segments, int thickness, pntr_color color);
PNTR_API void pntr_draw_rectangle_thick_rounded(pntr_image* dst, int x, int y, int width, int height, int topLeftRadius, int topRightRadius, int bottomLeftRadius, int bottomRightRadius, int thickness, pntr_color color);
PNTR_API void pntr_draw_line_vertical_thick(pntr_image* dst, int posX, int posY, int height, int thickness, pntr_color color);
PNTR_API void pntr_draw_line_horizontal_thick(pntr_image* dst, int posX, int posY, int width, int thickness, pntr_color color);
PNTR_API void pntr_draw_line_curve_thick(pntr_image* dst, pntr_vector point1, pntr_vector point2, pntr_vector point3, pntr_vector point4, int segments, int thickness, pntr_color color);
// Internal
PNTR_API void pntr_put_horizontal_line_unsafe(pntr_image* dst, int posX, int posY, int width, pntr_color color);
PNTR_API void pntr_draw_point_unsafe(pntr_image* dst, int x, int y, pntr_color color);
#ifdef __cplusplus
}
#endif
/**
* @defgroup colors Colors
* @{
*/
#ifndef PNTR_LIGHTGRAY
/**
* Light gray.
*/
#define PNTR_LIGHTGRAY pntr_new_color(200, 200, 200, 255)
#endif
#ifndef PNTR_GRAY
/**
* Gray.
*/
#define PNTR_GRAY pntr_new_color(130, 130, 130, 255)
#endif
#ifndef PNTR_DARKGRAY
/**
* Dark gray.
*/
#define PNTR_DARKGRAY pntr_new_color(80, 80, 80, 255)
#endif
#ifndef PNTR_YELLOW
/**
* Yellow.
*/
#define PNTR_YELLOW pntr_new_color(253, 249, 0, 255)
#endif
#ifndef PNTR_GOLD
/**
* Gold.
*/
#define PNTR_GOLD pntr_new_color(255, 203, 0, 255)
#endif
#ifndef PNTR_ORANGE
/**
* Orange.
*/
#define PNTR_ORANGE pntr_new_color(255, 161, 0, 255)
#endif
#ifndef PNTR_PINK
/**
* Pink.
*/
#define PNTR_PINK pntr_new_color(255, 109, 194, 255)
#endif
#ifndef PNTR_RED
/**
* Red.
*/
#define PNTR_RED pntr_new_color(230, 41, 55, 255)
#endif
#ifndef PNTR_MAROON
/**
* Maroon.
*/
#define PNTR_MAROON pntr_new_color(190, 33, 55, 255)
#endif
#ifndef PNTR_GREEN
/**
* Green.
*/
#define PNTR_GREEN pntr_new_color(0, 228, 48, 255)
#endif
#ifndef PNTR_LIME
/**
* Lime.
*/
#define PNTR_LIME pntr_new_color(0, 158, 47, 255)
#endif
#ifndef PNTR_DARKGREEN
/**
* Dark green.
*/
#define PNTR_DARKGREEN pntr_new_color(0, 117, 44, 255)
#endif
#ifndef PNTR_SKYBLUE
/**
* Sky blue.
*/
#define PNTR_SKYBLUE pntr_new_color(102, 191, 255, 255)
#endif
#ifndef PNTR_BLUE
/**
* Blue.
*/
#define PNTR_BLUE pntr_new_color(0, 121, 241, 255)
#endif
#ifndef PNTR_DARKBLUE
/**
* Dark blue.
*/
#define PNTR_DARKBLUE pntr_new_color(0, 82, 172, 255)
#endif
#ifndef PNTR_PURPLE
/**
* Purple.
*/
#define PNTR_PURPLE pntr_new_color(200, 122, 255, 255)
#endif
#ifndef PNTR_VIOLET
/**
* Violet.
*/
#define PNTR_VIOLET pntr_new_color(135, 60, 190, 255)
#endif
#ifndef PNTR_DARKPURPLE
/**
* Dark purple.
*/
#define PNTR_DARKPURPLE pntr_new_color(112, 31, 126, 255)
#endif
#ifndef PNTR_BEIGE
/**
* Beige.
*/
#define PNTR_BEIGE pntr_new_color(211, 176, 131, 255)
#endif
#ifndef PNTR_BROWN
/**
* Brown.
*/
#define PNTR_BROWN pntr_new_color(127, 106, 79, 255)
#endif
#ifndef PNTR_DARKBROWN
/**
* Dark brown.
*/
#define PNTR_DARKBROWN pntr_new_color(76, 63, 47, 255)
#endif
#ifndef PNTR_WHITE
/**
* White.
*/
#define PNTR_WHITE pntr_new_color(255, 255, 255, 255)
#endif
#ifndef PNTR_WHITE_VALUE
/**
* The integer representation of PNTR_WHITE.
*
* @note This is the same as \c PNTR_WHITE.value .
*
* @private
* @internal
*/
#define PNTR_WHITE_VALUE 4294967295
#endif // PNTR_WHITE_VALUE
#ifndef PNTR_BLACK
/**
* Black.
*/
#define PNTR_BLACK pntr_new_color(0, 0, 0, 255)
#endif
#ifndef PNTR_BLANK
/**
* Blank, or transparent.
*/
#define PNTR_BLANK pntr_new_color(0, 0, 0, 0)
#endif
#ifndef PNTR_MAGENTA
/**
* Magenta.
*/
#define PNTR_MAGENTA pntr_new_color(255, 0, 255, 255)
#endif
#ifndef PNTR_RAYWHITE
/**
* The white used in raylib.
*/
#define PNTR_RAYWHITE pntr_new_color(245, 245, 245, 255)
#endif
/**
* @}
*/
#endif // PNTR_H__
#ifdef PNTR_IMPLEMENTATION
#ifndef PNTR_IMPLEMENTATION_ONCE
#define PNTR_IMPLEMENTATION_ONCE
#if defined(PNTR_ENABLE_UTF8) && !defined(_DOXYGEN_)
#include "external/utf8.h"
#define PNTR_STRSTR utf8str
#define PNTR_STRCHR utf8chr
#define PNTR_STRLEN utf8len
#define PNTR_STRSIZE utf8size
#define PNTR_STRCODEPOINT utf8codepoint
typedef utf8_int32_t pntr_codepoint_t;
#else
/**
* A type representing a single character or UTF-8 codepoint.
*
* With UTF-8, a single character can be up to 4 bytes, so having this type define that helps determine its size quickly.
*
* @see PNTR_ENABLE_UTF8
*/
typedef char pntr_codepoint_t;
#endif
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup memory Memory
* @{
*/
#ifndef PNTR_MALLOC
#include <stdlib.h>
/**
* Allocates the requested memory and returns a pointer to it.
*
* @param size (size_t) number of bytes to allocate
*
* @return On success, returns the pointer to the beginning of newly allocated memory.
* @see PNTR_FREE
* @see https://en.cppreference.com/w/c/memory/malloc
*/
#define PNTR_MALLOC(size) malloc(size)
#endif // PNTR_MALLOC
#ifndef PNTR_FREE
#include <stdlib.h>
/**
* Deallocates the previously allocated memory.
*
* @param ptr (void*) pointer to the memory to deallocate
*
* @see PNTR_MALLOC
* @see https://en.cppreference.com/w/c/memory/free
*/
#define PNTR_FREE(ptr) free(ptr)
#endif // PNTR_FREE
#ifndef PNTR_REALLOC
#include <stdlib.h>
/**
* Attempts to resize the memory block pointed to that was previously allocated.
*
* @param ptr (void*) pointer to the memory area to be reallocated
* @param new_size (size_t) new size of the array in bytes
*
* @return On success, returns the pointer to the beginning of newly allocated memory. To avoid a memory leak, the returned pointer must be deallocated with free or realloc. The original pointer ptr is invalidated and any access to it is undefined behavior (even if reallocation was in-place).
*
* @see https://en.cppreference.com/w/c/memory/realloc
*/
#define PNTR_REALLOC(ptr, new_size) realloc(ptr, new_size)
#endif // PNTR_REALLOC
#ifndef PNTR_MEMCPY
#include <string.h>
/**
* Copies data from memory area src to the destination memory.
*
* @param dest (void*) pointer to the object to copy to
* @param src (const void*) pointer to the object to copy from
* @param n (size_t) number of bytes to copy
*
* @see https://en.cppreference.com/w/c/string/byte/memcpy
*/
#define PNTR_MEMCPY(dest, src, n) memcpy(dest, src, (n))
#endif // PNTR_MEMCPY
#ifndef PNTR_MEMSET
#include <string.h>
/**
* Copies the character c (an unsigned char) to the first n characters of the string pointed to, by the argument str.
*/
#define PNTR_MEMSET(str, c, n) memset((str), (c), (n))
#endif // PNTR_MEMSET
/**
* @}
*/
/**
* @defgroup strings String Manipulation
* @{
*/
#ifndef PNTR_STRSTR
#include <string.h>
/**
* Returns a pointer to the first occurrence of str2 in str1, or a null pointer if str2 is not part of str1.
*
* By default, will use string.h's `strstr`. When `PNTR_ENABLE_UTF8` is enabled, will be `utf8str`.
*
* @param str1 (const char*) C string to be scanned.
* @param str2 (const char*) containing the sequence of characters to match.
*
* @return A pointer to the first occurrence in str1 of the entire sequence of characters specified in str2, or a null pointer if the sequence is not present in str1.
*
* @see PNTR_ENABLE_UTF8
*/
#define PNTR_STRSTR strstr
#endif
#ifndef PNTR_STRCHR
#include <string.h>
/**
* Returns a pointer to the first occurance of a character in a string.
*
* By default, will use string.h's `strchr`. When `PNTR_ENABLE_UTF8` is enabled, will be `utf8chr`.
*
* @see PNTR_ENABLE_UTF8
*/
#define PNTR_STRCHR strchr
#endif
#ifndef PNTR_STRLEN
#include <string.h>
/**
* Returns the length of a string.
*
* By default, will use string.h's `strlen`. When `PNTR_ENABLE_UTF8` is enabled, will be `utf8len`.
*
* @see PNTR_ENABLE_UTF8
*/
#define PNTR_STRLEN strlen
#endif
#ifndef PNTR_STRSIZE
#include <string.h>
/**
* Calculates the amount of bytes in a string, including the null character.
*
* By default, will use string.h's `strlen(text) + 1`. When `PNTR_ENABLE_UTF8` is enabled, this will be `utf8size`.
*
* @see PNTR_ENABLE_UTF8
*/
#define PNTR_STRSIZE(text) ((PNTR_STRLEN(text) + (size_t)1))
#endif
#ifndef PNTR_STRCODEPOINT
/**
* Sets out_codepoint to the current utf8 codepoint in str, and returns the address of the next utf8 codepoint after the current one in str.
*
* @param str The string to get the codepoint from
* @param out_codepoint The codepoint to set
*
* @return The address of the next codepoint.
*
* @private
* @internal
* @see PNTR_ENABLE_UTF8
* @see utf8codepoint
*/
char* pntr_strcodepoint(const char * str, char* out_codepoint) {
if (str == NULL) {
*out_codepoint = 0;
}
*out_codepoint = str[0];
return (char*)(str + 1);
}
/**
* Sets out_codepoint to the current utf8 codepoint in str, and returns the address of the next utf8 codepoint after the current one in str.
*
* When `PNTR_ENABLE_UTF8` is enabled, will be `utf8codepoint`.
*
* @see PNTR_ENABLE_UTF8
* @see pntr_strcodepoint
*/
#define PNTR_STRCODEPOINT pntr_strcodepoint
#endif
/**
* @}
*/