Changeset 2609


Ignore:
Timestamp:
07/30/08 00:17:43 (5 years ago)
Author:
sam
Message:
  • pixels.c: speed up the RGBA32 -> float32 conversion, using a simple LUT.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libpipi/trunk/pipi/pixels.c

    r2605 r2609  
    2929#include "pipi_internals.h" 
    3030 
    31 #define C2I(p) (pow(((double)p)/255., 2.2)) 
    32 #define I2C(p) ((int)255.999*pow(((double)p), 1./2.2)) 
     31static void init_tables(void); 
     32 
     33static float u8tof32_table[256]; 
     34static inline float u8tof32(uint8_t p) { return u8tof32_table[(int)p]; } 
     35 
    3336 
    3437/* Return a direct pointer to an image's pixels. */ 
     
    6972        float *dest = (float *)img->p[type].pixels; 
    7073 
     74        init_tables(); 
     75 
    7176        for(y = 0; y < img->h; y++) 
    7277            for(x = 0; x < img->w; x++) 
    7378                for(i = 0; i < 4; i++) 
    7479                    dest[4 * (y * img->w + x) + i] 
    75                         = C2I(src[4 * (y * img->w + x) + i]); 
     80                        = u8tof32(src[4 * (y * img->w + x) + i]); 
    7681    } 
    7782    else if(img->last_modified == PIPI_PIXELS_RGBA_F 
     
    8489            for(x = 0; x < img->w; x++) 
    8590                for(i = 0; i < 4; i++) 
     91                { 
     92                    double p = src[4 * (y * img->w + x) + i]; 
    8693                    dest[4 * (y * img->w + x) + i] 
    87                         = I2C(src[4 * (y * img->w + x) + i]); 
     94                        = (int)(255.999 * pow(p, 1. / 2.2)); 
     95                } 
    8896    } 
    8997    else 
     
    97105} 
    98106 
     107 
     108static void init_tables(void) 
     109{ 
     110    static int done = 0; 
     111    int i; 
     112 
     113    if(done) 
     114        return; 
     115 
     116    for(i = 0; i < 256; i++) 
     117        u8tof32_table[i] = pow((double)i / 255., 2.2); 
     118 
     119    done = 1; 
     120} 
     121 
Note: See TracChangeset for help on using the changeset viewer.