BitmapToolkit Scol plugin
BitmapToolkit.cpp
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OpenSpace3D
4For the latest info, see http://www.openspace3d.com
5
6Copyright (c) 2012 I-maginer
7
8This program is free software; you can redistribute it and/or modify it under
9the terms of the GNU Lesser General Public License as published by the Free Software
10Foundation; either version 2 of the License, or (at your option) any later
11version.
12
13This program is distributed in the hope that it will be useful, but WITHOUT
14ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public License along with
18this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20http://www.gnu.org/copyleft/lesser.txt
21
22-----------------------------------------------------------------------------
23*/
24
25/*
26 Toolkit based on OpenCV library
27 First version : dec 2010
28 Author : Bastien BOURINEAU
29 */
30
37#include <boost/filesystem.hpp>
38#include "Prerequisites.h"
39#include "BitmapToolkitText.h"
40#include "ScolConvert.h"
41
44
45// CV mat destruction callback
46int destroyCVMat(mmachine m, SCOL_PTR_TYPE handsys, int obj)
47{
48 cv::Mat* obj_mat = MMgetPointer<cv::Mat*>(m, MTOP(obj));
49 SAFE_DELETE(obj_mat);
50 MMsetPointer<cv::Mat*>(m, MTOP(obj), 0);
51
52 MMechostr(MSKDEBUG, "ObjBTMat destroyed.\n");
53 return 0;
54}
55
64int _CRBTmat(mmachine m)
65{
66 int srcbitmap = MMpull(m);
67 int channel = MMget(m, 0);
68 if ((srcbitmap == NIL) || (channel == NIL))
69 {
70 MMset(m, 0, NIL);
71 return 0;
72 }
73
74 int src_bmp24 = MMfetch(m, MTOP(srcbitmap), 0);
75 int src_bmp8 = MMfetch(m, MTOP(srcbitmap), 1);
76
77 if (src_bmp24 == NIL || src_bmp8 == NIL)
78 {
79 MMset(m, 0, NIL);
80 return 0;
81 }
82
83 // Get scol bitmaps
84 PtrObjVoid ptr_bitmap = (PtrObjVoid)MMstart(m, MTOP(src_bmp24));
85 PtrObjBitmap obj_bitmap = (PtrObjBitmap)MMstart(m, MTOP(ptr_bitmap->Buffer));
86 PtrObjVoid ptr_bitmap8 = (PtrObjVoid)MMstart(m, MTOP(src_bmp8));
87 PtrObjBitmap obj_bitmap8 = (PtrObjBitmap)MMstart(m, MTOP(ptr_bitmap8->Buffer));
88
89 if ((obj_bitmap->bits == 0) || (obj_bitmap8->bits == 0))
90 {
91 MMset(m, 0, NIL);
92 return 0;
93 }
94
95 cv::Mat* mat = new cv::Mat(obj_bitmap->TailleH, obj_bitmap->TailleW, CV_8UC4);
96 ConversionTools::ScolBitmapToMatRGBA(obj_bitmap, obj_bitmap8, *mat);
97
98 // Store to tuple
99 // ----------------
100 if ((MMpushPointer(m, mat) != 0))
101 {
102 if (mat)
103 SAFE_DELETE(mat);
104 MMset(m, 0, NIL);
105 return MERRMEM;
106 }
107
108 return OBJcreate(m, SObjBTMat, SCOL_PTR mat, NIL, 0);
109}
110
118int _DSBTmat(mmachine m)
119{
120 int obj = MMget(m, 0);
121 if (obj == NIL)
122 {
123 MMset(m, 0, NIL);
124 return 0;
125 }
126
127 OBJdelTM(m, SObjBTMat, obj);
128 MMset(m, 0, ITOM(0));
129 return 0;
130}
131
139int _BTGETmatBuffer(mmachine m)
140{
141 int obj = MMget(m, 0);
142 if (obj == NIL)
143 {
144 MMset(m, 0, NIL);
145 return 0;
146 }
147 cv::Mat* mat = MMgetPointer<cv::Mat*>(m, MTOP(obj));
148
149 MMpull(m);
150 if ((MMpushPointer(m, mat->data) != 0))
151 {
152 MMpush(m, NIL);
153 return 0;
154 }
155 return 0;
156}
157
167int _BTBLURbitmap(mmachine m)
168{
169#ifdef _SCOL_DEBUG_
170 MMechostr(MSKDEBUG, "_BTBLURbitmap\n");
171#endif
172
173 /* Get stack data*/
174 int blurY = MMpull(m);
175 int blurX = MMpull(m);
176 int bitmap = MMget(m, 0);
177
178 if ((bitmap == NIL) || ((blurY == NIL) && (blurX == NIL)))
179 {
180 MMset(m, 0, NIL);
181 return 0;
182 }
183
184 blurX = MTOI(blurX);
185 blurY = MTOI(blurY);
186
187 PtrObjVoid OB = (PtrObjVoid)MMstart(m, MTOP(bitmap));
188 PtrObjBitmap B = (PtrObjBitmap)MMstart(m, MTOP(OB->Buffer));
189
190 if (B->bits == 0)
191 {
192 MMset(m, 0, NIL);
193 return 0;
194 }
195
196 cv::Mat imagesrc = ConversionTools::ScolBitmapToMat(B);
197 try
198 {
199 cv::Size blursize(blurX, blurY);
200 cv::blur(imagesrc, imagesrc, blursize);
201 }
202 catch (cv::Exception& e)
203 {
204 MMechostr(MSKDEBUG, "_BTBLURbitmap error %s\n", e.what());
205 return 0;
206 }
207
208#ifdef _SCOL_DEBUG_
209 MMechostr(MSKDEBUG, "ok\n");
210#endif
211 return 0;
212}
213
226int _BTBLURbitmapBuffer(mmachine m)
227{
228#ifdef _SCOL_DEBUG_
229 MMechostr(MSKDEBUG, "_BTBLURbitmapBuffer\n");
230#endif
231
232 /* Get stack data*/
233 int blurY = MMpull(m);
234 int blurX = MMpull(m);
235 int ibytesperpixel = MMpull(m);
236 int iheight = MMpull(m);
237 int iwidth = MMpull(m);
238 int iBuff = MMget(m, 0);
239
240 if ((iBuff == NIL) || (iheight == NIL) || (iwidth == NIL) || (ibytesperpixel == NIL) || ((blurY == NIL) && (blurX == NIL)))
241 {
242 MMset(m, 0, NIL);
243 return 0;
244 }
245
246 blurX = MTOI(blurX);
247 blurY = MTOI(blurY);
248
249 unsigned char* buffer = MMgetPointer<unsigned char*>(m, MTOP(iBuff));
250 if (buffer == NULL)
251 {
252 MMset(m, 0, NIL);
253 return 0;
254 }
255
256 ibytesperpixel = MTOI(ibytesperpixel);
257 iheight = MTOI(iheight);
258 iwidth = MTOI(iwidth);
259
260 cv::Mat imagesrc = ConversionTools::ScolBitmapBufferToMat((void*)buffer, iwidth, iheight, ibytesperpixel);
261 if (imagesrc.empty())
262 {
263 MMset(m, 0, NIL);
264 return 0;
265 }
266
267 try
268 {
269 cv::Size blursize(blurX, blurY);
270 cv::blur(imagesrc, imagesrc, blursize);
271 }
272 catch (cv::Exception& e)
273 {
274 MMechostr(MSKDEBUG, "_BTBLURbitmapBuffer error %s\n", e.what());
275 return 0;
276 }
277
278#ifdef _SCOL_DEBUG_
279 MMechostr(MSKDEBUG, "ok\n");
280#endif
281 return 0;
282}
283
315int _BTFILTERbitmap(mmachine m)
316{
317#ifdef _SCOL_DEBUG_
318 MMechostr(MSKDEBUG, "_BTFILTERbitmap\n");
319#endif
320
321 /* Get stack data*/
322 int itab = MMpull(m);
323 int bitmap = MMget(m, 0);
324
325 if ((bitmap == NIL) || (itab == NIL))
326 {
327 MMset(m, 0, NIL);
328 return 0;
329 }
330
331 int s = MMsize(m, MTOP(itab));
332 cv::Mat kernel = cv::Mat::ones(s, s, CV_32F) / (float)(s*s);
333
334 float val = 0.0f;
335 for (int i = 0; i < s; i++)
336 {
337 int jpp = MMfetch(m, MTOP(itab), i);
338 if (jpp != NIL)
339 {
340 int sj = MMsize(m, MTOP(jpp));
341 for (int j = 0; j < sj && j < s; j++)
342 {
343 val = MTOF(MMfetch(m, MTOP(jpp), j));
344 kernel.at<float>(i, j) = val;
345 }
346 }
347 }
348 //normalize
349 //kernel /= (float)(s*s);
350
351 PtrObjVoid OB = (PtrObjVoid)MMstart(m, MTOP(bitmap));
352 PtrObjBitmap B = (PtrObjBitmap)MMstart(m, MTOP(OB->Buffer));
353
354 if (B->bits == 0)
355 {
356 MMset(m, 0, NIL);
357 return 0;
358 }
359
360 cv::Mat imagesrc = ConversionTools::ScolBitmapToMat(B);
361 try
362 {
363 cv::filter2D(imagesrc, imagesrc, -1, kernel);
364 }
365 catch (cv::Exception& e)
366 {
367 MMechostr(MSKDEBUG, "_BTFILTERbitmap error %s\n", e.what());
368 return 0;
369 }
370
371#ifdef _SCOL_DEBUG_
372 MMechostr(MSKDEBUG, "ok\n");
373#endif
374 return 0;
375}
376
412{
413#ifdef _SCOL_DEBUG_
414 MMechostr(MSKDEBUG, "_BTFILTERbitmapBuffer\n");
415#endif
416
417 /* Get stack data*/
418 int itab = MMpull(m);
419 int ibytesperpixel = MMpull(m);
420 int iheight = MMpull(m);
421 int iwidth = MMpull(m);
422 int iBuff = MMget(m, 0);
423
424 if ((iBuff == NIL) || (iheight == NIL) || (iwidth == NIL) || (ibytesperpixel == NIL) || (itab == NIL))
425 {
426 MMset(m, 0, NIL);
427 return 0;
428 }
429
430 int s = MMsize(m, MTOP(itab));
431 cv::Mat kernel = cv::Mat::ones(s, s, CV_32F) / (float)(s*s);
432
433 float val = 0.0f;
434 for (int i = 0; i < s; i++)
435 {
436 int jpp = MMfetch(m, MTOP(itab), i);
437 if (jpp != NIL)
438 {
439 int sj = MMsize(m, MTOP(jpp));
440 for (int j = 0; j < sj && j < s; j++)
441 {
442 val = MTOF(MMfetch(m, MTOP(jpp), j));
443 kernel.at<float>(i, j) = val;
444 }
445 }
446 }
447 //normalize
448 //kernel /= (float)(s*s);
449
450 unsigned char* buffer = MMgetPointer<unsigned char*>(m, MTOP(iBuff));
451 if (buffer == NULL)
452 {
453 MMset(m, 0, NIL);
454 return 0;
455 }
456
457 ibytesperpixel = MTOI(ibytesperpixel);
458 iheight = MTOI(iheight);
459 iwidth = MTOI(iwidth);
460
461 cv::Mat imagesrc = ConversionTools::ScolBitmapBufferToMat((void*)buffer, iwidth, iheight, ibytesperpixel);
462 if (imagesrc.empty())
463 {
464 MMset(m, 0, NIL);
465 return 0;
466 }
467
468 try
469 {
470 cv::filter2D(imagesrc, imagesrc, -1, kernel);
471 }
472 catch (cv::Exception& e)
473 {
474 MMechostr(MSKDEBUG, "_BTFILTERbitmapBuffer error %s\n", e.what());
475 return 0;
476 }
477
478#ifdef _SCOL_DEBUG_
479 MMechostr(MSKDEBUG, "ok\n");
480#endif
481 return 0;
482}
483
492int _BTBRIGHTNESSbitmap(mmachine m)
493{
494#ifdef _SCOL_DEBUG_
495 MMechostr(MSKDEBUG, "_BTBRIGHTNESSbitmap\n");
496#endif
497
498 /* Get stack data*/
499 int icoef = MMpull(m);
500 int bitmap = MMget(m, 0);
501
502 if ((bitmap == NIL) || (icoef == NIL))
503 {
504 MMset(m, 0, NIL);
505 return 0;
506 }
507
508 icoef = MTOI(icoef);
509 float coef = (float)icoef / 100.0f;
510
511 PtrObjVoid OB = (PtrObjVoid)MMstart(m, MTOP(bitmap));
512 PtrObjBitmap B = (PtrObjBitmap)MMstart(m, MTOP(OB->Buffer));
513
514 if (B->bits == 0)
515 {
516 MMset(m, 0, NIL);
517 return 0;
518 }
519
520 cv::Mat imagesrc = ConversionTools::ScolBitmapToMat(B);
521 cv::Mat hsv;
522 try
523 {
524 cvtColor(imagesrc, hsv, cv::COLOR_BGR2HSV);
525 cv::Mat channels[3];
526 split(hsv, channels);
527 cv::Mat H = channels[0];
528 H.convertTo(H, CV_32F);
529 cv::Mat S = channels[1];
530 S.convertTo(S, CV_32F);
531 cv::Mat V = channels[2];
532 V.convertTo(V, CV_32F);
533
534 for (int i = 0; i < H.size().height; i++)
535 {
536 for (int j = 0; j < H.size().width; j++)
537 {
538 // scale pixel values up or down for channel 1(Saturation)
539 S.at<float>(i, j) *= coef;
540 if (S.at<float>(i, j) > 255)
541 S.at<float>(i, j) = 255;
542 // scale pixel values up or down for channel 2(Value)
543 V.at<float>(i, j) *= coef;
544 if (V.at<float>(i, j) > 255)
545 V.at<float>(i, j) = 255;
546 }
547 }
548 H.convertTo(H, CV_8U);
549 S.convertTo(S, CV_8U);
550 V.convertTo(V, CV_8U);
551 std::vector<cv::Mat> hsvChannels{ H,S,V };
552 cv::Mat hsvNew;
553 cv::merge(hsvChannels, hsvNew);
554 cvtColor(hsvNew, imagesrc, cv::COLOR_HSV2BGR);
555 }
556 catch (cv::Exception& e)
557 {
558 MMechostr(MSKDEBUG, "_BTBRIGHTNESSbitmap error %s\n", e.what());
559 return 0;
560 }
561
562#ifdef _SCOL_DEBUG_
563 MMechostr(MSKDEBUG, "ok\n");
564#endif
565 return 0;
566}
567
580{
581#ifdef _SCOL_DEBUG_
582 MMechostr(MSKDEBUG, "_BTBRIGHTNESSbitmapBuffer\n");
583#endif
584
585 /* Get stack data*/
586 int icoef = MMpull(m);
587 int ibytesperpixel = MMpull(m);
588 int iheight = MMpull(m);
589 int iwidth = MMpull(m);
590 int iBuff = MMget(m, 0);
591
592 if ((iBuff == NIL) || (iheight == NIL) || (iwidth == NIL) || (ibytesperpixel == NIL) || (icoef == NIL))
593 {
594 MMset(m, 0, NIL);
595 return 0;
596 }
597
598 icoef = MTOI(icoef);
599 float coef = (float)icoef / 100.0f;
600
601 unsigned char* buffer = MMgetPointer<unsigned char*>(m, MTOP(iBuff));
602 if (buffer == NULL)
603 {
604 MMset(m, 0, NIL);
605 return 0;
606 }
607
608 ibytesperpixel = MTOI(ibytesperpixel);
609 iheight = MTOI(iheight);
610 iwidth = MTOI(iwidth);
611
612 cv::Mat imagesrc = ConversionTools::ScolBitmapBufferToMat((void*)buffer, iwidth, iheight, ibytesperpixel);
613 if (imagesrc.empty())
614 {
615 MMset(m, 0, NIL);
616 return 0;
617 }
618
619 cv::Mat hsv;
620 try
621 {
622 cvtColor(imagesrc, hsv, cv::COLOR_BGR2HSV);
623 cv::Mat channels[3];
624 split(hsv, channels);
625 cv::Mat H = channels[0];
626 H.convertTo(H, CV_32F);
627 cv::Mat S = channels[1];
628 S.convertTo(S, CV_32F);
629 cv::Mat V = channels[2];
630 V.convertTo(V, CV_32F);
631
632 for (int i = 0; i < H.size().height; i++)
633 {
634 for (int j = 0; j < H.size().width; j++)
635 {
636 // scale pixel values up or down for channel 1(Saturation)
637 S.at<float>(i, j) *= coef;
638 if (S.at<float>(i, j) > 255)
639 S.at<float>(i, j) = 255;
640 // scale pixel values up or down for channel 2(Value)
641 V.at<float>(i, j) *= coef;
642 if (V.at<float>(i, j) > 255)
643 V.at<float>(i, j) = 255;
644 }
645 }
646 H.convertTo(H, CV_8U);
647 S.convertTo(S, CV_8U);
648 V.convertTo(V, CV_8U);
649 std::vector<cv::Mat> hsvChannels{ H,S,V };
650 cv::Mat hsvNew;
651 cv::merge(hsvChannels, hsvNew);
652 cvtColor(hsvNew, imagesrc, cv::COLOR_HSV2BGR);
653 }
654 catch (cv::Exception& e)
655 {
656 MMechostr(MSKDEBUG, "_BTBRIGHTNESSbitmapBuffer error %s\n", e.what());
657 return 0;
658 }
659
660#ifdef _SCOL_DEBUG_
661 MMechostr(MSKDEBUG, "ok\n");
662#endif
663 return 0;
664}
665
675int _BTLAPLACEbitmap(mmachine m)
676{
677#ifdef _SCOL_DEBUG_
678 MMechostr(MSKDEBUG, "_BTLAPLACEbitmap\n");
679#endif
680
681 /* Get stack data*/
682 int iksize = MMpull(m);
683 int iddepth = MMpull(m);
684 int bitmap = MMget(m, 0);
685
686 if ((bitmap == NIL) || (iddepth == NIL) || (iksize == NIL))
687 {
688 MMset(m, 0, NIL);
689 return 0;
690 }
691
692 int ksize = MTOI(iksize);
693 int ddepth = MTOI(iddepth);
694
695 PtrObjVoid OB = (PtrObjVoid)MMstart(m, MTOP(bitmap));
696 PtrObjBitmap B = (PtrObjBitmap)MMstart(m, MTOP(OB->Buffer));
697
698 if (B->bits == 0)
699 {
700 MMset(m, 0, NIL);
701 return 0;
702 }
703
704 cv::Mat imagesrc = ConversionTools::ScolBitmapToMat(B);
705 try
706 {
707 cv::Laplacian(imagesrc, imagesrc, ddepth, ksize);
708 }
709 catch (cv::Exception& e)
710 {
711 MMechostr(MSKDEBUG, "_BTLAPLACEbitmap error %s\n", e.what());
712 return 0;
713 }
714
715#ifdef _SCOL_DEBUG_
716 MMechostr(MSKDEBUG, "ok\n");
717#endif
718 return 0;
719}
720
734{
735#ifdef _SCOL_DEBUG_
736 MMechostr(MSKDEBUG, "_BTLAPLACEbitmapBuffer\n");
737#endif
738
739 /* Get stack data*/
740 int iksize = MMpull(m);
741 int iddepth = MMpull(m);
742 int ibytesperpixel = MMpull(m);
743 int iheight = MMpull(m);
744 int iwidth = MMpull(m);
745 int iBuff = MMget(m, 0);
746
747 if ((iBuff == NIL) || (iheight == NIL) || (iwidth == NIL) || (ibytesperpixel == NIL) || (iksize == NIL) || (iddepth == NIL))
748 {
749 MMset(m, 0, NIL);
750 return 0;
751 }
752
753 int ksize = MTOI(iksize);
754 int ddepth = MTOI(iddepth);
755
756 unsigned char* buffer = MMgetPointer<unsigned char*>(m, MTOP(iBuff));
757 if (buffer == NULL)
758 {
759 MMset(m, 0, NIL);
760 return 0;
761 }
762
763 ibytesperpixel = MTOI(ibytesperpixel);
764 iheight = MTOI(iheight);
765 iwidth = MTOI(iwidth);
766
767 cv::Mat imagesrc = ConversionTools::ScolBitmapBufferToMat((void*)buffer, iwidth, iheight, ibytesperpixel);
768 if (imagesrc.empty())
769 {
770 MMset(m, 0, NIL);
771 return 0;
772 }
773
774 try
775 {
776 cv::Laplacian(imagesrc, imagesrc, ddepth, ksize);
777 }
778 catch (cv::Exception& e)
779 {
780 MMechostr(MSKDEBUG, "_BTLAPLACEbitmapBuffer error %s\n", e.what());
781 return 0;
782 }
783
784#ifdef _SCOL_DEBUG_
785 MMechostr(MSKDEBUG, "ok\n");
786#endif
787 return 0;
788}
789
797int _BTFLIPbitmap(mmachine m)
798{
799#ifdef _SCOL_DEBUG_
800 MMechostr(MSKDEBUG, "_BTFLIPbitmap\n");
801#endif
802
803 /* Get stack data*/
804 int bitmap = MMget(m, 0);
805
806 if (bitmap == NIL)
807 {
808 MMset(m, 0, NIL);
809 return 0;
810 }
811
812 PtrObjVoid OB = (PtrObjVoid)MMstart(m, MTOP(bitmap));
813 PtrObjBitmap B = (PtrObjBitmap)MMstart(m, MTOP(OB->Buffer));
814
815 if (B->bits == 0)
816 {
817 MMset(m, 0, NIL);
818 return 0;
819 }
820
821 cv::Mat imagesrc = ConversionTools::ScolBitmapToMat(B);
822 try
823 {
824 cv::flip(imagesrc, imagesrc, 1);
825 }
826 catch (cv::Exception& e)
827 {
828 MMechostr(MSKDEBUG, "_BTFLIPbitmap error %s\n", e.what());
829 return 0;
830 }
831
832#ifdef _SCOL_DEBUG_
833 MMechostr(MSKDEBUG, "ok\n");
834#endif
835 return 0;
836}
837
848int _BTFLIPbuffer(mmachine m)
849{
850#ifdef _SCOL_DEBUG_
851 MMechostr(MSKDEBUG, "_BTFLIPbuffer\n");
852#endif
853
854 int ibytesperpixel = MMpull(m);
855 int iheight = MMpull(m);
856 int iwidth = MMpull(m);
857 int iBuff = MMget(m, 0);
858 if ((iBuff == NIL) || (iwidth == NIL) || (iheight == NIL) || (ibytesperpixel == NIL))
859 {
860 MMset(m, 0, NIL);
861 return 0;
862 }
863
864 unsigned char* buffer = MMgetPointer<unsigned char*>(m, MTOP(iBuff));
865 if (buffer == NULL)
866 {
867 MMset(m, 0, NIL);
868 return 0;
869 }
870
871 ibytesperpixel = MTOI(ibytesperpixel);
872 iheight = MTOI(iheight);
873 iwidth = MTOI(iwidth);
874
875 cv::Mat imagesrc = ConversionTools::ScolBitmapBufferToMat((void*)buffer, iwidth, iheight, ibytesperpixel, false);
876 if (imagesrc.empty())
877 {
878 MMset(m, 0, NIL);
879 return 0;
880 }
881
882 try
883 {
884 cv::flip(imagesrc, imagesrc, 1);
885 }
886 catch (cv::Exception& e)
887 {
888 MMechostr(MSKDEBUG, "_BTFLIPbuffer error %s\n", e.what());
889 return 0;
890 }
891
892#ifdef _SCOL_DEBUG_
893 MMechostr(MSKDEBUG, "ok\n");
894#endif
895 return 0;
896}
897
898#define ROW_PTR(img, y) ((uchar*)((img).data + (img).step * y))
908int _BTNORMALbitmap(mmachine m)
909{
910#ifdef _SCOL_DEBUG_
911 MMechostr(MSKDEBUG, "_BTNORMALbitmap\n");
912#endif
913
914 /* Get stack data*/
915 int iblur = MMpull(m);
916 int istrength = MMpull(m);
917 int bitmap = MMget(m, 0);
918
919 if (bitmap == NIL)
920 {
921 MMset(m, 0, NIL);
922 return 0;
923 }
924
925 PtrObjVoid OB = (PtrObjVoid)MMstart(m, MTOP(bitmap));
926 PtrObjBitmap B = (PtrObjBitmap)MMstart(m, MTOP(OB->Buffer));
927
928 if (B->bits == 0)
929 {
930 MMset(m, 0, NIL);
931 return 0;
932 }
933
934 float strength = 1.0f;
935 if (istrength != NIL)
936 strength = MTOF(istrength);
937
938 float blur = 0.0f;
939 if (iblur != NIL)
940 blur = MTOF(iblur);
941
942 cv::Mat imagesrc = ConversionTools::ScolBitmapToMat(B);
943 try
944 {
945 double scale = 1.0;
946 int delta = 127;
947
948 cv::Mat bwTexture;
949 if (imagesrc.channels() != 1)
950 cv::cvtColor(imagesrc, bwTexture, cv::COLOR_BGR2GRAY);
951 else
952 imagesrc.copyTo(bwTexture);
953
954 cv::Mat sobelZ, sobelX, sobelY;
955 cv::Sobel(bwTexture, sobelX, CV_8U, 1, 0, 3, scale, delta, cv::BORDER_DEFAULT);
956 cv::Sobel(bwTexture, sobelY, CV_8U, 0, 1, 3, scale, delta, cv::BORDER_DEFAULT);
957 cv::convertScaleAbs(sobelX, sobelX, 0.125, 127.5);
958 cv::convertScaleAbs(sobelY, sobelY, 0.125, 127.5);
959
960 sobelZ = cv::Mat(bwTexture.rows, bwTexture.cols, CV_8UC1);
961
962 for (int y = 0; y < bwTexture.rows; y++)
963 {
964 uchar *sobelXPtr = ROW_PTR(sobelX, y);
965 uchar *sobelYPtr = ROW_PTR(sobelY, y);
966 uchar *sobelZPtr = ROW_PTR(sobelZ, y);
967
968 for (int x = 0; x < bwTexture.cols; x++)
969 {
970 double Gx = ((double(sobelXPtr[x]) * 2.0) / 255.0) - 1.0;
971 double Gy = -(((double(sobelYPtr[x]) * 2.0) / 255.0) - 1.0);
972
973 cv::Vec3d dx = cv::Vec3d{ 1.0, 0.0, Gx };
974 cv::Vec3d dy = cv::Vec3d{ 0.0, 1.0, Gy };
975 dx = cv::normalize(dx);
976 dy = cv::normalize(dy);
977
978 cv::Vec3d nm = dx.cross(dy) * strength;
979 nm = cv::normalize(nm);
980 nm = (nm * 128.0) + cv::Vec3d{ 128.0, 128.0, 128.0 };
981 sobelXPtr[x] = uchar(nm[2]);
982 sobelYPtr[x] = uchar(nm[1]);
983 sobelZPtr[x] = uchar(nm[0]);
984 }
985 }
986
987 std::vector<cv::Mat>planes;
988 planes.push_back(sobelX);
989 planes.push_back(sobelY);
990 planes.push_back(sobelZ);
991
992 cv::Mat normalMap;
993 cv::merge(planes, normalMap);
994
995 if (blur > 0.0f)
996 {
997 cv::Mat originalNormalMap = normalMap.clone();
998 cv::Mat normalMapBlurred;
999
1000 for (int i = 0; i < 3; i++)
1001 {
1002 cv::GaussianBlur(normalMap, normalMapBlurred, cv::Size(13, 13), 5.0f * blur, 5.0f * blur);
1003 addWeighted(normalMap, 0.4, normalMapBlurred, 0.6, 0, normalMap);
1004 }
1005 addWeighted(originalNormalMap, 0.3, normalMapBlurred, 0.7, 0, normalMap);
1006 }
1007 else if (blur < 0.0f)
1008 {
1009 float sharp = std::min(abs(blur), 1.0f);
1010 cv::Mat originalNormalMap = normalMap.clone();
1011 cv::Mat normalMapSharpen;
1012 cv::Mat kernel(3, 3, CV_32F, cv::Scalar(0));
1013 // sharpen
1014 kernel.at<float>(1, 1) = 5.0;
1015 kernel.at<float>(0, 1) = -1.0;
1016 kernel.at<float>(2, 1) = -1.0;
1017 kernel.at<float>(1, 0) = -1.0;
1018 kernel.at<float>(1, 2) = -1.0;
1019 cv::filter2D(normalMap, normalMapSharpen, -1, kernel);
1020
1021 addWeighted(originalNormalMap, 1.0f - sharp, normalMapSharpen, sharp, 0.0, normalMap);
1022 }
1023 normalMap.copyTo(imagesrc);
1024 }
1025 catch (cv::Exception& e)
1026 {
1027 MMechostr(MSKDEBUG, "_BTNORMALbitmap error %s\n", e.what());
1028 return 0;
1029 }
1030
1031#ifdef _SCOL_DEBUG_
1032 MMechostr(MSKDEBUG, "ok\n");
1033#endif
1034 return 0;
1035}
1036
1050{
1051#ifdef _SCOL_DEBUG_
1052 MMechostr(MSKDEBUG, "_BTNORMALbitmapBuffer\n");
1053#endif
1054
1055 int iblur = MMpull(m);
1056 int istrength = MMpull(m);
1057 int ibytesperpixel = MMpull(m);
1058 int iheight = MMpull(m);
1059 int iwidth = MMpull(m);
1060 int iBuff = MMget(m, 0);
1061 if ((iBuff == NIL) || (iwidth == NIL) || (iheight == NIL) || (ibytesperpixel == NIL))
1062 {
1063 MMset(m, 0, NIL);
1064 return 0;
1065 }
1066
1067 unsigned char* buffer = MMgetPointer<unsigned char*>(m, MTOP(iBuff));
1068 if (buffer == NULL)
1069 {
1070 MMset(m, 0, NIL);
1071 return 0;
1072 }
1073
1074 ibytesperpixel = MTOI(ibytesperpixel);
1075 iheight = MTOI(iheight);
1076 iwidth = MTOI(iwidth);
1077
1078 cv::Mat imagesrc = ConversionTools::ScolBitmapBufferToMat((void*)buffer, iwidth, iheight, ibytesperpixel, false);
1079 if (imagesrc.empty())
1080 {
1081 MMset(m, 0, NIL);
1082 return 0;
1083 }
1084
1085 float strength = 1.0f;
1086 if (istrength != NIL)
1087 strength = MTOF(istrength);
1088
1089 float blur = 0.0f;
1090 if (iblur != NIL)
1091 blur = MTOF(iblur);
1092
1093 try
1094 {
1095 double scale = 1.0;
1096 int delta = 127;
1097 cv::Mat bwTexture;
1098 if (imagesrc.channels() != 1)
1099 cv::cvtColor(imagesrc, bwTexture, cv::COLOR_BGR2GRAY);
1100 else
1101 imagesrc.copyTo(bwTexture);
1102
1103 cv::Mat sobelZ, sobelX, sobelY;
1104 cv::Sobel(bwTexture, sobelX, CV_8U, 1, 0, 3, scale, delta, cv::BORDER_DEFAULT);
1105 cv::Sobel(bwTexture, sobelY, CV_8U, 0, 1, 3, scale, delta, cv::BORDER_DEFAULT);
1106 cv::convertScaleAbs(sobelX, sobelX, 0.125, 127.5);
1107 cv::convertScaleAbs(sobelY, sobelY, 0.125, 127.5);
1108
1109 sobelZ = cv::Mat(bwTexture.rows, bwTexture.cols, CV_8UC1);
1110
1111 for (int y = 0; y < bwTexture.rows; y++)
1112 {
1113 uchar *sobelXPtr = ROW_PTR(sobelX, y);
1114 uchar *sobelYPtr = ROW_PTR(sobelY, y);
1115 uchar *sobelZPtr = ROW_PTR(sobelZ, y);
1116
1117 for (int x = 0; x < bwTexture.cols; x++)
1118 {
1119 double Gx = ((double(sobelXPtr[x]) * 2.0) / 255.0) - 1.0;
1120 double Gy = -(((double(sobelYPtr[x]) * 2.0) / 255.0) - 1.0);
1121
1122 cv::Vec3d dx = cv::Vec3d{ 1.0, 0.0, Gx };
1123 cv::Vec3d dy = cv::Vec3d{ 0.0, 1.0, Gy };
1124 dx = cv::normalize(dx);
1125 dy = cv::normalize(dy);
1126
1127 cv::Vec3d nm = dx.cross(dy) * strength;
1128 nm = cv::normalize(nm);
1129 nm = (nm * 128.0) + cv::Vec3d{ 128.0, 128.0, 128.0 };
1130 sobelXPtr[x] = uchar(nm[2]);
1131 sobelYPtr[x] = uchar(nm[1]);
1132 sobelZPtr[x] = uchar(nm[0]);
1133 }
1134 }
1135
1136 std::vector<cv::Mat>planes;
1137 planes.push_back(sobelX);
1138 planes.push_back(sobelY);
1139 planes.push_back(sobelZ);
1140
1141 cv::Mat normalMap;
1142 cv::merge(planes, normalMap);
1143
1144 if (blur > 0.0f)
1145 {
1146 cv::Mat originalNormalMap = normalMap.clone();
1147 cv::Mat normalMapBlurred;
1148
1149 for (int i = 0; i < 3; i++)
1150 {
1151 cv::GaussianBlur(normalMap, normalMapBlurred, cv::Size(13, 13), 5.0f * blur, 5.0f * blur);
1152 addWeighted(normalMap, 0.4, normalMapBlurred, 0.6, 0, normalMap);
1153 }
1154 addWeighted(originalNormalMap, 0.3, normalMapBlurred, 0.7, 0, normalMap);
1155 }
1156 else if (blur < 0.0f)
1157 {
1158 float sharp = std::min(abs(blur), 1.0f);
1159 cv::Mat originalNormalMap = normalMap.clone();
1160 cv::Mat normalMapSharpen;
1161 cv::Mat kernel(3, 3, CV_32F, cv::Scalar(0));
1162 // sharpen
1163 kernel.at<float>(1, 1) = 5.0;
1164 kernel.at<float>(0, 1) = -1.0;
1165 kernel.at<float>(2, 1) = -1.0;
1166 kernel.at<float>(1, 0) = -1.0;
1167 kernel.at<float>(1, 2) = -1.0;
1168 cv::filter2D(normalMap, normalMapSharpen, -1, kernel);
1169
1170 addWeighted(originalNormalMap, 1.0f - sharp, normalMapSharpen, sharp, 0.0, normalMap);
1171 }
1172 normalMap.copyTo(imagesrc);
1173 }
1174 catch (cv::Exception& e)
1175 {
1176 MMechostr(MSKDEBUG, "_BTNORMALbitmapBuffer error %s\n", e.what());
1177 return 0;
1178 }
1179
1180#ifdef _SCOL_DEBUG_
1181 MMechostr(MSKDEBUG, "ok\n");
1182#endif
1183 return 0;
1184}
1185
1199int _BTDRAWcircle(mmachine m)
1200{
1201#ifdef _SCOL_DEBUG_
1202 MMechostr(MSKDEBUG, "_BTDRAWcircle\n");
1203#endif
1204
1205 /* Get stack data*/
1206 int ifill_color = MMpull(m);
1207 int ifilled = MMpull(m);
1208 int istroke_thickness = MMpull(m);
1209 int istroke_color = MMpull(m);
1210 int iradius = MMpull(m);
1211 int ipos = MMpull(m);
1212 int bitmap = MMget(m, 0);
1213
1214 if ((bitmap == NIL) || (ipos == NIL) || (iradius == NIL))
1215 {
1216 MMset(m, 0, NIL);
1217 return 0;
1218 }
1219
1220 // bitmap
1221 PtrObjVoid ptr_bitmap = (PtrObjVoid)MMstart(m, MTOP(bitmap));
1222 PtrObjBitmap obj_bitmap = (PtrObjBitmap)MMstart(m, MTOP(ptr_bitmap->Buffer));
1223
1224 if (obj_bitmap->bits == 0)
1225 {
1226 MMset(m, 0, NIL);
1227 return 0;
1228 }
1229
1230 cv::Mat imagesrc = ConversionTools::ScolBitmapToMat(obj_bitmap);
1231
1232 // position
1233 int iposX = MMfetch(m, MTOP(ipos), 0);
1234 int iposY = MMfetch(m, MTOP(ipos), 1);
1235 if (iposX == NIL || iposY == NIL)
1236 {
1237 MMset(m, 0, NIL);
1238 return 0;
1239 }
1240
1241 //stroke
1242 cv::Scalar stroke_color(0);
1243 int stroke_thickness = 1;
1244 if (istroke_color != NIL)
1245 {
1246 int color = MTOI(istroke_color);
1247 if (obj_bitmap->BytesPP == 1)
1248 stroke_color = cv::Scalar(color & 255, color & 255, color & 255, 255);
1249 else
1250 stroke_color = cv::Scalar((color >> 16) & 255, (color >> 8) & 255, color & 255, 255);
1251 }
1252
1253 if (istroke_thickness != NIL)
1254 stroke_thickness = MTOI(istroke_thickness);
1255
1256 // fill
1257 bool filled = false;
1258 if (ifilled != NIL)
1259 filled = (MTOI(ifilled) != 0);
1260
1261 // draw filled
1262 if (filled)
1263 {
1264 cv::Scalar fill_color(0);
1265 if (ifill_color != NIL)
1266 {
1267 int color = MTOI(ifill_color);
1268 if (obj_bitmap->BytesPP == 1)
1269 fill_color = cv::Scalar(color & 255, color & 255, color & 255, 255);
1270 else
1271 fill_color = cv::Scalar((color >> 16) & 255, (color >> 8) & 255, color & 255, 255);
1272 }
1273 try
1274 {
1275 cv::circle(imagesrc, cv::Point(MTOI(iposX), MTOI(iposY)), MTOI(iradius), fill_color, -1, 8);
1276 }
1277 catch (cv::Exception e)
1278 {
1279 MMechostr(MSKDEBUG, "%s", e.err.c_str());
1280 }
1281 }
1282
1283 // draw stroke
1284 try
1285 {
1286 cv::circle(imagesrc, cv::Point(MTOI(iposX), MTOI(iposY)), MTOI(iradius), stroke_color, stroke_thickness, 8);
1287 }
1288 catch (cv::Exception& e)
1289 {
1290 MMechostr(MSKDEBUG, "_BTDRAWcircle error %s\n", e.what());
1291 return 0;
1292 }
1293
1294#ifdef _SCOL_DEBUG_
1295 MMechostr(MSKDEBUG, "ok\n");
1296#endif
1297 return 0;
1298}
1299
1316int _BTDRAWcircleBuffer(mmachine m)
1317{
1318#ifdef _SCOL_DEBUG_
1319 MMechostr(MSKDEBUG, "_BTDRAWcircleBuffer\n");
1320#endif
1321
1322 int ifill_color = MMpull(m);
1323 int ifilled = MMpull(m);
1324 int istroke_thickness = MMpull(m);
1325 int istroke_color = MMpull(m);
1326 int iradius = MMpull(m);
1327 int ipos = MMpull(m);
1328
1329 int ibytesperpixel = MMpull(m);
1330 int iheight = MMpull(m);
1331 int iwidth = MMpull(m);
1332 int iBuff = MMget(m, 0);
1333 if ((iBuff == NIL) || (iwidth == NIL) || (iheight == NIL) || (ibytesperpixel == NIL) || (ipos == NIL) || (iradius == NIL))
1334 {
1335 MMset(m, 0, NIL);
1336 return 0;
1337 }
1338
1339 unsigned char* buffer = MMgetPointer<unsigned char*>(m, MTOP(iBuff));
1340 if (buffer == NULL)
1341 {
1342 MMset(m, 0, NIL);
1343 return 0;
1344 }
1345
1346 ibytesperpixel = MTOI(ibytesperpixel);
1347 iheight = MTOI(iheight);
1348 iwidth = MTOI(iwidth);
1349
1350 cv::Mat imagesrc = ConversionTools::ScolBitmapBufferToMat((void*)buffer, iwidth, iheight, ibytesperpixel);
1351 if (imagesrc.empty())
1352 {
1353 MMset(m, 0, NIL);
1354 return 0;
1355 }
1356
1357 // position
1358 int iposX = MMfetch(m, MTOP(ipos), 0);
1359 int iposY = MMfetch(m, MTOP(ipos), 1);
1360 if (iposX == NIL || iposY == NIL)
1361 {
1362 MMset(m, 0, NIL);
1363 return 0;
1364 }
1365
1366 //stroke
1367 cv::Scalar stroke_color(0);
1368 int stroke_thickness = 1;
1369 if (istroke_color != NIL)
1370 {
1371 int color = MTOI(istroke_color);
1372 if (ibytesperpixel == 1)
1373 stroke_color = cv::Scalar(color & 255, color & 255, color & 255, 255);
1374 else
1375 stroke_color = cv::Scalar((color >> 16) & 255, (color >> 8) & 255, color & 255, 255);
1376 }
1377
1378 if (istroke_thickness != NIL)
1379 stroke_thickness = MTOI(istroke_thickness);
1380
1381 // fill
1382 bool filled = false;
1383 if (ifilled != NIL)
1384 filled = (MTOI(ifilled) != 0);
1385
1386 // draw filled
1387 if (filled)
1388 {
1389 cv::Scalar fill_color(0);
1390 if (ifill_color != NIL)
1391 {
1392 int color = MTOI(ifill_color);
1393 if (ibytesperpixel == 1)
1394 fill_color = cv::Scalar(color & 255, color & 255, color & 255, 255);
1395 else
1396 fill_color = cv::Scalar((color >> 16) & 255, (color >> 8) & 255, color & 255, 255);
1397 }
1398 try
1399 {
1400 cv::circle(imagesrc, cv::Point(MTOI(iposX), MTOI(iposY)), MTOI(iradius), fill_color, -1, 8);
1401 }
1402 catch (cv::Exception e)
1403 {
1404 MMechostr(MSKDEBUG, "%s", e.err.c_str());
1405 }
1406 }
1407
1408 // draw stroke
1409 try
1410 {
1411 cv::circle(imagesrc, cv::Point(MTOI(iposX), MTOI(iposY)), MTOI(iradius), stroke_color, stroke_thickness, 8);
1412 }
1413 catch (cv::Exception& e)
1414 {
1415 MMechostr(MSKDEBUG, "_BTDRAWcircleBuffer error %s\n", e.what());
1416 return 0;
1417 }
1418
1419#ifdef _SCOL_DEBUG_
1420 MMechostr(MSKDEBUG, "ok\n");
1421#endif
1422 return 0;
1423}
1424
1437int _BTDRAWrect(mmachine m)
1438{
1439#ifdef _SCOL_DEBUG_
1440 MMechostr(MSKDEBUG, "_BTDRAWrect\n");
1441#endif
1442
1443 int ifill_color = MMpull(m);
1444 int ifilled = MMpull(m);
1445 int istroke_thickness = MMpull(m);
1446 int istroke_color = MMpull(m);
1447 int irect = MMpull(m);
1448 int ibitmap = MMget(m, 0);
1449
1450 if (ibitmap == NIL || irect == NIL)
1451 {
1452 MMset(m, 0, NIL);
1453 return 0;
1454 }
1455
1456 // bitmap
1457 PtrObjVoid ptr_bitmap = (PtrObjVoid)MMstart(m, MTOP(ibitmap));
1458 PtrObjBitmap obj_bitmap = (PtrObjBitmap)MMstart(m, MTOP(ptr_bitmap->Buffer));
1459 cv::Mat imagesrc = ConversionTools::ScolBitmapToMat(obj_bitmap);
1460
1461 // rect
1462 int iposx = MMfetch(m, MTOP(irect), 0);
1463 int iposy = MMfetch(m, MTOP(irect), 1);
1464 int iwidth = MMfetch(m, MTOP(irect), 2);
1465 int iheight = MMfetch(m, MTOP(irect), 3);
1466 if (iposx == NIL || iposy == NIL || iwidth == NIL || iheight == NIL)
1467 {
1468 MMset(m, 0, NIL);
1469 return 0;
1470 }
1471
1472 int posx = MTOI(iposx);
1473 int posy = MTOI(iposy);
1474 int width = MTOI(iwidth);
1475 int height = MTOI(iheight);
1476 cv::Rect rect(posx, posy, width, height);
1477
1478 if (rect.width < 0)
1479 {
1480 rect.width = abs(rect.width);
1481 rect.x = rect.x - rect.width;
1482 }
1483
1484 if (rect.height < 0)
1485 {
1486 rect.height = abs(rect.height);
1487 rect.y = rect.y - rect.height;
1488 }
1489
1490 // stroke
1491 cv::Scalar stroke_color(0);
1492 int stroke_thickness = 1;
1493 if (istroke_color != NIL)
1494 {
1495 int color = MTOI(istroke_color);
1496 if (obj_bitmap->BytesPP == 1)
1497 stroke_color = cv::Scalar(color & 255, color & 255, color & 255, 255);
1498 else
1499 stroke_color = cv::Scalar((color >> 16) & 255, (color >> 8) & 255, color & 255, 255);
1500 }
1501
1502 if (istroke_thickness != NIL)
1503 stroke_thickness = MTOI(istroke_thickness);
1504
1505 // fill
1506 bool filled = false;
1507 if (ifilled != NIL)
1508 filled = (MTOI(ifilled) != 0);
1509
1510 // draw filled
1511 if (filled)
1512 {
1513 cv::Scalar fill_color(0);
1514 if (ifill_color != NIL)
1515 {
1516 int color = MTOI(ifill_color);
1517 if (obj_bitmap->BytesPP == 1)
1518 fill_color = cv::Scalar(color & 255, color & 255, color & 255, 255);
1519 else
1520 fill_color = cv::Scalar((color >> 16) & 255, (color >> 8) & 255, color & 255, 255);
1521 }
1522 try
1523 {
1524 cv::rectangle(imagesrc, rect, fill_color, -1, 8);
1525 }
1526 catch (cv::Exception e)
1527 {
1528 MMechostr(MSKDEBUG, "%s", e.err.c_str());
1529 }
1530 }
1531
1532 // draw stroke
1533 try
1534 {
1535 cv::rectangle(imagesrc, rect, stroke_color, stroke_thickness, 8);
1536 }
1537 catch (cv::Exception e)
1538 {
1539 MMechostr(MSKDEBUG, "%s", e.err.c_str());
1540 }
1541
1542#ifdef _SCOL_DEBUG_
1543 MMechostr(MSKDEBUG, "end _BTDRAWrect\n");
1544#endif
1545
1546 return 0;
1547}
1548
1564int _BTDRAWrectBuffer(mmachine m)
1565{
1566#ifdef _SCOL_DEBUG_
1567 MMechostr(MSKDEBUG, "_BTDRAWrectBuffer\n");
1568#endif
1569
1570 int ifill_color = MMpull(m);
1571 int ifilled = MMpull(m);
1572 int istroke_thickness = MMpull(m);
1573 int istroke_color = MMpull(m);
1574 int irect = MMpull(m);
1575
1576 int ibytesperpixel = MMpull(m);
1577 int iheight = MMpull(m);
1578 int iwidth = MMpull(m);
1579 int iBuff = MMget(m, 0);
1580 if ((iBuff == NIL) || (iwidth == NIL) || (iheight == NIL) || (ibytesperpixel == NIL) || (irect == NIL))
1581 {
1582 MMset(m, 0, NIL);
1583 return 0;
1584 }
1585
1586 unsigned char* buffer = MMgetPointer<unsigned char*>(m, MTOP(iBuff));
1587 if (buffer == NULL)
1588 {
1589 MMset(m, 0, NIL);
1590 return 0;
1591 }
1592
1593 ibytesperpixel = MTOI(ibytesperpixel);
1594 iheight = MTOI(iheight);
1595 iwidth = MTOI(iwidth);
1596
1597 cv::Mat imagesrc = ConversionTools::ScolBitmapBufferToMat((void*)buffer, iwidth, iheight, ibytesperpixel);
1598 if (imagesrc.empty())
1599 {
1600 MMset(m, 0, NIL);
1601 return 0;
1602 }
1603
1604 // rect
1605 int iposx = MMfetch(m, MTOP(irect), 0);
1606 int iposy = MMfetch(m, MTOP(irect), 1);
1607 int irwidth = MMfetch(m, MTOP(irect), 2);
1608 int irheight = MMfetch(m, MTOP(irect), 3);
1609 if (iposx == NIL || iposy == NIL || irwidth == NIL || irheight == NIL)
1610 {
1611 MMset(m, 0, NIL);
1612 return 0;
1613 }
1614
1615 int rposx = MTOI(iposx);
1616 int rposy = MTOI(iposy);
1617 int rwidth = MTOI(irwidth);
1618 int rheight = MTOI(irheight);
1619 cv::Rect rect(rposx, rposy, rwidth, rheight);
1620
1621 if (rect.width < 0)
1622 {
1623 rect.width = abs(rect.width);
1624 rect.x = rect.x - rect.width;
1625 }
1626
1627 if (rect.height < 0)
1628 {
1629 rect.height = abs(rect.height);
1630 rect.y = rect.y - rect.height;
1631 }
1632
1633 // stroke
1634 cv::Scalar stroke_color(0);
1635 int stroke_thickness = 1;
1636 if (istroke_color != NIL)
1637 {
1638 int color = MTOI(istroke_color);
1639 if (ibytesperpixel == 1)
1640 stroke_color = cv::Scalar(color & 255, color & 255, color & 255, 255);
1641 else
1642 stroke_color = cv::Scalar((color >> 16) & 255, (color >> 8) & 255, color & 255, 255);
1643 }
1644
1645 if (istroke_thickness != NIL)
1646 stroke_thickness = MTOI(istroke_thickness);
1647
1648 // fill
1649 bool filled = false;
1650 if (ifilled != NIL)
1651 filled = (MTOI(ifilled) != 0);
1652
1653 // draw filled
1654 if (filled)
1655 {
1656 cv::Scalar fill_color(0);
1657 if (ifill_color != NIL)
1658 {
1659 int color = MTOI(ifill_color);
1660 if (ibytesperpixel == 1)
1661 fill_color = cv::Scalar(color & 255, color & 255, color & 255, 255);
1662 else
1663 fill_color = cv::Scalar((color >> 16) & 255, (color >> 8) & 255, color & 255, 255);
1664 }
1665 try
1666 {
1667 cv::rectangle(imagesrc, rect, fill_color, -1, 8);
1668 }
1669 catch (cv::Exception e)
1670 {
1671 MMechostr(MSKDEBUG, "%s", e.err.c_str());
1672 }
1673 }
1674
1675 // draw stroke
1676 try
1677 {
1678 cv::rectangle(imagesrc, rect, stroke_color, stroke_thickness, 8);
1679 }
1680 catch (cv::Exception e)
1681 {
1682 MMechostr(MSKDEBUG, "%s", e.err.c_str());
1683 }
1684
1685#ifdef _SCOL_DEBUG_
1686 MMechostr(MSKDEBUG, "end _BTDRAWrectBuffer\n");
1687#endif
1688
1689 return 0;
1690}
1691
1692
1704int _BTDRAWline(mmachine m)
1705{
1706#ifdef _SCOL_DEBUG_
1707 MMechostr(MSKDEBUG, "_BTDRAWline\n");
1708#endif
1709
1710 int istroke_thickness = MMpull(m);
1711 int istroke_color = MMpull(m);
1712 int iend = MMpull(m);
1713 int istart = MMpull(m);
1714 int ibitmap = MMget(m, 0);
1715
1716 if ((ibitmap == NIL) || (istart == NIL) || (iend == NIL))
1717 {
1718 MMset(m, 0, NIL);
1719 return 0;
1720 }
1721
1722 // bitmap
1723 PtrObjVoid ptr_bitmap = (PtrObjVoid)MMstart(m, MTOP(ibitmap));
1724 PtrObjBitmap obj_bitmap = (PtrObjBitmap)MMstart(m, MTOP(ptr_bitmap->Buffer));
1725 cv::Mat imagesrc = ConversionTools::ScolBitmapToMat(obj_bitmap);
1726
1727 // line coords
1728 int istartx = MMfetch(m, MTOP(istart), 0);
1729 int istarty = MMfetch(m, MTOP(istart), 1);
1730 int idestx = MMfetch(m, MTOP(iend), 0);
1731 int idesty = MMfetch(m, MTOP(iend), 1);
1732 if (istartx == NIL || istarty == NIL || idestx == NIL || idesty == NIL)
1733 {
1734 MMset(m, 0, NIL);
1735 return 0;
1736 }
1737
1738 cv::Point stpoint(MTOI(istartx), MTOI(istarty));
1739 cv::Point dstpoint(MTOI(idestx), MTOI(idesty));
1740
1741 // stroke
1742 cv::Scalar stroke_color(0);
1743 int stroke_thickness = 1;
1744 if (istroke_color != NIL)
1745 {
1746 int color = MTOI(istroke_color);
1747 if (obj_bitmap->BytesPP == 1)
1748 stroke_color = cv::Scalar(color & 255, color & 255, color & 255, 255);
1749 else
1750 stroke_color = cv::Scalar((color >> 16) & 255, (color >> 8) & 255, color & 255, 255);
1751 }
1752
1753 if (istroke_thickness != NIL)
1754 stroke_thickness = MTOI(istroke_thickness);
1755
1756 // draw line
1757 try
1758 {
1759 cv::line(imagesrc, stpoint, dstpoint, stroke_color, stroke_thickness, 8);
1760 }
1761 catch (cv::Exception e)
1762 {
1763 MMechostr(MSKDEBUG, "%s", e.err.c_str());
1764 }
1765
1766#ifdef _SCOL_DEBUG_
1767 MMechostr(MSKDEBUG, "end _BTDRAWline\n");
1768#endif
1769
1770 return 0;
1771}
1772
1787int _BTDRAWlineBuffer(mmachine m)
1788{
1789#ifdef _SCOL_DEBUG_
1790 MMechostr(MSKDEBUG, "_BTDRAWlineBuffer\n");
1791#endif
1792
1793 int istroke_thickness = MMpull(m);
1794 int istroke_color = MMpull(m);
1795 int iend = MMpull(m);
1796 int istart = MMpull(m);
1797
1798 int ibytesperpixel = MMpull(m);
1799 int iheight = MMpull(m);
1800 int iwidth = MMpull(m);
1801 int iBuff = MMget(m, 0);
1802 if ((iBuff == NIL) || (iwidth == NIL) || (iheight == NIL) || (ibytesperpixel == NIL) || (istart == NIL) || (iend == NIL))
1803 {
1804 MMset(m, 0, NIL);
1805 return 0;
1806 }
1807
1808 unsigned char* buffer = MMgetPointer<unsigned char*>(m, MTOP(iBuff));
1809 if (buffer == NULL)
1810 {
1811 MMset(m, 0, NIL);
1812 return 0;
1813 }
1814
1815 ibytesperpixel = MTOI(ibytesperpixel);
1816 iheight = MTOI(iheight);
1817 iwidth = MTOI(iwidth);
1818
1819 cv::Mat imagesrc = ConversionTools::ScolBitmapBufferToMat((void*)buffer, iwidth, iheight, ibytesperpixel);
1820 if (imagesrc.empty())
1821 {
1822 MMset(m, 0, NIL);
1823 return 0;
1824 }
1825
1826 // line coords
1827 int istartx = MMfetch(m, MTOP(istart), 0);
1828 int istarty = MMfetch(m, MTOP(istart), 1);
1829 int idestx = MMfetch(m, MTOP(iend), 0);
1830 int idesty = MMfetch(m, MTOP(iend), 1);
1831 if (istartx == NIL || istarty == NIL || idestx == NIL || idesty == NIL)
1832 {
1833 MMset(m, 0, NIL);
1834 return 0;
1835 }
1836
1837 cv::Point stpoint(MTOI(istartx), MTOI(istarty));
1838 cv::Point dstpoint(MTOI(idestx), MTOI(idesty));
1839
1840 // stroke
1841 cv::Scalar stroke_color(0);
1842 int stroke_thickness = 1;
1843 if (istroke_color != NIL)
1844 {
1845 int color = MTOI(istroke_color);
1846 if (ibytesperpixel == 1)
1847 stroke_color = cv::Scalar(color & 255, color & 255, color & 255, 255);
1848 else
1849 stroke_color = cv::Scalar((color >> 16) & 255, (color >> 8) & 255, color & 255, 255);
1850 }
1851
1852 if (istroke_thickness != NIL)
1853 stroke_thickness = MTOI(istroke_thickness);
1854
1855 // draw line
1856 try
1857 {
1858 cv::line(imagesrc, stpoint, dstpoint, stroke_color, stroke_thickness, 8);
1859 }
1860 catch (cv::Exception e)
1861 {
1862 MMechostr(MSKDEBUG, "%s", e.err.c_str());
1863 }
1864
1865#ifdef _SCOL_DEBUG_
1866 MMechostr(MSKDEBUG, "end _BTDRAWlineBuffer\n");
1867#endif
1868
1869 return 0;
1870}
1871
1872
1883int _BTDRAWpath(mmachine m)
1884{
1885#ifdef _SCOL_DEBUG_
1886 MMechostr(MSKDEBUG, "_BTDRAWpath\n");
1887#endif
1888
1889 int istroke_thickness = MMpull(m);
1890 int istroke_color = MMpull(m);
1891 int ilist = MMpull(m);
1892 int ibitmap = MMget(m, 0);
1893
1894 if ((ibitmap == NIL) || (ilist == NIL))
1895 {
1896 MMset(m, 0, NIL);
1897 return 0;
1898 }
1899
1900 // bitmap
1901 PtrObjVoid ptr_bitmap = (PtrObjVoid)MMstart(m, MTOP(ibitmap));
1902 PtrObjBitmap obj_bitmap = (PtrObjBitmap)MMstart(m, MTOP(ptr_bitmap->Buffer));
1903 cv::Mat imagesrc = ConversionTools::ScolBitmapToMat(obj_bitmap);
1904
1905 std::vector<cv::Point2i> linepath;
1906 // Load points
1907 if (ilist != NIL)
1908 {
1909 // Iterate through the recursive tuple
1910 int pointTuple;
1911 int x, y;
1912 ilist = MTOP(ilist);
1913 while (ilist != NIL)
1914 {
1915 // Get point coordinate
1916 pointTuple = MTOP(MMfetch(m, ilist, 0));
1917 x = MTOI(MMfetch(m, pointTuple, 0));
1918 y = MTOI(MMfetch(m, pointTuple, 1));
1919 ilist = MTOP(MMfetch(m, ilist, 1));
1920
1921 // Add point
1922 linepath.push_back(cv::Point2i(x, y));
1923 }
1924 }
1925
1926 // stroke
1927 cv::Scalar stroke_color(0);
1928 int stroke_thickness = 1;
1929 if (istroke_color != NIL)
1930 {
1931 int color = MTOI(istroke_color);
1932 if (obj_bitmap->BytesPP == 1)
1933 stroke_color = cv::Scalar(color & 255, color & 255, color & 255, 255);
1934 else
1935 stroke_color = cv::Scalar((color >> 16) & 255, (color >> 8) & 255, color & 255, 255);
1936 }
1937
1938 if (istroke_thickness != NIL)
1939 stroke_thickness = MTOI(istroke_thickness);
1940
1941 // draw line
1942 try
1943 {
1944 cv::polylines(imagesrc, linepath, false, stroke_color, stroke_thickness, 8);
1945 }
1946 catch (cv::Exception e)
1947 {
1948 MMechostr(MSKDEBUG, "%s", e.err.c_str());
1949 }
1950
1951#ifdef _SCOL_DEBUG_
1952 MMechostr(MSKDEBUG, "end _BTDRAWpath\n");
1953#endif
1954
1955 return 0;
1956}
1957
1971int _BTDRAWpathBuffer(mmachine m)
1972{
1973#ifdef _SCOL_DEBUG_
1974 MMechostr(MSKDEBUG, "_BTDRAWpathBuffer\n");
1975#endif
1976
1977 int istroke_thickness = MMpull(m);
1978 int istroke_color = MMpull(m);
1979 int ilist = MMpull(m);
1980
1981 int ibytesperpixel = MMpull(m);
1982 int iheight = MMpull(m);
1983 int iwidth = MMpull(m);
1984 int iBuff = MMget(m, 0);
1985 if ((iBuff == NIL) || (iwidth == NIL) || (iheight == NIL) || (ibytesperpixel == NIL) || (ilist == NIL))
1986 {
1987 MMset(m, 0, NIL);
1988 return 0;
1989 }
1990
1991 unsigned char* buffer = MMgetPointer<unsigned char*>(m, MTOP(iBuff));
1992 if (buffer == NULL)
1993 {
1994 MMset(m, 0, NIL);
1995 return 0;
1996 }
1997
1998 ibytesperpixel = MTOI(ibytesperpixel);
1999 iheight = MTOI(iheight);
2000 iwidth = MTOI(iwidth);
2001
2002 cv::Mat imagesrc = ConversionTools::ScolBitmapBufferToMat((void*)buffer, iwidth, iheight, ibytesperpixel);
2003 if (imagesrc.empty())
2004 {
2005 MMset(m, 0, NIL);
2006 return 0;
2007 }
2008
2009 std::vector<cv::Point2i> linepath;
2010 // Load points
2011 if (ilist != NIL)
2012 {
2013 // Iterate through the recursive tuple
2014 int pointTuple;
2015 int x, y;
2016 ilist = MTOP(ilist);
2017 while (ilist != NIL)
2018 {
2019 // Get point coordinate
2020 pointTuple = MTOP(MMfetch(m, ilist, 0));
2021 x = MTOI(MMfetch(m, pointTuple, 0));
2022 y = MTOI(MMfetch(m, pointTuple, 1));
2023 ilist = MTOP(MMfetch(m, ilist, 1));
2024
2025 // Add point
2026 linepath.push_back(cv::Point2i(x, y));
2027 }
2028 }
2029
2030 // stroke
2031 cv::Scalar stroke_color(0);
2032 int stroke_thickness = 1;
2033 if (istroke_color != NIL)
2034 {
2035 int color = MTOI(istroke_color);
2036 if (ibytesperpixel == 1)
2037 stroke_color = cv::Scalar(color & 255, color & 255, color & 255, 255);
2038 else
2039 stroke_color = cv::Scalar((color >> 16) & 255, (color >> 8) & 255, color & 255, 255);
2040 }
2041
2042 if (istroke_thickness != NIL)
2043 stroke_thickness = MTOI(istroke_thickness);
2044
2045 // draw line
2046 try
2047 {
2048 cv::polylines(imagesrc, linepath, false, stroke_color, stroke_thickness, 8);
2049 }
2050 catch (cv::Exception e)
2051 {
2052 MMechostr(MSKDEBUG, "%s", e.err.c_str());
2053 }
2054
2055#ifdef _SCOL_DEBUG_
2056 MMechostr(MSKDEBUG, "end _BTDRAWpathBuffer\n");
2057#endif
2058
2059 return 0;
2060}
2061
2072int _BTMOTIONdetect(mmachine m)
2073{
2074#ifdef _SCOL_DEBUG_
2075 MMechostr(MSKDEBUG, "_BTMOTIONdetect\n");
2076#endif
2077
2078 /* Get stack data*/
2079 int sensivity = MMpull(m);
2080 int threshold = MMpull(m);
2081 int cbitmap = MMpull(m);
2082 int pbitmap = MMget(m, 0);
2083
2084 if ((pbitmap == NIL) || (cbitmap == NIL) || (threshold == NIL) || (sensivity == NIL))
2085 {
2086 MMset(m, 0, NIL);
2087 return 0;
2088 }
2089
2090 PtrObjVoid pOB = (PtrObjVoid)MMstart(m, MTOP(pbitmap));
2091 PtrObjBitmap pB = (PtrObjBitmap)MMstart(m, MTOP(pOB->Buffer));
2092
2093 PtrObjVoid cOB = (PtrObjVoid)MMstart(m, MTOP(cbitmap));
2094 PtrObjBitmap cB = (PtrObjBitmap)MMstart(m, MTOP(cOB->Buffer));
2095
2096 if ((pB->TailleW != cB->TailleW) || (pB->TailleH != cB->TailleH))
2097 {
2098 MMset(m, 0, NIL);
2099 return 0;
2100 }
2101
2102 cv::Mat diff(cB->TailleH, cB->TailleW, CV_8UC3);
2103 cv::Mat tmp(cB->TailleH, cB->TailleW, CV_8UC3);
2104 try
2105 {
2106 cv::Mat prevImage = ConversionTools::ScolBitmapToMat(pB);
2107 cv::Mat curImage = ConversionTools::ScolBitmapToMat(cB);
2108 cv::absdiff(prevImage, curImage, diff);
2109
2110 //Convert the image to grayscale.
2111 cv::cvtColor(diff, tmp, cv::COLOR_RGB2GRAY);
2112
2113 //Convert the image to black and white.
2114 cv::threshold(tmp, tmp, MTOI(threshold), 255, cv::THRESH_BINARY);
2115
2116
2117 //Dilate and erode to get people blobs
2118 //cv::dilate(tmp, tmp, 0, 18);
2119 //cv::dilate(tmp, tmp, 0, 10);
2120
2121 //Find the contours of the moving images in the frame.
2122 //std::vector< std::vector<cv::Point> > contour;
2123 //cv::findContours(tmp, contour, CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE);
2124
2125 //cv::cvtColor(tmp, curImage, CV_GRAY2RGB);
2126 //ConversionTools::MatToScolBitmapRGB(curImage, cB);
2127 int count = cv::countNonZero(tmp);
2128 float percent = ((float)count / (float)(cB->TailleH * cB->TailleW)) * 100.0f;
2129
2130 MMset(m, 0, ITOM(percent >= ((100.0f - (float)MTOI(sensivity)) / 100.0f) ? 1 : 0));
2131 }
2132 catch (cv::Exception& e)
2133 {
2134 MMechostr(MSKDEBUG, "_BTMOTIONdetect error %s\n", e.what());
2135 MMset(m, 0, NIL);
2136 }
2137
2138 tmp.release();
2139 diff.release();
2140
2141#ifdef _SCOL_DEBUG_
2142 MMechostr(MSKDEBUG, "ok\n");
2143#endif
2144 return 0;
2145}
2146
2155int _BTCompBitmap(mmachine m)
2156{
2157#ifdef _SCOL_DEBUG_
2158 MMechostr(MSKDEBUG, "_BTCompBitmap\n");
2159#endif
2160
2161 /* Get stack data*/
2162 int ifactor = MMpull(m);
2163 int bitmap = MMget(m, 0);
2164
2165 if (bitmap == NIL)
2166 {
2167 MMset(m, 0, NIL);
2168 return 0;
2169 }
2170
2171 int factor = 1;
2172 if ((ifactor != NIL) && (MTOI(ifactor) > 0))
2173 factor = MTOI(ifactor);
2174
2175 PtrObjVoid OB = (PtrObjVoid)MMstart(m, MTOP(bitmap));
2176 PtrObjBitmap B = (PtrObjBitmap)MMstart(m, MTOP(OB->Buffer));
2177
2178 if (B->bits == 0)
2179 {
2180 MMset(m, 0, NIL);
2181 return 0;
2182 }
2183
2184 std::vector<int> p;
2185 p.push_back(cv::IMWRITE_JPEG_QUALITY);
2186 p.push_back(factor);
2187 std::vector<unsigned char> buf;
2188
2189 cv::Mat imagesrc = ConversionTools::ScolBitmapToMat(B);
2190 try
2191 {
2192 imencode(".jpg", imagesrc, buf, p);
2193 }
2194 catch (cv::Exception& e)
2195 {
2196 MMechostr(MSKDEBUG, "_BTCompBitmap error %s\n", e.what());
2197 MMset(m, 0, NIL);
2198 return 0;
2199 }
2200
2201 if (buf.empty())
2202 {
2203 MMset(m, 0, NIL);
2204 return 0;
2205 }
2206
2207 char* scolbuf = 0;
2208 int res = MMmalloc(m, STR_SIZE(buf.size()), TYPEBUF);
2209 if (res == NIL)
2210 {
2211 MMset(m, 0, NIL);
2212 return MERRMEM;
2213 }
2214
2215 MMstore(m, res, 0, buf.size());
2216 char* buffer = MMstartstr(m, res);
2217 std::vector<unsigned char>::iterator it;
2218 int i = 0;
2219 for (it = buf.begin(); it < buf.end(); it++)
2220 {
2221 buffer[i] = *it;
2222 i++;
2223 }
2224 buffer[buf.size()] = 0;
2225 MMset(m, 0, PTOM(res));
2226
2227#ifdef _SCOL_DEBUG_
2228 MMechostr(MSKDEBUG, "ok\n");
2229#endif
2230 return 0;
2231}
2232
2241int _BTUnCompBitmap(mmachine m)
2242{
2243#ifdef _SCOL_DEBUG_
2244 MMechostr(MSKDEBUG, "_BTUnCompBitmap\n");
2245#endif
2246
2247 /* Get stack data*/
2248 int bitmap = MMpull(m);
2249 int idata = MMget(m, 0);
2250
2251 if ((bitmap == NIL) || (idata == NIL))
2252 {
2253 MMset(m, 0, NIL);
2254 return 0;
2255 }
2256
2257 PtrObjVoid OB = (PtrObjVoid)MMstart(m, MTOP(bitmap));
2258 PtrObjBitmap B = (PtrObjBitmap)MMstart(m, MTOP(OB->Buffer));
2259
2260 if (B->bits == 0)
2261 {
2262 MMset(m, 0, NIL);
2263 return 0;
2264 }
2265
2266 int msize = MMsizestr(m, MTOP(idata));
2267 char* smess = (char*)MMstart(m, MTOP(idata) + 1);
2268
2269 //fill the buffer
2270 std::vector<char> data(smess, smess + msize);
2271 cv::Mat imagesrc = ConversionTools::ScolBitmapToMat(B);
2272 try
2273 {
2274 cv::imdecode(cv::Mat(data), 1, &imagesrc);
2275 MMset(m, 0, bitmap);
2276 }
2277 catch (cv::Exception& e)
2278 {
2279 MMechostr(MSKDEBUG, "_BTUnCompBitmap error %s\n", e.what());
2280 MMset(m, 0, NIL);
2281 return 0;
2282 }
2283
2284#ifdef _SCOL_DEBUG_
2285 MMechostr(MSKDEBUG, "ok\n");
2286#endif
2287 return 0;
2288}
2289
2299int _BTSCALEbitmap(mmachine m)
2300{
2301#ifdef _SCOL_DEBUG_
2302 MMechostr(MSKDEBUG, "_BTSCALEbitmap\n");
2303#endif
2304
2305 /* Get stack data*/
2306 int method = MMpull(m);
2307 int srcbitmap = MMpull(m);
2308 int dstbitmap = MMget(m, 0);
2309
2310 if ((srcbitmap == NIL) || (dstbitmap == NIL))
2311 {
2312 MMset(m, 0, NIL);
2313 return 0;
2314 }
2315
2316 switch (method)
2317 {
2318 case 0:
2319 method = cv::INTER_NEAREST;
2320 break;
2321
2322 case 1:
2323 method = cv::INTER_LINEAR;
2324 break;
2325
2326 case 2:
2327 method = cv::INTER_CUBIC;
2328 break;
2329
2330 case 3:
2331 method = cv::INTER_AREA;
2332 break;
2333
2334 case 4:
2335 method = cv::INTER_LANCZOS4;
2336 break;
2337
2338 case 5:
2339 method = cv::INTER_MAX;
2340 break;
2341
2342 case 6:
2343 method = cv::WARP_INVERSE_MAP;
2344 break;
2345
2346 default:
2347 method = cv::INTER_LINEAR;
2348 }
2349
2350 PtrObjVoid OBs = (PtrObjVoid)MMstart(m, MTOP(srcbitmap));
2351 PtrObjBitmap Bs = (PtrObjBitmap)MMstart(m, MTOP(OBs->Buffer));
2352
2353 PtrObjVoid OBd = (PtrObjVoid)MMstart(m, MTOP(dstbitmap));
2354 PtrObjBitmap Bd = (PtrObjBitmap)MMstart(m, MTOP(OBd->Buffer));
2355
2356
2357 if (Bs->bits == 0 || Bd->bits == 0)
2358 {
2359 MMset(m, 0, NIL);
2360 return 0;
2361 }
2362
2363 cv::Mat imgdest = ConversionTools::ScolBitmapToMat(Bd);
2364 cv::Mat imagesrc = ConversionTools::ScolBitmapToMat(Bs);
2365 try
2366 {
2367 cv::resize(imagesrc, imgdest, cv::Size(Bd->TailleW, Bd->TailleH), 0, 0, method);
2368 }
2369 catch (cv::Exception& e)
2370 {
2371 MMechostr(MSKDEBUG, "_BTSCALEbitmap error %s\n", e.what());
2372 return 0;
2373 }
2374
2375#ifdef _SCOL_DEBUG_
2376 MMechostr(MSKDEBUG, "ok\n");
2377#endif
2378 return 0;
2379}
2380
2390int _BTSCALEalphaBitmap(mmachine m)
2391{
2392#ifdef _SCOL_DEBUG_
2393 MMechostr(MSKDEBUG, "_BTSCALEbitmap\n");
2394#endif
2395
2396 /* Get stack data*/
2397 int method = MMpull(m);
2398 int srcbitmap = MMpull(m);
2399 int dstbitmap = MMget(m, 0);
2400
2401 if ((srcbitmap == NIL) || (dstbitmap == NIL))
2402 {
2403 MMset(m, 0, NIL);
2404 return 0;
2405 }
2406
2407 int src_bmp24 = MMfetch(m, MTOP(srcbitmap), 0);
2408 int src_bmp8 = MMfetch(m, MTOP(srcbitmap), 1);
2409 int dst_bmp24 = MMfetch(m, MTOP(dstbitmap), 0);
2410 int dst_bmp8 = MMfetch(m, MTOP(dstbitmap), 1);
2411
2412 if ((src_bmp24 == NIL) || (dst_bmp24 == NIL))
2413 {
2414 MMset(m, 0, NIL);
2415 return 0;
2416 }
2417
2418 bool hasBmp8 = ((src_bmp8 != NIL) && (dst_bmp8 != NIL)) ? true : false;
2419
2420 //BMP24
2421 // Get scol bitmaps
2422 PtrObjVoid ptr_src_bitmap = (PtrObjVoid)MMstart(m, MTOP(src_bmp24));
2423 PtrObjBitmap obj_src_bitmap = (PtrObjBitmap)MMstart(m, MTOP(ptr_src_bitmap->Buffer));
2424 PtrObjVoid ptr_dst_bitmap = (PtrObjVoid)MMstart(m, MTOP(dst_bmp24));
2425 PtrObjBitmap obj_dst_bitmap = (PtrObjBitmap)MMstart(m, MTOP(ptr_dst_bitmap->Buffer));
2426
2427 if ((obj_src_bitmap->bits == 0) || (obj_dst_bitmap->bits == 0))
2428 {
2429 MMset(m, 0, NIL);
2430 return 0;
2431 }
2432
2433 switch (method)
2434 {
2435 case 0:
2436 method = cv::INTER_NEAREST;
2437 break;
2438
2439 case 1:
2440 method = cv::INTER_LINEAR;
2441 break;
2442
2443 case 2:
2444 method = cv::INTER_CUBIC;
2445 break;
2446
2447 case 3:
2448 method = cv::INTER_AREA;
2449 break;
2450
2451 case 4:
2452 method = cv::INTER_LANCZOS4;
2453 break;
2454
2455 case 5:
2456 method = cv::INTER_MAX;
2457 break;
2458
2459 case 6:
2460 method = cv::WARP_INVERSE_MAP;
2461 break;
2462
2463 default:
2464 method = cv::INTER_LINEAR;
2465 }
2466
2467 cv::Mat imagesrc = ConversionTools::ScolBitmapToMat(obj_src_bitmap);
2468 cv::Mat imgdest = ConversionTools::ScolBitmapToMat(obj_dst_bitmap);
2469 try
2470 {
2471 cv::resize(imagesrc, imgdest, cv::Size(obj_dst_bitmap->TailleW, obj_dst_bitmap->TailleH), 0, 0, method);
2472 }
2473 catch (cv::Exception& e)
2474 {
2475 MMechostr(MSKDEBUG, "_BTSCALEbitmap error %s\n", e.what());
2476 return 0;
2477 }
2478
2479 //BMP8
2480 if (hasBmp8)
2481 {
2482 PtrObjVoid ptr_src_bitmap8 = (PtrObjVoid)MMstart(m, MTOP(src_bmp8));
2483 PtrObjBitmap obj_src_bitmap8 = (PtrObjBitmap)MMstart(m, MTOP(ptr_src_bitmap8->Buffer));
2484 PtrObjVoid ptr_dst_bitmap8 = (PtrObjVoid)MMstart(m, MTOP(dst_bmp8));
2485 PtrObjBitmap obj_dst_bitmap8 = (PtrObjBitmap)MMstart(m, MTOP(ptr_dst_bitmap8->Buffer));
2486
2487 if ((obj_src_bitmap8->bits == 0) || (obj_dst_bitmap8->bits == 0))
2488 {
2489 MMset(m, 0, NIL);
2490 return 0;
2491 }
2492
2493 cv::Mat imagesrc8 = ConversionTools::ScolBitmapToMat(obj_src_bitmap8);
2494 cv::Mat imgdest8 = ConversionTools::ScolBitmapToMat(obj_dst_bitmap8);
2495 try
2496 {
2497 cv::resize(imagesrc8, imgdest8, cv::Size(obj_dst_bitmap8->TailleW, obj_dst_bitmap8->TailleH), 0, 0, method);
2498 }
2499 catch (cv::Exception& e)
2500 {
2501 MMechostr(MSKDEBUG, "_BTSCALEbitmap error %s\n", e.what());
2502 return 0;
2503 }
2504 }
2505
2506#ifdef _SCOL_DEBUG_
2507 MMechostr(MSKDEBUG, "ok\n");
2508#endif
2509 return 0;
2510}
2511
2528{
2529#ifdef _SCOL_DEBUG_
2530 MMechostr(MSKDEBUG, "_BTSCALEbitmapBuffer\n");
2531#endif
2532
2533 /* Get stack data*/
2534 int method = MMpull(m);
2535 int isbitsperpixel = MMpull(m);
2536 int isheight = MMpull(m);
2537 int iswidth = MMpull(m);
2538 int isBuff = MMpull(m);
2539
2540 int idbitsperpixel = MMpull(m);
2541 int idheight = MMpull(m);
2542 int idwidth = MMpull(m);
2543 int idBuff = MMget(m, 0);
2544
2545 if ((isBuff == NIL) || (iswidth == NIL) || (isheight == NIL) || (isbitsperpixel == NIL) ||
2546 (idBuff == NIL) || (idwidth == NIL) || (idheight == NIL) || (idbitsperpixel == NIL))
2547 {
2548 MMset(m, 0, NIL);
2549 return 0;
2550 }
2551
2552 switch (method)
2553 {
2554 case 0:
2555 method = cv::INTER_NEAREST;
2556 break;
2557
2558 case 1:
2559 method = cv::INTER_LINEAR;
2560 break;
2561
2562 case 2:
2563 method = cv::INTER_CUBIC;
2564 break;
2565
2566 case 3:
2567 method = cv::INTER_AREA;
2568 break;
2569
2570 case 4:
2571 method = cv::INTER_LANCZOS4;
2572 break;
2573
2574 case 5:
2575 method = cv::INTER_MAX;
2576 break;
2577
2578 case 6:
2579 method = cv::WARP_INVERSE_MAP;
2580 break;
2581
2582 default:
2583 method = cv::INTER_LINEAR;
2584 }
2585
2586 unsigned char* sbuffer = MMgetPointer<unsigned char*>(m, MTOP(isBuff));
2587 if (sbuffer == NULL)
2588 {
2589 MMset(m, 0, NIL);
2590 return 0;
2591 }
2592
2593 isbitsperpixel = MTOI(isbitsperpixel);
2594 isheight = MTOI(isheight);
2595 iswidth = MTOI(iswidth);
2596
2597 cv::Mat imagesrc = ConversionTools::ScolBitmapBufferToMat((void*)sbuffer, iswidth, isheight, isbitsperpixel);
2598 if (imagesrc.empty())
2599 {
2600 MMset(m, 0, NIL);
2601 return 0;
2602 }
2603
2604 unsigned char* dbuffer = MMgetPointer<unsigned char*>(m, MTOP(idBuff));
2605 if (dbuffer == NULL)
2606 {
2607 MMset(m, 0, NIL);
2608 return 0;
2609 }
2610
2611 idbitsperpixel = MTOI(idbitsperpixel);
2612 idheight = MTOI(idheight);
2613 idwidth = MTOI(idwidth);
2614
2615 cv::Mat imgdest = ConversionTools::ScolBitmapBufferToMat((void*)dbuffer, idwidth, idheight, idbitsperpixel);
2616 if (imgdest.empty())
2617 {
2618 MMset(m, 0, NIL);
2619 return 0;
2620 }
2621
2622 try
2623 {
2624 cv::resize(imagesrc, imgdest, cv::Size(idwidth, idheight), 0, 0, method);
2625 }
2626 catch (cv::Exception& e)
2627 {
2628 MMechostr(MSKDEBUG, "_BTSCALEbitmapBuffer error %s\n", e.what());
2629 return 0;
2630 }
2631
2632#ifdef _SCOL_DEBUG_
2633 MMechostr(MSKDEBUG, "ok\n");
2634#endif
2635 return 0;
2636}
2637
2646int _BTSAVEbitmap(mmachine m)
2647{
2648#ifdef SCOL_DEBUG
2649 MMechostr(MSKDEBUG, "_BTSAVEbitmap\n");
2650#endif
2651
2652 int ipath = MMpull(m);
2653 int ibitmap = MMget(m, 0);
2654
2655 if (ibitmap == NIL || ipath == NIL)
2656 {
2657 MMechostr(MSKRUNTIME, "_BTSAVEbitmap error: some arguments are NIL\n");
2658 MMset(m, 0, NIL);
2659 return 0;
2660 }
2661
2662 // Scol path to boost::filesystem::path
2663 boost::filesystem::path path = MMstartstr(m, MTOP(ipath));
2664
2665 // Get scol bitmaps
2666 PtrObjVoid ptr_bitmap = (PtrObjVoid)MMstart(m, MTOP(ibitmap));
2667 PtrObjBitmap obj_bitmap = (PtrObjBitmap)MMstart(m, MTOP(ptr_bitmap->Buffer));
2668
2669 if (obj_bitmap->bits == 0)
2670 {
2671 MMset(m, 0, NIL);
2672 return 0;
2673 }
2674
2675 // Convert to cv::Mat
2676 cv::Mat bitmap = ConversionTools::ScolBitmapToMat(obj_bitmap);
2677
2678 // Save to path
2679 try
2680 {
2681 if (boost::filesystem::exists(path))
2682 boost::filesystem::remove(path);
2683
2684 imwrite(path.generic_string(), bitmap);
2685 }
2686 catch (cv::Exception& ex)
2687 {
2688 MMechostr(MSKRUNTIME, "_BTSAVEbitmap Exception writing image in %s : %s\n", path.generic_string().c_str(), ex.what());
2689 return 0;
2690 }
2691
2692 // return path
2693 MMpull(m);
2694 Mpushstrbloc(m, (char*)path.generic_string().c_str());
2695
2696#ifdef SCOL_DEBUG
2697 MMechostr(MSKDEBUG, "end _BTSAVEbitmap\n");
2698#endif
2699 return 0;
2700}
2701
2702
2711int _BTSAVEalphaBitmap(mmachine m)
2712{
2713#ifdef SCOL_DEBUG
2714 MMechostr(MSKDEBUG, "_BTSAVEbitmapWithAlpha\n");
2715#endif
2716 int ipath = MMpull(m);
2717 int ialphabitmap = MMget(m, 0);
2718
2719 if (ialphabitmap == NIL || ipath == NIL)
2720 {
2721 MMechostr(MSKRUNTIME, "_BTSAVEalphaBitmap error: some arguments are NIL\n");
2722 MMset(m, 0, NIL);
2723 return 0;
2724 }
2725
2726 // Scol path to boost::filesystem::path
2727 boost::filesystem::path path = MMstartstr(m, MTOP(ipath));
2728
2729 int bmp24 = MMfetch(m, MTOP(ialphabitmap), 0);
2730 int bmp8 = MMfetch(m, MTOP(ialphabitmap), 1);
2731
2732 // Get scol bitmaps
2733 PtrObjVoid ptr_bitmap = (PtrObjVoid)MMstart(m, MTOP(bmp24));
2734 PtrObjBitmap obj_bitmap = (PtrObjBitmap)MMstart(m, MTOP(ptr_bitmap->Buffer));
2735
2736 PtrObjVoid ptr_bitmap8 = (PtrObjVoid)MMstart(m, MTOP(bmp8));
2737 PtrObjBitmap obj_bitmap8 = (PtrObjBitmap)MMstart(m, MTOP(ptr_bitmap8->Buffer));
2738
2739 if (obj_bitmap->bits == 0)
2740 {
2741 MMset(m, 0, NIL);
2742 return 0;
2743 }
2744
2745 // Convert to cv::Mat
2746 cv::Mat bitmap(obj_bitmap->TailleH, obj_bitmap->TailleW, CV_8UC4);
2747 ConversionTools::ScolBitmapToMatRGBA(obj_bitmap, obj_bitmap8, bitmap);
2748
2749 // Save to path
2750 try
2751 {
2752 if (boost::filesystem::exists(path))
2753 boost::filesystem::remove(path);
2754
2755 imwrite(path.generic_string(), bitmap);
2756 }
2757 catch (cv::Exception& ex)
2758 {
2759 MMechostr(MSKRUNTIME, "_BTSAVEalphaBitmap Exception writing image in %s : %s\n", path.generic_string().c_str(), ex.what());
2760 return 0;
2761 }
2762
2763 // return path
2764 MMpull(m);
2765 Mpushstrbloc(m, (char*)path.generic_string().c_str());
2766
2767#ifdef SCOL_DEBUG
2768 MMechostr(MSKDEBUG, "end _BTSAVEbitmapWithAlpha\n");
2769#endif
2770 return 0;
2771}
2772
2773
2782int _BTLOADbitmap(mmachine m)
2783{
2784 #ifdef _SCOL_DEBUG_
2785 MMechostr(MSKDEBUG, "_BTLOADbitmap\n");
2786 #endif
2787
2788 int ipath = MMpull(m);
2789
2790 if (ipath == NIL)
2791 {
2792 MMset(m, 0, NIL);
2793 return 0;
2794 }
2795
2796 boost::filesystem::path path = MMstartstr(m, MTOP(ipath));
2797
2798 cv::Mat lbitmap = cv::imread(path.generic_string(), cv::IMREAD_COLOR);
2799 if (!lbitmap.data)
2800 {
2801 MMechostr(MSKRUNTIME, "_BTLOADbitmap : Could not read the image file > %s\n", path.generic_string().c_str());
2802 MMset(m, 0, NIL);
2803 return 0;
2804 }
2805
2806 //create scol bitmap
2807 //stack : channel
2808
2809 //push the size w h
2810 MMpush(m, ITOM(lbitmap.cols));
2811 MMpush(m, ITOM(lbitmap.rows));
2812
2813 //stack : channel sizew sizeh
2814 //push _CRbitmap
2815 if ((MMpush(m, Msearchinsyspak(m, "_CRbitmap"))) < 0)
2816 {
2817 MMechostr(0, "\n_GETarMarkerBitmap : error interpreting _CRbitmap\n");
2818 MMpull(m);
2819 MMpull(m);
2820 MMset(m, 0, NIL);
2821 return 0;
2822 }
2823
2824 //execute scol cmd
2825 Minterpreter(m);
2826
2827 int objbmp = MMget(m, 0);
2828 if (objbmp == NIL)
2829 {
2830 MMechostr(MSKRUNTIME, "_BTLOADbitmap : Could not create the bitmap from file > %s\n", path.generic_string().c_str());
2831 MMset(m, 0, NIL);
2832 return 0;
2833 }
2834
2835 PtrObjVoid OB = (PtrObjVoid) MMstart(m, MTOP(objbmp));
2836 PtrObjBitmap B = (PtrObjBitmap) MMstart(m, MTOP(OB->Buffer));
2837
2838 if (B->bits == 0)
2839 {
2840 MMset(m, 0, NIL);
2841 return 0;
2842 }
2844
2845 #ifdef _SCOL_DEBUG_
2846 MMechostr(MSKDEBUG, "ok\n");
2847 #endif
2848 return 0;
2849}
2850
2862int _BTBLENDbitmaps(mmachine m)
2863{
2864
2865#ifdef SCOL_DEBUG
2866 MMechostr(MSKDEBUG, "_BTBLENDbitmaps\n");
2867#endif
2868
2869 int imix = MMpull(m);
2870 int isrcrect = MMpull(m);
2871 int isrcbmap = MMpull(m);
2872 int idstrect = MMpull(m);
2873 int idstbmap = MMget(m, 0);
2874
2875 if (imix == NIL || isrcrect == NIL || isrcbmap == NIL || idstrect == NIL || idstbmap == NIL)
2876 {
2877 MMechostr(MSKRUNTIME, "_BTBLENDbitmaps error: some arguments are NIL\n");
2878 MMset(m, 0, NIL);
2879 return 0;
2880 }
2881
2882 float mix = MAX(MIN(MTOF(imix), 1.0f), 0.0f);
2883
2884 int idstrectx = MMfetch(m, MTOP(idstrect), 0);
2885 int idstrecty = MMfetch(m, MTOP(idstrect), 1);
2886 int idstrectw = MMfetch(m, MTOP(idstrect), 2);
2887 int idstrecth = MMfetch(m, MTOP(idstrect), 3);
2888 if (idstrectx == NIL || idstrecty == NIL || idstrectw == NIL || idstrecth == NIL)
2889 {
2890 MMechostr(MSKRUNTIME, "_BTBLENDbitmaps error: some dest rect parameters are NIL\n");
2891 MMset(m, 0, NIL);
2892 return 0;
2893 }
2894
2895 int isrcrectx = MMfetch(m, MTOP(isrcrect), 0);
2896 int isrcrecty = MMfetch(m, MTOP(isrcrect), 1);
2897 int isrcrectw = MMfetch(m, MTOP(isrcrect), 2);
2898 int isrcrecth = MMfetch(m, MTOP(isrcrect), 3);
2899 if (isrcrectx == NIL || isrcrecty == NIL || isrcrectw == NIL || isrcrecth == NIL)
2900 {
2901 MMechostr(MSKRUNTIME, "_BTBLENDbitmaps error: some src rect parameters are NIL\n");
2902 MMset(m, 0, NIL);
2903 return 0;
2904 }
2905
2906 // Parsing rect
2907 // -----------
2908 cv::Rect dst_rect(MTOI(idstrectx), MTOI(idstrecty), MTOI(idstrectw), MTOI(idstrecth));
2909 cv::Rect src_rect(MTOI(isrcrectx), MTOI(isrcrecty), MTOI(isrcrectw), MTOI(isrcrecth));
2910
2911 // Parsing bitmaps
2912 // -----------
2913
2914 PtrObjVoid ptr_dst_bmap = (PtrObjVoid)MMstart(m, MTOP(idstbmap));
2915 PtrObjVoid ptr_src_bmap = (PtrObjVoid)MMstart(m, MTOP(isrcbmap));
2916
2917 PtrObjBitmap obj_dst_bmap = (PtrObjBitmap)MMstart(m, MTOP(ptr_dst_bmap->Buffer));
2918 PtrObjBitmap obj_src_bmap = (PtrObjBitmap)MMstart(m, MTOP(ptr_src_bmap->Buffer));
2919
2920 if ((obj_dst_bmap->bits == 0) || (obj_src_bmap->bits == 0))
2921 {
2922 MMset(m, 0, NIL);
2923 return 0;
2924 }
2925
2926 cv::Mat dst_bmap = ConversionTools::ScolBitmapToMat(obj_dst_bmap);
2927 cv::Mat src_bmap = ConversionTools::ScolBitmapToMat(obj_src_bmap);
2928
2929 // Check bounds
2930 // --------------
2931 if (!(ConversionTools::ClipBitmapRect(src_bmap, src_rect, dst_bmap, dst_rect)))
2932 {
2933 MMechostr(MSKRUNTIME, "_BTBLENDbitmaps error: src rect size <= 0\n");
2934 MMset(m, 0, NIL);
2935 return 0;
2936 }
2937
2938 // Getting subbitmaps
2939 // -----------------
2940 cv::Mat dst_subbmap = dst_bmap(dst_rect);
2941 cv::Mat src_subbmap = src_bmap(src_rect);
2942
2943 // Resize src subbitmap to dst subbitmap
2944 if (src_subbmap.cols != dst_subbmap.cols || src_subbmap.rows != dst_subbmap.rows)
2945 cv::resize(src_subbmap, src_subbmap, dst_subbmap.size(), 0, 0, cv::INTER_CUBIC);
2946
2947 ConversionTools::Blend(dst_subbmap, src_subbmap, mix);
2948
2949#ifdef SCOL_DEBUG
2950 MMechostr(MSKDEBUG, "end _BTBLENDbitmaps\n");
2951#endif
2952
2953 return 0;
2954}
2955
2968{
2969#ifdef SCOL_DEBUG
2970 MMechostr(MSKDEBUG, "_BTBLENDalphaBitmaps\n");
2971#endif
2972
2973 int imix = MMpull(m);
2974 int isrcrect = MMpull(m);
2975 int isrcbmap = MMpull(m);
2976 int idstrect = MMpull(m);
2977 int idstbmap = MMget(m, 0);
2978
2979 if (isrcrect == NIL || isrcbmap == NIL || idstrect == NIL || idstbmap == NIL)
2980 {
2981 MMechostr(MSKRUNTIME, "_BTBLENDalphaBitmaps error: some arguments are NIL\n");
2982 MMset(m, 0, NIL);
2983 return 0;
2984 }
2985
2986 float mix = 0.5f;
2987 if (imix != NIL)
2988 mix = MTOF(imix);
2989
2990 int idstrectx = MMfetch(m, MTOP(idstrect), 0);
2991 int idstrecty = MMfetch(m, MTOP(idstrect), 1);
2992 int idstrectw = MMfetch(m, MTOP(idstrect), 2);
2993 int idstrecth = MMfetch(m, MTOP(idstrect), 3);
2994 if (idstrectx == NIL || idstrecty == NIL || idstrectw == NIL || idstrecth == NIL)
2995 {
2996 MMechostr(MSKRUNTIME, "_BTBLENDalphaBitmaps error: some dest rect parameters are NIL\n");
2997 MMset(m, 0, NIL);
2998 return 0;
2999 }
3000
3001 int isrcrectx = MMfetch(m, MTOP(isrcrect), 0);
3002 int isrcrecty = MMfetch(m, MTOP(isrcrect), 1);
3003 int isrcrectw = MMfetch(m, MTOP(isrcrect), 2);
3004 int isrcrecth = MMfetch(m, MTOP(isrcrect), 3);
3005 if (isrcrectx == NIL || isrcrecty == NIL || isrcrectw == NIL || isrcrecth == NIL)
3006 {
3007 MMechostr(MSKRUNTIME, "_BTBLENDalphaBitmaps error: some src rect parameters are NIL\n");
3008 MMset(m, 0, NIL);
3009 return 0;
3010 }
3011
3012 // Parsing rect
3013 // -----------
3014 cv::Rect dst_rect(MTOI(idstrectx), MTOI(idstrecty), MTOI(idstrectw), MTOI(idstrecth));
3015 cv::Rect src_rect(MTOI(isrcrectx), MTOI(isrcrecty), MTOI(isrcrectw), MTOI(isrcrecth));
3016
3017 // Parsing bitmaps
3018 // -----------
3019 int idstbmap24 = MMfetch(m, MTOP(idstbmap), 0);
3020 int idstbmap8 = MMfetch(m, MTOP(idstbmap), 1);
3021 int isrcbmap24 = MMfetch(m, MTOP(isrcbmap), 0);
3022 int isrcbmap8 = MMfetch(m, MTOP(isrcbmap), 1);
3023
3024 if (idstbmap24 == NIL || idstbmap8 == NIL || isrcbmap24 == NIL || isrcbmap8 == NIL)
3025 {
3026 MMechostr(MSKRUNTIME, "_BTBLENDalphaBitmaps error: AlphaBitmaps miscreated or alpha part is missing\n");
3027 MMset(m, 0, NIL);
3028 return 0;
3029 }
3030
3031 PtrObjVoid ptr_dst_bmap = (PtrObjVoid)MMstart(m, MTOP(idstbmap24));
3032 PtrObjVoid ptr_dst_bmap8 = (PtrObjVoid)MMstart(m, MTOP(idstbmap8));
3033 PtrObjVoid ptr_src_bmap = (PtrObjVoid)MMstart(m, MTOP(isrcbmap24));
3034 PtrObjVoid ptr_src_bmap8 = (PtrObjVoid)MMstart(m, MTOP(isrcbmap8));
3035
3036 PtrObjBitmap obj_dst_bmap = (PtrObjBitmap)MMstart(m, MTOP(ptr_dst_bmap->Buffer));
3037 PtrObjBitmap obj_dst_bmap8 = (PtrObjBitmap)MMstart(m, MTOP(ptr_dst_bmap8->Buffer));
3038 PtrObjBitmap obj_src_bmap = (PtrObjBitmap)MMstart(m, MTOP(ptr_src_bmap->Buffer));
3039 PtrObjBitmap obj_src_bmap8 = (PtrObjBitmap)MMstart(m, MTOP(ptr_src_bmap8->Buffer));
3040
3041 if ((obj_dst_bmap->bits == 0) || (obj_src_bmap->bits == 0) || (obj_dst_bmap8->bits == 0) || (obj_src_bmap8->bits == 0))
3042 {
3043 MMechostr(MSKRUNTIME, "_BTBLENDalphaBitmaps error: empty alpha channel\n");
3044 MMset(m, 0, NIL);
3045 return 0;
3046 }
3047
3048 cv::Mat dst_bmap = ConversionTools::ScolBitmapToMat(obj_dst_bmap);
3049 cv::Mat src_bmap = ConversionTools::ScolBitmapToMat(obj_src_bmap);
3050 cv::Mat dst_bmap8 = ConversionTools::ScolBitmapToMat(obj_dst_bmap8);
3051 cv::Mat src_bmap8 = ConversionTools::ScolBitmapToMat(obj_src_bmap8);
3052
3053 // Check bounds
3054 // --------------
3055 if (!(ConversionTools::ClipBitmapRect(src_bmap, src_rect, dst_bmap, dst_rect)))
3056 {
3057 MMechostr(MSKRUNTIME, "_BTBLENDalphaBitmaps error: src rect size <= 0\n");
3058 MMset(m, 0, NIL);
3059 return 0;
3060 }
3061
3062 // Getting subbitmaps
3063 // -----------------
3064 cv::Mat dst_subbmap = dst_bmap(dst_rect);
3065 cv::Mat src_subbmap = src_bmap(src_rect);
3066 cv::Mat dst_subbmap8 = dst_bmap8(dst_rect);
3067 cv::Mat src_subbmap8 = src_bmap8(src_rect);
3068
3069 // Resize src subbitmap to dst subbitmap
3070 if (src_subbmap.cols != dst_subbmap.cols || src_subbmap.rows != dst_subbmap.rows)
3071 cv::resize(src_subbmap, src_subbmap, dst_subbmap.size(), 0, 0, cv::INTER_CUBIC);
3072
3073 if (src_subbmap8.cols != dst_subbmap8.cols || src_subbmap8.rows != dst_subbmap8.rows)
3074 cv::resize(src_subbmap8, src_subbmap8, dst_subbmap8.size(), 0, 0, cv::INTER_CUBIC);
3075
3076 ConversionTools::Blend(dst_subbmap, dst_subbmap8, src_subbmap, src_subbmap8, mix);
3077
3078#ifdef SCOL_DEBUG
3079 MMechostr(MSKDEBUG, "end _BTBLENDalphaBitmaps\n");
3080#endif
3081
3082 return 0;
3083}
3084
3103{
3104#ifdef SCOL_DEBUG
3105 MMechostr(MSKDEBUG, "_BTBLENDbitmapsBuffer\n");
3106#endif
3107
3108 int imix = MMpull(m);
3109 int isrcrect = MMpull(m);
3110
3111 int isbitsperpixel = MMpull(m);
3112 int isheight = MMpull(m);
3113 int iswidth = MMpull(m);
3114 int isBuff = MMpull(m);
3115
3116 int idstrect = MMpull(m);
3117 int idbitsperpixel = MMpull(m);
3118 int idheight = MMpull(m);
3119 int idwidth = MMpull(m);
3120 int idBuff = MMget(m, 0);
3121
3122 if ((isBuff == NIL) || (iswidth == NIL) || (isheight == NIL) || (isbitsperpixel == NIL) ||
3123 (idBuff == NIL) || (idwidth == NIL) || (idheight == NIL) || (idbitsperpixel == NIL) ||
3124 (imix == NIL) || (isrcrect == NIL) || (idstrect == NIL))
3125 {
3126 MMechostr(MSKRUNTIME, "_BTBLENDbitmapsBuffer error: some arguments are NIL\n");
3127 MMset(m, 0, NIL);
3128 return 0;
3129 }
3130
3131 float mix = MAX(MIN(MTOF(imix), 1.0f), 0.0f);
3132
3133 int idstrectx = MMfetch(m, MTOP(idstrect), 0);
3134 int idstrecty = MMfetch(m, MTOP(idstrect), 1);
3135 int idstrectw = MMfetch(m, MTOP(idstrect), 2);
3136 int idstrecth = MMfetch(m, MTOP(idstrect), 3);
3137 if (idstrectx == NIL || idstrecty == NIL || idstrectw == NIL || idstrecth == NIL)
3138 {
3139 MMechostr(MSKRUNTIME, "_BTBLENDbitmapsBuffer error: some dest rect parameters are NIL\n");
3140 MMset(m, 0, NIL);
3141 return 0;
3142 }
3143
3144 int isrcrectx = MMfetch(m, MTOP(isrcrect), 0);
3145 int isrcrecty = MMfetch(m, MTOP(isrcrect), 1);
3146 int isrcrectw = MMfetch(m, MTOP(isrcrect), 2);
3147 int isrcrecth = MMfetch(m, MTOP(isrcrect), 3);
3148 if (isrcrectx == NIL || isrcrecty == NIL || isrcrectw == NIL || isrcrecth == NIL)
3149 {
3150 MMechostr(MSKRUNTIME, "_BTBLENDbitmapsBuffer error: some src rect parameters are NIL\n");
3151 MMset(m, 0, NIL);
3152 return 0;
3153 }
3154
3155 // Parsing rect
3156 // -----------
3157 cv::Rect dst_rect(MTOI(idstrectx), MTOI(idstrecty), MTOI(idstrectw), MTOI(idstrecth));
3158 cv::Rect src_rect(MTOI(isrcrectx), MTOI(isrcrecty), MTOI(isrcrectw), MTOI(isrcrecth));
3159
3160 // Parsing bitmaps
3161 // -----------
3162 unsigned char* sbuffer = MMgetPointer<unsigned char*>(m, MTOP(isBuff));
3163 if (sbuffer == NULL)
3164 {
3165 MMset(m, 0, NIL);
3166 return 0;
3167 }
3168
3169 isbitsperpixel = MTOI(isbitsperpixel);
3170 isheight = MTOI(isheight);
3171 iswidth = MTOI(iswidth);
3172
3173 cv::Mat src_bmap = ConversionTools::ScolBitmapBufferToMat((void*)sbuffer, iswidth, isheight, isbitsperpixel);
3174 if (src_bmap.empty())
3175 {
3176 MMset(m, 0, NIL);
3177 return 0;
3178 }
3179
3180 unsigned char* dbuffer = MMgetPointer<unsigned char*>(m, MTOP(idBuff));
3181 if (dbuffer == NULL)
3182 {
3183 MMset(m, 0, NIL);
3184 return 0;
3185 }
3186
3187 idbitsperpixel = MTOI(idbitsperpixel);
3188 idheight = MTOI(idheight);
3189 idwidth = MTOI(idwidth);
3190
3191 cv::Mat dst_bmap = ConversionTools::ScolBitmapBufferToMat((void*)dbuffer, idwidth, idheight, idbitsperpixel);
3192 if (dst_bmap.empty())
3193 {
3194 MMset(m, 0, NIL);
3195 return 0;
3196 }
3197
3198 // Check bounds
3199 // --------------
3200 if (!(ConversionTools::ClipBitmapRect(src_bmap, src_rect, dst_bmap, dst_rect)))
3201 {
3202 MMechostr(MSKRUNTIME, "_BTBLENDbitmapsBuffer error: src rect size <= 0\n");
3203 MMset(m, 0, NIL);
3204 return 0;
3205 }
3206
3207 // Getting subbitmaps
3208 // -----------------
3209 cv::Mat dst_subbmap = dst_bmap(dst_rect);
3210 cv::Mat src_subbmap = src_bmap(src_rect);
3211
3212 // Resize src subbitmap to dst subbitmap
3213 if (src_subbmap.cols != dst_subbmap.cols || src_subbmap.rows != dst_subbmap.rows)
3214 cv::resize(src_subbmap, src_subbmap, dst_subbmap.size(), 0, 0, cv::INTER_CUBIC);
3215
3216 ConversionTools::Blend(dst_subbmap, src_subbmap, mix);
3217
3218#ifdef SCOL_DEBUG
3219 MMechostr(MSKDEBUG, "end _BTBLENDbitmapsBuffer\n");
3220#endif
3221
3222 return 0;
3223}
3224
3235int _BTCPbitmapRect(mmachine m)
3236{
3237#ifdef SCOL_DEBUG
3238 MMechostr(MSKDEBUG, "_BTCPbitmapRect\n");
3239#endif
3240
3241 int isrcrect = MMpull(m);
3242 int isrcbmap = MMpull(m);
3243 int idstrect = MMpull(m);
3244 int idstbmap = MMget(m, 0);
3245
3246 if (isrcrect == NIL || isrcbmap == NIL || idstrect == NIL || idstbmap == NIL)
3247 {
3248 MMechostr(MSKRUNTIME, "_BTCPbitmapRect error: some arguments are NIL\n");
3249 MMset(m, 0, NIL);
3250 return 0;
3251 }
3252
3253 int idstrectx = MMfetch(m, MTOP(idstrect), 0);
3254 int idstrecty = MMfetch(m, MTOP(idstrect), 1);
3255 int idstrectw = MMfetch(m, MTOP(idstrect), 2);
3256 int idstrecth = MMfetch(m, MTOP(idstrect), 3);
3257 if (idstrectx == NIL || idstrecty == NIL || idstrectw == NIL || idstrecth == NIL)
3258 {
3259 MMechostr(MSKRUNTIME, "_BTCPbitmapRect error: some dest rect parameters are NIL\n");
3260 MMset(m, 0, NIL);
3261 return 0;
3262 }
3263
3264 int isrcrectx = MMfetch(m, MTOP(isrcrect), 0);
3265 int isrcrecty = MMfetch(m, MTOP(isrcrect), 1);
3266 int isrcrectw = MMfetch(m, MTOP(isrcrect), 2);
3267 int isrcrecth = MMfetch(m, MTOP(isrcrect), 3);
3268 if (isrcrectx == NIL || isrcrecty == NIL || isrcrectw == NIL || isrcrecth == NIL)
3269 {
3270 MMechostr(MSKRUNTIME, "_BTCPbitmapRect error: some src rect parameters are NIL\n");
3271 MMset(m, 0, NIL);
3272 return 0;
3273 }
3274
3275 // Parsing rect
3276 // -----------
3277 cv::Rect dst_rect(MTOI(idstrectx), MTOI(idstrecty), MTOI(idstrectw), MTOI(idstrecth));
3278 cv::Rect src_rect(MTOI(isrcrectx), MTOI(isrcrecty), MTOI(isrcrectw), MTOI(isrcrecth));
3279
3280 // Parsing bitmaps
3281 // -----------
3282
3283 PtrObjVoid ptr_dst_bmap = (PtrObjVoid)MMstart(m, MTOP(idstbmap));
3284 PtrObjVoid ptr_src_bmap = (PtrObjVoid)MMstart(m, MTOP(isrcbmap));
3285
3286 PtrObjBitmap obj_dst_bmap = (PtrObjBitmap)MMstart(m, MTOP(ptr_dst_bmap->Buffer));
3287 PtrObjBitmap obj_src_bmap = (PtrObjBitmap)MMstart(m, MTOP(ptr_src_bmap->Buffer));
3288
3289 if ((obj_dst_bmap->bits == 0) || (obj_src_bmap->bits == 0))
3290 {
3291 MMset(m, 0, NIL);
3292 return 0;
3293 }
3294
3295 cv::Mat dst_bmap = ConversionTools::ScolBitmapToMat(obj_dst_bmap);
3296 cv::Mat src_bmap = ConversionTools::ScolBitmapToMat(obj_src_bmap);
3297
3298 // Check bounds
3299 // --------------
3300 if (!(ConversionTools::ClipBitmapRect(src_bmap, src_rect, dst_bmap, dst_rect)))
3301 {
3302 MMechostr(MSKRUNTIME, "_BTCPbitmapRect error: src rect size <= 0\n");
3303 MMset(m, 0, NIL);
3304 return 0;
3305 }
3306
3307 // Getting subbitmaps
3308 // -----------------
3309 cv::Mat dst_subbmap = dst_bmap(dst_rect);
3310 cv::Mat src_subbmap = src_bmap(src_rect);
3311
3312 // Resize src subbitmap to dst subbitmap
3313 if (src_subbmap.cols != dst_subbmap.cols || src_subbmap.rows != dst_subbmap.rows)
3314 cv::resize(src_subbmap, dst_subbmap, dst_subbmap.size(), 0, 0, cv::INTER_CUBIC);
3315 else
3316 src_subbmap.copyTo(dst_bmap(dst_rect));
3317
3318#ifdef SCOL_DEBUG
3319 MMechostr(MSKDEBUG, "end _BTCPbitmapRect\n");
3320#endif
3321
3322 return 0;
3323}
3324
3336{
3337#ifdef SCOL_DEBUG
3338 MMechostr(MSKDEBUG, "_BTCPalphaBitmapRect\n");
3339#endif
3340
3341 int isrcrect = MMpull(m);
3342 int isrcbmap = MMpull(m);
3343 int idstrect = MMpull(m);
3344 int idstbmap = MMget(m, 0);
3345
3346 if (isrcrect == NIL || isrcbmap == NIL || idstrect == NIL || idstbmap == NIL)
3347 {
3348 MMechostr(MSKRUNTIME, "_BTCPalphaBitmapRect error: some arguments are NIL\n");
3349 MMset(m, 0, NIL);
3350 return 0;
3351 }
3352
3353 int idstrectx = MMfetch(m, MTOP(idstrect), 0);
3354 int idstrecty = MMfetch(m, MTOP(idstrect), 1);
3355 int idstrectw = MMfetch(m, MTOP(idstrect), 2);
3356 int idstrecth = MMfetch(m, MTOP(idstrect), 3);
3357 if (idstrectx == NIL || idstrecty == NIL || idstrectw == NIL || idstrecth == NIL)
3358 {
3359 MMechostr(MSKRUNTIME, "_BTCPalphaBitmapRect error: some dest rect parameters are NIL\n");
3360 MMset(m, 0, NIL);
3361 return 0;
3362 }
3363
3364 int isrcrectx = MMfetch(m, MTOP(isrcrect), 0);
3365 int isrcrecty = MMfetch(m, MTOP(isrcrect), 1);
3366 int isrcrectw = MMfetch(m, MTOP(isrcrect), 2);
3367 int isrcrecth = MMfetch(m, MTOP(isrcrect), 3);
3368 if (isrcrectx == NIL || isrcrecty == NIL || isrcrectw == NIL || isrcrecth == NIL)
3369 {
3370 MMechostr(MSKRUNTIME, "_BTCPalphaBitmapRect error: some src rect parameters are NIL\n");
3371 MMset(m, 0, NIL);
3372 return 0;
3373 }
3374
3375 // Parsing rect
3376 // -----------
3377 cv::Rect dst_rect(MTOI(idstrectx), MTOI(idstrecty), MTOI(idstrectw), MTOI(idstrecth));
3378 cv::Rect src_rect(MTOI(isrcrectx), MTOI(isrcrecty), MTOI(isrcrectw), MTOI(isrcrecth));
3379
3380 // Parsing bitmaps
3381 // -----------
3382 int idstbmap24 = MMfetch(m, MTOP(idstbmap), 0);
3383 int idstbmap8 = MMfetch(m, MTOP(idstbmap), 1);
3384 int isrcbmap24 = MMfetch(m, MTOP(isrcbmap), 0);
3385 int isrcbmap8 = MMfetch(m, MTOP(isrcbmap), 1);
3386
3387 if ((idstbmap24 == NIL) || (isrcbmap24 == NIL))
3388 {
3389 MMechostr(MSKRUNTIME, "_BTCPalphaBitmapRect error: AlphaBitmaps miscreated\n");
3390 MMset(m, 0, NIL);
3391 return 0;
3392 }
3393
3394 bool hasBmp8 = ((isrcbmap8 != NIL) && (idstbmap8 != NIL)) ? true : false;
3395
3396 //BMP24
3397 PtrObjVoid ptr_dst_bmap = (PtrObjVoid)MMstart(m, MTOP(idstbmap24));
3398 PtrObjVoid ptr_src_bmap = (PtrObjVoid)MMstart(m, MTOP(isrcbmap24));
3399 PtrObjBitmap obj_dst_bmap = (PtrObjBitmap)MMstart(m, MTOP(ptr_dst_bmap->Buffer));
3400 PtrObjBitmap obj_src_bmap = (PtrObjBitmap)MMstart(m, MTOP(ptr_src_bmap->Buffer));
3401
3402 cv::Mat dst_bmap = ConversionTools::ScolBitmapToMat(obj_dst_bmap);
3403 cv::Mat src_bmap = ConversionTools::ScolBitmapToMat(obj_src_bmap);
3404
3405 if (!(ConversionTools::ClipBitmapRect(src_bmap, src_rect, dst_bmap, dst_rect)))
3406 {
3407 MMechostr(MSKRUNTIME, "_BTCPalphaBitmapRect error: src rect size <= 0\n");
3408 MMset(m, 0, NIL);
3409 return 0;
3410 }
3411
3412 // Getting subbitmaps
3413 // -----------------
3414 cv::Mat dst_subbmap = dst_bmap(dst_rect);
3415 cv::Mat src_subbmap = src_bmap(src_rect);
3416
3417 // Resize src subbitmap to dst subbitmap
3418 if (src_subbmap.cols != dst_subbmap.cols || src_subbmap.rows != dst_subbmap.rows)
3419 cv::resize(src_subbmap, dst_subbmap, dst_subbmap.size(), 0, 0, cv::INTER_AREA);
3420 else
3421 src_subbmap.copyTo(dst_bmap(dst_rect));
3422
3423 PtrObjVoid ptr_dst_bmap8 = (PtrObjVoid)MMstart(m, MTOP(idstbmap8));
3424 PtrObjVoid ptr_src_bmap8 = (PtrObjVoid)MMstart(m, MTOP(isrcbmap8));
3425 PtrObjBitmap obj_dst_bmap8 = (PtrObjBitmap)MMstart(m, MTOP(ptr_dst_bmap8->Buffer));
3426 PtrObjBitmap obj_src_bmap8 = (PtrObjBitmap)MMstart(m, MTOP(ptr_src_bmap8->Buffer));
3427
3428 //BMP8
3429 if (hasBmp8)
3430 {
3431 if ((obj_dst_bmap8->bits == 0) || (obj_src_bmap8->bits == 0))
3432 {
3433 MMset(m, 0, NIL);
3434 return 0;
3435 }
3436
3437 cv::Mat dst_bmap8 = ConversionTools::ScolBitmapToMat(obj_dst_bmap8);
3438 cv::Mat src_bmap8 = ConversionTools::ScolBitmapToMat(obj_src_bmap8);
3439 cv::Mat dst_subbmap8 = dst_bmap8(dst_rect);
3440 cv::Mat src_subbmap8 = src_bmap8(src_rect);
3441
3442 // Resize src subbitmap to dst subbitmap
3443 if (src_subbmap8.cols != dst_subbmap8.cols || src_subbmap8.rows != dst_subbmap8.rows)
3444 cv::resize(src_subbmap8, dst_subbmap8, dst_subbmap8.size(), 0, 0, cv::INTER_AREA);
3445 else
3446 src_subbmap8.copyTo(dst_bmap8(dst_rect));
3447 }
3448
3449#ifdef SCOL_DEBUG
3450 MMechostr(MSKDEBUG, "end _BTCPalphaBitmapRect\n");
3451#endif
3452
3453 return 0;
3454}
3455
3473{
3474#ifdef SCOL_DEBUG
3475 MMechostr(MSKDEBUG, "_BTCPbitmapBufferRect");
3476#endif
3477
3478 int isrcrect = MMpull(m);
3479
3480 int isbitsperpixel = MMpull(m);
3481 int isheight = MMpull(m);
3482 int iswidth = MMpull(m);
3483 int isBuff = MMpull(m);
3484
3485 int idstrect = MMpull(m);
3486 int idbitsperpixel = MMpull(m);
3487 int idheight = MMpull(m);
3488 int idwidth = MMpull(m);
3489 int idBuff = MMget(m, 0);
3490
3491 if ((isBuff == NIL) || (iswidth == NIL) || (isheight == NIL) || (isbitsperpixel == NIL) ||
3492 (idBuff == NIL) || (idwidth == NIL) || (idheight == NIL) || (idbitsperpixel == NIL) || (isrcrect == NIL) || (idstrect == NIL))
3493 {
3494 MMechostr(MSKRUNTIME, "_BTCPbitmapBufferRect error: some arguments are NIL\n");
3495 MMset(m, 0, NIL);
3496 return 0;
3497 }
3498
3499 int idstrectx = MMfetch(m, MTOP(idstrect), 0);
3500 int idstrecty = MMfetch(m, MTOP(idstrect), 1);
3501 int idstrectw = MMfetch(m, MTOP(idstrect), 2);
3502 int idstrecth = MMfetch(m, MTOP(idstrect), 3);
3503 if (idstrectx == NIL || idstrecty == NIL || idstrectw == NIL || idstrecth == NIL)
3504 {
3505 MMechostr(MSKRUNTIME, "_BTCPbitmapBufferRect error: some dest rect parameters are NIL\n");
3506 MMset(m, 0, NIL);
3507 return 0;
3508 }
3509
3510 int isrcrectx = MMfetch(m, MTOP(isrcrect), 0);
3511 int isrcrecty = MMfetch(m, MTOP(isrcrect), 1);
3512 int isrcrectw = MMfetch(m, MTOP(isrcrect), 2);
3513 int isrcrecth = MMfetch(m, MTOP(isrcrect), 3);
3514 if (isrcrectx == NIL || isrcrecty == NIL || isrcrectw == NIL || isrcrecth == NIL)
3515 {
3516 MMechostr(MSKRUNTIME, "_BTCPbitmapBufferRect error: some src rect parameters are NIL\n");
3517 MMset(m, 0, NIL);
3518 return 0;
3519 }
3520
3521 // Parsing rect
3522 // -----------
3523 cv::Rect dst_rect(MTOI(idstrectx), MTOI(idstrecty), MTOI(idstrectw), MTOI(idstrecth));
3524 cv::Rect src_rect(MTOI(isrcrectx), MTOI(isrcrecty), MTOI(isrcrectw), MTOI(isrcrecth));
3525
3526 // Parsing bitmaps
3527 // -----------
3528 unsigned char* sbuffer = MMgetPointer<unsigned char*>(m, MTOP(isBuff));
3529 if (sbuffer == NULL)
3530 {
3531 MMset(m, 0, NIL);
3532 return 0;
3533 }
3534
3535 isbitsperpixel = MTOI(isbitsperpixel);
3536 isheight = MTOI(isheight);
3537 iswidth = MTOI(iswidth);
3538
3539 cv::Mat src_bmap = ConversionTools::ScolBitmapBufferToMat((void*)sbuffer, iswidth, isheight, isbitsperpixel);
3540 if (src_bmap.empty())
3541 {
3542 MMset(m, 0, NIL);
3543 return 0;
3544 }
3545
3546 unsigned char* dbuffer = MMgetPointer<unsigned char*>(m, MTOP(idBuff));
3547 if (dbuffer == NULL)
3548 {
3549 MMset(m, 0, NIL);
3550 return 0;
3551 }
3552
3553 idbitsperpixel = MTOI(idbitsperpixel);
3554 idheight = MTOI(idheight);
3555 idwidth = MTOI(idwidth);
3556
3557 cv::Mat dst_bmap = ConversionTools::ScolBitmapBufferToMat((void*)dbuffer, idwidth, idheight, idbitsperpixel);
3558 if (dst_bmap.empty())
3559 {
3560 MMset(m, 0, NIL);
3561 return 0;
3562 }
3563
3564 if (!(ConversionTools::ClipBitmapRect(src_bmap, src_rect, dst_bmap, dst_rect)))
3565 {
3566 MMechostr(MSKRUNTIME, "_BTCPbitmapBufferRect error: src rect size <= 0\n");
3567 MMset(m, 0, NIL);
3568 return 0;
3569 }
3570
3571 // Getting subbitmaps
3572 // -----------------
3573 cv::Mat dst_subbmap = dst_bmap(dst_rect);
3574 cv::Mat src_subbmap = src_bmap(src_rect);
3575
3576 if (idbitsperpixel != isbitsperpixel)
3577 {
3578 if ((idbitsperpixel == 3) && (isbitsperpixel == 4))
3579 cv::cvtColor(src_subbmap, src_subbmap, cv::COLOR_RGBA2RGB);
3580 else if ((idbitsperpixel == 4) && (isbitsperpixel == 3))
3581 cv::cvtColor(src_subbmap, src_subbmap, cv::COLOR_RGB2RGBA);
3582 else if ((idbitsperpixel == 1) && (isbitsperpixel == 3))
3583 cv::cvtColor(src_subbmap, src_subbmap, cv::COLOR_RGB2GRAY);
3584 else if ((idbitsperpixel == 1) && (isbitsperpixel == 4))
3585 cv::cvtColor(src_subbmap, src_subbmap, cv::COLOR_RGBA2GRAY);
3586 }
3587
3588 // Resize src subbitmap to dst subbitmap
3589 if (src_subbmap.cols != dst_subbmap.cols || src_subbmap.rows != dst_subbmap.rows)
3590 cv::resize(src_subbmap, dst_subbmap, dst_subbmap.size(), 0, 0, cv::INTER_CUBIC);
3591 else
3592 src_subbmap.copyTo(dst_bmap(dst_rect));
3593
3594#ifdef SCOL_DEBUG
3595 MMechostr(MSKDEBUG, "end _BTCPbitmapBufferRect\n");
3596#endif
3597
3598 return 0;
3599}
3600
3615int _BTGETbitmapBuffer(mmachine m)
3616{
3617#ifdef _SCOL_DEBUG_
3618 MMechostr(MSKDEBUG, "_BTGETbitmapBuffer\n");
3619#endif
3620
3621 /* Get stack data*/
3622 int bitmap = MMget(m, 0);
3623
3624 if (bitmap == NIL)
3625 {
3626 MMset(m, 0, NIL);
3627 return 0;
3628 }
3629
3630 PtrObjVoid OB = (PtrObjVoid)MMstart(m, MTOP(bitmap));
3631 PtrObjBitmap B = (PtrObjBitmap)MMstart(m, MTOP(OB->Buffer));
3632
3633 if (B->bits == 0)
3634 {
3635 MMset(m, 0, NIL);
3636 return 0;
3637 }
3638
3639 MMpull(m);
3640 if ((MMpushPointer(m, B->bits) != 0))
3641 {
3642 MMpush(m, NIL);
3643 return 0;
3644 }
3645
3646#ifdef _SCOL_DEBUG_
3647 MMechostr(MSKDEBUG, "ok\n");
3648#endif
3649 return 0;
3650}
3651
3652
3668{
3669#ifdef _SCOL_DEBUG_
3670 MMechostr(MSKDEBUG, "_BTGETbitmapBufferExt\n");
3671#endif
3672
3673 /* Get stack data*/
3674 int bitmap = MMget(m, 0);
3675
3676 if (bitmap == NIL)
3677 {
3678 MMset(m, 0, NIL);
3679 return 0;
3680 }
3681
3682 PtrObjVoid OB = (PtrObjVoid)MMstart(m, MTOP(bitmap));
3683 PtrObjBitmap B = (PtrObjBitmap)MMstart(m, MTOP(OB->Buffer));
3684
3685 if (B->bits == 0)
3686 {
3687 MMset(m, 0, NIL);
3688 return 0;
3689 }
3690
3691 MMpull(m);
3692 if ((MMpushPointer(m, B->bits) != 0))
3693 {
3694 MMpush(m, NIL);
3695 return 0;
3696 }
3697
3698 MMpush(m, ITOM(B->TailleW));
3699 MMpush(m, ITOM(B->TailleH));
3700 MMpush(m, ITOM(B->BytesPP));
3701 MMpush(m, ITOM(4));
3702 MBdeftab(m);
3703
3704#ifdef _SCOL_DEBUG_
3705 MMechostr(MSKDEBUG, "ok\n");
3706#endif
3707 return 0;
3708}
3709
3710/*
3711*********************************************
3712* SCOL PART
3713*********************************************
3714*/
3715
3716NativeDefinition bitmapToolkitEngine[] =
3717{
3718 { "_BTBLURbitmap", 3, "fun [ObjBitmap I I] ObjBitmap", _BTBLURbitmap },
3719 { "_BTBLURbitmap8", 3, "fun [ObjBitmap8 I I] ObjBitmap8", _BTBLURbitmap },
3720 { "_BTBLURbitmapBuffer", 6, "fun [ObjBuff I I I I I] ObjBitmap", _BTBLURbitmapBuffer },
3721
3722 { "_BTFILTERbitmap", 2, "fun [ObjBitmap tab tab F] ObjBitmap", _BTFILTERbitmap },
3723 { "_BTFILTERbitmap8", 2, "fun [ObjBitmap8 tab tab F] ObjBitmap8", _BTFILTERbitmap },
3724 { "_BTFILTERbitmapBuffer", 5, "fun [ObjBuff I I I tab tab F] ObjBitmap", _BTFILTERbitmapBuffer },
3725
3726 { "_BTBRIGHTNESSbitmap", 2, "fun [ObjBitmap I] ObjBitmap", _BTBRIGHTNESSbitmap },
3727 { "_BTBRIGHTNESSbitmap8", 2, "fun [ObjBitmap8 I] ObjBitmap8", _BTBRIGHTNESSbitmap },
3728 { "_BTBRIGHTNESSbitmapBuffer", 5, "fun [ObjBuff I I I I] ObjBitmap", _BTBRIGHTNESSbitmapBuffer },
3729
3730 { "_BTLAPLACEbitmap", 3, "fun [ObjBitmap I I] ObjBitmap", _BTLAPLACEbitmap },
3731 { "_BTLAPLACEbitmap8", 3, "fun [ObjBitmap8 I I] ObjBitmap8", _BTLAPLACEbitmap },
3732 { "_BTLAPLACEbitmapBuffer", 6, "fun [ObjBuff I I I I I] ObjBitmap", _BTLAPLACEbitmapBuffer },
3733
3734 { "_BTFLIPbitmap", 1, "fun [ObjBitmap] ObjBitmap", _BTFLIPbitmap },
3735 { "_BTFLIPbitmap8", 1, "fun [ObjBitmap8] ObjBitmap8", _BTFLIPbitmap },
3736 { "_BTFLIPbuffer", 4, "fun [ObjBuff I I I] ObjBuff", _BTFLIPbuffer },
3737
3738 { "_BTNORMALbitmap", 3, "fun [ObjBitmap F F] ObjBitmap", _BTNORMALbitmap },
3739 { "_BTNORMALbitmapBuffer", 6, "fun [ObjBuff I I I F F] ObjBitmap", _BTNORMALbitmapBuffer },
3740
3741 { "_BTDRAWcircle", 5, "fun [ObjBitmap [I I] I I I I I] ObjBitmap", _BTDRAWcircle },
3742 { "_BTDRAWcircle8", 5, "fun [ObjBitmap8 [I I] I I I I I] ObjBitmap8", _BTDRAWcircle },
3743 { "_BTDRAWcircleBuffer", 8, "fun [ObjBuff I I I [I I] I I I I I] ObjBuff", _BTDRAWcircleBuffer },
3744
3745 { "_BTDRAWrect", 6, "fun [ObjBitmap [I I I I] I I I I] ObjBitmap", _BTDRAWrect },
3746 { "_BTDRAWrect8", 6, "fun [ObjBitmap8 [I I I I] I I I I] ObjBitmap8", _BTDRAWrect },
3747 { "_BTDRAWrectBuffer", 9, "fun [ObjBuff I I I [I I I I] I I I I] ObjBuff", _BTDRAWrectBuffer },
3748
3749 { "_BTDRAWline", 5, "fun [ObjBitmap [I I] [I I] I I] ObjBitmap", _BTDRAWline },
3750 { "_BTDRAWline8", 5, "fun [ObjBitmap8 [I I] [I I] I I] ObjBitmap8", _BTDRAWline },
3751 { "_BTDRAWlineBuffer", 8, "fun [ObjBuff I I I [I I] [I I] I I] ObjBuff", _BTDRAWlineBuffer },
3752
3753 { "_BTDRAWpath", 4, "fun [ObjBitmap [[I I] r1] I I] ObjBitmap", _BTDRAWpath },
3754 { "_BTDRAWpath8", 4, "fun [ObjBitmap8 [[I I] r1] I I] ObjBitmap8", _BTDRAWpath },
3755 { "_BTDRAWpathBuffer", 7, "fun [ObjBuff I I I [[I I] r1] I I] ObjBuff", _BTDRAWpathBuffer },
3756
3757 { "_BTCompBitmap", 2, "fun [ObjBitmap I] S", _BTCompBitmap },
3758 { "_BTUnCompBitmap", 2, "fun [S ObjBitmap] ObjBitmap", _BTUnCompBitmap },
3759
3760 { "_BTMOTIONdetect", 4, "fun [ObjBitmap ObjBitmap I I] I", _BTMOTIONdetect },
3761
3762 { "_BTSCALEbitmap", 3, "fun [ObjBitmap ObjBitmap I] ObjBitmap", _BTSCALEbitmap },
3763 { "_BTSCALEalphaBitmap", 3, "fun [AlphaBitmap AlphaBitmap I] AlphaBitmap", _BTSCALEalphaBitmap },
3764 { "_BTSCALEbitmap8", 3, "fun [ObjBitmap8 ObjBitmap8 I] ObjBitmap8", _BTSCALEbitmap },
3765 { "_BTSCALEbitmapBuffer", 9, "fun [ObjBuff I I I ObjBuff I I I I] ObjBuff", _BTSCALEbitmapBuffer },
3766
3767 { "_BTSAVEbitmap", 2, "fun [ObjBitmap W] P", _BTSAVEbitmap },
3768 { "_BTSAVEbitmap8", 2, "fun [ObjBitmap8 W] P", _BTSAVEbitmap },
3769 { "_BTSAVEalphaBitmap", 2, "fun [AlphaBitmap W] P", _BTSAVEalphaBitmap },
3770
3771 { "_BTLOADbitmap", 2, "fun [Chn P] ObjBitmap", _BTLOADbitmap },
3772
3773 { "_BTBLENDbitmaps", 5, "fun [ObjBitmap [I I I I] ObjBitmap [I I I I] F] ObjBitmap", _BTBLENDbitmaps },
3774 { "_BTBLENDbitmaps8", 5, "fun [ObjBitmap8 [I I I I] ObjBitmap8 [I I I I] F] ObjBitmap8", _BTBLENDbitmaps },
3775 { "_BTBLENDalphaBitmaps", 5, "fun [AlphaBitmap [I I I I] AlphaBitmap [I I I I] F] AlphaBitmap", _BTBLENDalphaBitmaps },
3776 { "_BTBLENDbitmapsBuffer", 11, "fun [ObjBuff I I I [I I I I] ObjBuff I I I [I I I I] F] ObjBuff", _BTBLENDbitmapsBuffer },
3777
3778 { "_BTCPbitmapRect", 4, "fun [ObjBitmap [I I I I] ObjBitmap [I I I I]] ObjBitmap", _BTCPbitmapRect },
3779 { "_BTCPbitmapRect8", 4, "fun [ObjBitmap8 [I I I I] ObjBitmap8 [I I I I]] ObjBitmap8", _BTCPbitmapRect },
3780 { "_BTCPalphaBitmapRect", 4, "fun [AlphaBitmap [I I I I] AlphaBitmap [I I I I]] AlphaBitmap", _BTCPalphaBitmapRect },
3781 { "_BTCPbitmapBufferRect", 10, "fun [ObjBuff I I I [I I I I] ObjBuff I I I [I I I I]] ObjBuff", _BTCPbitmapBufferRect },
3782
3783 { "_BTGETbitmapBuffer", 1, "fun [ObjBitmap] ObjBuff", _BTGETbitmapBuffer },
3784 { "_BTGETbitmapBuffer8", 1, "fun [ObjBitmap8] ObjBuff", _BTGETbitmapBuffer },
3785
3786 { "_BTGETbitmapBufferExt", 1, "fun [ObjBitmap] [ObjBuff I I I]", _BTGETbitmapBufferExt },
3787 { "_BTGETbitmapBuffer8Ext", 1, "fun [ObjBitmap8] [ObjBuff I I I]", _BTGETbitmapBufferExt },
3788
3789 { "ObjBTMat", TYPTYPE, NULL, NULL },
3790 { "_CRBTmat", 2, "fun [Chn AlphaBitmap] ObjBTMat", _CRBTmat },
3791 { "_DSBTmat", 1, "fun [ObjBTMat] I", _DSBTmat },
3792 { "_BTGETmatBuffer", 1, "fun [ObjBTMat] ObjBuff", _BTGETmatBuffer },
3793
3794 { "ObjBTFont", TYPTYPE, NULL, NULL },
3795 { "_CRBTfont", 5, "fun [Chn S I I F] ObjBTFont", _CRBTfont },
3796 { "_CRBTfontFromFile", 5, "fun [Chn P I I F] ObjBTFont", _CRBTfontFromFile },
3797 { "_DSBTfont", 1, "fun [ObjBTFont] I", _DSBTfont },
3798
3799 { "BT_FONT_BOLD", TYPVAR, "I", SCOL_TYPTYPE(BT_FONT_BOLD) },
3800 { "BT_FONT_ITALIC", TYPVAR, "I", SCOL_TYPTYPE(BT_FONT_ITALIC) },
3801 { "BT_FONT_ANTIALIAS", TYPVAR, "I", SCOL_TYPTYPE(BT_FONT_ANTIALIAS) },
3802 { "BT_FONT_FILLED", TYPVAR, "I", SCOL_TYPTYPE(BT_FONT_FILLED) },
3803 { "BT_FONT_HOLLOW", TYPVAR, "I", SCOL_TYPTYPE(BT_FONT_HOLLOW) },
3804 { "BT_FONT_SANS", TYPVAR, "I", SCOL_TYPTYPE(BT_FONT_SANS) },
3805 { "BT_FONT_SERIF", TYPVAR, "I", SCOL_TYPTYPE(BT_FONT_SERIF) },
3806 { "BT_FONT_SCRIPT", TYPVAR, "I", SCOL_TYPTYPE(BT_FONT_SCRIPT) },
3807 { "BT_TEXT_HORIZ_MASK", TYPVAR, "I", SCOL_TYPTYPE(BT_TEXT_HORIZ_MASK) },
3808 { "BT_TEXT_HORIZ_LEFT", TYPVAR, "I", SCOL_TYPTYPE(BT_TEXT_HORIZ_LEFT) },
3809 { "BT_TEXT_HORIZ_RIGHT", TYPVAR, "I", SCOL_TYPTYPE(BT_TEXT_HORIZ_RIGHT) },
3810 { "BT_TEXT_HORIZ_CENTERED", TYPVAR, "I", SCOL_TYPTYPE(BT_TEXT_HORIZ_CENTERED) },
3811 { "BT_TEXT_HORIZ_JUSTIFIED", TYPVAR, "I", SCOL_TYPTYPE(BT_TEXT_HORIZ_JUSTIFIED) },
3812 { "BT_TEXT_VERT_MASK", TYPVAR, "I", SCOL_TYPTYPE(BT_TEXT_VERT_MASK) },
3813 { "BT_TEXT_VERT_TOP", TYPVAR, "I", SCOL_TYPTYPE(BT_TEXT_VERT_TOP) },
3814 { "BT_TEXT_VERT_CENTER", TYPVAR, "I", SCOL_TYPTYPE(BT_TEXT_VERT_CENTER) },
3815 { "BT_TEXT_VERT_BOTTOM", TYPVAR, "I", SCOL_TYPTYPE(BT_TEXT_VERT_BOTTOM) },
3816 { "BT_TEXT_WORD_WRAP", TYPVAR, "I", SCOL_TYPTYPE(BT_TEXT_WORD_WRAP) },
3817
3818 { "_BTDRAWtextBitmap", 6, "fun [ObjBitmap ObjBTFont [I I] I I S] ObjBitmap", _BTDRAWtextBitmap },
3819 { "_BTDRAWtextBitmap8", 6, "fun [ObjBitmap8 ObjBTFont [I I] I I S] ObjBitmap8", _BTDRAWtextBitmap },
3820 { "_BTDRAWtextAreaBitmap", 7, "fun [ObjBitmap ObjBTFont [I I I I] [I I] I I S] ObjBitmap", _BTDRAWtextAreaBitmap },
3821 { "_BTDRAWtextAreaBitmap8", 7, "fun [ObjBitmap8 ObjBTFont [I I I I] [I I] I I S] ObjBitmap8", _BTDRAWtextAreaBitmap },
3822 { "_BTDRAWtextAlphaBitmap", 7, "fun [AlphaBitmap ObjBTFont [I I] I I I S] AlphaBitmap", _BTDRAWtextAlphaBitmap },
3823 { "_BTDRAWtextAreaAlphaBitmap", 8, "fun [AlphaBitmap ObjBTFont [I I I I] [I I] I I I S] AlphaBitmap", _BTDRAWtextAreaAlphaBitmap },
3824 { "_BTGETtextSize", 2, "fun [ObjBTFont S] [I I]", _BTGETtextSize },
3825 { "_BTGETtextAreaHeight", 4, "fun [ObjBTFont S I I] I", _BTGETtextAreaHeight }
3826
3827};
3828
3829// Everything inside _cond and _endcond is ignored by doxygen
3831
3836int LoadBitmapToolKit(mmachine m)
3837{
3838 int k;
3839 MMechostr(MSKDEBUG, " > Loading BitmapToolkit\n");
3840 SObjBTFont = OBJregister(0, 0, destroyCVFont, "ObjBTFont");
3841 SObjBTMat = OBJregister(0, 0, destroyCVMat, "ObjBTMat");
3842 k = PKhardpak2(m, "BitmapToolkitEngine", sizeof(bitmapToolkitEngine) / sizeof(bitmapToolkitEngine[0]), bitmapToolkitEngine);
3843 MMechostr(MSKDEBUG, " > Successfully Loaded\n\n");
3844 return k;
3845}
3846
int destroyCVMat(mmachine m, SCOL_PTR_TYPE handsys, int obj)
NativeDefinition bitmapToolkitEngine[]
#define ROW_PTR(img, y)
int SObjBTMat
int SObjBTFont
#define BT_TEXT_HORIZ_LEFT
#define BT_FONT_ITALIC
#define BT_TEXT_HORIZ_RIGHT
#define BT_TEXT_VERT_MASK
#define BT_TEXT_VERT_CENTER
#define BT_TEXT_VERT_TOP
#define BT_TEXT_HORIZ_JUSTIFIED
#define BT_FONT_BOLD
#define BT_FONT_FILLED
#define BT_FONT_ANTIALIAS
#define BT_TEXT_HORIZ_CENTERED
#define BT_FONT_SCRIPT
#define BT_TEXT_VERT_BOTTOM
#define BT_TEXT_HORIZ_MASK
#define BT_FONT_SANS
#define BT_TEXT_WORD_WRAP
#define BT_FONT_SERIF
#define BT_FONT_HOLLOW
int destroyCVFont(mmachine m, SCOL_PTR_TYPE handsys, int obj)
int LoadBitmapToolKit(mmachine m)
static cv::Mat ScolBitmapBufferToMat(void *buffer, int width, int height, int nbcomponents, bool align=true)
static void Blend(cv::Mat &base, const cv::Mat &top, float mix)
static void ScolBitmapToMatRGBA(PtrObjBitmap scolBitmap, PtrObjBitmap scolBitmap8, cv::Mat &mat)
static cv::Mat ScolBitmapToMat(PtrObjBitmap scolBitmap)
static void MatToScolBitmapRGB(cv::Mat mat, PtrObjBitmap scolBitmap)
static bool ClipBitmapRect(const cv::Mat src, cv::Rect &srect, const cv::Mat dst, cv::Rect &drect)
int _BTSCALEalphaBitmap(mmachine m)
_BTSCALEalphaBitmap : This function scale an alpha bitmap to an another alpha bitmap Prototype: fun [...
int _BTDRAWrectBuffer(mmachine m)
_BTDRAWrectBuffer : This function draw a rectangle into a bitmap buffer Prototype: fun [ObjBuff I I I...
int _BTBLENDbitmapsBuffer(mmachine m)
_BTBLENDbitmapsBuffer : blends 2 bitmaps buffer from percentage value. Takes a piece of the src to bl...
int _BTFILTERbitmap(mmachine m)
_BTFILTERbitmap : This function apply a kernel filter on a bitmap Prototype: fun [ObjBitmap tab tab F...
int _BTMOTIONdetect(mmachine m)
_BTMOTIONdetect : This function detect the motion between two bitmaps Prototype: fun [ObjBitmap ObjBi...
int _BTSAVEalphaBitmap(mmachine m)
_BTSAVEbitmapWithAlpha : This function saves a scol RGB bitmap with alpha bitmap to a defined path....
int _BTGETbitmapBuffer(mmachine m)
_BTGETbitmapBuffer : This function return the bitmap buffer Prototype: fun [ObjBitmap] ObjBuff
int _BTDRAWcircle(mmachine m)
_BTDRAWcircle : This function draw a circle into a bitmap Prototype: fun [ObjBitmap [I I] I I I I I] ...
int _BTLOADbitmap(mmachine m)
_BTLOADbitmap : This function loads an RGB bitmap from a defined path. Prototype: fun [Chn P] ObjBitm...
int _BTSCALEbitmap(mmachine m)
_BTSCALEbitmap : This function scale a bitmap to an another bitmap Prototype: fun [ObjBitmap ObjBitma...
int _BTBRIGHTNESSbitmap(mmachine m)
_BTBRIGHTNESSbitmap : This function change the brightness of a bitmap Prototype: fun [ObjBitmap I] Ob...
int _BTGETmatBuffer(mmachine m)
_BTGETmatBuffer : Get a cv mat buffer Prototype: fun [ObjBTMat] ObjBuff
int _BTFLIPbuffer(mmachine m)
_BTFLIPbuffer : This function apply vertical flip on a pixel buffer Prototype: fun [ObjBuff I I I] Ob...
int _BTBLURbitmap(mmachine m)
_BTBLURbitmap : This function apply a blur on a bitmap Prototype: fun [ObjBitmap I I] ObjBitmap
int _BTBLENDalphaBitmaps(mmachine m)
_BTBLENDalphaBitmaps : blends 2 alpha bitmaps. Takes a piece of the src to blit it in a piece of the ...
int _BTNORMALbitmapBuffer(mmachine m)
_BTNORMALbitmapBuffer :This function convert an height map to a normal map bitmap Prototype: fun [Obj...
int _BTSCALEbitmapBuffer(mmachine m)
_BTSCALEbitmapBuffer : This function scale a bitmap to an another bitmap Prototype: fun [ObjBuff I I ...
int _BTGETbitmapBufferExt(mmachine m)
_BTGETbitmapBufferExt : This function return the bitmap buffer Prototype: fun [ObjBitmap] [ObjBuff I ...
int _BTFLIPbitmap(mmachine m)
_BTFLIPbitmap : This function apply vertical flip on a bitmap Prototype: fun [ObjBitmap] ObjBitmap
int _BTCompBitmap(mmachine m)
_BTCompBitmap : This function compress a bitmap and return the buffer as string Prototype: fun [ObjBi...
int _BTDRAWpathBuffer(mmachine m)
_BTDRAWpathBuffer : This function draw a line into a bitmap buffer Prototype: fun [ObjBuff I I I [[I ...
int _DSBTmat(mmachine m)
_DSBTmat : Deletes a cv mat object Prototype: fun [ObjBTMat] I
int _BTBLENDbitmaps(mmachine m)
_BTBLENDbitmaps : blends 2 bitmaps from percentage value. Takes a piece of the src to blit it in a pi...
int _BTDRAWpath(mmachine m)
_BTDRAWpath : This function draw a path into a bitmap Prototype: fun [ObjBitmap [[I I] r1] I I] ObjBi...
int _BTLAPLACEbitmapBuffer(mmachine m)
_BTLAPLACEbitmapBuffer : This function apply LAPLACE filter on a bitmap buffer Prototype: fun [ObjBuf...
int _BTCPalphaBitmapRect(mmachine m)
_BTCPalphaBitmapRect : copy a bitmap buffer rect to another. Takes a piece of the src to blit it in a...
int _BTSAVEbitmap(mmachine m)
_BTSAVEbitmap : This function saves a scol RGB bitmap to a defined path. The format is defined by the...
int _BTUnCompBitmap(mmachine m)
_BTUnCompBitmap : This function uncompress a bitmap data to an existed bitmap Prototype: fun [S ObjBi...
int _BTDRAWrect(mmachine m)
_BTDRAWrect : This function draw a rectangle into a bitmap Prototype: fun [ObjBitmap [I I I I] I I I ...
int _BTDRAWline(mmachine m)
_BTDRAWline : This function draw a line into a bitmap Prototype: fun [ObjBitmap [I I] [I I] I I] ObjB...
int _BTBLURbitmapBuffer(mmachine m)
_BTBLURbitmapBuffer : This function apply a blur on a bitmap buffer Prototype: fun [ObjBuff I I I I I...
int _BTDRAWlineBuffer(mmachine m)
_BTDRAWlineBuffer : This function draw a line into a bitmap buffer Prototype: fun [ObjBuff I I I [I I...
int _BTLAPLACEbitmap(mmachine m)
_BTLAPLACEbitmap : This function apply a LAPLACE filter on a bitmap Prototype: fun [ObjBitmap I I] Ob...
int _BTCPbitmapBufferRect(mmachine m)
_BTCPbitmapBufferRect : copy a bitmap buffer rect to another. Takes a piece of the src to blit it in ...
int _BTDRAWcircleBuffer(mmachine m)
_BTDRAWcircleBuffer : This function draw a circle into a bitmap buffer Prototype: fun [ObjBuff I I I ...
int _CRBTmat(mmachine m)
_CRBTmat : Creates a ObjBTMat object from an AlphaBitmap Prototype: fun [Chn AlphaBitmap] ObjBTMat
int _BTFILTERbitmapBuffer(mmachine m)
_BTFILTERbitmapBuffer : This function apply a kernel filter on a bitmap buffer Prototype: fun [ObjBuf...
int _BTNORMALbitmap(mmachine m)
_BTNORMALbitmap : This function convert an height map to a normal map bitmap Prototype: fun [ObjBitma...
int _BTCPbitmapRect(mmachine m)
_BTCPbitmapRect : copy a bitmap buffer rect to another. Takes a piece of the src to blit it in a piec...
int _BTBRIGHTNESSbitmapBuffer(mmachine m)
_BTBRIGHTNESSbitmapBuffer : This function change the brightness of a bitmap buffer Prototype: fun [Ob...
int _CRBTfont(mmachine m)
_CRBTfont : Creates a ObjBTFont object Prototype: fun [Chn S I I F] ObjBTFont
int _CRBTfontFromFile(mmachine m)
_CRBTfontFromFile : Creates a ObjBTFont object Prototype: fun [Chn P I I F] ObjBTFont
int _BTDRAWtextAlphaBitmap(mmachine m)
_BTDRAWtextAlphaBitmap : Draws a text to a bitmap Prototype: fun [AlphaBitmap ObjBTFont [I I] I I I S...
int _BTDRAWtextAreaAlphaBitmap(mmachine m)
_BTDRAWtextAreaAlphaBitmap : Draws a text to an alpha bitmap, within a defined area Prototype: fun [A...
int _BTDRAWtextBitmap(mmachine m)
_BTDRAWtextBitmap : Draws a text to a bitmap Prototype: fun [ObjBitmap S ObjBTFont [I I] I I] ObjBitm...
int _BTGETtextSize(mmachine m)
_BTGETtextSize : Gets the length of a text line Prototype: fun [ObjBTFont S] [I I]
int _BTGETtextAreaHeight(mmachine m)
_BTGETtextAreaHeight : Gets the height of a formated text area Prototype: fun [ObjBTFont S I I] I
int _DSBTfont(mmachine m)
_DSBTfont : Deletes a cv font object Prototype: fun [ObjBTFont] I
int _BTDRAWtextAreaBitmap(mmachine m)
_BTDRAWtextAreaBitmap : Draws a text to a bitmap, within a defined area Prototype: fun [ObjBitmap Obj...