1 /* Mednafen - Multi-system Emulator
2  *
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16  */
17 
18 #include "../mednafen.h"
19 #include "surface.h"
20 
MDFN_PixelFormat()21 MDFN_PixelFormat::MDFN_PixelFormat()
22 {
23    bpp = 0;
24    colorspace = 0;
25 
26    Rshift = 0;
27    Gshift = 0;
28    Bshift = 0;
29    Ashift = 0;
30 }
31 
MDFN_PixelFormat(const unsigned int p_colorspace,const uint8 p_rs,const uint8 p_gs,const uint8 p_bs,const uint8 p_as)32 MDFN_PixelFormat::MDFN_PixelFormat(const unsigned int p_colorspace, const uint8 p_rs, const uint8 p_gs, const uint8 p_bs, const uint8 p_as)
33 {
34    bpp = 32;
35    colorspace = p_colorspace;
36 
37    Rshift = p_rs;
38    Gshift = p_gs;
39    Bshift = p_bs;
40    Ashift = p_as;
41 }
42 
MDFN_Surface()43 MDFN_Surface::MDFN_Surface()
44 {
45    format = MDFN_PixelFormat();
46 
47    pixels = NULL;
48    pitchinpix = 0;
49    w = 0;
50    h = 0;
51 }
52 
MDFN_Surface(void * const p_pixels,const uint32 p_width,const uint32 p_height,const uint32 p_pitchinpix,const MDFN_PixelFormat & nf)53 MDFN_Surface::MDFN_Surface(void *const p_pixels, const uint32 p_width, const uint32 p_height, const uint32 p_pitchinpix, const MDFN_PixelFormat &nf)
54 {
55    Init(p_pixels, p_width, p_height, p_pitchinpix, nf);
56 }
57 
Init(void * const p_pixels,const uint32 p_width,const uint32 p_height,const uint32 p_pitchinpix,const MDFN_PixelFormat & nf)58 bool MDFN_Surface::Init(void *const p_pixels, const uint32 p_width, const uint32 p_height, const uint32 p_pitchinpix, const MDFN_PixelFormat &nf)
59 {
60    void *rpix = NULL;
61    assert(nf.bpp == 16 || nf.bpp == 32);
62 
63    format = nf;
64 
65    pixels = NULL;
66 
67    rpix = calloc(1, p_pitchinpix * p_height * (nf.bpp / 8));
68    if(!rpix)
69       return false;
70 
71    pixels = (uint32 *)rpix;
72 
73    w = p_width;
74    h = p_height;
75 
76    pitchinpix = p_pitchinpix;
77 
78    return true;
79 }
80 
81 // When we're converting, only convert the w*h area(AKA leave the last part of the line, pitch32 - w, alone),
82 // for places where we store auxillary information there(graphics viewer in the debugger), and it'll be faster
83 // to boot.
SetFormat(const MDFN_PixelFormat & nf,bool convert)84 void MDFN_Surface::SetFormat(const MDFN_PixelFormat &nf, bool convert)
85 {
86    format = nf;
87 }
88 
~MDFN_Surface()89 MDFN_Surface::~MDFN_Surface()
90 {
91    if(pixels)
92       free(pixels);
93 }
94 
95