Bladeren bron

* src/bitmap.c:

+ Implemented caca_set_bitmap_gamma().
tags/v0.99.beta14
Sam Hocevar sam 20 jaren geleden
bovenliggende
commit
3fce0e7843
2 gewijzigde bestanden met toevoegingen van 36 en 7 verwijderingen
  1. +35
    -7
      src/bitmap.c
  2. +1
    -0
      src/caca.h

+ 35
- 7
src/bitmap.c Bestand weergeven

@@ -45,6 +45,7 @@ typedef unsigned int uint32_t;
#include <stdlib.h>
#include <limits.h>
#include <string.h>
#include <math.h>

#include "caca.h"
#include "caca_internals.h"
@@ -170,6 +171,8 @@ struct caca_bitmap
int rleft, gleft, bleft, aleft;
void (*get_hsv)(struct caca_bitmap *, char *, int, int);
int red[256], green[256], blue[256], alpha[256];
float gammaval;
int gammatab[4097];
};
#endif

@@ -223,6 +226,7 @@ struct caca_bitmap *caca_create_bitmap(unsigned int bpp, unsigned int w,
unsigned int bmask, unsigned int amask)
{
struct caca_bitmap *bitmap;
int i;

/* Minor sanity test */
if(!w || !h || !pitch || bpp > 32 || bpp < 8)
@@ -257,7 +261,6 @@ struct caca_bitmap *caca_create_bitmap(unsigned int bpp, unsigned int w,
/* In 8 bpp mode, default to a grayscale palette */
if(bpp == 8)
{
int i;
bitmap->has_palette = 1;
bitmap->has_alpha = 0;
for(i = 0; i < 256; i++)
@@ -268,6 +271,10 @@ struct caca_bitmap *caca_create_bitmap(unsigned int bpp, unsigned int w,
}
}

/* Default gamma value */
for(i = 0; i < 4096; i++)
bitmap->gammatab[i] = i;

return bitmap;
}

@@ -313,6 +320,27 @@ void caca_set_bitmap_palette(struct caca_bitmap *bitmap,
bitmap->has_alpha = has_alpha;
}

/**
* \brief Set the gamma of a bitmap object.
*
* Set the gamma of bitmap.
*
* \param bitmap Bitmap object.
* \param red Gamma value.
*/
void caca_set_bitmap_gamma(struct caca_bitmap *bitmap, float gammaval)
{
int i;

if(gammaval <= 0.0)
return;

bitmap->gammaval = gammaval;

for(i = 0; i < 4096; i++)
bitmap->gammatab[i] = 4096.0 * powf((float)i / 4096.0, 1.0 / gammaval);
}

/**
* \brief Free the memory associated with a bitmap.
*
@@ -370,16 +398,16 @@ static void get_rgba_default(struct caca_bitmap const *bitmap, uint8_t *pixels,

if(bitmap->has_palette)
{
*r += bitmap->red[bits];
*g += bitmap->green[bits];
*b += bitmap->blue[bits];
*r += bitmap->gammatab[bitmap->red[bits]];
*g += bitmap->gammatab[bitmap->green[bits]];
*b += bitmap->gammatab[bitmap->blue[bits]];
*a += bitmap->alpha[bits];
}
else
{
*r += ((bits & bitmap->rmask) >> bitmap->rright) << bitmap->rleft;
*g += ((bits & bitmap->gmask) >> bitmap->gright) << bitmap->gleft;
*b += ((bits & bitmap->bmask) >> bitmap->bright) << bitmap->bleft;
*r += bitmap->gammatab[((bits & bitmap->rmask) >> bitmap->rright) << bitmap->rleft];
*g += bitmap->gammatab[((bits & bitmap->gmask) >> bitmap->gright) << bitmap->gleft];
*b += bitmap->gammatab[((bits & bitmap->bmask) >> bitmap->bright) << bitmap->bleft];
*a += ((bits & bitmap->amask) >> bitmap->aright) << bitmap->aleft;
}
}


+ 1
- 0
src/caca.h Bestand weergeven

@@ -347,6 +347,7 @@ struct caca_bitmap *caca_create_bitmap(unsigned int, unsigned int,
void caca_set_bitmap_palette(struct caca_bitmap *,
unsigned int r[], unsigned int g[],
unsigned int b[], unsigned int a[]);
void caca_set_bitmap_gamma(struct caca_bitmap *, float);
void caca_draw_bitmap(int, int, int, int, struct caca_bitmap const *, void *);
void caca_free_bitmap(struct caca_bitmap *);
/* @} */


Laden…
Annuleren
Opslaan