1 | /*␊ |
2 | * libeg/image_view.c␊ |
3 | * Image View handling functions (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 | #include "libegint.h"␊ |
37 | ␊ |
38 | //␊ |
39 | // Basic image view handling␊ |
40 | //␊ |
41 | ␊ |
42 | EG_IMAGE_VIEW * egCreateImageView(IN UINTN Width, IN UINTN Height, IN BOOLEAN HasAlpha, IN UINTN PosX, IN UINTN PosY, IN CHAR16 *Name)␊ |
43 | {␊ |
44 | ␉EG_IMAGE_VIEW * NewImageView;␊ |
45 | ␉NewImageView = (EG_IMAGE_VIEW *) AllocateZeroPool(sizeof(EG_IMAGE_VIEW));␊ |
46 | if (NewImageView == NULL)␊ |
47 | return NULL;␊ |
48 | ␊ |
49 | NewImageView->Image = egCreateImage(Width, Height, HasAlpha);␊ |
50 | if (NewImageView->Image == NULL) {␊ |
51 | ␉␉FreePool(NewImageView);␊ |
52 | return NULL;␊ |
53 | ␉}␊ |
54 | ␉␊ |
55 | NewImageView->Name = PoolPrint(Name);␊ |
56 | if (NewImageView->Name == NULL) {␊ |
57 | egFreeImage(NewImageView->Image);␊ |
58 | ␉␉FreePool(NewImageView);␊ |
59 | return NULL;␊ |
60 | }␊ |
61 | ␊ |
62 | NewImageView->PosX = PosX;␊ |
63 | NewImageView->PosY = PosY;␊ |
64 | return NewImageView;␊ |
65 | }␊ |
66 | ␊ |
67 | EG_IMAGE_VIEW * egCreateImageViewFromData(IN EG_PIXEL *PixelData, IN UINTN Width, IN UINTN Height, IN BOOLEAN HasAlpha, IN UINTN PosX, IN UINTN PosY, IN CHAR16 *Name, BOOLEAN NeedFlip)␊ |
68 | {␊ |
69 | EG_IMAGE_VIEW * NewImageView;␊ |
70 | ␊ |
71 | NewImageView = egCreateImageView(Width, Height, HasAlpha, PosX, PosY, Name);␊ |
72 | if (NewImageView == NULL)␊ |
73 | return NULL;␊ |
74 | ␊ |
75 | NewImageView->Image->NeedFlip = NeedFlip;␊ |
76 | ␊ |
77 | memcpy(NewImageView->Image->PixelData, PixelData, Width * Height * sizeof(EG_PIXEL));␊ |
78 | return NewImageView;␊ |
79 | }␊ |
80 | ␊ |
81 | VOID egFreeImageView(IN EG_IMAGE_VIEW *ImageView)␊ |
82 | {␊ |
83 | if (ImageView != NULL) {␊ |
84 | if (ImageView->Image != NULL)␊ |
85 | egFreeImage(ImageView->Image);␊ |
86 | ␉␉if (ImageView->Name != NULL)␊ |
87 | FreePool(ImageView->Name);␊ |
88 | FreePool(ImageView);␊ |
89 | }␊ |
90 | }␊ |
91 | |