Compare commits
No commits in common. "8d369579560210434d08b5774c720cbb53077b76" and "d9d2db45b0061f30d57c0d7488897988be8227a5" have entirely different histories.
8d36957956
...
d9d2db45b0
68
Lib/bmp.c
68
Lib/bmp.c
@ -19,13 +19,15 @@
|
||||
#include "bmp.h" /* maybe I can hardcoded bmp.h here ? */
|
||||
|
||||
/*::------------------------------------------------------------------::*/
|
||||
static void fatal_error(char *txt)
|
||||
static void
|
||||
fatal_error(char *txt)
|
||||
{
|
||||
fprintf(stderr, "BMP: Fatal error: %s\n", txt);
|
||||
exit(10);
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
int Image_BMP_infos(char *nom, int *pw, int *ph, int *pt, int verb)
|
||||
int
|
||||
Image_BMP_infos(char *nom, int *pw, int *ph, int *pt, int verb)
|
||||
{
|
||||
FILE *fp;
|
||||
BMPHEAD head;
|
||||
@ -33,20 +35,17 @@ int foo;
|
||||
|
||||
if (verb) printf("BMP_Infos : '%s'\n", nom);
|
||||
|
||||
if ((fp=fopen(nom, "r")) == NULL) {
|
||||
if ((fp=fopen(nom, "r")) == NULL)
|
||||
{
|
||||
fprintf(stderr, "BMP_Infos: can't open %s\n", nom);
|
||||
return FILE_NOT_FOUND;
|
||||
}
|
||||
|
||||
foo = fread(&head, 1, sizeof(head), fp);
|
||||
if (sizeof(head) != foo) {
|
||||
fprintf(stderr, "%s: err read header of %s\n", __func__, nom);
|
||||
fclose(fp);
|
||||
return UNKNOW_ERROR;
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
if (verb) {
|
||||
if (verb)
|
||||
{
|
||||
printf("signature %c%c filesize %8ld\n",
|
||||
head.id[0], head.id[1], head.filesize);
|
||||
printf("headerSize %8ld infoSize %8ld\n",
|
||||
@ -55,7 +54,7 @@ if (verb) {
|
||||
head.width, head.height, head.bits);
|
||||
printf("colors: used %ld important %ld\n",
|
||||
head.clrused, head.clrimportant);
|
||||
printf("taille structure header %ld\n", sizeof(BMPHEAD));
|
||||
printf("taille structure header %d\n", sizeof(BMPHEAD));
|
||||
}
|
||||
/*
|
||||
* now, return some usefull informations.
|
||||
@ -71,32 +70,28 @@ return 0;
|
||||
*/
|
||||
#define PIX2BYTE(n) ((n+7)/8)
|
||||
|
||||
Image_Desc * Image_BMP_alloc_load(char *nom, int reserved)
|
||||
Image_Desc *
|
||||
Image_BMP_alloc_load(char *nom, int reserved)
|
||||
{
|
||||
(void)reserved; /* WARNING KILLER */
|
||||
FILE *fp;
|
||||
BMPHEAD head;
|
||||
int ligne, foo, larg, col, ligne2;
|
||||
Image_Desc *image;
|
||||
uint8_t *buffer;
|
||||
|
||||
if ((fp=fopen(nom, "r")) == NULL) {
|
||||
if ((fp=fopen(nom, "r")) == NULL)
|
||||
{
|
||||
fprintf(stderr, "can't open %s\n", nom);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
foo = fread(&head, 1, sizeof(head), fp);
|
||||
if (sizeof(head) != foo) {
|
||||
fprintf(stderr, "%s: err read header of %s\n", __func__, nom);
|
||||
fclose(fp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "BMP: on a lu %d octets pour le header.\n", foo);
|
||||
#endif
|
||||
|
||||
if ( head.id[0] != 'B' || head.id[1] != 'M' ) {
|
||||
if ( head.id[0] != 'B' || head.id[1] != 'M' )
|
||||
{
|
||||
fprintf(stderr, "BMP_Alloc_Load: BAD MAGIC %s\n", nom);
|
||||
return NULL;
|
||||
}
|
||||
@ -108,13 +103,15 @@ fprintf(stderr, "BMP_Alloc_Load: image depth = %d\n", head.bits);
|
||||
/*
|
||||
* first step: allocating the memory.
|
||||
*/
|
||||
switch (head.bits) {
|
||||
switch (head.bits)
|
||||
{
|
||||
case 1: case 4: case 8:
|
||||
fprintf(stderr, "bit depth %d not supported\n", head.bits);
|
||||
return NULL;
|
||||
break;
|
||||
|
||||
case 24:
|
||||
|
||||
if ( (image=Image_alloc(head.width, head.height, 3))==NULL)
|
||||
fatal_error("no memory for picture in 'alloc_load'\n");
|
||||
|
||||
@ -122,6 +119,7 @@ switch (head.bits) {
|
||||
fatal_error("no memory for buffer in 'alloc_load'\n");
|
||||
|
||||
larg = head.width * 3;
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -134,7 +132,8 @@ switch (head.bits) {
|
||||
/*
|
||||
* round up to an even dword boundary (?)
|
||||
*/
|
||||
if (larg & 0x00000003) {
|
||||
if (larg & 0x00000003)
|
||||
{
|
||||
larg |= 0x00000003;
|
||||
larg++;
|
||||
}
|
||||
@ -144,14 +143,17 @@ if (larg & 0x00000003) {
|
||||
*
|
||||
* (no default case, filtered in first step)
|
||||
*/
|
||||
switch (head.bits) {
|
||||
switch (head.bits)
|
||||
{
|
||||
case 24:
|
||||
|
||||
for (ligne=0; ligne<head.height; ligne++) {
|
||||
for (ligne=0; ligne<head.height; ligne++)
|
||||
{
|
||||
foo=fread(buffer, 1, larg, fp);
|
||||
/* printf("ligne %5d lu %d\n", ligne, foo); */
|
||||
ligne2 = head.height - ligne - 1;
|
||||
for (col=0; col<head.width; col++) {
|
||||
for (col=0; col<head.width; col++)
|
||||
{
|
||||
(image->Bpix[ligne2])[col] = buffer[ col*3 ];
|
||||
(image->Gpix[ligne2])[col] = buffer[ (col*3) + 1 ];
|
||||
(image->Rpix[ligne2])[col] = buffer[ (col*3) + 2 ];
|
||||
@ -170,9 +172,9 @@ return image;
|
||||
*
|
||||
* et cette fois-ci, on va faire gaffe au boutisme :)
|
||||
*/
|
||||
int Image_BMP_save_24(char *filename, Image_Desc *img, int flag)
|
||||
int
|
||||
Image_BMP_save_24(char *filename, Image_Desc *img, int flag)
|
||||
{
|
||||
(void)flag; /* WARNING KILLER */
|
||||
FILE *fp;
|
||||
long grand;
|
||||
short court;
|
||||
@ -185,7 +187,8 @@ fprintf(stderr, "%s : writing %p to %s, flag=%d\n", __func__,
|
||||
img, filename, flag);
|
||||
#endif
|
||||
|
||||
if ((fp=fopen(filename, "w")) == NULL) {
|
||||
if ((fp=fopen(filename, "w")) == NULL)
|
||||
{
|
||||
fprintf(stderr, "can't open %s for writing\n", filename);
|
||||
return FILE_CREATE_ERR;
|
||||
}
|
||||
@ -203,7 +206,8 @@ if (bytes & 0x3)
|
||||
bytes++;
|
||||
}
|
||||
*/
|
||||
switch (bytes & 0x3) {
|
||||
switch (bytes & 0x3)
|
||||
{
|
||||
case 0: /* OK */ break;
|
||||
case 1: bytes+=3; break;
|
||||
case 2: bytes+=2; break;
|
||||
@ -257,12 +261,14 @@ fflush(fp);
|
||||
if ((buffer=(uint8_t *)malloc(sizeof(uint8_t)*4*img->width)) == NULL)
|
||||
fatal_error("no memory buffer for BMP24 save operation");
|
||||
|
||||
for (line=img->height-1; line>=0; line--) {
|
||||
for (line=img->height-1; line>=0; line--)
|
||||
{
|
||||
ptr = buffer;
|
||||
Rptr = img->Rpix[line];
|
||||
Gptr = img->Gpix[line];
|
||||
Bptr = img->Bpix[line];
|
||||
for (foo=0; foo<img->width; foo++) {
|
||||
for (foo=0; foo<img->width; foo++)
|
||||
{
|
||||
*ptr++ = Bptr[foo];
|
||||
*ptr++ = Gptr[foo];
|
||||
*ptr++ = Rptr[foo];
|
||||
|
12
Lib/dither.c
12
Lib/dither.c
@ -16,9 +16,7 @@ int Image_dither_Bayer_0(Image_Desc *s, Image_Desc *d, int uh)
|
||||
{
|
||||
int dx, dy, x, y, r, g, b;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, s, d, uh);
|
||||
#endif
|
||||
|
||||
/* directement copie de la page 389 de "Bitmapped graphics" de
|
||||
Steve Rimmer. */
|
||||
@ -65,9 +63,7 @@ int Image_dither_crude(Image_Desc *s, Image_Desc *d, int uh)
|
||||
int x, y, r, g, b;
|
||||
int som;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, s, d, uh);
|
||||
#endif
|
||||
|
||||
if (s != d) Image_clear(d, 0, 0, 0);
|
||||
|
||||
@ -109,16 +105,14 @@ return OLL_KORRECT;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*
|
||||
* Il ne marche pas tres fort, ce truc...
|
||||
* ça ne marche pas très fort, ce truc...
|
||||
*/
|
||||
int Image_dither_2x2(Image_Desc *s, Image_Desc *d, int uh)
|
||||
{
|
||||
int x, y, xm, ym;
|
||||
int r, g, b, v;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, s, d, uh);
|
||||
#endif
|
||||
|
||||
x = s->width; xm = (x&1) ? (x-1) : x;
|
||||
y = s->height; ym = (y&1) ? (y-1) : y;
|
||||
@ -159,9 +153,7 @@ int Image_dither_seuil_random(Image_Desc *s, Image_Desc *d, int uh)
|
||||
int x, y, r, g, b;
|
||||
int foo;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, s, d, uh);
|
||||
#endif
|
||||
|
||||
if ( (foo=Image_compare_desc(s, d)) ) {
|
||||
fprintf(stderr, "%s: images are differents %d\n", __func__, foo);
|
||||
@ -200,9 +192,7 @@ int x, y, xa, xb, inc, errR, errG, errB;
|
||||
int r, g, b, dr, dg, db;
|
||||
int foo;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, s, d, uh);
|
||||
#endif
|
||||
|
||||
if ( (foo=Image_compare_desc(s, d)) ) {
|
||||
fprintf(stderr, "%s: images are differents %d\n", __func__, foo);
|
||||
|
@ -18,7 +18,8 @@
|
||||
* Les colors maps sont censees etre compatible avec celles
|
||||
* de FRACTINT, mais il faudrait verifier.
|
||||
*/
|
||||
int Image_save_color_Map(char *file, char *name, RGB_map *map)
|
||||
int
|
||||
Image_save_color_Map(char *file, char *name, RGB_map *map)
|
||||
{
|
||||
int foo;
|
||||
FILE *fp;
|
||||
@ -76,16 +77,15 @@ return OLL_KORRECT;
|
||||
* What is the 'right thing' to do when we get more than
|
||||
* 256 lines of data ? return an error ?
|
||||
*/
|
||||
int Image_load_color_Map(char *file, char *name, RGB_map *where)
|
||||
int
|
||||
Image_load_color_Map(char *file, char *name, RGB_map *where)
|
||||
{
|
||||
FILE *fp;
|
||||
int nbre, r, g, b, foo, errcode;
|
||||
char buffer[256];
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( '%s' '%s' %p )\n", __func__,
|
||||
file, name, where);
|
||||
#endif
|
||||
|
||||
if ( name != NULL ) {
|
||||
if (strlen(name)>IMG_OBJNAME_LEN) return STRING_TOO_LONG;
|
||||
@ -94,8 +94,8 @@ if ( name != NULL ) {
|
||||
else strcpy(where->name, "<noname>");
|
||||
|
||||
/*
|
||||
* patch du 11 Decembre 2001: on utilise une fonction qui recherche le
|
||||
* fichier dans differents endroits. Cf 'mustopen.c' pour + de details.
|
||||
* patch du 11 Décembre 2001: on utilise une fonction qui recherche le
|
||||
* fichier dans differents endroits. Cf 'mustopen.c' pour + de détails.
|
||||
*/
|
||||
if ((fp=Image_must_fopen(file, "r", 0)) == NULL) {
|
||||
/* safety poke */
|
||||
@ -134,12 +134,13 @@ return errcode;
|
||||
*
|
||||
* XXX voir aussi indexcol.x XXX
|
||||
*/
|
||||
int Image_attach_Map(Image_Desc *im, char *nom_map, int flags)
|
||||
int
|
||||
Image_attach_Map(Image_Desc *im, char *nom_map, int flags)
|
||||
{
|
||||
RGB_map map;
|
||||
int foo;
|
||||
|
||||
fprintf(stderr, "%s: cette fonction n'est pas finie\n", __func__);
|
||||
fprintf(stderr, "Image attach Map: cette fonction n'est pas finie\n");
|
||||
foo = Image_load_color_Map(nom_map, "", &map);
|
||||
if (foo == 0) {
|
||||
fprintf(stderr, "Attach Map: foo is zero ?\n");
|
||||
@ -150,7 +151,8 @@ return FUNC_NOT_FINISH;
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/* new 31 Juillet 2000 */
|
||||
|
||||
int Image_make_random_Map(char *nom, RGB_map *map, int nbre)
|
||||
int
|
||||
Image_make_random_Map(char *nom, RGB_map *map, int nbre)
|
||||
{
|
||||
int foo;
|
||||
|
||||
@ -174,7 +176,8 @@ return OLL_KORRECT;
|
||||
/* 21 Sept 2000
|
||||
Make a 2x2x2 color palette.
|
||||
*/
|
||||
int Image_make_222_Map(char *nom, RGB_map *map, int noise)
|
||||
int
|
||||
Image_make_222_Map(char *nom, RGB_map *map, int noise)
|
||||
{
|
||||
int foo, r, g, b;
|
||||
|
||||
@ -203,12 +206,13 @@ return OLL_KORRECT;
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/* 15 Mai 2001
|
||||
* A big classic: the three-sinus color map.
|
||||
* parametres:
|
||||
* paramètres:
|
||||
* 0,1,2 R,G,B period
|
||||
* 3,4,5 R,G,B phase
|
||||
* 6,7 reserved
|
||||
*/
|
||||
int Image_palette_3sinus(char *nom, RGB_map *ou, double pars[8])
|
||||
int
|
||||
Image_palette_3sinus(char *nom, RGB_map *ou, double pars[8])
|
||||
{
|
||||
int foo;
|
||||
double dfoo, dra, dga, dba;
|
||||
@ -237,7 +241,8 @@ return FUNC_IS_BETA;
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/* new 18 Dec 2001
|
||||
*/
|
||||
int Image_mix_palettes(RGB_map *p1, RGB_map *p2, RGB_map *d, char *txt, int k)
|
||||
int
|
||||
Image_mix_palettes(RGB_map *p1, RGB_map *p2, RGB_map *d, char *txt, int k)
|
||||
{
|
||||
int idx, k2;
|
||||
int r1, g1, b1, r2, g2, b2;
|
||||
@ -249,7 +254,8 @@ fprintf(stderr, "Image mix palette: work in progress...\n");
|
||||
k2 = 10000 - k;
|
||||
|
||||
for (idx=0; idx<256; idx++) {
|
||||
if (idx < p1->nbre) {
|
||||
if (idx < p1->nbre)
|
||||
{
|
||||
r1 = p1->red[idx];
|
||||
g1 = p1->green[idx];
|
||||
b1 = p1->blue[idx];
|
||||
@ -284,7 +290,7 @@ return FUNC_IS_BETA;
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/* new 01 aout 2008 */
|
||||
|
||||
/* XXX HACK XXX */ /* please explain ! */
|
||||
/* XXX HACK XXX */
|
||||
double round(double);
|
||||
/* XXX HACK XXX */
|
||||
|
||||
@ -394,6 +400,6 @@ for (foo=0; foo<p->nbre; foo++) {
|
||||
|
||||
fclose(fp);
|
||||
|
||||
return FUNC_IS_BETA;
|
||||
return FULL_NUCKED;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
|
@ -497,7 +497,8 @@ return OLL_KORRECT;
|
||||
* que les images RGB. il manque le GRIS !!!
|
||||
* ! il manque aussi la decompression !
|
||||
*/
|
||||
Image_Desc * Image_TGA_alloc_load(char *nom)
|
||||
Image_Desc *
|
||||
Image_TGA_alloc_load(char *nom)
|
||||
{
|
||||
Tga_file_header head;
|
||||
FILE *fp;
|
||||
@ -515,11 +516,6 @@ if ( (fp=fopen(nom, "rb")) == NULL )
|
||||
memset(&head, 0, sizeof(Tga_file_header));
|
||||
|
||||
foo = Image_TGA_read_header(fp, &head);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: read error %d on header\n", __func__, foo);
|
||||
fclose(fp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if DEBUG_LEVEL > 1
|
||||
printf("TGA ALLOC LOAD: read header -> %d\n", foo);
|
||||
|
Loading…
Reference in New Issue
Block a user