    CImg<T>& _load_heif(const char *const filename) {
#ifndef cimg_use_heif
      return load_other(filename);
#else
      try {
        heif::Context ctx;
        ctx.read_from_file(filename);

        heif::ImageHandle handle = ctx.get_primary_image_handle();
        const heif::Image image =
          handle.decode_image(heif_colorspace_RGB,handle.has_alpha_channel()?heif_chroma_interleaved_RGBA:
                              heif_chroma_interleaved_RGB);
        const int
          W = image.get_width(heif_channel_interleaved),
          H = image.get_height(heif_channel_interleaved),
          S = handle.has_alpha_channel()?4:3;
        assign(W,H,1,S);

        int stride;
        const unsigned char *const buffer = image.get_plane(heif_channel_interleaved,&stride);
        T *ptr_r = _data, *ptr_g = data(0,0,0,1), *ptr_b = data(0,0,0,2), *ptr_a = S>3?data(0,0,0,3):0;
        cimg_forY(*this,y) {
          const unsigned char *ptrs = buffer + y*stride;
          if (ptr_a) cimg_forX(*this,x) { // RGBA
              *(ptr_r++) = (T)*(ptrs++);
              *(ptr_g++) = (T)*(ptrs++);
              *(ptr_b++) = (T)*(ptrs++);
              *(ptr_a++) = (T)*(ptrs++);
            }
          else cimg_forX(*this,x) { // RGB
              *(ptr_r++) = (T)*(ptrs++);
              *(ptr_g++) = (T)*(ptrs++);
              *(ptr_b++) = (T)*(ptrs++);
            }
        }
      } catch (const heif::Error& e) {
        throw CImgInstanceException(_cimg_instance
                                    "load_heif(): Unable to decode image: %s",
                                    cimg_instance,
                                    e.get_message().c_str());
      } catch (...) {
        throw;
      }
      return *this;
#endif
    }
    CImg<T>& _load_heif(const char *const filename) {
#ifndef cimg_use_heif
      return load_other(filename);
#else
      try {
        heif::Context ctx;
        ctx.read_from_file(filename);

        heif::ImageHandle handle = ctx.get_primary_image_handle();
        const heif::Image image =
          handle.decode_image(heif_colorspace_RGB,handle.has_alpha_channel()?heif_chroma_interleaved_RGBA:
                              heif_chroma_interleaved_RGB);
        const int
          W = image.get_width(heif_channel_interleaved),
          H = image.get_height(heif_channel_interleaved),
          S = handle.has_alpha_channel()?4:3;
        assign(W,H,1,S);

        int stride;
        const unsigned char *const buffer = image.get_plane(heif_channel_interleaved,&stride);
        T *ptr_r = _data, *ptr_g = data(0,0,0,1), *ptr_b = data(0,0,0,2), *ptr_a = S>3?data(0,0,0,3):0;
        cimg_forY(*this,y) {
          const unsigned char *ptrs = buffer + y*stride;
          if (ptr_a) cimg_forX(*this,x) {  
              *(ptr_r++) = (T)*(ptrs++);
              *(ptr_g++) = (T)*(ptrs++);
              *(ptr_b++) = (T)*(ptrs++);
              *(ptr_a++) = (T)*(ptrs++);
            }
          else cimg_forX(*this,x) {  
              *(ptr_r++) = (T)*(ptrs++);
              *(ptr_g++) = (T)*(ptrs++);
              *(ptr_b++) = (T)*(ptrs++);
            }
        }
      } catch (const heif::Error& e) {
        throw CImgInstanceException(_cimg_instance
                                    "load_heif(): Unable to decode image: %s",
                                    cimg_instance,
                                    e.get_message().c_str());
      } catch (...) {
        throw;
      }
      return *this;
#endif
    }