webp.bmx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. ' Copyright (c) 2021-2023 Bruce A Henderson
  2. '
  3. ' This software is provided 'as-is', without any express or implied
  4. ' warranty. In no event will the authors be held liable for any damages
  5. ' arising from the use of this software.
  6. '
  7. ' Permission is granted to anyone to use this software for any purpose,
  8. ' including commercial applications, and to alter it and redistribute it
  9. ' freely, subject to the following restrictions:
  10. '
  11. ' 1. The origin of this software must not be misrepresented; you must not
  12. ' claim that you wrote the original software. If you use this software
  13. ' in a product, an acknowledgment in the product documentation would be
  14. ' appreciated but is not required.
  15. '
  16. ' 2. Altered source versions must be plainly marked as such, and must not be
  17. ' misrepresented as being the original software.
  18. '
  19. ' 3. This notice may not be removed or altered from any source
  20. ' distribution.
  21. '
  22. SuperStrict
  23. Rem
  24. bbdoc: Image/WebP Loader
  25. about: The WebP loader module provides the ability to load WebP format #pixmaps.
  26. End Rem
  27. Module Image.Webp
  28. ModuleInfo "Version: 1.02"
  29. ModuleInfo "License: libwebp - BSD"
  30. ModuleInfo "License: Wrapper - zlib/libpng"
  31. ModuleInfo "Copyright: libwebp - 2010 Google"
  32. ModuleInfo "Copyright: Wrapper - 2021-2023 Bruce A Henderson"
  33. ModuleInfo "History: 1.02"
  34. ModuleInfo "History: Updated to libwebp 1.3.2.d7a0506"
  35. ModuleInfo "History: 1.01"
  36. ModuleInfo "History: Updated to libwebp 1.3.2."
  37. ModuleInfo "History: 1.00"
  38. ModuleInfo "History: Initial Release."
  39. Import BRL.Pixmap
  40. Import "common.bmx"
  41. Private
  42. Type TPixmapLoaderWebp Extends TPixmapLoader
  43. Method LoadPixmap:TPixmap( stream:TStream ) Override
  44. Local data:Byte[] = LoadByteArray(stream)
  45. If data Then
  46. Local width:Int
  47. Local height:Int
  48. If WebPGetInfo(data, Size_T(data.Length), width, height) Then
  49. Local pix:TPixmap = CreatePixmap( width, height, PF_RGBA8888, 4)
  50. Local res:Byte Ptr = WebPDecodeRGBAInto(data, Size_T(data.Length), pix.pixels, Size_T(width * height * 4), pix.pitch)
  51. If res Then
  52. Return pix
  53. End If
  54. End If
  55. End If
  56. End Method
  57. End Type
  58. New TPixmapLoaderWebp