comparison lib64gfx.c @ 435:e4a3f183e463

Modularize some more.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 03 Nov 2012 16:08:30 +0200
parents ba6ec5ee5929
children afa7f8dd4a8f
comparison
equal deleted inserted replaced
434:380c226c75af 435:e4a3f183e463
5 * (C) Copyright 2012 Tecnic Software productions (TNSP) 5 * (C) Copyright 2012 Tecnic Software productions (TNSP)
6 * 6 *
7 * Please read file 'COPYING' for information on license and distribution. 7 * Please read file 'COPYING' for information on license and distribution.
8 */ 8 */
9 #include "lib64gfx.h" 9 #include "lib64gfx.h"
10 #include <errno.h> 10
11 11
12 const char *dmC64ImageTypeNames[DM_C64IFMT_LAST_TYPE] = 12 const char *dmC64ImageTypeNames[DM_C64IFMT_LAST_TYPE] =
13 { 13 {
14 "hires", 14 "hires",
15 "multicolor", 15 "multicolor",
49 C64_SCR_SCREEN_SIZE, 49 C64_SCR_SCREEN_SIZE,
50 1, 50 1,
51 C64_SCR_EXTRADATA, 51 C64_SCR_EXTRADATA,
52 }; 52 };
53 53
54
55
56 DMImage * dmImageAlloc(int width, int height)
57 {
58 DMImage *img = dmCalloc(1, sizeof(DMImage));
59 if (img == NULL)
60 return NULL;
61
62 img->width = img->pitch = width;
63 img->height = height;
64 img->data = dmMalloc(width * height * sizeof(Uint8));
65 if (img->data == NULL)
66 {
67 dmFree(img);
68 return NULL;
69 }
70
71 return img;
72 }
73
74
75 void dmImageFree(DMImage *img)
76 {
77 if (img != NULL)
78 {
79 if (!img->constpal)
80 {
81 dmFree(img->pal);
82 }
83 dmFree(img->data);
84 dmFree(img);
85 }
86 }
87
88
89 int dmImageGetBytesPerPixel(int format)
90 {
91 switch (format)
92 {
93 case DM_IFMT_PALETTE : return 1;
94
95 case DM_IFMT_RGB_PLANE :
96 case DM_IFMT_RGB : return 3;
97
98 case DM_IFMT_RGBA : return 4;
99
100 default: return 0;
101 }
102 }
103 54
104 55
105 int dmC64ConvertCSData(DMImage *img, 56 int dmC64ConvertCSData(DMImage *img,
106 int xoffs, int yoffs, const Uint8 *buf, 57 int xoffs, int yoffs, const Uint8 *buf,
107 int width, int height, BOOL multicolor, int *colors) 58 int width, int height, BOOL multicolor, int *colors)