posix.d 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * pixiv_down - CLI-based downloading tool for https://www.pixiv.net.
  3. * Copyright (C) 2024 Mio
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, version 3 of the License.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. module pd.image_reader.posix;
  18. version(PD_USE_MAGICK):
  19. import core.stdc.string;
  20. import pd.imaging.magick;
  21. import std.string;
  22. import std.experimental.logger;
  23. public class ImageReader
  24. {
  25. this(string filename)
  26. {
  27. fHandle = NewMagickWand();
  28. MagickReadImage(fHandle, toStringz(filename));
  29. fHandle.SetImageDispose(PreviousDispose);
  30. }
  31. ~this()
  32. {
  33. dispose(false);
  34. }
  35. void dispose()
  36. {
  37. dispose(true);
  38. }
  39. MagickWand* getSystemRef() {
  40. return this.fHandle;
  41. }
  42. private:
  43. MagickWand* fHandle;
  44. bool fDisposed = false;
  45. void dispose(bool disposing)
  46. {
  47. if (fDisposed) {
  48. return;
  49. }
  50. if (disposing) {
  51. if (null !is fHandle) {
  52. DestroyMagickWand(fHandle);
  53. }
  54. }
  55. fDisposed = true;
  56. }
  57. }