Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Mein <mein@cs.umn.edu>2004-12-09 16:09:11 +0300
committerKent Mein <mein@cs.umn.edu>2004-12-09 16:09:11 +0300
commitbdffe196afee7ea2cd5bbdffa3514b4ae2b68196 (patch)
tree80860cf841f227bafe614f068ee20c0b7ca36c48
parenteae5d39899652f86e2b9288a69395dfcec27c8b1 (diff)
This fixes bug #1990
It moves targa, bmp, iris and png loading so that were not opening 2 file handles for each file, and made them like the jpeg stuff. Also cleaned up some minor other stuff. Kent
-rw-r--r--source/blender/imbuf/intern/IMB_bmp.h2
-rw-r--r--source/blender/imbuf/intern/IMB_iris.h2
-rw-r--r--source/blender/imbuf/intern/IMB_png.h2
-rw-r--r--source/blender/imbuf/intern/IMB_targa.h2
-rw-r--r--source/blender/imbuf/intern/bmp.c8
-rw-r--r--source/blender/imbuf/intern/iris.c65
-rw-r--r--source/blender/imbuf/intern/png.c8
-rw-r--r--source/blender/imbuf/intern/targa.c14
-rw-r--r--source/blender/imbuf/intern/writeimage.c51
9 files changed, 32 insertions, 122 deletions
diff --git a/source/blender/imbuf/intern/IMB_bmp.h b/source/blender/imbuf/intern/IMB_bmp.h
index d220c564652..7516c8b4add 100644
--- a/source/blender/imbuf/intern/IMB_bmp.h
+++ b/source/blender/imbuf/intern/IMB_bmp.h
@@ -44,7 +44,7 @@ struct ImBuf;
int imb_is_a_bmp(void *buf);
struct ImBuf *imb_bmp_decode(unsigned char *mem, int size, int flags);
-short imb_savebmp(struct ImBuf *ibuf, int outfile, int flags);
+short imb_savebmp(struct ImBuf *ibuf, char *name, int flags);
#endif
diff --git a/source/blender/imbuf/intern/IMB_iris.h b/source/blender/imbuf/intern/IMB_iris.h
index 046cff62947..74126a1a166 100644
--- a/source/blender/imbuf/intern/IMB_iris.h
+++ b/source/blender/imbuf/intern/IMB_iris.h
@@ -43,7 +43,7 @@
struct ImBuf;
struct ImBuf *imb_loadiris(unsigned char *mem, int flags);
-short imb_saveiris(struct ImBuf * ibuf, int file, int flags);
+short imb_saveiris(struct ImBuf * ibuf, char *name, int flags);
#endif
diff --git a/source/blender/imbuf/intern/IMB_png.h b/source/blender/imbuf/intern/IMB_png.h
index 63638deff00..6557bfb13a0 100644
--- a/source/blender/imbuf/intern/IMB_png.h
+++ b/source/blender/imbuf/intern/IMB_png.h
@@ -45,7 +45,7 @@ struct ImBuf;
int imb_is_a_png(void *buf);
struct ImBuf *imb_loadpng(unsigned char *mem, int size, int flags);
-short imb_savepng(struct ImBuf *ibuf, int file, int flags);
+short imb_savepng(struct ImBuf *ibuf, char *name, int flags);
#endif
diff --git a/source/blender/imbuf/intern/IMB_targa.h b/source/blender/imbuf/intern/IMB_targa.h
index 6aa8f65dca5..2d3b1ab3288 100644
--- a/source/blender/imbuf/intern/IMB_targa.h
+++ b/source/blender/imbuf/intern/IMB_targa.h
@@ -45,7 +45,7 @@ struct ImBuf;
int imb_is_a_targa(void *buf);
struct ImBuf *imb_loadtarga(unsigned char *mem, int flags);
-short imb_savetarga(struct ImBuf * ibuf, int file, int flags);
+short imb_savetarga(struct ImBuf * ibuf, char *name, int flags);
#endif
diff --git a/source/blender/imbuf/intern/bmp.c b/source/blender/imbuf/intern/bmp.c
index cc1040abdcc..2cd9e35ba88 100644
--- a/source/blender/imbuf/intern/bmp.c
+++ b/source/blender/imbuf/intern/bmp.c
@@ -44,10 +44,6 @@
#include "IMB_cmap.h"
#include "IMB_bmp.h"
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
/* some code copied from article on microsoft.com, copied
here for enhanced BMP support in the future
http://www.microsoft.com/msj/defaultframe.asp?page=/msj/0197/mfcp1/mfcp1.htm&nav=/msj/0197/newnav.htm
@@ -199,7 +195,7 @@ int putShortLSB(unsigned short us,FILE *ofile) {
}
/* Found write info at http://users.ece.gatech.edu/~slabaugh/personal/c/bitmapUnix.c */
-short imb_savebmp(struct ImBuf *ibuf, int outfile, int flags) {
+short imb_savebmp(struct ImBuf *ibuf, char *name, int flags) {
BMPINFOHEADER infoheader;
int bytesize, extrabytes, x, y, t, ptr;
@@ -210,7 +206,7 @@ short imb_savebmp(struct ImBuf *ibuf, int outfile, int flags) {
bytesize = (ibuf->x * 3 + extrabytes) * ibuf->y;
data = (uchar *) ibuf->rect;
- ofile = fdopen(outfile,"ab");
+ ofile = fopen(name,"ab");
putShortLSB(19778,ofile); /* "BM" */
putIntLSB(0,ofile); /* This can be 0 for BI_RGB bitmaps */
diff --git a/source/blender/imbuf/intern/iris.c b/source/blender/imbuf/intern/iris.c
index 499154d565a..48b6f9bcf15 100644
--- a/source/blender/imbuf/intern/iris.c
+++ b/source/blender/imbuf/intern/iris.c
@@ -41,10 +41,6 @@
#include "IMB_allocimbuf.h"
#include "IMB_iris.h"
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
typedef struct {
unsigned short imagic; /* stuff saved on disk . . */
unsigned short type;
@@ -115,10 +111,6 @@ static void interleaverow(unsigned char *lptr, unsigned char *cptr, int z, int n
static int compressrow(unsigned char *lbuf, unsigned char *rlebuf, int z, int cnt);
static void lumrow(unsigned char *rgbptr, unsigned char *lumptr, int n);
-/* not used... */
-/* static void copybw(int *lptr, int n); */
-/* static void setalpha(unsigned char *lptr, int n); */
-
/*
* byte order independent read/write of shorts and ints.
*
@@ -423,53 +415,6 @@ static void interleaverow(unsigned char *lptr, unsigned char *cptr, int z, int n
}
}
-/* not used? */
-/*static void copybw(int *lptr, int n) */
-/* int *lptr; */
-/* int n; */
-/*{
- while(n>=8) {
- lptr[0] = 0xff000000+(0x010101*(lptr[0]&0xff));
- lptr[1] = 0xff000000+(0x010101*(lptr[1]&0xff));
- lptr[2] = 0xff000000+(0x010101*(lptr[2]&0xff));
- lptr[3] = 0xff000000+(0x010101*(lptr[3]&0xff));
- lptr[4] = 0xff000000+(0x010101*(lptr[4]&0xff));
- lptr[5] = 0xff000000+(0x010101*(lptr[5]&0xff));
- lptr[6] = 0xff000000+(0x010101*(lptr[6]&0xff));
- lptr[7] = 0xff000000+(0x010101*(lptr[7]&0xff));
- lptr += 8;
- n-=8;
- }
- while(n--) {
- *lptr = 0xff000000+(0x010101*(*lptr&0xff));
- lptr++;
- }
-}
-*/
-
-/* not used ? */
-/*static void setalpha(unsigned char *lptr, int n)*/
-/* unsigned char *lptr; */
-/*{
- while(n>=8) {
- lptr[0*4] = 0xff;
- lptr[1*4] = 0xff;
- lptr[2*4] = 0xff;
- lptr[3*4] = 0xff;
- lptr[4*4] = 0xff;
- lptr[5*4] = 0xff;
- lptr[6*4] = 0xff;
- lptr[7*4] = 0xff;
- lptr += 4*8;
- n -= 8;
- }
- while(n--) {
- *lptr = 0xff;
- lptr += 4;
- }
-}
-*/
-
static void expandrow(unsigned char *optr, unsigned char *iptr, int z)
{
unsigned char pixel, count;
@@ -532,7 +477,7 @@ static void expandrow(unsigned char *optr, unsigned char *iptr, int z)
* Added: zbuf write
*/
-static int output_iris(unsigned int *lptr, int xsize, int ysize, int zsize, int file, int *zptr)
+static int output_iris(unsigned int *lptr, int xsize, int ysize, int zsize, char *name, int *zptr)
{
FILE *outf;
IMAGE *image;
@@ -543,10 +488,10 @@ static int output_iris(unsigned int *lptr, int xsize, int ysize, int zsize, int
int rlebuflen, goodwrite;
goodwrite = 1;
- outf = fdopen(file, "wb");
+ outf = fopen(name, "wb");
if(!outf) {
- perror("fdopen");
+ perror("fopen");
fprintf(stderr,"output_iris: can't open output file\n");
return 0;
}
@@ -690,7 +635,7 @@ static int compressrow(unsigned char *lbuf, unsigned char *rlebuf, int z, int cn
return optr - (unsigned char *)rlebuf;
}
-short imb_saveiris(struct ImBuf * ibuf, int file, int flags)
+short imb_saveiris(struct ImBuf * ibuf, char *name, int flags)
{
short zsize;
int ret;
@@ -701,7 +646,7 @@ short imb_saveiris(struct ImBuf * ibuf, int file, int flags)
IMB_convert_rgba_to_abgr(ibuf->x*ibuf->y, ibuf->rect);
test_endian_zbuf(ibuf);
- ret = output_iris(ibuf->rect, ibuf->x, ibuf->y, zsize, file, ibuf->zbuf);
+ ret = output_iris(ibuf->rect, ibuf->x, ibuf->y, zsize, name, ibuf->zbuf);
/* restore! Quite clumsy, 2 times a switch... maybe better a malloc ? */
IMB_convert_rgba_to_abgr(ibuf->x*ibuf->y, ibuf->rect);
diff --git a/source/blender/imbuf/intern/png.c b/source/blender/imbuf/intern/png.c
index d8ec1a293dc..50b65befe48 100644
--- a/source/blender/imbuf/intern/png.c
+++ b/source/blender/imbuf/intern/png.c
@@ -33,10 +33,6 @@
#include "png.h"
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
#ifdef WIN32
#include "BLI_winstuff.h"
#endif
@@ -106,7 +102,7 @@ static void ReadData( png_structp png_ptr, png_bytep data, png_size_t length)
longjmp(png_jmpbuf(png_ptr), 1);
}
-short imb_savepng(struct ImBuf *ibuf, int file, int flags)
+short imb_savepng(struct ImBuf *ibuf, char *name, int flags)
{
png_structp png_ptr;
png_infop info_ptr;
@@ -198,7 +194,7 @@ short imb_savepng(struct ImBuf *ibuf, int file, int flags)
WriteData,
Flush);
} else {
- fp = fdopen(file, "wb");
+ fp = fopen(name, "wb");
png_init_io(png_ptr, fp);
}
diff --git a/source/blender/imbuf/intern/targa.c b/source/blender/imbuf/intern/targa.c
index 0ad4d0ae77d..a20c9917c06 100644
--- a/source/blender/imbuf/intern/targa.c
+++ b/source/blender/imbuf/intern/targa.c
@@ -30,10 +30,6 @@
* $Id$
*/
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
#ifdef WIN32
#include "BLI_winstuff.h"
#include <io.h>
@@ -242,7 +238,7 @@ static int dumptarga(struct ImBuf * ibuf, FILE * file)
}
-short imb_savetarga(struct ImBuf * ibuf, int file, int flags)
+short imb_savetarga(struct ImBuf * ibuf, char *name, int flags)
{
char buf[20];
FILE *fildes;
@@ -294,14 +290,16 @@ short imb_savetarga(struct ImBuf * ibuf, int file, int flags)
if (ibuf->depth==32) {
buf[17] |= 0x08;
}
+ fildes = fopen(name,"ab");
+
+
+ if (fwrite(buf, 1, 18,fildes) != 18) return (0);
- if (write(file, buf, 18) != 18) return (0);
if (ibuf->cmap){
for (i = 0 ; i<ibuf->maxcol ; i++){
- if (write(file,((uchar *)(ibuf->cmap + i)) + 1,3) != 3) return (0);
+ if (fwrite(((uchar *)(ibuf->cmap + i)) + 1,1,3,fildes) != 3) return (0);
}
}
- fildes = fdopen(file,"ab");
if (ibuf->cmap && (flags & IB_cmap) == 0) IMB_converttocmap(ibuf);
diff --git a/source/blender/imbuf/intern/writeimage.c b/source/blender/imbuf/intern/writeimage.c
index e8dabe8d268..abbc8356aa4 100644
--- a/source/blender/imbuf/intern/writeimage.c
+++ b/source/blender/imbuf/intern/writeimage.c
@@ -55,11 +55,6 @@
#include "IMB_bitplanes.h"
#include "IMB_divers.h"
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-
short IMB_saveiff(struct ImBuf *ibuf,char *naam,int flags)
{
short ok=TRUE,delpl=FALSE;
@@ -73,6 +68,18 @@ short IMB_saveiff(struct ImBuf *ibuf,char *naam,int flags)
if(imb_savejpeg(ibuf, naam, flags)) return (0);
else return (TRUE);
}
+ if (IS_png(ibuf)) {
+ return imb_savepng(ibuf,naam,flags);
+ }
+ if (IS_bmp(ibuf)) {
+ return imb_savebmp(ibuf,naam,flags);
+ }
+ if (IS_tga(ibuf)) {
+ return imb_savetarga(ibuf,naam,flags);
+ }
+ if (IS_iris(ibuf)) {
+ return imb_saveiris(ibuf,naam,flags);
+ }
file = open(naam, O_BINARY | O_RDWR | O_CREAT | O_TRUNC, 0666);
if (file < 0) return (FALSE);
@@ -84,40 +91,8 @@ short IMB_saveiff(struct ImBuf *ibuf,char *naam,int flags)
}
/* Put formats that take a filehandle here */
- if (IS_png(ibuf)) {
- ok = imb_savepng(ibuf,file,flags);
- if (ok) {
- close (file);
- return (ok);
- }
- }
-
- if (IS_bmp(ibuf)) {
- ok = imb_savebmp(ibuf,file,flags);
- if (ok) {
- close (file);
- return (ok);
- }
- }
-
- if (IS_tga(ibuf)) {
- ok = imb_savetarga(ibuf,file,flags);
- if (ok) {
- close (file);
- return (ok);
- }
- }
-
- if (IS_iris(ibuf)) {
- ok = imb_saveiris(ibuf,file,flags);
- if (ok) {
- close (file);
- return (ok);
- }
- }
- if (ok) ok = imb_start_iff(ibuf,file);
-
+ ok = imb_start_iff(ibuf,file);
if (IS_amiga(ibuf)){
IMB_flipy(ibuf);
if (flags & IB_rect){