summaryrefslogtreecommitdiff
path: root/packages/amunits/src/otherlibs/render.pas
blob: f2dccd6046fe123740fea6a49e1cc0f0e4b37d29 (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
{
  This file is part of the Free Pascal run time library.

  A file in Amiga system run time library.
  Copyright (c) 2003 by Nils Sjöholm.
  member of the Amiga RTL development team.

  This is a unit for render.library

  See the file COPYING.FPC, included in this distribution,
  for details about the copyright.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

**********************************************************************}
{
  History:

  First version of this unit.
  16 Jan 2003.

  Changed cardinal > longword.
  Changed startcode for unit.
  12 Feb 2003

  nils.sjoholm@mailbox.swipnet.se Nils Sjoholm
}

{$mode objfpc}
{$I useamigasmartlink.inc}
{$ifdef use_amiga_smartlink}
   {$smartlink on}
{$endif use_amiga_smartlink}

UNIT RENDER;

INTERFACE
USES Exec,utility,graphics;

VAR RenderBase : pLibrary;

type
    pPLANEPTR = ^PLANEPTR;

const
    RENDERNAME : PChar = 'render.library';

{
        $VER: render.h v40 (19.12.2002)
        render.library definitions
   }

  const
     RND_TAGBASE = TAG_USER + $1000;
  {

        memhandler

                                                                          }
  { type of memhandler, see below  }
     RND_MemType = RND_TAGBASE + 1;
  { ptr to block of memory  }
     RND_MemBlock = RND_TAGBASE + 2;
  { size of memblock [bytes]  }
     RND_MemSize = RND_TAGBASE + 3;
  { memflags (exec/memory.h)  }
     RND_MemFlags = RND_TAGBASE + 18;
  { to pass a memhandler as an argument  }
     RND_RMHandler = RND_TAGBASE + 12;
  {
        memhandler types
    }
  { v39 exec dynamic pool  }
     RMHTYPE_POOL = 1;
  { private memory pool  }
     RMHTYPE_PRIVATE = 2;
  { common public memory  }
     RMHTYPE_PUBLIC = 3;
  {

        palette

                                                                          }
  { palette import/export format  }
     RND_PaletteFormat = RND_TAGBASE + 19;
  { tag to indicate a palette is EHB  }
     RND_EHBPalette = RND_TAGBASE + 22;
  { first palette entry  }
     RND_FirstColor = RND_TAGBASE + 23;
  { dispose the old palette and load a new one  }
     RND_NewPalette = RND_TAGBASE + 24;
  { quantization factors  }
     RND_RGBWeight = RND_TAGBASE + 11;
  {
        palette format types
    }
  { ULONG red,green,blue  }
     PALFMT_RGB32 = 1;
  { ULONG 0x00rrggbb  }
     PALFMT_RGB8 = 2;
  { UWORD 0xrgb  }
     PALFMT_RGB4 = 3;
  { render.library palette  }
     PALFMT_PALETTE = 4;
  {
        palette sort mode types
        for the use with SortPalette()
    }
  { no particular order  }
     PALMODE_NONE = $0000;
  { sort palette entries by brightness  }
     PALMODE_BRIGHTNESS = $0001;
  { sort palette entries by the number of pixels that they represent.
           You must supply the RND_Histogram taglist argument.  }
     PALMODE_POPULARITY = $0002;
  { sort palette entries by the number of histogram entries that they
           represent. You must supply the RND_Histogram taglist argument.  }
     PALMODE_REPRESENTATION = $0003;
  { sort palette entries by their optical significance for the human
           eye. Implementation is unknown to you and may change.
           You must supply the RND_Histogram taglist argument.  }
     PALMODE_SIGNIFICANCE = $0004;
  { sort palette entries by color intensity  }
     PALMODE_SATURATION = $0005;
  { By default, sort direction is descending, i.e. the precedence is
           more-to-less. Combine with this flag to invert the sort direction.  }
     PALMODE_ASCENDING = $0008;
  {

        histogram related

                                                                          }
  { histogram type, see below  }
     RND_HSType = RND_TAGBASE + 4;
  { a histogram as an argument  }
     RND_Histogram = RND_TAGBASE + 9;
  {
        Histogram / Palette types
        to be specified with RND_HSType
    }
  { 12bit dynamic histogram  }
     HSTYPE_12BIT = 4;
  { 15bit dynamic histogram  }
     HSTYPE_15BIT = 5;
  { 18bit dynamic histogram  }
     HSTYPE_18BIT = 6;
  { 21bit dynamic histogram  }
     HSTYPE_21BIT = 7;
  { 24bit dynamic histogram  }
     HSTYPE_24BIT = 8;
  { 12bit tabular histogram  }
     HSTYPE_12BIT_TURBO = 20;
  { 15bit tabular histogram  }
     HSTYPE_15BIT_TURBO = 21;
  { 18bit tabular histogram  }
     HSTYPE_18BIT_TURBO = 22;
  {
        tags that can be queried via QueryHistogram()
    }
  { # pixels in a histogram  }
     RND_NumPixels = RND_TAGBASE + 5;
  { # colors in a histogram  }
     RND_NumColors = RND_TAGBASE + 6;
  {

        rendering and conversions

                                                                          }
  { color mode, see below  }
     RND_ColorMode = RND_TAGBASE + 7;
  { dither mode, see below  }
     RND_DitherMode = RND_TAGBASE + 8;
  { dither amount  }
     RND_DitherAmount = RND_TAGBASE + 26;
  { first color index to be output  }
     RND_OffsetColorZero = RND_TAGBASE + 10;
  {
        color mode types
        to be specified with RND_ColorMode
    }
  { normal palette lookup  }
     COLORMODE_CLUT = $0000;
  { HAM8 mode  }
     COLORMODE_HAM8 = $0001;
  { HAM6 mode  }
     COLORMODE_HAM6 = $0002;
  { mask to determine COLORMODE  }
     COLORMODE_MASK = $0003;
  {
        dither mode types
        to be specified with RND_DitherMode
    }
  { no dither  }
     DITHERMODE_NONE = $0000;
  { Floyd-Steinberg dither  }
     DITHERMODE_FS = $0001;
  { random dither. amount required.  }
     DITHERMODE_RANDOM = $0002;
  { EDD dither  }
     DITHERMODE_EDD = $0003;
  {

        miscellaneous

                                                                          }
  { progress callback hook  }
     RND_ProgressHook = RND_TAGBASE + 13;
  { total input width [pixels]  }
     RND_SourceWidth = RND_TAGBASE + 14;
  { total output width [pixels]  }
     RND_DestWidth = RND_TAGBASE + 15;
  { ptr to a chunky conversion table  }
     RND_PenTable = RND_TAGBASE + 16;
  { chunky data left edge [pixels]  }
     RND_LeftEdge = RND_TAGBASE + 17;
  { line callback hook  }
     RND_LineHook = RND_TAGBASE + 20;
  { Mapping-Engine  }
     RND_MapEngine = RND_TAGBASE + 27;
  { Interleave  }
     RND_Interleave = RND_TAGBASE + 28;
  { Palette  }
     RND_Palette = RND_TAGBASE + 29;
  { Weight factor  }
     RND_Weight = RND_TAGBASE + 30;
  { ScaleEngine  }
     RND_ScaleEngine = RND_TAGBASE + 31;
  { Texture coordinates  }
     RND_DestCoordinates = RND_TAGBASE + 42;
  { backcolor for filling  }
     RND_BGColor = RND_TAGBASE + 43;
  { backpen for filling  }
     RND_BGPen = RND_TAGBASE + 44;
  {

        alpha-channel and masking

                                                                          }
  { custom alpha-channel  }
     RND_AlphaChannel = RND_TAGBASE + 32;
  { bytes between alpha-channel pixels  }
     RND_AlphaModulo = RND_TAGBASE + 33;
  { width of alpha-channel array  }
     RND_AlphaWidth = RND_TAGBASE + 34;
  { masking RGB for CreateAlphaArray  }
     RND_MaskRGB = RND_TAGBASE + 35;
  { mask value for outside color range  }
     RND_MaskFalse = RND_TAGBASE + 36;
  { mask value for inside color range  }
     RND_MaskTrue = RND_TAGBASE + 37;
  { total source width for 3channel operations  }
     RND_SourceWidth2 = RND_TAGBASE + 38;
  { second custom alpha-channel  }
     RND_AlphaChannel2 = RND_TAGBASE + 39;
  { pixel modulo for a second alpha-channel  }
     RND_AlphaModulo2 = RND_TAGBASE + 40;
  { width of a second alpha-channel array  }
     RND_AlphaWidth2 = RND_TAGBASE + 41;
  {

        PixelFormat

                                                                          }
  { pixel format, see below  }
     RND_PixelFormat = RND_TAGBASE + 25;
     PIXFMTB_CHUNKY = 3;
     PIXFMTB_BITMAP = 4;
     PIXFMTB_RGB = 5;
     PIXFMT_CHUNKY_CLUT = (1 shl PIXFMTB_CHUNKY) + COLORMODE_CLUT;
     PIXFMT_0RGB_32 = (1 shl PIXFMTB_RGB) + 0;
  {
        these types are currently not used by render.library, but
        some of them are applicable for guigfx.library functions:
    }
     PIXFMT_CHUNKY_HAM8 = (1 shl PIXFMTB_CHUNKY) + COLORMODE_HAM8;
     PIXFMT_CHUNKY_HAM6 = (1 shl PIXFMTB_CHUNKY) + COLORMODE_HAM6;
     PIXFMT_BITMAP_CLUT = (1 shl PIXFMTB_BITMAP) + COLORMODE_CLUT;
     PIXFMT_BITMAP_HAM8 = (1 shl PIXFMTB_BITMAP) + COLORMODE_HAM8;
     PIXFMT_BITMAP_HAM6 = (1 shl PIXFMTB_BITMAP) + COLORMODE_HAM6;
     PIXFMT_RGB_24 = (1 shl PIXFMTB_RGB) + 1;
  {
        strictly internal:
    }
     PIXFMT_BITMAP_RGB = (1 shl PIXFMTB_BITMAP) + (1 shl PIXFMTB_RGB);
  {

        ExtractPalette return codes

        You must at least check for EXTP_SUCCESS.
        EXTP_NO_DATA indicates that there were no colors
        in the histogram.

                                                                          }
     EXTP_SUCCESS = 0;
     EXTP_NOT_ENOUGH_MEMORY = 1;
     EXTP_CALLBACK_ABORTED = 2;
     EXTP_NO_DATA = 3;
  {

        AddRGB, AddRGBImage and AddChunkyImage return codes

        You must at least check for ADDH_SUCCESS.
        If not delivered, the histogram might be
        inaccurate.

                                                                          }
     ADDH_SUCCESS = 0;
     ADDH_NOT_ENOUGH_MEMORY = 1;
     ADDH_CALLBACK_ABORTED = 2;
     ADDH_NO_DATA = 3;
  {

        Render return codes

        You must at least check for REND_SUCCESS.
        If not delivered, the image has not been
        rendered completely.

                                                                          }
     REND_SUCCESS = 0;
     REND_NOT_ENOUGH_MEMORY = 1;
     REND_CALLBACK_ABORTED = 2;
     REND_NO_VALID_PALETTE = 3;
     REND_NO_DATA = 3;
  {

        SortPalette return codes

        You must at least check for SORTP_SUCCESS.
        SORTP_NO_DATA indicates that there were data missing,
        e.g. you specified no histogram or the histogram was empty.

                                                                          }
     SORTP_SUCCESS = 0;
     SORTP_NO_DATA = 1;
     SORTP_NOT_ENOUGH_MEMORY = 2;
     SORTP_NOT_IMPLEMENTED = 3;
  {

        conversion return codes

        These return codes apply to conversion functions
        such as Chunky2RGB and ConvertChunky.

                                                                          }
     CONV_SUCCESS = 0;
     CONV_CALLBACK_ABORTED = 1;
     CONV_NOT_ENOUGH_MEMORY = 2;
     CONV_NO_DATA = 3;





FUNCTION AddChunkyImageA(histogram : POINTER; chunky : pByte; width : WORD; height : WORD; palette : POINTER; taglist : pTagItem) : longword;
FUNCTION AddHistogramA(histogram1 : POINTER; histogram2 : POINTER; taglist : pTagItem) : longword;
FUNCTION AddRGB(histogram : POINTER; RGB : longword; count : longword) : longword;
FUNCTION AddRGBImageA(histogram : POINTER; rgb : pULONG; width : WORD; height : WORD; taglist : pTagItem) : longword;
FUNCTION AllocRenderMem(rendermemhandler : POINTER; size : longword) : POINTER;
FUNCTION AllocRenderVec(rendermemhandler : POINTER; size : longword) : POINTER;
FUNCTION AllocRenderVecClear(rendermemhandler : POINTER; size : longword) : POINTER;
PROCEDURE ApplyAlphaChannelA(sourcearray : pULONG; width : WORD; height : WORD; destarray : pULONG; taglist : pTagItem);
FUNCTION BestPen(palette : POINTER; rgb : longword) : LONGINT;
PROCEDURE Chunky2BitMapA(chunky : pByte; sx : WORD; sy : WORD; width : WORD; height : WORD; bitmap : pBitMap; dx : WORD; dy : WORD; taglist : pTagItem);
FUNCTION Chunky2RGBA(chunky : pByte; width : WORD; height : WORD; rgb : pULONG; palette : POINTER; taglist : pTagItem) : longword;
FUNCTION ChunkyArrayDiversityA(chunky : pByte; palette : POINTER; width : WORD; height : WORD; taglist : pTagItem) : LONGINT;
FUNCTION ConvertChunkyA(source : pByte; oldpalette : POINTER; width : WORD; height : WORD; dest : pByte; newpalette : POINTER; taglist : pTagItem) : longword;
FUNCTION CountRGB(histogram : POINTER; rgb : longword) : longword;
PROCEDURE CreateAlphaArrayA(rgbarray : pULONG; width : WORD; height : WORD; taglist : pTagItem);
FUNCTION CreateHistogramA(taglist : pTagItem) : POINTER;
FUNCTION CreateMapEngineA(palette : POINTER; taglist : pTagItem) : POINTER;
FUNCTION CreatePaletteA(taglist : pTagItem) : POINTER;
PROCEDURE CreatePenTableA(chunky : pByte; oldpalette : POINTER; width : WORD; height : WORD; newpalette : POINTER; convtab : pByte; taglist : pTagItem);
FUNCTION CreateRMHandlerA(taglist : pTagItem) : POINTER;
FUNCTION CreateScaleEngineA(sourcewidth : WORD; sourceheight : WORD; destwidth : WORD; destheight : WORD; taglist : pTagItem) : POINTER;
PROCEDURE DeleteHistogram(histogram : POINTER);
PROCEDURE DeleteMapEngine(engine : POINTER);
PROCEDURE DeletePalette(palette : POINTER);
PROCEDURE DeleteRMHandler(rmh : POINTER);
PROCEDURE DeleteScaleEngine(engine : POINTER);
PROCEDURE ExportPaletteA(palette : POINTER; coltab : POINTER; taglist : pTagItem);
PROCEDURE ExtractAlphaChannelA(rgbarray : pULONG; width : WORD; height : WORD; chunkyarray : pByte; taglist : pTagItem);
FUNCTION ExtractPaletteA(histogram : POINTER; palette : pULONG; numcolors : WORD; taglist : pTagItem) : longword;
PROCEDURE FlushPalette(palette : POINTER);
PROCEDURE FreeRenderMem(rendermemhandler : POINTER; mem : POINTER; size : longword);
PROCEDURE FreeRenderVec(mem : POINTER);
PROCEDURE ImportPaletteA(palette : POINTER; coltab : POINTER; numcols : WORD; taglist : pTagItem);
PROCEDURE InsertAlphaChannelA(maskarray : pByte; width : WORD; height : WORD; rgbarray : pULONG; taglist : pTagItem);
FUNCTION MapChunkyArrayA(engine : POINTER; source : pByte; palette : POINTER; width : WORD; height : WORD; dest : pByte; taglist : pTagItem) : longword;
FUNCTION MapRGBArrayA(engine : POINTER; rgb : pULONG; width : WORD; height : WORD; chunky : pByte; taglist : pTagItem) : longword;
PROCEDURE MixAlphaChannelA(source1 : pULONG; source2 : pULONG; width : WORD; height : WORD; dest : pULONG; taglist : pTagItem);
PROCEDURE MixRGBArrayA(sourcearray : pULONG; width : WORD; height : WORD; destarray : pULONG; ratio : WORD; taglist : pTagItem);
PROCEDURE Planar2ChunkyA(planetab : pPLANEPTR; bytewidth : WORD; height : WORD; depth : WORD; bytesperrow : WORD; chunky : pByte; taglist : pTagItem);
FUNCTION QueryHistogram(histogram : POINTER; d0arg : longword) : longword;
FUNCTION RenderA(rgb : pULONG; width : WORD; height : WORD; chunky : pByte; palette : POINTER; taglist : pTagItem) : longword;
FUNCTION RGBArrayDiversityA(rgb : pULONG; width : WORD; height : WORD; taglist : pTagItem) : LONGINT;
FUNCTION ScaleA(engine : POINTER; source : POINTER; dest : POINTER; taglist : pTagItem) : longword;
FUNCTION ScaleOrdinate(source : WORD; dest : WORD; ordinate : WORD) : WORD;
FUNCTION SortPaletteA(palette : POINTER; mode : longword; taglist : pTagItem) : longword;
PROCEDURE TintRGBArrayA(source : pULONG; width : WORD; height : WORD; RGB : longword; ratio : WORD; dest : pULONG; taglist : pTagItem);
{
 Functions and procedures with array of const go here
}
FUNCTION AddChunkyImage(histogram : POINTER; chunky : pByte; width : WORD; height : WORD; palette : POINTER; const taglist : Array Of Const) : longword;
FUNCTION AddHistogram(histogram1 : POINTER; histogram2 : POINTER; const taglist : Array Of Const) : longword;
FUNCTION AddRGBImage(histogram : POINTER; rgb : pULONG; width : WORD; height : WORD; const taglist : Array Of Const) : longword;
PROCEDURE ApplyAlphaChannel(sourcearray : pULONG; width : WORD; height : WORD; destarray : pULONG; const taglist : Array Of Const);
PROCEDURE Chunky2BitMap(chunky : pByte; sx : WORD; sy : WORD; width : WORD; height : WORD; bitmap : pBitMap; dx : WORD; dy : WORD; const taglist : Array Of Const);
FUNCTION Chunky2RGB(chunky : pByte; width : WORD; height : WORD; rgb : pULONG; palette : POINTER; const taglist : Array Of Const) : longword;
FUNCTION ChunkyArrayDiversity(chunky : pByte; palette : POINTER; width : WORD; height : WORD; const taglist : Array Of Const) : LONGINT;
FUNCTION ConvertChunky(source : pByte; oldpalette : POINTER; width : WORD; height : WORD; dest : pByte; newpalette : POINTER; const taglist : Array Of Const) : longword;
PROCEDURE CreateAlphaArray(rgbarray : pULONG; width : WORD; height : WORD; const taglist : Array Of Const);
FUNCTION CreateHistogram(const taglist : Array Of Const) : POINTER;
FUNCTION CreateMapEngine(palette : POINTER; const taglist : Array Of Const) : POINTER;
FUNCTION CreatePalette(const taglist : Array Of Const) : POINTER;
PROCEDURE CreatePenTable(chunky : pByte; oldpalette : POINTER; width : WORD; height : WORD; newpalette : POINTER; convtab : pByte; const taglist : Array Of Const);
FUNCTION CreateRMHandler(const taglist : Array Of Const) : POINTER;
FUNCTION CreateScaleEngine(sourcewidth : WORD; sourceheight : WORD; destwidth : WORD; destheight : WORD; const taglist : Array Of Const) : POINTER;
PROCEDURE ExportPalette(palette : POINTER; coltab : POINTER; const taglist : Array Of Const);
PROCEDURE ExtractAlphaChannel(rgbarray : pULONG; width : WORD; height : WORD; chunkyarray : pByte; const taglist : Array Of Const);
FUNCTION ExtractPalette(histogram : POINTER; palette : pULONG; numcolors : WORD; const taglist : Array Of Const) : longword;
PROCEDURE ImportPalette(palette : POINTER; coltab : POINTER; numcols : WORD; const taglist : Array Of Const);
PROCEDURE InsertAlphaChannel(maskarray : pByte; width : WORD; height : WORD; rgbarray : pULONG; const taglist : Array Of Const);
FUNCTION MapChunkyArray(engine : POINTER; source : pByte; palette : POINTER; width : WORD; height : WORD; dest : pByte; const taglist : Array Of Const) : longword;
FUNCTION MapRGBArray(engine : POINTER; rgb : pULONG; width : WORD; height : WORD; chunky : pByte; const taglist : Array Of Const) : longword;
PROCEDURE MixAlphaChannel(source1 : pULONG; source2 : pULONG; width : WORD; height : WORD; dest : pULONG; const taglist : Array Of Const);
PROCEDURE MixRGBArray(sourcearray : pULONG; width : WORD; height : WORD; destarray : pULONG; ratio : WORD; const taglist : Array Of Const);
PROCEDURE Planar2Chunky(planetab : pPLANEPTR; bytewidth : WORD; height : WORD; depth : WORD; bytesperrow : WORD; chunky : pByte; const taglist : Array Of Const);
FUNCTION RenderTags(rgb : pULONG; width : WORD; height : WORD; chunky : pByte; palette : POINTER; const taglist : Array Of Const) : longword;
FUNCTION RGBArrayDiversity(rgb : pULONG; width : WORD; height : WORD; const taglist : Array Of Const) : LONGINT;
FUNCTION Scale(engine : POINTER; source : POINTER; dest : POINTER; const taglist : Array Of Const) : longword;
FUNCTION SortPalette(palette : POINTER; mode : longword; const taglist : Array Of Const) : longword;
PROCEDURE TintRGBArray(source : pULONG; width : WORD; height : WORD; RGB : longword; ratio : WORD; dest : pULONG; const taglist : Array Of Const);

{You can remove this include and use a define instead}
{$I useautoopenlib.inc}
{$ifdef use_init_openlib}
procedure InitRENDERLibrary;
{$endif use_init_openlib}

{This is a variable that knows how the unit is compiled}
var
    RENDERIsCompiledHow : longint;

IMPLEMENTATION

uses
{$ifndef dont_use_openlib}
msgbox,
{$endif dont_use_openlib}
tagsarray;

FUNCTION AddChunkyImageA(histogram : POINTER; chunky : pByte; width : WORD; height : WORD; palette : POINTER; taglist : pTagItem) : longword;
BEGIN
  ASM
        MOVE.L  A6,-(A7)
        MOVEA.L histogram,A0
        MOVEA.L chunky,A1
        MOVE.L  width,D0
        MOVE.L  height,D1
        MOVEA.L palette,A2
        MOVEA.L taglist,A3
        MOVEA.L RenderBase,A6
        JSR     -108(A6)
        MOVEA.L (A7)+,A6
        MOVE.L  D0,@RESULT
  END;
END;

FUNCTION AddHistogramA(histogram1 : POINTER; histogram2 : POINTER; taglist : pTagItem) : longword;
BEGIN
  ASM
        MOVE.L  A6,-(A7)
        MOVEA.L histogram1,A0
        MOVEA.L histogram2,A1
        MOVEA.L taglist,A2
        MOVEA.L RenderBase,A6
        JSR     -222(A6)
        MOVEA.L (A7)+,A6
        MOVE.L  D0,@RESULT
  END;
END;

FUNCTION AddRGB(histogram : POINTER; RGB : longword; count : longword) : longword;
BEGIN
  ASM
        MOVE.L  A6,-(A7)
        MOVEA.L histogram,A0
        MOVE.L  RGB,D0
        MOVE.L  count,D1
        MOVEA.L RenderBase,A6
        JSR     -096(A6)
        MOVEA.L (A7)+,A6
        MOVE.L  D0,@RESULT
  END;
END;

FUNCTION AddRGBImageA(histogram : POINTER; rgb : pULONG; width : WORD; height : WORD; taglist : pTagItem) : longword;
BEGIN
  ASM
        MOVE.L  A6,-(A7)
        MOVEA.L histogram,A0
        MOVEA.L rgb,A1
        MOVE.L  width,D0
        MOVE.L  height,D1
        MOVEA.L taglist,A2
        MOVEA.L RenderBase,A6
        JSR     -102(A6)
        MOVEA.L (A7)+,A6
        MOVE.L  D0,@RESULT
  END;
END;

FUNCTION AllocRenderMem(rendermemhandler : POINTER; size : longword) : POINTER;
BEGIN
  ASM
        MOVE.L  A6,-(A7)
        MOVEA.L rendermemhandler,A0
        MOVE.L  size,D0
        MOVEA.L RenderBase,A6
        JSR     -054(A6)
        MOVEA.L (A7)+,A6
        MOVE.L  D0,@RESULT
  END;
END;

FUNCTION AllocRenderVec(rendermemhandler : POINTER; size : longword) : POINTER;
BEGIN
  ASM
        MOVE.L  A6,-(A7)
        MOVEA.L rendermemhandler,A0
        MOVE.L  size,D0
        MOVEA.L RenderBase,A6
        JSR     -066(A6)
        MOVEA.L (A7)+,A6
        MOVE.L  D0,@RESULT
  END;
END;

FUNCTION AllocRenderVecClear(rendermemhandler : POINTER; size : longword) : POINTER;
BEGIN
  ASM
        MOVE.L  A6,-(A7)
        MOVEA.L rendermemhandler,A0
        MOVE.L  size,D0
        MOVEA.L RenderBase,A6
        JSR     -306(A6)
        MOVEA.L (A7)+,A6
        MOVE.L  D0,@RESULT
  END;
END;

PROCEDURE ApplyAlphaChannelA(sourcearray : pULONG; width : WORD; height : WORD; destarray : pULONG; taglist : pTagItem);
BEGIN
  ASM
        MOVE.L  A6,-(A7)
        MOVEA.L sourcearray,A0
        MOVE.L  width,D0
        MOVE.L  height,D1
        MOVEA.L destarray,A1
        MOVEA.L taglist,A2
        MOVEA.L RenderBase,A6
        JSR     -294(A6)
        MOVEA.L (A7)+,A6
  END;
END;

FUNCTION BestPen(palette : POINTER; rgb : longword) : LONGINT;
BEGIN
  ASM
        MOVE.L  A6,-(A7)
        MOVEA.L palette,A0
        MOVE.L  rgb,D0
        MOVEA.L RenderBase,A6
        JSR     -204(A6)
        MOVEA.L (A7)+,A6
        MOVE.L  D0,@RESULT
  END;
END;

PROCEDURE Chunky2BitMapA(chunky : pByte; sx : WORD; sy : WORD; width : WORD; height : WORD; bitmap : pBitMap; dx : WORD; dy : WORD; taglist : pTagItem);
BEGIN
  ASM
        MOVE.L  A6,-(A7)
        MOVEA.L chunky,A0
        MOVE.L  sx,D0
        MOVE.L  sy,D1
        MOVE.L  width,D2
        MOVE.L  height,D3
        MOVEA.L bitmap,A1
        MOVE.L  dx,D4
        MOVE.L  dy,D5
        MOVEA.L taglist,A2
        MOVEA.L RenderBase,A6
        JSR     -138(A6)
        MOVEA.L (A7)+,A6
  END;
END;

FUNCTION Chunky2RGBA(chunky : pByte; width : WORD; height : WORD; rgb : pULONG; palette : POINTER; taglist : pTagItem) : longword;
BEGIN
  ASM
        MOVE.L  A6,-(A7)
        MOVEA.L chunky,A0
        MOVE.L  width,D0
        MOVE.L  height,D1
        MOVEA.L rgb,A1
        MOVEA.L palette,A2
        MOVEA.L taglist,A3
        MOVEA.L RenderBase,A6
        JSR     -132(A6)
        MOVEA.L (A7)+,A6
        MOVE.L  D0,@RESULT
  END;
END;

FUNCTION ChunkyArrayDiversityA(chunky : pByte; palette : POINTER; width : WORD; height : WORD; taglist : pTagItem) : LONGINT;
BEGIN
  ASM
        MOVE.L  A6,-(A7)
        MOVEA.L chunky,A0
        MOVEA.L palette,A1
        MOVE.L  width,D0
        MOVE.L  height,D1
        MOVEA.L taglist,A2
        MOVEA.L RenderBase,A6
        JSR     -270(A6)
        MOVEA.L (A7)+,A6
        MOVE.L  D0,@RESULT
  END;
END;

FUNCTION ConvertChunkyA(source : pByte; oldpalette : POINTER; width : WORD; height : WORD; dest : pByte; newpalette : POINTER; taglist : pTagItem) : longword;
BEGIN
  ASM
        MOVE.L  A6,-(A7)
        MOVEA.L source,A0
        MOVEA.L oldpalette,A1
        MOVE.L  width,D0
        MOVE.L  height,D1
        MOVEA.L dest,A2
        MOVEA.L newpalette,A3
        MOVEA.L taglist,A4
        MOVEA.L RenderBase,A6
        JSR     -162(A6)
        MOVEA.L (A7)+,A6
        MOVE.L  D0,@RESULT
  END;
END;

FUNCTION CountRGB(histogram : POINTER; rgb : longword) : longword;
BEGIN
  ASM
        MOVE.L  A6,-(A7)
        MOVEA.L histogram,A0
        MOVE.L  rgb,D0
        MOVEA.L RenderBase,A6
        JSR     -198(A6)
        MOVEA.L (A7)+,A6
        MOVE.L  D0,@RESULT
  END;
END;

PROCEDURE CreateAlphaArrayA(rgbarray : pULONG; width : WORD; height : WORD; taglist : pTagItem);
BEGIN
  ASM
        MOVE.L  A6,-(A7)
        MOVEA.L rgbarray,A0
        MOVE.L  width,D0
        MOVE.L  height,D1
        MOVEA.L taglist,A1
        MOVEA.L RenderBase,A6
        JSR     -312(A6)
        MOVEA.L (A7)+,A6
  END;
END;

FUNCTION CreateHistogramA(taglist : pTagItem) : POINTER;
BEGIN
  ASM
        MOVE.L  A6,-(A7)
        MOVEA.L taglist,A1
        MOVEA.L RenderBase,A6
        JSR     -078(A6)
        MOVEA.L (A7)+,A6
        MOVE.L  D0,@RESULT
  END;
END;

FUNCTION CreateMapEngineA(palette : POINTER; taglist : pTagItem) : POINTER;
BEGIN
  ASM
        MOVE.L  A6,-(A7)
        MOVEA.L palette,A0
        MOVEA.L taglist,A1
        MOVEA.L RenderBase,A6
        JSR     -246(A6)
        MOVEA.L (A7)+,A6
        MOVE.L  D0,@RESULT
  END;
END;

FUNCTION CreatePaletteA(taglist : pTagItem) : POINTER;
BEGIN
  ASM
        MOVE.L  A6,-(A7)
        MOVEA.L taglist,A1
        MOVEA.L RenderBase,A6
        JSR     -174(A6)
        MOVEA.L (A7)+,A6
        MOVE.L  D0,@RESULT
  END;
END;

PROCEDURE CreatePenTableA(chunky : pByte; oldpalette : POINTER; width : WORD; height : WORD; newpalette : POINTER; convtab : pByte; taglist : pTagItem);
BEGIN
  ASM
        MOVE.L  A6,-(A7)
        MOVEA.L chunky,A0
        MOVEA.L oldpalette,A1
        MOVE.L  width,D0
        MOVE.L  height,D1
        MOVEA.L newpalette,A2
        MOVEA.L convtab,A3
        MOVEA.L taglist,A4
        MOVEA.L RenderBase,A6
        JSR     -168(A6)
        MOVEA.L (A7)+,A6
  END;
END;

FUNCTION CreateRMHandlerA(taglist : pTagItem) : POINTER;
BEGIN
  ASM
        MOVE.L  A6,-(A7)
        MOVEA.L taglist,A1
        MOVEA.L RenderBase,A6
        JSR     -042(A6)
        MOVEA.L (A7)+,A6
        MOVE.L  D0,@RESULT
  END;
END;

FUNCTION CreateScaleEngineA(sourcewidth : WORD; sourceheight : WORD; destwidth : WORD; destheight : WORD; taglist : pTagItem) : POINTER;
BEGIN
  ASM
        MOVE.L  A6,-(A7)
        MOVE.L  sourcewidth,D0
        MOVE.L  sourceheight,D1
        MOVE.L  destwidth,D2
        MOVE.L  destheight,D3
        MOVEA.L taglist,A1
        MOVEA.L RenderBase,A6
        JSR     -144(A6)
        MOVEA.L (A7)+,A6
        MOVE.L  D0,@RESULT
  END;
END;

PROCEDURE DeleteHistogram(histogram : POINTER);
BEGIN
  ASM
        MOVE.L  A6,-(A7)
        MOVEA.L histogram,A0
        MOVEA.L RenderBase,A6
        JSR     -084(A6)
        MOVEA.L (A7)+,A6
  END;
END;

PROCEDURE DeleteMapEngine(engine : POINTER);
BEGIN
  ASM
        MOVE.L  A6,-(A7)
        MOVEA.L engine,A0
        MOVEA.L RenderBase,A6
        JSR     -252(A6)
        MOVEA.L (A7)+,A6
  END;
END;

PROCEDURE DeletePalette(palette : POINTER);
BEGIN
  ASM
        MOVE.L  A6,-(A7)
        MOVEA.L palette,A0
        MOVEA.L RenderBase,A6
        JSR     -180(A6)
        MOVEA.L (A7)+,A6
  END;
END;

PROCEDURE DeleteRMHandler(rmh : POINTER);
BEGIN
  ASM
        MOVE.L  A6,-(A7)
        MOVEA.L rmh,A0
        MOVEA.L RenderBase,A6
        JSR     -048(A6)
        MOVEA.L (A7)+,A6
  END;
END;

PROCEDURE DeleteScaleEngine(engine : POINTER);
BEGIN
  ASM
        MOVE.L  A6,-(A7)
        MOVEA.L engine,A0
        MOVEA.L RenderBase,A6
        JSR     -150(A6)
        MOVEA.L (A7)+,A6
  END;
END;

PROCEDURE ExportPaletteA(palette : POINTER; coltab : POINTER; taglist : pTagItem);
BEGIN
  ASM
        MOVE.L  A6,-(A7)
        MOVEA.L palette,A0
        MOVEA.L coltab,A1
        MOVEA.L taglist,A2
        MOVEA.L RenderBase,A6
        JSR     -192(A6)
        MOVEA.L (A7)+,A6
  END;
END;

PROCEDURE ExtractAlphaChannelA(rgbarray : pULONG; width : WORD; height : WORD; chunkyarray : pByte; taglist : pTagItem);
BEGIN
  ASM
        MOVE.L  A6,-(A7)
        MOVEA.L rgbarray,A0
        MOVE.L  width,D0
        MOVE.L  height,D1
        MOVEA.L chunkyarray,A1
        MOVEA.L taglist,A2
        MOVEA.L RenderBase,A6
        JSR     -288(A6)
        MOVEA.L (A7)+,A6
  END;
END;

FUNCTION ExtractPaletteA(histogram : POINTER; palette : pULONG; numcolors : WORD; taglist : pTagItem) : longword;
BEGIN
  ASM
        MOVE.L  A6,-(A7)
        MOVEA.L histogram,A0
        MOVEA.L palette,A1
        MOVE.L  numcolors,D0
        MOVEA.L taglist,A2
        MOVEA.L RenderBase,A6
        JSR     -114(A6)
        MOVEA.L (A7)+,A6
        MOVE.L  D0,@RESULT
  END;
END;

PROCEDURE FlushPalette(palette : POINTER);
BEGIN
  ASM
        MOVE.L  A6,-(A7)
        MOVEA.L palette,A0
        MOVEA.L RenderBase,A6
        JSR     -210(A6)
        MOVEA.L (A7)+,A6
  END;
END;

PROCEDURE FreeRenderMem(rendermemhandler : POINTER; mem : POINTER; size : longword);
BEGIN
  ASM
        MOVE.L  A6,-(A7)
        MOVEA.L rendermemhandler,A0
        MOVEA.L mem,A1
        MOVE.L  size,D0
        MOVEA.L RenderBase,A6
        JSR     -060(A6)
        MOVEA.L (A7)+,A6
  END;
END;

PROCEDURE FreeRenderVec(mem : POINTER);
BEGIN
  ASM
        MOVE.L  A6,-(A7)
        MOVEA.L mem,A0
        MOVEA.L RenderBase,A6
        JSR     -072(A6)
        MOVEA.L (A7)+,A6
  END;
END;

PROCEDURE ImportPaletteA(palette : POINTER; coltab : POINTER; numcols : WORD; taglist : pTagItem);
BEGIN
  ASM
        MOVE.L  A6,-(A7)
        MOVEA.L palette,A0
        MOVEA.L coltab,A1
        MOVE.L  numcols,D0
        MOVEA.L taglist,A2
        MOVEA.L RenderBase,A6
        JSR     -186(A6)
        MOVEA.L (A7)+,A6
  END;
END;

PROCEDURE InsertAlphaChannelA(maskarray : pByte; width : WORD; height : WORD; rgbarray : pULONG; taglist : pTagItem);
BEGIN
  ASM
        MOVE.L  A6,-(A7)
        MOVEA.L maskarray,A0
        MOVE.L  width,D0
        MOVE.L  height,D1
        MOVEA.L rgbarray,A1
        MOVEA.L taglist,A2
        MOVEA.L RenderBase,A6
        JSR     -282(A6)
        MOVEA.L (A7)+,A6
  END;
END;

FUNCTION MapChunkyArrayA(engine : POINTER; source : pByte; palette : POINTER; width : WORD; height : WORD; dest : pByte; taglist : pTagItem) : longword;
BEGIN
  ASM
        MOVE.L  A6,-(A7)
        MOVEA.L engine,A0
        MOVEA.L source,A1
        MOVEA.L palette,A2
        MOVE.L  width,D0
        MOVE.L  height,D1
        MOVEA.L dest,A3
        MOVEA.L taglist,A4
        MOVEA.L RenderBase,A6
        JSR     -276(A6)
        MOVEA.L (A7)+,A6
        MOVE.L  D0,@RESULT
  END;
END;

FUNCTION MapRGBArrayA(engine : POINTER; rgb : pULONG; width : WORD; height : WORD; chunky : pByte; taglist : pTagItem) : longword;
BEGIN
  ASM
        MOVE.L  A6,-(A7)
        MOVEA.L engine,A0
        MOVEA.L rgb,A1
        MOVE.L  width,D0
        MOVE.L  height,D1
        MOVEA.L chunky,A2
        MOVEA.L taglist,A3
        MOVEA.L RenderBase,A6
        JSR     -258(A6)
        MOVEA.L (A7)+,A6
        MOVE.L  D0,@RESULT
  END;
END;

PROCEDURE MixAlphaChannelA(source1 : pULONG; source2 : pULONG; width : WORD; height : WORD; dest : pULONG; taglist : pTagItem);
BEGIN
  ASM
        MOVE.L  A6,-(A7)
        MOVEA.L source1,A0
        MOVEA.L source2,A1
        MOVE.L  width,D0
        MOVE.L  height,D1
        MOVEA.L dest,A2
        MOVEA.L taglist,A3
        MOVEA.L RenderBase,A6
        JSR     -318(A6)
        MOVEA.L (A7)+,A6
  END;
END;

PROCEDURE MixRGBArrayA(sourcearray : pULONG; width : WORD; height : WORD; destarray : pULONG; ratio : WORD; taglist : pTagItem);
BEGIN
  ASM
        MOVE.L  A6,-(A7)
        MOVEA.L sourcearray,A0
        MOVE.L  width,D0
        MOVE.L  height,D1
        MOVEA.L destarray,A1
        MOVE.L  ratio,D2
        MOVEA.L taglist,A2
        MOVEA.L RenderBase,A6
        JSR     -300(A6)
        MOVEA.L (A7)+,A6
  END;
END;

PROCEDURE Planar2ChunkyA(planetab : pPLANEPTR; bytewidth : WORD; height : WORD; depth : WORD; bytesperrow : WORD; chunky : pByte; taglist : pTagItem);
BEGIN
  ASM
        MOVE.L  A6,-(A7)
        MOVEA.L planetab,A0
        MOVE.L  bytewidth,D0
        MOVE.L  height,D1
        MOVE.L  depth,D2
        MOVE.L  bytesperrow,D3
        MOVEA.L chunky,A1
        MOVEA.L taglist,A2
        MOVEA.L RenderBase,A6
        JSR     -126(A6)
        MOVEA.L (A7)+,A6
  END;
END;

FUNCTION QueryHistogram(histogram : POINTER; d0arg : longword) : longword;
BEGIN
  ASM
        MOVE.L  A6,-(A7)
        MOVEA.L histogram,A0
        MOVE.L  d0arg,D0
        MOVEA.L RenderBase,A6
        JSR     -090(A6)
        MOVEA.L (A7)+,A6
        MOVE.L  D0,@RESULT
  END;
END;

FUNCTION RenderA(rgb : pULONG; width : WORD; height : WORD; chunky : pByte; palette : POINTER; taglist : pTagItem) : longword;
BEGIN
  ASM
        MOVE.L  A6,-(A7)
        MOVEA.L rgb,A0
        MOVE.L  width,D0
        MOVE.L  height,D1
        MOVEA.L chunky,A1
        MOVEA.L palette,A2
        MOVEA.L taglist,A3
        MOVEA.L RenderBase,A6
        JSR     -120(A6)
        MOVEA.L (A7)+,A6
        MOVE.L  D0,@RESULT
  END;
END;

FUNCTION RGBArrayDiversityA(rgb : pULONG; width : WORD; height : WORD; taglist : pTagItem) : LONGINT;
BEGIN
  ASM
        MOVE.L  A6,-(A7)
        MOVEA.L rgb,A0
        MOVE.L  width,D0
        MOVE.L  height,D1
        MOVEA.L taglist,A1
        MOVEA.L RenderBase,A6
        JSR     -264(A6)
        MOVEA.L (A7)+,A6
        MOVE.L  D0,@RESULT
  END;
END;

FUNCTION ScaleA(engine : POINTER; source : POINTER; dest : POINTER; taglist : pTagItem) : longword;
BEGIN
  ASM
        MOVE.L  A6,-(A7)
        MOVEA.L engine,A0
        MOVEA.L source,A1
        MOVEA.L dest,A2
        MOVEA.L taglist,A3
        MOVEA.L RenderBase,A6
        JSR     -156(A6)
        MOVEA.L (A7)+,A6
        MOVE.L  D0,@RESULT
  END;
END;

FUNCTION ScaleOrdinate(source : WORD; dest : WORD; ordinate : WORD) : WORD;
BEGIN
  ASM
        MOVE.L  A6,-(A7)
        MOVE.L  source,D0
        MOVE.L  dest,D1
        MOVE.L  ordinate,D2
        MOVEA.L RenderBase,A6
        JSR     -228(A6)
        MOVEA.L (A7)+,A6
        MOVE.L  D0,@RESULT
  END;
END;

FUNCTION SortPaletteA(palette : POINTER; mode : longword; taglist : pTagItem) : longword;
BEGIN
  ASM
        MOVE.L  A6,-(A7)
        MOVEA.L palette,A0
        MOVE.L  mode,D0
        MOVEA.L taglist,A1
        MOVEA.L RenderBase,A6
        JSR     -216(A6)
        MOVEA.L (A7)+,A6
        MOVE.L  D0,@RESULT
  END;
END;

PROCEDURE TintRGBArrayA(source : pULONG; width : WORD; height : WORD; RGB : longword; ratio : WORD; dest : pULONG; taglist : pTagItem);
BEGIN
  ASM
        MOVE.L  A6,-(A7)
        MOVEA.L source,A0
        MOVE.L  width,D0
        MOVE.L  height,D1
        MOVE.L  RGB,D2
        MOVE.L  ratio,D3
        MOVEA.L dest,A1
        MOVEA.L taglist,A2
        MOVEA.L RenderBase,A6
        JSR     -324(A6)
        MOVEA.L (A7)+,A6
  END;
END;

{
 Functions and procedures with array of const go here
}
FUNCTION AddChunkyImage(histogram : POINTER; chunky : pByte; width : WORD; height : WORD; palette : POINTER; const taglist : Array Of Const) : longword;
begin
    AddChunkyImage := AddChunkyImageA(histogram , chunky , width , height , palette , readintags(taglist));
end;

FUNCTION AddHistogram(histogram1 : POINTER; histogram2 : POINTER; const taglist : Array Of Const) : longword;
begin
    AddHistogram := AddHistogramA(histogram1 , histogram2 , readintags(taglist));
end;

FUNCTION AddRGBImage(histogram : POINTER; rgb : pULONG; width : WORD; height : WORD; const taglist : Array Of Const) : longword;
begin
    AddRGBImage := AddRGBImageA(histogram , rgb , width , height , readintags(taglist));
end;

PROCEDURE ApplyAlphaChannel(sourcearray : pULONG; width : WORD; height : WORD; destarray : pULONG; const taglist : Array Of Const);
begin
    ApplyAlphaChannelA(sourcearray , width , height , destarray , readintags(taglist));
end;

PROCEDURE Chunky2BitMap(chunky : pByte; sx : WORD; sy : WORD; width : WORD; height : WORD; bitmap : pBitMap; dx : WORD; dy : WORD; const taglist : Array Of Const);
begin
    Chunky2BitMapA(chunky , sx , sy , width , height , bitmap , dx , dy , readintags(taglist));
end;

FUNCTION Chunky2RGB(chunky : pByte; width : WORD; height : WORD; rgb : pULONG; palette : POINTER; const taglist : Array Of Const) : longword;
begin
    Chunky2RGB := Chunky2RGBA(chunky , width , height , rgb , palette , readintags(taglist));
end;

FUNCTION ChunkyArrayDiversity(chunky : pByte; palette : POINTER; width : WORD; height : WORD; const taglist : Array Of Const) : LONGINT;
begin
    ChunkyArrayDiversity := ChunkyArrayDiversityA(chunky , palette , width , height , readintags(taglist));
end;

FUNCTION ConvertChunky(source : pByte; oldpalette : POINTER; width : WORD; height : WORD; dest : pByte; newpalette : POINTER; const taglist : Array Of Const) : longword;
begin
    ConvertChunky := ConvertChunkyA(source , oldpalette , width , height , dest , newpalette , readintags(taglist));
end;

PROCEDURE CreateAlphaArray(rgbarray : pULONG; width : WORD; height : WORD; const taglist : Array Of Const);
begin
    CreateAlphaArrayA(rgbarray , width , height , readintags(taglist));
end;

FUNCTION CreateHistogram(const taglist : Array Of Const) : POINTER;
begin
    CreateHistogram := CreateHistogramA(readintags(taglist));
end;

FUNCTION CreateMapEngine(palette : POINTER; const taglist : Array Of Const) : POINTER;
begin
    CreateMapEngine := CreateMapEngineA(palette , readintags(taglist));
end;

FUNCTION CreatePalette(const taglist : Array Of Const) : POINTER;
begin
    CreatePalette := CreatePaletteA(readintags(taglist));
end;

PROCEDURE CreatePenTable(chunky : pByte; oldpalette : POINTER; width : WORD; height : WORD; newpalette : POINTER; convtab : pByte; const taglist : Array Of Const);
begin
    CreatePenTableA(chunky , oldpalette , width , height , newpalette , convtab , readintags(taglist));
end;

FUNCTION CreateRMHandler(const taglist : Array Of Const) : POINTER;
begin
    CreateRMHandler := CreateRMHandlerA(readintags(taglist));
end;

FUNCTION CreateScaleEngine(sourcewidth : WORD; sourceheight : WORD; destwidth : WORD; destheight : WORD; const taglist : Array Of Const) : POINTER;
begin
    CreateScaleEngine := CreateScaleEngineA(sourcewidth , sourceheight , destwidth , destheight , readintags(taglist));
end;

PROCEDURE ExportPalette(palette : POINTER; coltab : POINTER; const taglist : Array Of Const);
begin
    ExportPaletteA(palette , coltab , readintags(taglist));
end;

PROCEDURE ExtractAlphaChannel(rgbarray : pULONG; width : WORD; height : WORD; chunkyarray : pByte; const taglist : Array Of Const);
begin
    ExtractAlphaChannelA(rgbarray , width , height , chunkyarray , readintags(taglist));
end;

FUNCTION ExtractPalette(histogram : POINTER; palette : pULONG; numcolors : WORD; const taglist : Array Of Const) : longword;
begin
    ExtractPalette := ExtractPaletteA(histogram , palette , numcolors , readintags(taglist));
end;

PROCEDURE ImportPalette(palette : POINTER; coltab : POINTER; numcols : WORD; const taglist : Array Of Const);
begin
    ImportPaletteA(palette , coltab , numcols , readintags(taglist));
end;

PROCEDURE InsertAlphaChannel(maskarray : pByte; width : WORD; height : WORD; rgbarray : pULONG; const taglist : Array Of Const);
begin
    InsertAlphaChannelA(maskarray , width , height , rgbarray , readintags(taglist));
end;

FUNCTION MapChunkyArray(engine : POINTER; source : pByte; palette : POINTER; width : WORD; height : WORD; dest : pByte; const taglist : Array Of Const) : longword;
begin
    MapChunkyArray := MapChunkyArrayA(engine , source , palette , width , height , dest , readintags(taglist));
end;

FUNCTION MapRGBArray(engine : POINTER; rgb : pULONG; width : WORD; height : WORD; chunky : pByte; const taglist : Array Of Const) : longword;
begin
    MapRGBArray := MapRGBArrayA(engine , rgb , width , height , chunky , readintags(taglist));
end;

PROCEDURE MixAlphaChannel(source1 : pULONG; source2 : pULONG; width : WORD; height : WORD; dest : pULONG; const taglist : Array Of Const);
begin
    MixAlphaChannelA(source1 , source2 , width , height , dest , readintags(taglist));
end;

PROCEDURE MixRGBArray(sourcearray : pULONG; width : WORD; height : WORD; destarray : pULONG; ratio : WORD; const taglist : Array Of Const);
begin
    MixRGBArrayA(sourcearray , width , height , destarray , ratio , readintags(taglist));
end;

PROCEDURE Planar2Chunky(planetab : pPLANEPTR; bytewidth : WORD; height : WORD; depth : WORD; bytesperrow : WORD; chunky : pByte; const taglist : Array Of Const);
begin
    Planar2ChunkyA(planetab , bytewidth , height , depth , bytesperrow , chunky , readintags(taglist));
end;

FUNCTION RenderTags(rgb : pULONG; width : WORD; height : WORD; chunky : pByte; palette : POINTER; const taglist : Array Of Const) : longword;
begin
    RenderTags := RenderA(rgb , width , height , chunky , palette , readintags(taglist));
end;

FUNCTION RGBArrayDiversity(rgb : pULONG; width : WORD; height : WORD; const taglist : Array Of Const) : LONGINT;
begin
    RGBArrayDiversity := RGBArrayDiversityA(rgb , width , height , readintags(taglist));
end;

FUNCTION Scale(engine : POINTER; source : POINTER; dest : POINTER; const taglist : Array Of Const) : longword;
begin
    Scale := ScaleA(engine , source , dest , readintags(taglist));
end;

FUNCTION SortPalette(palette : POINTER; mode : longword; const taglist : Array Of Const) : longword;
begin
    SortPalette := SortPaletteA(palette , mode , readintags(taglist));
end;

PROCEDURE TintRGBArray(source : pULONG; width : WORD; height : WORD; RGB : longword; ratio : WORD; dest : pULONG; const taglist : Array Of Const);
begin
    TintRGBArrayA(source , width , height , RGB , ratio , dest , readintags(taglist));
end;

const
    { Change VERSION and LIBVERSION to proper values }

    VERSION : string[2] = '0';
    LIBVERSION : longword = 0;

{$ifdef use_init_openlib}
  {$Info Compiling initopening of render.library}
  {$Info don't forget to use InitRENDERLibrary in the beginning of your program}

var
    render_exit : Pointer;

procedure CloserenderLibrary;
begin
    ExitProc := render_exit;
    if RenderBase <> nil then begin
        CloseLibrary(RenderBase);
        RenderBase := nil;
    end;
end;

procedure InitRENDERLibrary;
begin
    RenderBase := nil;
    RenderBase := OpenLibrary(RENDERNAME,LIBVERSION);
    if RenderBase <> nil then begin
        render_exit := ExitProc;
        ExitProc := @CloserenderLibrary;
    end else begin
        MessageBox('FPC Pascal Error',
        'Can''t open render.library version ' + VERSION + #10 +
        'Deallocating resources and closing down',
        'Oops');
        halt(20);
    end;
end;

begin
    RENDERIsCompiledHow := 2;
{$endif use_init_openlib}

{$ifdef use_auto_openlib}
  {$Info Compiling autoopening of render.library}

var
    render_exit : Pointer;

procedure CloserenderLibrary;
begin
    ExitProc := render_exit;
    if RenderBase <> nil then begin
        CloseLibrary(RenderBase);
        RenderBase := nil;
    end;
end;

begin
    RenderBase := nil;
    RenderBase := OpenLibrary(RENDERNAME,LIBVERSION);
    if RenderBase <> nil then begin
        render_exit := ExitProc;
        ExitProc := @CloserenderLibrary;
        RENDERIsCompiledHow := 1;
    end else begin
        MessageBox('FPC Pascal Error',
        'Can''t open render.library version ' + VERSION + #10 +
        'Deallocating resources and closing down',
        'Oops');
        halt(20);
    end;

{$endif use_auto_openlib}

{$ifdef dont_use_openlib}
begin
    RENDERIsCompiledHow := 3;
   {$Warning No autoopening of render.library compiled}
   {$Warning Make sure you open render.library yourself}
{$endif dont_use_openlib}


END. (* UNIT RENDER *)