| |
| |
|
|
| #ifndef SRC_COMMON_H_ |
| #define SRC_COMMON_H_ |
|
|
| #include <string> |
| #include <tuple> |
| #include <vector> |
| #include <atomic> |
|
|
| #include <napi.h> |
| #include <vips/vips8> |
|
|
| |
|
|
| #if (VIPS_MAJOR_VERSION < 8) || \ |
| (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION < 15) || \ |
| (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION == 15 && VIPS_MICRO_VERSION < 3) |
| #error "libvips version 8.15.3+ is required - please see https://sharp.pixelplumbing.com/install" |
| #endif |
|
|
| #if ((!defined(__clang__)) && defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 6))) |
| #error "GCC version 4.6+ is required for C++11 features - please see https://sharp.pixelplumbing.com/install" |
| #endif |
|
|
| #if (defined(__clang__) && defined(__has_feature)) |
| #if (!__has_feature(cxx_range_for)) |
| #error "clang version 3.0+ is required for C++11 features - please see https://sharp.pixelplumbing.com/install" |
| #endif |
| #endif |
|
|
| using vips::VImage; |
|
|
| namespace sharp { |
|
|
| struct InputDescriptor { |
| std::string name; |
| std::string file; |
| char *buffer; |
| VipsFailOn failOn; |
| uint64_t limitInputPixels; |
| bool unlimited; |
| VipsAccess access; |
| size_t bufferLength; |
| bool isBuffer; |
| double density; |
| bool ignoreIcc; |
| VipsBandFormat rawDepth; |
| int rawChannels; |
| int rawWidth; |
| int rawHeight; |
| bool rawPremultiplied; |
| int pages; |
| int page; |
| int level; |
| int subifd; |
| int createChannels; |
| int createWidth; |
| int createHeight; |
| std::vector<double> createBackground; |
| std::string createNoiseType; |
| double createNoiseMean; |
| double createNoiseSigma; |
| std::string textValue; |
| std::string textFont; |
| std::string textFontfile; |
| int textWidth; |
| int textHeight; |
| VipsAlign textAlign; |
| bool textJustify; |
| int textDpi; |
| bool textRgba; |
| int textSpacing; |
| VipsTextWrap textWrap; |
| int textAutofitDpi; |
|
|
| InputDescriptor(): |
| buffer(nullptr), |
| failOn(VIPS_FAIL_ON_WARNING), |
| limitInputPixels(0x3FFF * 0x3FFF), |
| unlimited(false), |
| access(VIPS_ACCESS_RANDOM), |
| bufferLength(0), |
| isBuffer(false), |
| density(72.0), |
| ignoreIcc(false), |
| rawDepth(VIPS_FORMAT_UCHAR), |
| rawChannels(0), |
| rawWidth(0), |
| rawHeight(0), |
| rawPremultiplied(false), |
| pages(1), |
| page(0), |
| level(0), |
| subifd(-1), |
| createChannels(0), |
| createWidth(0), |
| createHeight(0), |
| createBackground{ 0.0, 0.0, 0.0, 255.0 }, |
| createNoiseMean(0.0), |
| createNoiseSigma(0.0), |
| textWidth(0), |
| textHeight(0), |
| textAlign(VIPS_ALIGN_LOW), |
| textJustify(false), |
| textDpi(72), |
| textRgba(false), |
| textSpacing(0), |
| textWrap(VIPS_TEXT_WRAP_WORD), |
| textAutofitDpi(0) {} |
| }; |
|
|
| |
| bool HasAttr(Napi::Object obj, std::string attr); |
| std::string AttrAsStr(Napi::Object obj, std::string attr); |
| std::string AttrAsStr(Napi::Object obj, unsigned int const attr); |
| uint32_t AttrAsUint32(Napi::Object obj, std::string attr); |
| int32_t AttrAsInt32(Napi::Object obj, std::string attr); |
| int32_t AttrAsInt32(Napi::Object obj, unsigned int const attr); |
| double AttrAsDouble(Napi::Object obj, std::string attr); |
| double AttrAsDouble(Napi::Object obj, unsigned int const attr); |
| bool AttrAsBool(Napi::Object obj, std::string attr); |
| std::vector<double> AttrAsVectorOfDouble(Napi::Object obj, std::string attr); |
| std::vector<int32_t> AttrAsInt32Vector(Napi::Object obj, std::string attr); |
| template <class T> T AttrAsEnum(Napi::Object obj, std::string attr, GType type) { |
| return static_cast<T>( |
| vips_enum_from_nick(nullptr, type, AttrAsStr(obj, attr).data())); |
| } |
|
|
| |
| InputDescriptor* CreateInputDescriptor(Napi::Object input); |
|
|
| enum class ImageType { |
| JPEG, |
| PNG, |
| WEBP, |
| JP2, |
| TIFF, |
| GIF, |
| SVG, |
| HEIF, |
| PDF, |
| MAGICK, |
| OPENSLIDE, |
| PPM, |
| FITS, |
| EXR, |
| JXL, |
| VIPS, |
| RAW, |
| UNKNOWN, |
| MISSING |
| }; |
|
|
| enum class Canvas { |
| CROP, |
| EMBED, |
| MAX, |
| MIN, |
| IGNORE_ASPECT |
| }; |
|
|
| |
| extern std::atomic<int> counterQueue; |
|
|
| |
| extern std::atomic<int> counterProcess; |
|
|
| |
| bool IsJpeg(std::string const &str); |
| bool IsPng(std::string const &str); |
| bool IsWebp(std::string const &str); |
| bool IsJp2(std::string const &str); |
| bool IsGif(std::string const &str); |
| bool IsTiff(std::string const &str); |
| bool IsHeic(std::string const &str); |
| bool IsHeif(std::string const &str); |
| bool IsAvif(std::string const &str); |
| bool IsJxl(std::string const &str); |
| bool IsDz(std::string const &str); |
| bool IsDzZip(std::string const &str); |
| bool IsV(std::string const &str); |
|
|
| |
| |
| |
| std::string TrimEnd(std::string const &str); |
|
|
| |
| |
| |
| std::string ImageTypeId(ImageType const imageType); |
|
|
| |
| |
| |
| ImageType DetermineImageType(void *buffer, size_t const length); |
|
|
| |
| |
| |
| ImageType DetermineImageType(char const *file); |
|
|
| |
| |
| |
| bool ImageTypeSupportsPage(ImageType imageType); |
|
|
| |
| |
| |
| bool ImageTypeSupportsUnlimited(ImageType imageType); |
|
|
| |
| |
| |
| std::tuple<VImage, ImageType> OpenInput(InputDescriptor *descriptor); |
|
|
| |
| |
| |
| bool HasProfile(VImage image); |
|
|
| |
| |
| |
| std::pair<char*, size_t> GetProfile(VImage image); |
|
|
| |
| |
| |
| VImage SetProfile(VImage image, std::pair<char*, size_t> icc); |
|
|
| |
| |
| |
| |
| bool HasAlpha(VImage image); |
|
|
| |
| |
| |
| VImage RemoveExif(VImage image); |
|
|
| |
| |
| |
| int ExifOrientation(VImage image); |
|
|
| |
| |
| |
| VImage SetExifOrientation(VImage image, int const orientation); |
|
|
| |
| |
| |
| VImage RemoveExifOrientation(VImage image); |
|
|
| |
| |
| |
| VImage SetAnimationProperties(VImage image, int nPages, int pageHeight, std::vector<int> delay, int loop); |
|
|
| |
| |
| |
| VImage RemoveAnimationProperties(VImage image); |
|
|
| |
| |
| |
| VImage RemoveGifPalette(VImage image); |
|
|
| |
| |
| |
| bool HasDensity(VImage image); |
|
|
| |
| |
| |
| int GetDensity(VImage image); |
|
|
| |
| |
| |
| VImage SetDensity(VImage image, const double density); |
|
|
| |
| |
| |
| |
| int GetPageHeight(VImage image); |
|
|
| |
| |
| |
| void AssertImageTypeDimensions(VImage image, ImageType const imageType); |
|
|
| |
| |
| |
| extern std::function<void(void*, char*)> FreeCallback; |
|
|
| |
| |
| |
| void VipsWarningCallback(char const* log_domain, GLogLevelFlags log_level, char const* message, void* ignore); |
|
|
| |
| |
| |
| std::string VipsWarningPop(); |
|
|
| |
| |
| |
| void SetTimeout(VImage image, int const timeoutSeconds); |
|
|
| |
| |
| |
| void VipsProgressCallBack(VipsImage *image, VipsProgress *progress, int *timeoutSeconds); |
|
|
| |
| |
| |
| |
| std::tuple<int, int> CalculateEmbedPosition(int const inWidth, int const inHeight, |
| int const outWidth, int const outHeight, int const gravity); |
|
|
| |
| |
| |
| |
| std::tuple<int, int> CalculateCrop(int const inWidth, int const inHeight, |
| int const outWidth, int const outHeight, int const gravity); |
|
|
| |
| |
| |
| |
| std::tuple<int, int> CalculateCrop(int const inWidth, int const inHeight, |
| int const outWidth, int const outHeight, int const x, int const y); |
|
|
| |
| |
| |
| bool Is16Bit(VipsInterpretation const interpretation); |
|
|
| |
| |
| |
| |
| double MaximumImageAlpha(VipsInterpretation const interpretation); |
|
|
| |
| |
| |
| std::vector<double> GetRgbaAsColourspace(std::vector<double> const rgba, |
| VipsInterpretation const interpretation, bool premultiply); |
|
|
| |
| |
| |
| std::tuple<VImage, std::vector<double>> ApplyAlpha(VImage image, std::vector<double> colour, bool premultiply); |
|
|
| |
| |
| |
| VImage RemoveAlpha(VImage image); |
|
|
| |
| |
| |
| VImage EnsureAlpha(VImage image, double const value); |
|
|
| |
| |
| |
| std::pair<double, double> ResolveShrink(int width, int height, int targetWidth, int targetHeight, |
| Canvas canvas, bool withoutEnlargement, bool withoutReduction); |
|
|
| |
| |
| |
| VImage StaySequential(VImage image, bool condition = true); |
|
|
| } |
|
|
| #endif |
|
|