svc_imgwrite.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #ifndef _SVC_IMGWRITE_H
  2. #define _SVC_IMGWRITE_H
  3. #include <api/service/services.h>
  4. #include <bfc/platform/platform.h>
  5. #include <bfc/dispatch.h>
  6. class NOVTABLE svc_imageWriter : public Dispatchable {
  7. public:
  8. static FOURCC getServiceType() { return WaSvc::IMAGEWRITER; }
  9. // returns a human readable string about the format. eg "JPEG"
  10. const wchar_t * getImageTypeName();
  11. // returns a semi-colon delimited list of file extensions for this format. eg "jpg;jpeg"
  12. // MUST BE LOWER CASE
  13. const wchar_t * getExtensions();
  14. // valid items include "quality" for jpeg files with value "0" to "100"
  15. // return value is 1 if the config item is supported, 0 if it is not.
  16. int setConfig(const wchar_t * item, const wchar_t * value);
  17. // valid items include "quality" for jpeg files with value "0" to "100", "lossless" returns "1" if it is "0" otherwise
  18. // return value is 1 if the config item is supported, 0 if it is not.
  19. int getConfig(const wchar_t * item, wchar_t * value, int valuelen);
  20. // returns 1 if the bit depth is supported (eg 32 for ARGB32, 24 for RGB24)
  21. // ARGB32 MUST be supported
  22. int bitDepthSupported(int depth);
  23. // returns the image in our format, free the returned buffer with api_memmgr::sysFree()
  24. void * convert(const void *pixels, int bitDepth, int w, int h, int *length);
  25. enum {
  26. GETIMAGETYPENAME=10,
  27. GETEXTENSIONS=20,
  28. SETCONFIG=30,
  29. GETCONFIG=40,
  30. BITDEPTHSUPPORTED=50,
  31. CONVERT=60,
  32. };
  33. };
  34. inline const wchar_t *svc_imageWriter::getImageTypeName() {
  35. return _call(GETIMAGETYPENAME, L"");
  36. }
  37. inline const wchar_t *svc_imageWriter::getExtensions() {
  38. return _call(GETEXTENSIONS, L"");
  39. }
  40. inline int svc_imageWriter::setConfig(const wchar_t * item, const wchar_t * value) {
  41. return _call(SETCONFIG, (int)0, item, value);
  42. }
  43. inline int svc_imageWriter::getConfig(const wchar_t * item, wchar_t * value, int valuelen) {
  44. return _call(GETCONFIG, (int)0, item, value, valuelen);
  45. }
  46. inline int svc_imageWriter::bitDepthSupported(int depth) {
  47. return _call(BITDEPTHSUPPORTED, (int)0, depth);
  48. }
  49. inline void * svc_imageWriter::convert(const void *pixels, int bitDepth, int w, int h, int *length) {
  50. return _call(CONVERT, (void*)0, pixels, bitDepth, w, h, length);
  51. }
  52. // derive from this one
  53. class NOVTABLE svc_imageWriterI : public svc_imageWriter {
  54. public:
  55. virtual const wchar_t * getExtensions()=0;
  56. virtual const wchar_t * getImageTypeName()=0;
  57. virtual int setConfig(const wchar_t * item, const wchar_t * value){return 0;}
  58. virtual int getConfig(const wchar_t * item, wchar_t * value, int valuelen){return 0;}
  59. virtual int bitDepthSupported(int depth)=0;
  60. virtual void * convert(const void *pixels, int bitDepth, int w, int h, int *length)=0;
  61. protected:
  62. RECVS_DISPATCH;
  63. };
  64. /* do we still use svc_enum?
  65. #include <bfc/svc_enum.h>
  66. class ImgWriterEnum : public SvcEnumT<svc_imageWriter> {
  67. public:
  68. ImgWriterEnum(const char *_ext=NULL) : ext(_ext) { }
  69. protected:
  70. virtual int testService(svc_imageWriter *svc) {
  71. if (ext.isempty()) return 1;
  72. else {
  73. PathParser pp(svc->getExtensions(), ";");
  74. for (int i = 0; i < pp.getNumStrings(); i++)
  75. if (STRCASEEQL(ext, pp.enumString(i))) return 1;
  76. return 0;
  77. }
  78. }
  79. String ext;
  80. };
  81. */
  82. #endif