Brunobkr/llama.cpp_AlgMor24_github
ΩFFFΣLLIa • llama.cpp • AlgMor24 ██████╗ ███████╗███████╗███████╗██╗ ██╗ ██╗ █████╗ ██╔═══██╗██╔════╝██╔════╝██╔════╝██║ ██║ ██║██╔══██╗ ██║ ██║█████╗ █████╗ █████╗ ██║ ██║ ██║███████║ ██║ ██║██╔══╝ ██╔══╝ ██╔══╝ ██║ ██║ ██║██╔══██║ ╚██████╔╝██║ ██║ ███████╗███████╗███████╗██║██║ ██║ ╚═════╝ ╚═╝ ╚═╝ ╚══════╝╚══════╝╚══════╝╚═╝╚═╝ ╚═╝ High-Performance LLM / VLM Inference & Autonomous Agentic Ecosystem… See the full description on the dataset page: https://huggingface.co/datasets/Brunobkr/llama.cpp_AlgMor24_github.
03k
1/*!2 Copyright 2013 Lovell Fuller and others.3 SPDX-License-Identifier: Apache-2.04*/5 6#ifndef SRC_COMMON_H_7#define SRC_COMMON_H_8 9#include <atomic>10#include <string>11#include <tuple>12#include <utility>13#include <vector>14 15#include <napi.h>16#include <vips/vips8>17 18// Verify platform and compiler compatibility19 20#if (VIPS_MAJOR_VERSION < 8) || \21 (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION < 18) || \22 (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION == 18 && VIPS_MICRO_VERSION < 3)23#error "libvips version 8.18.3+ is required - please see https://sharp.pixelplumbing.com/install"24#endif25 26#if defined(__has_include)27#if !__has_include(<filesystem>)28#error "C++17 compiler required - please see https://sharp.pixelplumbing.com/install"29#endif30#endif31 32#ifdef __EMSCRIPTEN__33#define SHARP_CALLBACK_FN_NAME Call34#else35#define SHARP_CALLBACK_FN_NAME MakeCallback36#endif37 38using vips::VImage;39 40namespace sharp {41 42 struct InputDescriptor {43 std::string name;44 std::string file;45 bool autoOrient;46 char *buffer;47 VipsFailOn failOn;48 uint64_t limitInputPixels;49 uint64_t limitInputChannels;50 bool unlimited;51 VipsAccess access;52 size_t bufferLength;53 bool isBuffer;54 double density;55 bool ignoreIcc;56 VipsBandFormat rawDepth;57 int rawChannels;58 int rawWidth;59 int rawHeight;60 bool rawPremultiplied;61 int rawPageHeight;62 int pages;63 int page;64 int createChannels;65 int createWidth;66 int createHeight;67 int createPageHeight;68 std::vector<double> createBackground;69 std::string createNoiseType;70 double createNoiseMean;71 double createNoiseSigma;72 std::string textValue;73 std::string textFont;74 std::string textFontfile;75 int textWidth;76 int textHeight;77 VipsAlign textAlign;78 bool textJustify;79 int textDpi;80 bool textRgba;81 int textSpacing;82 VipsTextWrap textWrap;83 int textAutofitDpi;84 bool joinAnimated;85 int joinAcross;86 int joinShim;87 std::vector<double> joinBackground;88 VipsAlign joinHalign;89 VipsAlign joinValign;90 std::string svgStylesheet;91 bool svgHighBitdepth;92 int tiffSubifd;93 int openSlideLevel;94 std::vector<double> pdfBackground;95 bool jp2Oneshot;96 97 InputDescriptor():98 autoOrient(false),99 buffer(nullptr),100 failOn(VIPS_FAIL_ON_WARNING),101 limitInputPixels(0x3FFF * 0x3FFF),102 limitInputChannels(5),103 unlimited(false),104 access(VIPS_ACCESS_SEQUENTIAL),105 bufferLength(0),106 isBuffer(false),107 density(72.0),108 ignoreIcc(false),109 rawDepth(VIPS_FORMAT_UCHAR),110 rawChannels(0),111 rawWidth(0),112 rawHeight(0),113 rawPremultiplied(false),114 rawPageHeight(0),115 pages(1),116 page(-1),117 createChannels(0),118 createWidth(0),119 createHeight(0),120 createPageHeight(0),121 createBackground{ 0.0, 0.0, 0.0, 255.0 },122 createNoiseMean(0.0),123 createNoiseSigma(0.0),124 textWidth(0),125 textHeight(0),126 textAlign(VIPS_ALIGN_LOW),127 textJustify(false),128 textDpi(72),129 textRgba(false),130 textSpacing(0),131 textWrap(VIPS_TEXT_WRAP_WORD),132 textAutofitDpi(0),133 joinAnimated(false),134 joinAcross(1),135 joinShim(0),136 joinBackground{ 0.0, 0.0, 0.0, 255.0 },137 joinHalign(VIPS_ALIGN_LOW),138 joinValign(VIPS_ALIGN_LOW),139 svgHighBitdepth(false),140 tiffSubifd(-1),141 openSlideLevel(0),142 pdfBackground{ 255.0, 255.0, 255.0, 255.0 },143 jp2Oneshot(false) {}144 };145 146 // Convenience methods to access the attributes of a Napi::Object147 bool HasAttr(Napi::Object obj, std::string attr);148 std::string AttrAsStr(Napi::Object obj, std::string attr);149 std::string AttrAsStr(Napi::Object obj, unsigned int const attr);150 uint32_t AttrAsUint32(Napi::Object obj, std::string attr);151 int32_t AttrAsInt32(Napi::Object obj, std::string attr);152 int32_t AttrAsInt32(Napi::Object obj, unsigned int const attr);153 double AttrAsDouble(Napi::Object obj, std::string attr);154 double AttrAsDouble(Napi::Object obj, unsigned int const attr);155 bool AttrAsBool(Napi::Object obj, std::string attr);156 std::vector<double> AttrAsVectorOfDouble(Napi::Object obj, std::string attr);157 std::vector<int32_t> AttrAsInt32Vector(Napi::Object obj, std::string attr);158 template <class T> T AttrAsEnum(Napi::Object obj, std::string attr, GType type) {159 return static_cast<T>(160 vips_enum_from_nick(nullptr, type, AttrAsStr(obj, attr).data()));161 }162 163 // Create an InputDescriptor instance from a Napi::Object describing an input image164 InputDescriptor* CreateInputDescriptor(Napi::Object input);165 166 enum class ImageType {167 JPEG,168 PNG,169 WEBP,170 JP2,171 TIFF,172 GIF,173 SVG,174 HEIF,175 PDF,176 MAGICK,177 OPENSLIDE,178 PPM,179 FITS,180 EXR,181 JXL,182 RAD,183 DCRAW,184 UHDR,185 VIPS,186 RAW,187 UNKNOWN,188 MISSING189 };190 191 enum class Canvas {192 CROP,193 EMBED,194 MAX,195 MIN,196 IGNORE_ASPECT197 };198 199 // How many tasks are in the queue?200 extern std::atomic<int> counterQueue;201 202 // How many tasks are being processed?203 extern std::atomic<int> counterProcess;204 205 // Filename extension checkers206 bool IsJpeg(std::string const &str);207 bool IsPng(std::string const &str);208 bool IsWebp(std::string const &str);209 bool IsJp2(std::string const &str);210 bool IsGif(std::string const &str);211 bool IsTiff(std::string const &str);212 bool IsHeic(std::string const &str);213 bool IsHeif(std::string const &str);214 bool IsAvif(std::string const &str);215 bool IsJxl(std::string const &str);216 bool IsDz(std::string const &str);217 bool IsDzZip(std::string const &str);218 bool IsV(std::string const &str);219 220 /*221 Trim space from end of string.222 */223 std::string TrimEnd(std::string const &str);224 225 /*226 Provide a string identifier for the given image type.227 */228 std::string ImageTypeId(ImageType const imageType);229 230 /*231 Determine image format of a buffer.232 */233 ImageType DetermineImageType(void *buffer, size_t const length);234 235 /*236 Determine image format of a file.237 */238 ImageType DetermineImageType(char const *file);239 240 /*241 Format-specific options builder242 */243 vips::VOption* GetOptionsForImageType(ImageType imageType, InputDescriptor *descriptor);244 245 /*246 Open an image from the given InputDescriptor (filesystem, compressed buffer, raw pixel data)247 */248 std::tuple<VImage, ImageType> OpenInput(InputDescriptor *descriptor);249 250 /*251 Does this image have an embedded profile?252 */253 bool HasProfile(VImage image);254 255 /*256 Get copy of embedded profile.257 */258 std::pair<char*, size_t> GetProfile(VImage image);259 260 /*261 Set embedded profile.262 */263 VImage SetProfile(VImage image, std::pair<char*, size_t> icc);264 265 /*266 Remove all EXIF-related image fields.267 */268 VImage RemoveExif(VImage image);269 270 /*271 Get EXIF Orientation of image, if any.272 */273 int ExifOrientation(VImage image);274 275 /*276 Set EXIF Orientation of image.277 */278 VImage SetExifOrientation(VImage image, int const orientation);279 280 /*281 Remove EXIF Orientation from image.282 */283 VImage RemoveExifOrientation(VImage image);284 285 /*286 Set animation properties if necessary.287 */288 VImage SetAnimationProperties(VImage image, int nPages, int pageHeight, std::vector<int> delay, int loop);289 290 /*291 Remove animation properties from image.292 */293 VImage RemoveAnimationProperties(VImage image);294 295 /*296 Remove GIF palette from image.297 */298 VImage RemoveGifPalette(VImage image);299 300 /*301 Does this image have a non-default density?302 */303 bool HasDensity(VImage image);304 305 /*306 Get pixels/mm resolution as pixels/inch density.307 */308 int GetDensity(VImage image);309 310 /*311 Set pixels/mm resolution based on a pixels/inch density.312 */313 VImage SetDensity(VImage image, const double density);314 315 /*316 Multi-page images can have a page height. Fetch it, and sanity check it.317 If page-height is not set, it defaults to the image height318 */319 int GetPageHeight(VImage image);320 321 /*322 Check the proposed format supports the current dimensions.323 */324 void AssertImageTypeDimensions(VImage image, ImageType const imageType);325 326 /*327 Called when a Buffer undergoes GC, required to support mixed runtime libraries in Windows328 */329 extern std::function<void(void*, char*)> FreeCallback;330 331 /*332 Called with warnings from the glib-registered "VIPS" domain333 */334 void VipsWarningCallback(char const* log_domain, GLogLevelFlags log_level, char const* message, void* ignore);335 336 /*337 Pop the oldest warning message from the queue338 */339 std::string VipsWarningPop();340 341 /*342 Attach an event listener for progress updates, used to detect timeout343 */344 void SetTimeout(VImage image, int const timeoutSeconds);345 346 /*347 Event listener for progress updates, used to detect timeout348 */349 void VipsProgressCallBack(VipsImage *image, VipsProgress *progress, int *timeoutSeconds);350 351 /*352 Calculate the (left, top) coordinates of the output image353 within the input image, applying the given gravity during an embed.354 */355 std::tuple<int, int> CalculateEmbedPosition(int const inWidth, int const inHeight,356 int const outWidth, int const outHeight, int const gravity);357 358 /*359 Calculate the (left, top) coordinates of the output image360 within the input image, applying the given gravity.361 */362 std::tuple<int, int> CalculateCrop(int const inWidth, int const inHeight,363 int const outWidth, int const outHeight, int const gravity);364 365 /*366 Calculate the (left, top) coordinates of the output image367 within the input image, applying the given x and y offsets of the output image.368 */369 std::tuple<int, int> CalculateCrop(int const inWidth, int const inHeight,370 int const outWidth, int const outHeight, int const x, int const y);371 372 /*373 Are pixel values in this image 16-bit integer?374 */375 bool Is16Bit(VipsInterpretation const interpretation);376 377 /*378 Convert RGBA value to another colourspace379 */380 std::vector<double> GetRgbaAsColourspace(std::vector<double> const rgba,381 VipsInterpretation const interpretation, bool premultiply);382 383 /*384 Apply the alpha channel to a given colour385 */386 std::tuple<VImage, std::vector<double>> ApplyAlpha(VImage image, std::vector<double> colour, bool premultiply);387 388 /*389 Removes alpha channels, if any.390 */391 VImage RemoveAlpha(VImage image);392 393 /*394 Ensures alpha channel, if missing.395 */396 VImage EnsureAlpha(VImage image, double const value);397 398 /*399 Calculate the horizontal and vertical shrink factors, taking the canvas mode into account.400 */401 std::pair<double, double> ResolveShrink(int width, int height, int targetWidth, int targetHeight,402 Canvas canvas, bool withoutEnlargement, bool withoutReduction);403 404 /*405 Ensure decoding remains sequential.406 */407 VImage StaySequential(VImage image, bool condition = true);408 409 /*410 Does this image have a gain map?411 */412 bool HasGainMap(VImage image);413 414 /*415 Removes gain map, if any.416 */417 VImage RemoveGainMap(VImage image);418 419} // namespace sharp420 421#endif // SRC_COMMON_H_422 