comparison tools/lib64gfx.c @ 2094:4276b8c0fef0

Revamp how the DMImage palette system and color formats work, as preparation for future work on supporting non-indexed/paletted images. It is still messy.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 05 Mar 2019 09:56:47 +0200
parents 221a95caa91e
children 5f8f170f8774
comparison
equal deleted inserted replaced
2093:d17512dbb4ef 2094:4276b8c0fef0
106 indent, fmt->format->chWidth, fmt->format->chHeight); 106 indent, fmt->format->chWidth, fmt->format->chHeight);
107 } 107 }
108 } 108 }
109 109
110 110
111 void dmSetDefaultC64Palette(DMImage *img) 111 int dmSetDefaultC64Palette(DMImage *img)
112 { 112 {
113 img->constpal = TRUE; 113 int res;
114 img->pal = dmDefaultC64Palette; 114 if ((res = dmPaletteAlloc(&(img->pal), C64_NCOLORS, 255)) != DMERR_OK)
115 img->ncolors = C64_NCOLORS; 115 return res;
116 img->ctransp = 255; 116
117 } 117 memcpy(img->pal->colors, dmDefaultC64Palette, img->pal->ncolors * sizeof(DMColor));
118 118
119 119 return DMERR_OK;
120 BOOL dmSetMixedColorC64Palette(DMImage *img) 120 }
121 { 121
122 if (!dmImagePaletteAlloc(img, C64_NCOLORS * C64_NCOLORS, -1)) 122
123 return FALSE; 123 int dmSetMixedColorC64Palette(DMImage *img)
124 {
125 int res;
126 if ((res = dmPaletteAlloc(&(img->pal), C64_NCOLORS * C64_NCOLORS, -1)) != DMERR_OK)
127 return res;
124 128
125 int n = 0; 129 int n = 0;
126 for (int n1 = 0; n1 < C64_NCOLORS; n1++) 130 for (int n1 = 0; n1 < C64_NCOLORS; n1++)
127 { 131 {
128 const DMColor *col1 = &dmDefaultC64Palette[n1]; 132 const DMColor *col1 = &dmDefaultC64Palette[n1];
129 for (int n2 = 0; n2 < C64_NCOLORS; n2++) 133 for (int n2 = 0; n2 < C64_NCOLORS; n2++)
130 { 134 {
131 const DMColor *col2 = &dmDefaultC64Palette[n2]; 135 const DMColor *col2 = &dmDefaultC64Palette[n2];
132 img->pal[n].r = (col1->r + col2->r) / 2; 136 img->pal->colors[n].r = (col1->r + col2->r) / 2;
133 img->pal[n].g = (col1->g + col2->g) / 2; 137 img->pal->colors[n].g = (col1->g + col2->g) / 2;
134 img->pal[n].b = (col1->b + col2->b) / 2; 138 img->pal->colors[n].b = (col1->b + col2->b) / 2;
135 n++; 139 n++;
136 } 140 }
137 } 141 }
138 142
139 return TRUE; 143 return DMERR_OK;
140 } 144 }
141 145
142 146
143 BOOL dmCompareAddr16(const DMGrowBuf *buf, const size_t offs, const Uint16 addr) 147 BOOL dmCompareAddr16(const DMGrowBuf *buf, const size_t offs, const Uint16 addr)
144 { 148 {
1399 if ((*pdst = dst = dmImageAlloc( 1403 if ((*pdst = dst = dmImageAlloc(
1400 src->fmt->width, src->fmt->height, DM_COLFMT_PALETTE, -1)) == NULL) 1404 src->fmt->width, src->fmt->height, DM_COLFMT_PALETTE, -1)) == NULL)
1401 return DMERR_MALLOC; 1405 return DMERR_MALLOC;
1402 1406
1403 // Set partial palette information 1407 // Set partial palette information
1404 dst->ncolors = C64_NCOLORS; 1408 if ((res = dmSetDefaultC64Palette(dst)) != DMERR_OK)
1405 dst->constpal = TRUE; 1409 return res;
1406 dst->pal = dmDefaultC64Palette;
1407 1410
1408 // Convert 1411 // Convert
1409 if (fmt->format->convertFrom != NULL) 1412 if (fmt->format->convertFrom != NULL)
1410 res = fmt->format->convertFrom(dst, src, fmt, spec); 1413 res = fmt->format->convertFrom(dst, src, fmt, spec);
1411 else 1414 else