1 | /*␊ |
2 | * egpng.c␊ |
3 | * Loading function for PNG images (extension for libeg)␊ |
4 | *␊ |
5 | * Copyright (c) 2012-2013 Cadet-Petit Armel␊ |
6 | * All rights reserved.␊ |
7 | *␊ |
8 | * Redistribution and use in source and binary forms, with or without␊ |
9 | * modification, are permitted provided that the following conditions are␊ |
10 | * met:␊ |
11 | *␊ |
12 | * * Redistributions of source code must retain the above copyright␊ |
13 | * notice, this list of conditions and the following disclaimer.␊ |
14 | *␊ |
15 | * * Redistributions in binary form must reproduce the above copyright␊ |
16 | * notice, this list of conditions and the following disclaimer in the␊ |
17 | * documentation and/or other materials provided with the␊ |
18 | * distribution.␊ |
19 | *␊ |
20 | * * Neither the name of Cadet-Petit Armel nor the names of the␊ |
21 | * contributors may be used to endorse or promote products derived␊ |
22 | * from this software without specific prior written permission.␊ |
23 | *␊ |
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS␊ |
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT␊ |
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR␊ |
27 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT␊ |
28 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,␊ |
29 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT␊ |
30 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,␊ |
31 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY␊ |
32 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT␊ |
33 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE␊ |
34 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.␊ |
35 | */␊ |
36 | ␊ |
37 | #include "libegint.h"␊ |
38 | #include <pexpert/i386/modules.h>␊ |
39 | #include "PngFile.h"␊ |
40 | ␊ |
41 | EG_IMAGE * egDecodePNG(IN UINT8 *FileData, IN UINTN FileDataLength, IN UINTN IconSize, IN BOOLEAN WantAlpha)␊ |
42 | {␊ |
43 | EG_IMAGE *NewImage;␊ |
44 | ␉UINT8␉␉␉␉*imagedata;␊ |
45 | ␉int␉␉␉␉␉width,height;␉␊ |
46 | ␉int␉␉␉␉␉piChannels;␊ |
47 | ␉VOID␉␉␉␉*BkgColor = NULL;␊ |
48 | ␉BOOLEAN␉␉␉␉ret ;␊ |
49 | ␊ |
50 | ␉if (FileData == NULL)␊ |
51 | ␉␉return NULL;␊ |
52 | ␉␊ |
53 | ␉width = 0;␊ |
54 | ␉height = 0;␊ |
55 | ␉piChannels = 0;␊ |
56 | ␉imagedata = NULL;␊ |
57 | ␉BkgColor = NULL;␊ |
58 | ␉ ␊ |
59 | ret = PngLoadData(FileData, FileDataLength, &width,␊ |
60 | ␉␉␉␉␉ &height, &imagedata, &piChannels, BkgColor);␊ |
61 | ␊ |
62 | ␉if (ret == FALSE) ␊ |
63 | ␉{␊ |
64 | ␉␉return NULL;␊ |
65 | ␉}␊ |
66 | ␉␊ |
67 | if (width && height && imagedata && piChannels)␊ |
68 | ␉{␊ |
69 | ␉␉NewImage = egCreateImageFromData((EG_PIXEL*)imagedata, width, height, (piChannels == 4) ? TRUE : FALSE, FALSE);␊ |
70 | ␉␉␊ |
71 | ␉␉if (NewImage) {␊ |
72 | ␉␉␉egFlipRB(NewImage);␉␉␉␉␉␊ |
73 | ␉␉␉return NewImage;␊ |
74 | ␉␉}␊ |
75 | ␊ |
76 | ␉}␊ |
77 | ␉␊ |
78 | ␉return NULL; ␊ |
79 | } |