poly.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include "precomp.h"
  2. #include "poly.h"
  3. #include <api/xml/xmlparams.h>
  4. #include <api/memmgr/api_memmgr.h>
  5. #ifndef _WASABIRUNTIME
  6. BEGIN_SERVICES(PolyGen_Svc);
  7. DECLARE_SERVICETSINGLE(svc_imageGenerator, PolyImage);
  8. END_SERVICES(PolyGen_Svc, _PolyGen_Svc);
  9. #ifdef _X86_
  10. extern "C" { int _link_PolyGen_Svc; }
  11. #else
  12. extern "C" { int __link_PolyGen_Svc; }
  13. #endif
  14. #endif
  15. int PolyImage::testDesc(const wchar_t *desc) {
  16. return !_wcsicmp(desc, L"$polygon");
  17. }
  18. void premultiply(ARGB32 *m_pBits, int nwords);
  19. #include <bfc/draw/drawpoly.h>
  20. ARGB32 *PolyImage::genImage(const wchar_t *desc, int *has_alpha, int *w, int *h, ifc_xmlreaderparams *params)
  21. {
  22. int _w = (params->getItemValueInt(L"w", 1));
  23. if (_w == 0) _w = 1;
  24. int _h = (params->getItemValueInt(L"h", 1));
  25. if (_h == 0) _h = 1;
  26. if (_w <= 0 || _h <= 0) return NULL;
  27. const wchar_t *bgcolorstr = params->getItemValue(L"bgcolor");
  28. ARGB32 bgcolor = (bgcolorstr == NULL || *bgcolorstr=='\0') ? 0 : _byteswap_ulong(WASABI_API_SKIN->parse(params->getItemValue(L"bgcolor"), L"color")<<8);
  29. unsigned int bgalpha = params->getItemValueInt(L"bgalpha", 0);
  30. bgcolor |= ((bgalpha & 0xff) << 24);
  31. premultiply(&bgcolor, 1);
  32. #ifdef WASABI_COMPILE_MEMMGR
  33. ARGB32 *ret = (ARGB32*)WASABI_API_MEMMGR->sysMalloc(_w * _h * sizeof(ARGB32));
  34. #else
  35. ARGB32 *ret = (ARGB32*)MALLOC(_w * _h * sizeof(ARGB32));
  36. #endif
  37. MEMFILL<ARGB32>(ret, bgcolor, _w * _h);
  38. Draw::drawPointList(ret, _w, _h, params->getItemValue(L"points"));
  39. *w = _w;
  40. *h = _h;
  41. *has_alpha = 1;
  42. return ret;
  43. }