Changeset 2633


Ignore:
Timestamp:
08/02/08 02:01:08 (5 years ago)
Author:
sam
Message:
  • pixels.c: start supporting grayscale images.
Location:
libpipi/trunk/pipi
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libpipi/trunk/pipi/pipi.h

    r2630 r2633  
    3535    PIPI_PIXELS_BGR24 = 1, 
    3636    PIPI_PIXELS_RGBA_F = 2, 
     37    PIPI_PIXELS_Y_F = 3, 
    3738 
    38     PIPI_PIXELS_MAX = 3 
     39    PIPI_PIXELS_MAX = 4 
    3940} 
    4041pipi_format_t; 
  • libpipi/trunk/pipi/pixels.c

    r2630 r2633  
    6363            bytes = img->w * img->h * 4 * sizeof(float); 
    6464            break; 
     65        case PIPI_PIXELS_Y_F: 
     66            bytes = img->w * img->h * sizeof(float); 
     67            break; 
    6568        default: 
    6669            return NULL; 
     
    177180                } 
    178181    } 
     182    else if(img->last_modified == PIPI_PIXELS_Y_F 
     183                       && type == PIPI_PIXELS_RGBA_F) 
     184    { 
     185        float *src = (float *)img->p[PIPI_PIXELS_Y_F].pixels; 
     186        float *dest = (float *)img->p[PIPI_PIXELS_RGBA_F].pixels; 
     187 
     188        init_tables(); 
     189 
     190        for(y = 0; y < img->h; y++) 
     191            for(x = 0; x < img->w; x++) 
     192            { 
     193                float p = src[y * img->w + x]; 
     194                dest[4 * (y * img->w + x)] = p; 
     195                dest[4 * (y * img->w + x) + 1] = p; 
     196                dest[4 * (y * img->w + x) + 2] = p; 
     197                dest[4 * (y * img->w + x) + 3] = 1.0; 
     198            } 
     199    } 
     200    else if(img->last_modified == PIPI_PIXELS_RGBA_F 
     201                       && type == PIPI_PIXELS_Y_F) 
     202    { 
     203        float *src = (float *)img->p[PIPI_PIXELS_RGBA_F].pixels; 
     204        float *dest = (float *)img->p[PIPI_PIXELS_Y_F].pixels; 
     205 
     206        init_tables(); 
     207 
     208        for(y = 0; y < img->h; y++) 
     209            for(x = 0; x < img->w; x++) 
     210            { 
     211                float p = 0.; 
     212                p += 0.299 * src[4 * (y * img->w + x)]; 
     213                p += 0.587 * src[4 * (y * img->w + x) + 1]; 
     214                p += 0.114 * src[4 * (y * img->w + x) + 2]; 
     215                dest[y * img->w + x] = p; 
     216            } 
     217    } 
    179218    else 
    180219    { 
Note: See TracChangeset for help on using the changeset viewer.