Changeset 172 for trunk/Lucide/SOURCE


Ignore:
Timestamp:
Dec 29, 2006, 4:04:59 PM (15 years ago)
Author:
Eugene Romanenko
Message:

neuquant optimization

Location:
trunk/Lucide/SOURCE/gui
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Lucide/SOURCE/gui/neuquant.cpp

    r171 r172  
    2525#include "neuquant.h"
    2626#include "globals.h"
    27 
    28 #define FI_RGBA_RED             2
    29 #define FI_RGBA_GREEN           1
    30 #define FI_RGBA_BLUE            0
    31 
    32 // ----------------------------------------------------------------
    33 // Constant definitions
    34 // ----------------------------------------------------------------
    35 
    36 static const int netbiasshift = 4;
    37 static const int ncycles = 100;
    38 static const int intbiasshift = 16;
    39 static const int intbias = (((int)1) << intbiasshift);
    40 static const int gammashift = 10;
    41 static const int betashift = 10;
    42 static const int beta = (intbias >> betashift);
    43 static const int betagamma = (intbias << (gammashift-betashift));
    44 static const int radiusbiasshift = 6;
    45 static const int radiusbias = (((int)1) << radiusbiasshift);
    46 static const int radiusdec = 30;
    47 static const int alphabiasshift = 10;
    48 static const int initalpha = (((int)1) << alphabiasshift);
    49 static const int radbiasshift = 8;
    50 static const int radbias = (((int)1) << radbiasshift);
    51 static const int alpharadbshift = (alphabiasshift+radbiasshift);
    52 static const int alpharadbias = (((int)1) << alpharadbshift);
    5327
    5428
     
    372346// ------------------
    373347
    374 /**
    375  Get a pixel sample at position pos. Handle 4-byte boundary alignment.
    376  @param pos pixel position in a WxHxbpp pixel buffer
    377  @param b blue pixel component
    378  @param g green pixel component
    379  @param r red pixel component
    380 */
    381 void NeuQuantizer::getSample(long pos, int *b, int *g, int *r)
    382 {
    383     // get equivalent pixel coordinates
    384     int x = pos % img_line;
    385     int y = pos / img_line;
    386 
    387     unsigned char *bpos = pixbits + ( ( y * img_line_len ) + x );
    388 
    389     *b = bpos[FI_RGBA_BLUE] << netbiasshift;
    390     *g = bpos[FI_RGBA_GREEN] << netbiasshift;
    391     *r = bpos[FI_RGBA_RED] << netbiasshift;
    392 }
    393 
    394348void NeuQuantizer::learn(int sampling_factor)
    395349{
  • trunk/Lucide/SOURCE/gui/neuquant.h

    r171 r172  
    2424
    2525// NEUQUANT Neural-Net quantization algorithm by Anthony Dekker
     26
     27#define FI_RGBA_RED             2
     28#define FI_RGBA_GREEN           1
     29#define FI_RGBA_BLUE            0
     30
     31// ----------------------------------------------------------------
     32// Constant definitions
     33// ----------------------------------------------------------------
     34
     35#define netbiasshift    4
     36#define ncycles         100
     37#define intbiasshift    16
     38#define intbias         (((int)1) << intbiasshift)
     39#define gammashift      10
     40#define betashift       10
     41#define beta            (intbias >> betashift)
     42#define betagamma       (intbias << (gammashift-betashift))
     43#define radiusbiasshift 6
     44#define radiusbias      (((int)1) << radiusbiasshift)
     45#define radiusdec       30
     46#define alphabiasshift  10
     47#define initalpha       (((int)1) << alphabiasshift)
     48#define radbiasshift    8
     49#define radbias         (((int)1) << radbiasshift)
     50#define alpharadbshift  (alphabiasshift+radbiasshift)
     51#define alpharadbias    (((int)1) << alpharadbshift)
    2652
    2753
     
    102128};
    103129
     130/**
     131 Get a pixel sample at position pos. Handle 4-byte boundary alignment.
     132 @param pos pixel position in a WxHxbpp pixel buffer
     133 @param b blue pixel component
     134 @param g green pixel component
     135 @param r red pixel component
     136*/
     137inline void NeuQuantizer::getSample(long pos, int *b, int *g, int *r)
     138{
     139    // get equivalent pixel coordinates
     140    int x = pos % img_line;
     141    int y = pos / img_line;
     142
     143    unsigned char *bpos = pixbits + ( ( y * img_line_len ) + x );
     144
     145    *b = bpos[FI_RGBA_BLUE] << netbiasshift;
     146    *g = bpos[FI_RGBA_GREEN] << netbiasshift;
     147    *r = bpos[FI_RGBA_RED] << netbiasshift;
     148}
     149
    104150#endif // __NEUQUANT_H
Note: See TracChangeset for help on using the changeset viewer.