updated .c files to include:
[blender.git] / source / blender / imbuf / intern / util.c
1 /**
2  *
3  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version. The Blender
9  * Foundation also sells licenses for use in proprietary software under
10  * the Blender License.  See http://www.blender.org/BL/ for information
11  * about this.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software Foundation,
20  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21  *
22  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
23  * All rights reserved.
24  *
25  * The Original Code is: all of this file.
26  *
27  * Contributor(s): none yet.
28  *
29  * ***** END GPL/BL DUAL LICENSE BLOCK *****
30  * util.c
31  *
32  * $Id$
33  */
34
35 #include "BLI_blenlib.h"
36
37 #include "imbuf.h"
38 #include "imbuf_patch.h"
39 #include "IMB_imbuf_types.h"
40 #include "IMB_imbuf.h"
41
42 #include "IMB_targa.h"
43 #include "IMB_png.h"
44
45 #ifdef HAVE_CONFIG_H
46 #include <config.h>
47 #endif
48
49 /* from misc_util: flip the bytes from x  */
50 #define GS(x) (((unsigned char *)(x))[0] << 8 | ((unsigned char *)(x))[1])
51
52 /* this one is only def-ed once, strangely... */
53 #define GSS(x) (((uchar *)(x))[1] << 8 | ((uchar *)(x))[0])
54
55 int IMB_ispic(char *name)
56 {
57         struct stat st;
58         int fp, buf[10];
59         int ofs = 0;
60         
61         if (ib_stat(name,&st) == -1) return(0);
62         if (((st.st_mode) & S_IFMT) == S_IFREG){
63                 if ((fp = open(name,O_BINARY|O_RDONLY)) >= 0){
64                         if (read(fp,buf,32)==32){
65                                 close(fp);
66                                 if (buf[ofs] == CAT) ofs += 3;
67                                 if (buf[ofs] == FORM){
68                                         if (buf[ofs + 2] == ILBM) return(AMI);
69                                         if (buf[ofs + 2] == ANIM){
70                                                 if (buf[ofs + 3] == FORM){
71                                                         return(ANIM);
72                                                 }else{
73                                                         return(Anim);
74                                                 }
75                                         }
76                                 } else {
77                                         if (GS(buf) == IMAGIC) return(IMAGIC);
78                                         if (GSS(buf) == IMAGIC) return(IMAGIC);
79                                         if ((BIG_LONG(buf[0]) & 0xfffffff0) == 0xffd8ffe0) return(JPG);
80
81                                         /* at windows there are ".ffl" files with the same magic numnber... 
82                                            besides that,  tim images are not really important anymore! */
83                                         /* if ((BIG_LONG(buf[0]) == 0x10000000) && ((BIG_LONG(buf[1]) & 0xf0ffffff) == 0)) return(TIM); */
84
85                                 }
86                                 if (imb_is_a_png(buf)) return(PNG);
87                                 if (imb_is_a_targa(buf)) return(TGA);
88                                 return(FALSE);
89                         }
90                         close(fp);
91                 }
92         }
93         return(FALSE);
94 }