1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: himgutil.cpp,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "precompile.h"
42 static int ImageMagicType(const uchar
* magicno
)
46 if (strncmp((char *) magicno
, "GIF87a", 6) == 0 ||
47 strncmp((char *) magicno
, "GIF89a", 6) == 0)
49 else if (strncmp((char *) magicno
, "VIEW", 4) == 0 ||
50 strncmp((char *) magicno
, "WEIV", 4) == 0)
52 else if (magicno
[0] == 'P' && magicno
[1] >= '1' && magicno
[1] <= '6')
54 /* note: have to check XPM before XBM, as first 2 chars are the same */
55 else if (strncmp((char *) magicno
, "/* XPM */", 9) == 0)
57 else if (strncmp((char *) magicno
, "#define", 7) == 0 ||
58 (magicno
[0] == '/' && magicno
[1] == '*'))
60 else if (magicno
[0] == 0x59 && (magicno
[1] & 0x7f) == 0x26 &&
61 magicno
[2] == 0x6a && (magicno
[3] & 0x7f) == 0x15)
63 else if (magicno
[0] == 'B' && magicno
[1] == 'M')
65 else if (magicno
[0] == 0x52 && magicno
[1] == 0xcc)
67 else if ((magicno
[0] == 0x01 && magicno
[1] == 0xda) ||
68 (magicno
[0] == 0xda && magicno
[1] == 0x01))
70 else if (magicno
[0] == 0x1f && magicno
[1] == 0x9d)
72 else if (magicno
[0] == 0x0a && magicno
[1] <= 5)
74 else if (strncmp((char *) magicno
, "FORM", 4) == 0 &&
75 strncmp((char *) magicno
+ 8, "ILBM", 4) == 0)
77 else if (magicno
[0] == 0 && magicno
[1] == 0 &&
78 magicno
[2] == 2 && magicno
[3] == 0 &&
79 magicno
[4] == 0 && magicno
[5] == 0 &&
80 magicno
[6] == 0 && magicno
[7] == 0)
82 else if (magicno
[4] == 0x00 && magicno
[5] == 0x00 &&
83 magicno
[6] == 0x00 && magicno
[7] == 0x07)
85 else if (strncmp((char *) magicno
, "SIMPLE ", 8) == 0 &&
88 else if (magicno
[0] == 0xff && magicno
[1] == 0xd8 && magicno
[2] == 0xff)
90 else if ((magicno
[0] == 'M' && magicno
[1] == 'M') ||
91 (magicno
[0] == 'I' && magicno
[1] == 'I'))
93 else if (strncmp((char *) magicno
, "%!", 2) == 0 ||
94 strncmp((char *) magicno
, "\004%!", 3) == 0)
96 else if (strncmp((char *) magicno
, "\xd7\xcd\xc6\x9a", 4) == 0 ||
97 strncmp((char *) magicno
, "\x01\x00\x09\x00\x00\x03", 6) == 0)
103 const char *GetEmbImgname(const EmPicture
* empic
)
105 static char fname
[256];
110 if (!empic
|| !empic
->name
[0] || (0 == (ptr
= strrchr(fname
, DIRSEP
))))
112 switch (ImageMagicType((uchar
*) empic
->data
))
169 sprintf(ptr
+ 1, "mz_%s.%s", empic
->name
,ext
);