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.
03.1k
1/*!2 Copyright 2013 Lovell Fuller and others.3 SPDX-License-Identifier: Apache-2.04*/5 6const is = require('./is.cjs');7 8/**9 * Weighting to apply when using contain/cover fit.10 * @member11 * @private12 */13const gravity = {14 center: 0,15 centre: 0,16 north: 1,17 east: 2,18 south: 3,19 west: 4,20 northeast: 5,21 southeast: 6,22 southwest: 7,23 northwest: 824};25 26/**27 * Position to apply when using contain/cover fit.28 * @member29 * @private30 */31const position = {32 top: 1,33 right: 2,34 bottom: 3,35 left: 4,36 'right top': 5,37 'right bottom': 6,38 'left bottom': 7,39 'left top': 840};41 42/**43 * How to extend the image.44 * @member45 * @private46 */47const extendWith = {48 background: 'background',49 copy: 'copy',50 repeat: 'repeat',51 mirror: 'mirror'52};53 54/**55 * Strategies for automagic cover behaviour.56 * @member57 * @private58 */59const strategy = {60 entropy: 16,61 attention: 1762};63 64/**65 * Reduction kernels.66 * @member67 * @private68 */69const kernel = {70 nearest: 'nearest',71 linear: 'linear',72 cubic: 'cubic',73 mitchell: 'mitchell',74 lanczos2: 'lanczos2',75 lanczos3: 'lanczos3',76 mks2013: 'mks2013',77 mks2021: 'mks2021'78};79 80/**81 * Methods by which an image can be resized to fit the provided dimensions.82 * @member83 * @private84 */85const fit = {86 contain: 'contain',87 cover: 'cover',88 fill: 'fill',89 inside: 'inside',90 outside: 'outside'91};92 93/**94 * Map external fit property to internal canvas property.95 * @member96 * @private97 */98const mapFitToCanvas = {99 contain: 'embed',100 cover: 'crop',101 fill: 'ignore_aspect',102 inside: 'max',103 outside: 'min'104};105 106/**107 * @private108 */109function isRotationExpected (options) {110 return (options.angle % 360) !== 0 || options.rotationAngle !== 0;111}112 113/**114 * @private115 */116function isResizeExpected (options) {117 return options.width !== -1 || options.height !== -1;118}119 120/**121 * Resize image to `width`, `height` or `width x height`.122 *123 * When both a `width` and `height` are provided, the possible methods by which the image should **fit** these are:124 * - `cover`: (default) Preserving aspect ratio, attempt to ensure the image covers both provided dimensions by cropping/clipping to fit.125 * - `contain`: Preserving aspect ratio, contain within both provided dimensions using "letterboxing" where necessary.126 * - `fill`: Ignore the aspect ratio of the input and stretch to both provided dimensions.127 * - `inside`: Preserving aspect ratio, resize the image to be as large as possible while ensuring its dimensions are less than or equal to both those specified.128 * - `outside`: Preserving aspect ratio, resize the image to be as small as possible while ensuring its dimensions are greater than or equal to both those specified.129 *130 * Some of these values are based on the [object-fit](https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit) CSS property.131 *132 * <img alt="Examples of various values for the fit property when resizing" width="100%" style="aspect-ratio: 998/243" src="/api-resize-fit.svg">133 *134 * When using a **fit** of `cover` or `contain`, the default **position** is `centre`. Other options are:135 * - `sharp.position`: `top`, `right top`, `right`, `right bottom`, `bottom`, `left bottom`, `left`, `left top`.136 * - `sharp.gravity`: `north`, `northeast`, `east`, `southeast`, `south`, `southwest`, `west`, `northwest`, `center` or `centre`.137 * - `sharp.strategy`: `cover` only, dynamically crop using either the `entropy` or `attention` strategy.138 *139 * Some of these values are based on the [object-position](https://developer.mozilla.org/en-US/docs/Web/CSS/object-position) CSS property.140 *141 * The strategy-based approach initially resizes so one dimension is at its target length142 * then repeatedly ranks edge regions, discarding the edge with the lowest score based on the selected strategy.143 * - `entropy`: focus on the region with the highest [Shannon entropy](https://en.wikipedia.org/wiki/Entropy_%28information_theory%29).144 * - `attention`: focus on the region with the highest luminance frequency, colour saturation and presence of skin tones.145 *146 * Possible downsizing kernels are:147 * - `nearest`: Use [nearest neighbour interpolation](http://en.wikipedia.org/wiki/Nearest-neighbor_interpolation).148 * - `linear`: Use a [triangle filter](https://en.wikipedia.org/wiki/Triangular_function).149 * - `cubic`: Use a [Catmull-Rom spline](https://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline).150 * - `mitchell`: Use a [Mitchell-Netravali spline](https://www.cs.utexas.edu/~fussell/courses/cs384g-fall2013/lectures/mitchell/Mitchell.pdf).151 * - `lanczos2`: Use a [Lanczos kernel](https://en.wikipedia.org/wiki/Lanczos_resampling#Lanczos_kernel) with `a=2`.152 * - `lanczos3`: Use a Lanczos kernel with `a=3` (the default).153 * - `mks2013`: Use a [Magic Kernel Sharp](https://johncostella.com/magic/mks.pdf) 2013 kernel, as adopted by Facebook.154 * - `mks2021`: Use a Magic Kernel Sharp 2021 kernel, with more accurate (reduced) sharpening than the 2013 version.155 *156 * When upsampling, these kernels map to `nearest`, `linear` and `cubic` interpolators.157 * Downsampling kernels without a matching upsampling interpolator map to `cubic`.158 *159 * Only one resize can occur per pipeline.160 * Previous calls to `resize` in the same pipeline will be ignored.161 *162 * @example163 * sharp(input)164 * .resize({ width: 100 })165 * .toBuffer()166 * .then(data => {167 * // 100 pixels wide, auto-scaled height168 * });169 *170 * @example171 * sharp(input)172 * .resize({ height: 100 })173 * .toBuffer()174 * .then(data => {175 * // 100 pixels high, auto-scaled width176 * });177 *178 * @example179 * sharp(input)180 * .resize(200, 300, {181 * kernel: sharp.kernel.nearest,182 * fit: 'contain',183 * position: 'right top',184 * background: { r: 255, g: 255, b: 255, alpha: 0.5 }185 * })186 * .toFile('output.png')187 * .then(() => {188 * // output.png is a 200 pixels wide and 300 pixels high image189 * // containing a nearest-neighbour scaled version190 * // contained within the north-east corner of a semi-transparent white canvas191 * });192 *193 * @example194 * const transformer = sharp()195 * .resize({196 * width: 200,197 * height: 200,198 * fit: sharp.fit.cover,199 * position: sharp.strategy.entropy200 * });201 * // Read image data from readableStream202 * // Write 200px square auto-cropped image data to writableStream203 * readableStream204 * .pipe(transformer)205 * .pipe(writableStream);206 *207 * @example208 * sharp(input)209 * .resize(200, 200, {210 * fit: sharp.fit.inside,211 * withoutEnlargement: true212 * })213 * .toFormat('jpeg')214 * .toBuffer()215 * .then(function(outputBuffer) {216 * // outputBuffer contains JPEG image data217 * // no wider and no higher than 200 pixels218 * // and no larger than the input image219 * });220 *221 * @example222 * sharp(input)223 * .resize(200, 200, {224 * fit: sharp.fit.outside,225 * withoutReduction: true226 * })227 * .toFormat('jpeg')228 * .toBuffer()229 * .then(function(outputBuffer) {230 * // outputBuffer contains JPEG image data231 * // of at least 200 pixels wide and 200 pixels high while maintaining aspect ratio232 * // and no smaller than the input image233 * });234 *235 * @example236 * const scaleByHalf = await sharp(input)237 * .metadata()238 * .then(({ width }) => sharp(input)239 * .resize(Math.round(width * 0.5))240 * .toBuffer()241 * );242 *243 * @param {number} [width] - How many pixels wide the resultant image should be. Use `null` or `undefined` to auto-scale the width to match the height.244 * @param {number} [height] - How many pixels high the resultant image should be. Use `null` or `undefined` to auto-scale the height to match the width.245 * @param {Object} [options]246 * @param {number} [options.width] - An alternative means of specifying `width`. If both are present this takes priority.247 * @param {number} [options.height] - An alternative means of specifying `height`. If both are present this takes priority.248 * @param {String} [options.fit='cover'] - How the image should be resized/cropped to fit the target dimension(s), one of `cover`, `contain`, `fill`, `inside` or `outside`.249 * @param {String} [options.position='centre'] - A position, gravity or strategy to use when `fit` is `cover` or `contain`.250 * @param {String|Object} [options.background={r: 0, g: 0, b: 0, alpha: 1}] - background colour when `fit` is `contain`, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to black without transparency.251 * @param {String} [options.kernel='lanczos3'] - The kernel to use for image reduction and the inferred interpolator to use for upsampling. Use the `fastShrinkOnLoad` option to control kernel vs shrink-on-load.252 * @param {Boolean} [options.withoutEnlargement=false] - Do not scale up if the width *or* height are already less than the target dimensions, equivalent to GraphicsMagick's `>` geometry option. This may result in output dimensions smaller than the target dimensions.253 * @param {Boolean} [options.withoutReduction=false] - Do not scale down if the width *or* height are already greater than the target dimensions, equivalent to GraphicsMagick's `<` geometry option. This may still result in a crop to reach the target dimensions.254 * @param {Boolean} [options.fastShrinkOnLoad=true] - Take greater advantage of the JPEG and WebP shrink-on-load feature, which can lead to a slight moiré pattern or round-down of an auto-scaled dimension.255 * @returns {Sharp}256 * @throws {Error} Invalid parameters257 */258function resize (widthOrOptions, height, options) {259 if (isResizeExpected(this.options)) {260 this.options.debuglog('ignoring previous resize options');261 }262 if (this.options.widthPost !== -1) {263 this.options.debuglog('operation order will be: extract, resize, extract');264 }265 if (is.defined(widthOrOptions)) {266 if (is.object(widthOrOptions) && !is.defined(options)) {267 options = widthOrOptions;268 } else if (is.integer(widthOrOptions) && widthOrOptions > 0) {269 this.options.width = widthOrOptions;270 } else {271 throw is.invalidParameterError('width', 'positive integer', widthOrOptions);272 }273 } else {274 this.options.width = -1;275 }276 if (is.defined(height)) {277 if (is.integer(height) && height > 0) {278 this.options.height = height;279 } else {280 throw is.invalidParameterError('height', 'positive integer', height);281 }282 } else {283 this.options.height = -1;284 }285 if (is.object(options)) {286 // Width287 if (is.defined(options.width)) {288 if (is.integer(options.width) && options.width > 0) {289 this.options.width = options.width;290 } else {291 throw is.invalidParameterError('width', 'positive integer', options.width);292 }293 }294 // Height295 if (is.defined(options.height)) {296 if (is.integer(options.height) && options.height > 0) {297 this.options.height = options.height;298 } else {299 throw is.invalidParameterError('height', 'positive integer', options.height);300 }301 }302 // Fit303 if (is.defined(options.fit)) {304 const canvas = mapFitToCanvas[options.fit];305 if (is.string(canvas)) {306 this.options.canvas = canvas;307 } else {308 throw is.invalidParameterError('fit', 'valid fit', options.fit);309 }310 }311 // Position312 if (is.defined(options.position)) {313 const pos = is.integer(options.position)314 ? options.position315 : strategy[options.position] || position[options.position] || gravity[options.position];316 if (is.integer(pos) && (is.inRange(pos, 0, 8) || is.inRange(pos, 16, 17))) {317 this.options.position = pos;318 } else {319 throw is.invalidParameterError('position', 'valid position/gravity/strategy', options.position);320 }321 }322 // Background323 this._setBackgroundColourOption('resizeBackground', options.background);324 // Kernel325 if (is.defined(options.kernel)) {326 if (is.string(kernel[options.kernel])) {327 this.options.kernel = kernel[options.kernel];328 } else {329 throw is.invalidParameterError('kernel', 'valid kernel name', options.kernel);330 }331 }332 // Without enlargement333 if (is.defined(options.withoutEnlargement)) {334 this._setBooleanOption('withoutEnlargement', options.withoutEnlargement);335 }336 // Without reduction337 if (is.defined(options.withoutReduction)) {338 this._setBooleanOption('withoutReduction', options.withoutReduction);339 }340 // Shrink on load341 if (is.defined(options.fastShrinkOnLoad)) {342 this._setBooleanOption('fastShrinkOnLoad', options.fastShrinkOnLoad);343 }344 }345 if (isRotationExpected(this.options) && isResizeExpected(this.options)) {346 this.options.rotateBefore = true;347 }348 return this;349}350 351/**352 * Extend / pad / extrude one or more edges of the image with either353 * the provided background colour or pixels derived from the image.354 * This operation will always occur after resizing and extraction, if any.355 *356 * @example357 * // Resize to 140 pixels wide, then add 10 transparent pixels358 * // to the top, left and right edges and 20 to the bottom edge359 * sharp(input)360 * .resize(140)361 * .extend({362 * top: 10,363 * bottom: 20,364 * left: 10,365 * right: 10,366 * background: { r: 0, g: 0, b: 0, alpha: 0 }367 * })368 * ...369 *370* @example371 * // Add a row of 10 red pixels to the bottom372 * sharp(input)373 * .extend({374 * bottom: 10,375 * background: 'red'376 * })377 * ...378 *379 * @example380 * // Extrude image by 8 pixels to the right, mirroring existing right hand edge381 * sharp(input)382 * .extend({383 * right: 8,384 * background: 'mirror'385 * })386 * ...387 *388 * @param {(number|Object)} extend - single pixel count to add to all edges or an Object with per-edge counts389 * @param {number} [extend.top=0] - number of pixels to add to the top edge, valid values are integers in the range 0-10000390 * @param {number} [extend.left=0] - number of pixels to add to the left edge, valid values are integers in the range 0-10000391 * @param {number} [extend.bottom=0] - number of pixels to add to the bottom edge, valid values are integers in the range 0-10000392 * @param {number} [extend.right=0] - number of pixels to add to the right edge, valid values are integers in the range 0-10000393 * @param {String} [extend.extendWith='background'] - populate new pixels using this method, one of: background, copy, repeat, mirror.394 * @param {String|Object} [extend.background={r: 0, g: 0, b: 0, alpha: 1}] - background colour, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to black without transparency.395 * @returns {Sharp}396 * @throws {Error} Invalid parameters397*/398function extend (extend) {399 if (is.integer(extend)) {400 if (is.inRange(extend, 1, 10000)) {401 this.options.extendTop = extend;402 this.options.extendBottom = extend;403 this.options.extendLeft = extend;404 this.options.extendRight = extend;405 } else {406 throw is.invalidParameterError('extend', 'integer between 1 and 10000', extend);407 }408 } else if (is.object(extend)) {409 if (is.defined(extend.top)) {410 if (is.integer(extend.top) && is.inRange(extend.top, 0, 10000)) {411 this.options.extendTop = extend.top;412 } else {413 throw is.invalidParameterError('top', 'integer between 0 and 10000', extend.top);414 }415 }416 if (is.defined(extend.bottom)) {417 if (is.integer(extend.bottom) && is.inRange(extend.bottom, 0, 10000)) {418 this.options.extendBottom = extend.bottom;419 } else {420 throw is.invalidParameterError('bottom', 'integer between 0 and 10000', extend.bottom);421 }422 }423 if (is.defined(extend.left)) {424 if (is.integer(extend.left) && is.inRange(extend.left, 0, 10000)) {425 this.options.extendLeft = extend.left;426 } else {427 throw is.invalidParameterError('left', 'integer between 0 and 10000', extend.left);428 }429 }430 if (is.defined(extend.right)) {431 if (is.integer(extend.right) && is.inRange(extend.right, 0, 10000)) {432 this.options.extendRight = extend.right;433 } else {434 throw is.invalidParameterError('right', 'integer between 0 and 10000', extend.right);435 }436 }437 this._setBackgroundColourOption('extendBackground', extend.background);438 if (is.defined(extend.extendWith)) {439 if (is.string(extendWith[extend.extendWith])) {440 this.options.extendWith = extendWith[extend.extendWith];441 } else {442 throw is.invalidParameterError('extendWith', 'one of: background, copy, repeat, mirror', extend.extendWith);443 }444 }445 } else {446 throw is.invalidParameterError('extend', 'integer or object', extend);447 }448 return this;449}450 451/**452 * Extract/crop a region of the image.453 *454 * - Use `extract` before `resize` for pre-resize extraction.455 * - Use `extract` after `resize` for post-resize extraction.456 * - Use `extract` twice and `resize` once for extract-then-resize-then-extract in a fixed operation order.457 *458 * @example459 * sharp(input)460 * .extract({ left: left, top: top, width: width, height: height })461 * .toFile(output, function(err) {462 * // Extract a region of the input image, saving in the same format.463 * });464 * @example465 * sharp(input)466 * .extract({ left: leftOffsetPre, top: topOffsetPre, width: widthPre, height: heightPre })467 * .resize(width, height)468 * .extract({ left: leftOffsetPost, top: topOffsetPost, width: widthPost, height: heightPost })469 * .toFile(output, function(err) {470 * // Extract a region, resize, then extract from the resized image471 * });472 *473 * @param {Object} options - describes the region to extract using integral pixel values474 * @param {number} options.left - zero-indexed offset from left edge, an integer between 0 and 100000000475 * @param {number} options.top - zero-indexed offset from top edge, an integer between 0 and 100000000476 * @param {number} options.width - width of region to extract, an integer between 0 and 100000000477 * @param {number} options.height - height of region to extract, an integer between 0 and 100000000478 * @returns {Sharp}479 * @throws {Error} Invalid parameters480 */481function extract (options) {482 const suffix = isResizeExpected(this.options) || this.options.widthPre !== -1 ? 'Post' : 'Pre';483 if (this.options[`width${suffix}`] !== -1) {484 this.options.debuglog('ignoring previous extract options');485 }486 ['left', 'top', 'width', 'height'].forEach(function (name) {487 const value = options[name];488 if (is.integer(value) && is.inRange(value, 0, 100000000)) {489 this.options[name + (name === 'left' || name === 'top' ? 'Offset' : '') + suffix] = value;490 } else {491 throw is.invalidParameterError(name, 'integer between 0 and 100000000', value);492 }493 }, this);494 // Ensure existing rotation occurs before pre-resize extraction495 if (isRotationExpected(this.options) && !isResizeExpected(this.options)) {496 if (this.options.widthPre === -1 || this.options.widthPost === -1) {497 this.options.rotateBefore = true;498 }499 }500 if (this.options.input.autoOrient) {501 this.options.orientBefore = true;502 }503 return this;504}505 506/**507 * Trim pixels from all edges that contain values similar to the given background colour, which defaults to that of the top-left pixel.508 *509 * Images with an alpha channel will use the combined bounding box of alpha and non-alpha channels.510 *511 * If the result of this operation would trim an image to nothing then no change is made.512 *513 * Use the `lineArt` and `threshold` options for control over sensitivity.514 *515 * The `info` response Object will contain `trimOffsetLeft` and `trimOffsetTop` properties.516 *517 * @example518 * // Trim pixels with a colour similar to that of the top-left pixel.519 * await sharp(input)520 * .trim()521 * .toFile(output);522 *523 * @example524 * // Trim pixels with the exact same colour as that of the top-left pixel.525 * await sharp(input)526 * .trim({527 * threshold: 0528 * })529 * .toFile(output);530 *531 * @example532 * // Assume input is line art and trim only pixels with a similar colour to red.533 * const output = await sharp(input)534 * .trim({535 * background: "#FF0000",536 * lineArt: true537 * })538 * .toBuffer();539 *540 * @example541 * // Trim all "yellow-ish" pixels, being more lenient with the higher threshold.542 * const output = await sharp(input)543 * .trim({544 * background: "yellow",545 * threshold: 42,546 * })547 * .toBuffer();548 *549 * @example550 * // Trim image leaving (up to) a 10 pixel margin around the trimmed content.551 * const output = await sharp(input)552 * .trim({553 * margin: 10554 * })555 * .toBuffer();556 *557 * @param {Object} [options]558 * @param {string|Object} [options.background='top-left pixel'] - Background colour, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to that of the top-left pixel.559 * @param {number} [options.threshold=10] - Allowed difference from the above colour, a positive number.560 * @param {boolean} [options.lineArt=false] - Does the input more closely resemble line art (e.g. vector) rather than being photographic?561 * @param {number} [options.margin=0] - Leave a margin around trimmed content, integral number of pixels between 0 and 10000000.562 * @returns {Sharp}563 * @throws {Error} Invalid parameters564 */565function trim (options) {566 this.options.trimThreshold = 10;567 if (is.defined(options)) {568 if (is.object(options)) {569 if (is.defined(options.background)) {570 this._setBackgroundColourOption('trimBackground', options.background);571 }572 if (is.defined(options.threshold)) {573 if (is.number(options.threshold) && options.threshold >= 0) {574 this.options.trimThreshold = options.threshold;575 } else {576 throw is.invalidParameterError('threshold', 'positive number', options.threshold);577 }578 }579 if (is.defined(options.lineArt)) {580 this._setBooleanOption('trimLineArt', options.lineArt);581 }582 if (is.defined(options.margin)) {583 if (is.integer(options.margin) && is.inRange(options.margin, 0, 10000000)) {584 this.options.trimMargin = options.margin;585 } else {586 throw is.invalidParameterError('margin', 'integer between 0 and 10000000', options.margin);587 }588 }589 } else {590 throw is.invalidParameterError('trim', 'object', options);591 }592 }593 if (isRotationExpected(this.options)) {594 this.options.rotateBefore = true;595 }596 return this;597}598 599/**600 * Decorate the Sharp prototype with resize-related functions.601 * @module Sharp602 * @private603 */604module.exports = (Sharp) => {605 Object.assign(Sharp.prototype, {606 resize,607 extend,608 extract,609 trim610 });611 // Class attributes612 Sharp.gravity = gravity;613 Sharp.strategy = strategy;614 Sharp.kernel = kernel;615 Sharp.fit = fit;616 Sharp.position = position;617};618 