ResLib.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include "Common.h"
  2. #include "BFApp.h"
  3. #include "img/PSDReader.h"
  4. #include "gfx/RenderDevice.h"
  5. #include "gfx/Texture.h"
  6. #include "util/PerfTimer.h"
  7. USING_NS_BF;
  8. static UTF16String gTempUTF16String;
  9. BF_EXPORT PSDReader* BF_CALLTYPE Res_OpenPSD(const char* fileName)
  10. {
  11. //gPerfManager->StartRecording();
  12. PSDReader* aPSDReader = new PSDReader();
  13. if (!aPSDReader->Init(fileName))
  14. {
  15. delete aPSDReader;
  16. return NULL;
  17. }
  18. return aPSDReader;
  19. }
  20. BF_EXPORT void BF_CALLTYPE Res_DeletePSDReader(PSDReader* pSDReader)
  21. {
  22. delete pSDReader;
  23. gPerfManager->StopRecording();
  24. gPerfManager->DbgPrint();
  25. }
  26. BF_EXPORT TextureSegment* BF_CALLTYPE Res_PSD_GetLayerTexture(PSDReader* pSDReader, int layerIdx, int* ofsX, int* ofsY)
  27. {
  28. Texture* texture = pSDReader->LoadLayerTexture(layerIdx, ofsX, ofsY);
  29. if (texture == NULL)
  30. return NULL;
  31. TextureSegment* textureSegment = new TextureSegment();
  32. textureSegment->InitFromTexture(texture);
  33. return textureSegment;
  34. }
  35. BF_EXPORT TextureSegment* BF_CALLTYPE Res_PSD_GetMergedLayerTexture(PSDReader* pSDReader, int* layerIndices, int count, int* ofsX, int* ofsY)
  36. {
  37. std::vector<int> aLayerIndices;
  38. aLayerIndices.insert(aLayerIndices.begin(), layerIndices, layerIndices + count);
  39. Texture* texture = pSDReader->LoadMergedLayerTexture(aLayerIndices, ofsX, ofsY);
  40. if (texture == NULL)
  41. return NULL;
  42. TextureSegment* textureSegment = new TextureSegment();
  43. textureSegment->InitFromTexture(texture);
  44. return textureSegment;
  45. }
  46. BF_EXPORT int BF_CALLTYPE Res_PSD_GetLayerCount(PSDReader* pSDReader)
  47. {
  48. return (int) pSDReader->mPSDLayerInfoVector.size();
  49. }
  50. BF_EXPORT PSDLayerInfo* BF_CALLTYPE Res_PSD_GetLayerInfo(PSDReader* pSDReader, int layerIdx)
  51. {
  52. return pSDReader->mPSDLayerInfoVector[layerIdx];
  53. }
  54. BF_EXPORT void BF_CALLTYPE Res_PSDLayer_GetSize(PSDLayerInfo* layerInfo, int* x, int* y, int* width, int* height)
  55. {
  56. *x = layerInfo->mX;
  57. *y = layerInfo->mY;
  58. *width = layerInfo->mWidth;
  59. *height = layerInfo->mHeight;
  60. }
  61. BF_EXPORT int BF_CALLTYPE Res_PSDLayer_GetLayerId(PSDLayerInfo* layerInfo)
  62. {
  63. return layerInfo->mLayerId;
  64. }
  65. BF_EXPORT const char* BF_CALLTYPE Res_PSDLayer_GetName(PSDLayerInfo* layerInfo)
  66. {
  67. return layerInfo->mName.c_str();
  68. }
  69. BF_EXPORT int BF_CALLTYPE Res_PSDLayer_IsVisible(PSDLayerInfo* layerInfo)
  70. {
  71. return layerInfo->mVisible ? 1 : 0;
  72. }