Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.1KB

  1. // Copyright 2021 Jean Pierre Cimalando
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. //
  15. // SPDX-License-Identifier: Apache-2.0
  16. //
  17. #define STB_IMAGE_IMPLEMENTATION
  18. #define STB_IMAGE_STATIC
  19. #define STBI_WINDOWS_UTF8
  20. #if defined(__GNUC__)
  21. # pragma GCC diagnostic push
  22. # pragma GCC diagnostic ignored "-Wunused-function"
  23. #endif
  24. #include "stb_image.h"
  25. #if defined(__GNUC__)
  26. # pragma GCC diagnostic pop
  27. #endif
  28. //------------------------------------------------------------------------------
  29. #include "WDL/lice/lice.h"
  30. #include "WDL/wdltypes.h"
  31. static LICE_IBitmap *LICE_LoadSTB(const char *filename, LICE_IBitmap *bmp)
  32. {
  33. LICE_IBitmap *delbmp = nullptr;
  34. stbi_uc *srcpx = nullptr;
  35. LICE_pixel *dstpx = nullptr;
  36. bool dstflip = false;
  37. unsigned dstspan = 0;
  38. unsigned w = 0;
  39. unsigned h = 0;
  40. unsigned ch = 0;
  41. srcpx = stbi_load(filename, (int *)&w, (int *)&h, (int *)&ch, 4);
  42. if (!srcpx)
  43. goto fail;
  44. if (bmp)
  45. bmp->resize(w, h);
  46. else
  47. bmp = delbmp = new WDL_NEW LICE_MemBitmap(w, h);
  48. if (!bmp || (unsigned)bmp->getWidth() != w || (unsigned)bmp->getHeight() != h)
  49. goto fail;
  50. dstpx = bmp->getBits();
  51. dstflip = bmp->isFlipped();
  52. dstspan = bmp->getRowSpan();
  53. for (unsigned row = 0; row < h; ++row) {
  54. const stbi_uc *src = srcpx + row * (4 * w);
  55. LICE_pixel *dst = dstpx + dstspan * (dstflip ? (h - 1 - row) : row);
  56. for (unsigned col = 0; col < w; ++col, src += 4, ++dst)
  57. *dst = LICE_RGBA(src[0], src[1], src[2], src[3]);
  58. }
  59. stbi_image_free(srcpx);
  60. return bmp;
  61. fail:
  62. delete delbmp;
  63. stbi_image_free(srcpx);
  64. return nullptr;
  65. }