1
0

grad.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include "precomp.h"
  2. #include "grad.h"
  3. #include <api/xml/xmlparams.h>
  4. #include <api/memmgr/api_memmgr.h>
  5. #ifndef _WASABIRUNTIME
  6. BEGIN_SERVICES(GradientGen_Svc);
  7. DECLARE_SERVICETSINGLE(svc_imageGenerator, GradientImage);
  8. END_SERVICES(GradientGen_Svc, _GradientGen_Svc);
  9. #ifdef _X86_
  10. extern "C" { int _link_GradientGen_Svc; }
  11. #else
  12. extern "C" { int __link_GradientGen_Svc; }
  13. #endif
  14. #endif
  15. int GradientImage::testDesc(const wchar_t *desc) {
  16. return !_wcsicmp(desc, L"$gradient");
  17. }
  18. ARGB32 *GradientImage::genImage(const wchar_t *desc, int *has_alpha, int *w, int *h, ifc_xmlreaderparams *params)
  19. {
  20. int _w = params->getItemValueInt(L"w",1);
  21. if (_w == 0) _w = 1;
  22. int _h = params->getItemValueInt(L"h",1);
  23. if (_h == 0) _h = 1;
  24. if (_w <= 0 || _h <= 0) return NULL;
  25. #ifdef WASABI_COMPILE_MEMMGR
  26. ARGB32 *ret = (ARGB32*)WASABI_API_MEMMGR->sysMalloc(_w * _h * sizeof(ARGB32));
  27. #else
  28. ARGB32 *ret = (ARGB32*)MALLOC(_w * _h * sizeof(ARGB32));
  29. #endif
  30. setX1((float)WTOF(params->getItemValue(L"gradient_x1")));
  31. setY1((float)WTOF(params->getItemValue(L"gradient_y1")));
  32. setX2((float)WTOF(params->getItemValue(L"gradient_x2")));
  33. setY2((float)WTOF(params->getItemValue(L"gradient_y2")));
  34. setPoints(params->getItemValue(L"points"));
  35. setMode(params->getItemValue(L"mode"));
  36. setReverseColors(TRUE); // cuz we're imggen
  37. setAntialias(params->getItemValueInt(L"antialias"));
  38. renderGradient(ret, _w, _h);
  39. *w = _w;
  40. *h = _h;
  41. *has_alpha = 1; // will be optimized anyway
  42. return ret;
  43. }