⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 neurquant.pas

📁 ·ImageEn 2.3.0 ImageEn一组用于图像处理、查看和分析的Delphi控件。能够保存几种图像格式
💻 PAS
字号:
(*
Copyright (c) 1998-2007 by HiComponents. All rights reserved.

This software comes without express or implied warranty.
In no case shall the author be liable for any damage or unwanted behavior of any
computer hardware and/or software.

HiComponents grants you the right to include the compiled component
in your application, whether COMMERCIAL, SHAREWARE, or FREEWARE,
BUT YOU MAY NOT DISTRIBUTE THIS SOURCE CODE OR ITS COMPILED .DCU IN ANY FORM.

ImageEn, IEvolution and ImageEn ActiveX may not be included in any commercial,
shareware or freeware libraries or components.

email: support@hicomponents.com

http://www.hicomponents.com
*)

(*
NeuQuant Neural-Net Quantization algorithm by Anthony Dekker.
*)

unit neurquant;

{$R-}
{$Q-}

{$I ie.inc}

interface

uses Windows, Graphics, classes, sysutils, imageen, ImageEnProc, hyiedefs, hyieutils;

type
  TIEQuantizer = class
  private
    fMethod: integer;
    fQT: pointer;
    fGrayScale: boolean;
    fSQ: PRGBROW; // simple quantizer
    fNCol: integer;
    fSrcBmp: TIEBitmap;
    function GetRGBIndex(const cl: TRGB): integer;
  public
    constructor Create(SrcBitmap: TIEBitmap; var ColorMap: array of TRGB; NCol: integer; Quality: integer; qmethod: integer);
    destructor Destroy; override;
    property RGBIndex[const cl: TRGB]: integer read GetRGBIndex;
    property GrayScale: boolean read fGrayScale;
  end;

implementation

uses stdquant;

{$R-}

const

  prime1 = 499;
  prime2 = 491;
  prime3 = 487;
  prime4 = 503;
  minpicturebytes = 3 * prime4;
  netbiasshift = 4;
  ncycles = 100;
  intbiasshift = 16;
  intbias = 1 shl intbiasshift;
  gammashift = 10;
  gamma = 1 shl gammashift;
  betashift = 10;
  beta = intbias shr betashift;
  betagamma = intbias shl (gammashift - betashift);
  radiusbiasshift = 6;
  radiusbias = 1 shl radiusbiasshift;
  radiusdec = 30;
  alphabiasshift = 10;
  initalpha = 1 shl alphabiasshift;
  radbiasshift = 8;
  radbias = 1 shl radbiasshift;
  alpharadbshift = alphabiasshift + radbiasshift;
  alpharadbias = 1 shl alpharadbshift;

type

  pixel = array[0..3] of integer;
  ppixel = ^pixel;

  integerarray = array[0..Maxint div 16] of integer;
  pintegerarray = ^integerarray;
  pixelarray = array[0..Maxint div 32] of pixel;
  ppixelarray = ^pixelarray;

  TVars = record
    netsize: integer;
    maxnetpos: integer;
    initrad: integer;
    initradius: integer;
    alphadec: integer;
    Bitmap: TIEBitmap;
    lengthcount: integer;
    samplefac: integer;
    network: ppixelarray;
    netindex: array[0..255] of integer;
    bias: pintegerarray;
    freq: pintegerarray;
    radpower: pintegerarray;
    bitmapwidth, bitmapheight: integer;
  end;
  PVars = ^TVars;

  // im=width*height dell'immagine
  // Calcola Quality (1..30) in base alla dimensione dell'immagine

function AutoCalcQuality(im: integer): integer;
const
  // Valori di riferimento
  IM1 = 2000;
  Q1 = 2;
  IM2 = 150000;
  Q2 = 15;
begin
  if im < 2000 then
    result := 1 // massima qualit

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -