Mercurial > hg > dmlib
comparison tools/lib64gfx.c @ 1775:4e4d54135baf
Refactor the c64 bitmap format definitions handling to be more flexible. Again.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 12 Jun 2018 17:12:48 +0300 |
parents | 88354355b8e1 |
children | 5ea4713e9e0f |
comparison
equal
deleted
inserted
replaced
1774:88354355b8e1 | 1775:4e4d54135baf |
---|---|
50 | 50 |
51 void dmC64ImageDump(FILE *fh, const DMC64Image *img, const DMC64ImageFormat *fmt) | 51 void dmC64ImageDump(FILE *fh, const DMC64Image *img, const DMC64ImageFormat *fmt) |
52 { | 52 { |
53 char typeStr[64], typeStr2[64]; | 53 char typeStr[64], typeStr2[64]; |
54 | 54 |
55 dmC64GetImageTypeString(typeStr, sizeof(typeStr), fmt->type, TRUE); | 55 dmC64GetImageTypeString(typeStr, sizeof(typeStr), fmt->format->type, TRUE); |
56 | 56 |
57 if (fmt != NULL) | 57 if (fmt != NULL) |
58 { | 58 { |
59 fprintf(fh, | 59 fprintf(fh, |
60 "Format : %s [%s]\n", | 60 "Format : %s [%s]\n", |
87 | 87 |
88 fprintf(fh, | 88 fprintf(fh, |
89 "Width x Height : %d x %d [%d x %d]\n" | 89 "Width x Height : %d x %d [%d x %d]\n" |
90 "CHwidth x CHheight : %d x %d [%d x %d]\n", | 90 "CHwidth x CHheight : %d x %d [%d x %d]\n", |
91 img->width, img->height, | 91 img->width, img->height, |
92 fmt->width, fmt->height, | 92 fmt->format->width, fmt->format->height, |
93 img->chWidth, img->chHeight, | 93 img->chWidth, img->chHeight, |
94 fmt->chWidth, fmt->chHeight); | 94 fmt->format->chWidth, fmt->format->chHeight); |
95 } | 95 } |
96 else | 96 else |
97 { | 97 { |
98 fprintf(fh, | 98 fprintf(fh, |
99 "Type : %s\n" | 99 "Type : %s\n" |
100 "Width x Height : %d x %d\n" | 100 "Width x Height : %d x %d\n" |
101 "CHwidth x CHheight : %d x %d\n", | 101 "CHwidth x CHheight : %d x %d\n", |
102 typeStr, | 102 typeStr, |
103 fmt->width, fmt->height, | 103 fmt->format->width, fmt->format->height, |
104 fmt->chWidth, fmt->chHeight); | 104 fmt->format->chWidth, fmt->format->chHeight); |
105 } | 105 } |
106 } | 106 } |
107 | 107 |
108 | 108 |
109 void dmSetDefaultC64Palette(DMImage *img) | 109 void dmSetDefaultC64Palette(DMImage *img) |
203 | 203 |
204 if (img == NULL) | 204 if (img == NULL) |
205 return NULL; | 205 return NULL; |
206 | 206 |
207 // Initialize image information | 207 // Initialize image information |
208 img->type = fmt->type; | 208 img->type = fmt->format->type; |
209 img->width = fmt->width; | 209 img->width = fmt->format->width; |
210 img->height = fmt->height; | 210 img->height = fmt->format->height; |
211 img->chWidth = fmt->chWidth; | 211 img->chWidth = fmt->format->chWidth; |
212 img->chHeight = fmt->chHeight; | 212 img->chHeight = fmt->format->chHeight; |
213 img->nbanks = dmC64ImageGetNumBanks(fmt); | 213 img->nbanks = dmC64ImageGetNumBanks(fmt); |
214 | 214 |
215 // Allocate banks | 215 // Allocate banks |
216 if ((img->color = dmCalloc(img->nbanks, sizeof(DMC64MemBlock))) == NULL || | 216 if ((img->color = dmCalloc(img->nbanks, sizeof(DMC64MemBlock))) == NULL || |
217 (img->bitmap = dmCalloc(img->nbanks, sizeof(DMC64MemBlock))) == NULL || | 217 (img->bitmap = dmCalloc(img->nbanks, sizeof(DMC64MemBlock))) == NULL || |
732 { | 732 { |
733 switch (op->subject) | 733 switch (op->subject) |
734 { | 734 { |
735 case DS_SCREEN_RAM: | 735 case DS_SCREEN_RAM: |
736 case DS_COLOR_RAM: | 736 case DS_COLOR_RAM: |
737 *size = fmt->chHeight * fmt->chWidth; | 737 *size = fmt->format->chHeight * fmt->format->chWidth; |
738 break; | 738 break; |
739 | 739 |
740 case DS_BITMAP_RAM: | 740 case DS_BITMAP_RAM: |
741 *size = fmt->chHeight * fmt->chWidth * 8; | 741 *size = fmt->format->chHeight * fmt->format->chWidth * 8; |
742 break; | 742 break; |
743 | 743 |
744 case DS_CHAR_DATA: | 744 case DS_CHAR_DATA: |
745 *size = C64_MAX_CHARS * C64_CHR_SIZE; | 745 *size = C64_MAX_CHARS * C64_CHR_SIZE; |
746 break; | 746 break; |
788 | 788 |
789 if (buf == NULL || buf->data == NULL || img == NULL || fmt == NULL) | 789 if (buf == NULL || buf->data == NULL || img == NULL || fmt == NULL) |
790 return DMERR_NULLPTR; | 790 return DMERR_NULLPTR; |
791 | 791 |
792 // Clear the image structure, set basics | 792 // Clear the image structure, set basics |
793 img->type = fmt->type; | 793 img->type = fmt->format->type; |
794 img->width = fmt->width; | 794 img->width = fmt->format->width; |
795 img->height = fmt->height; | 795 img->height = fmt->format->height; |
796 img->chWidth = fmt->chWidth; | 796 img->chWidth = fmt->format->chWidth; |
797 img->chHeight = fmt->chHeight; | 797 img->chHeight = fmt->format->chHeight; |
798 img->nbanks = dmC64ImageGetNumBanks(fmt); | 798 img->nbanks = dmC64ImageGetNumBanks(fmt); |
799 | 799 |
800 // Perform decoding | 800 // Perform decoding |
801 for (int i = 0; i < D64_MAX_ENCDEC_OPS; i++) | 801 for (int i = 0; i < D64_MAX_ENCDEC_OPS; i++) |
802 { | 802 { |
933 break; | 933 break; |
934 | 934 |
935 case D64_CHCFG_LINEAR: | 935 case D64_CHCFG_LINEAR: |
936 for (int bank = 0; bank < img->nbanks; bank++) | 936 for (int bank = 0; bank < img->nbanks; bank++) |
937 { | 937 { |
938 for (int offs = 0; offs < fmt->chHeight * fmt->chWidth; offs++) | 938 for (int offs = 0; offs < fmt->format->chHeight * fmt->format->chWidth; offs++) |
939 img->screen[bank].data[offs] = offs & 0xff; | 939 img->screen[bank].data[offs] = offs & 0xff; |
940 } | 940 } |
941 break; | 941 break; |
942 | 942 |
943 default: | 943 default: |
966 break; | 966 break; |
967 } | 967 } |
968 } | 968 } |
969 | 969 |
970 // Sanity check certain things .. | 970 // Sanity check certain things .. |
971 if ((fmt->type & D64_FMT_ILACE) && img->laceType == D64_ILACE_NONE) | 971 if ((fmt->format->type & D64_FMT_ILACE) && img->laceType == D64_ILACE_NONE) |
972 { | 972 { |
973 return dmError(DMERR_INTERNAL, | 973 return dmError(DMERR_INTERNAL, |
974 "Format '%s' (%s) has interlace flag set, but interlace type is not set.\n", | 974 "Format '%s' (%s) has interlace flag set, but interlace type is not set.\n", |
975 fmt->name, fmt->fext); | 975 fmt->name, fmt->fext); |
976 } | 976 } |
1176 } | 1176 } |
1177 | 1177 |
1178 dmMemset(dst->data, 0, dst->size); | 1178 dmMemset(dst->data, 0, dst->size); |
1179 | 1179 |
1180 // Check pixel getter function | 1180 // Check pixel getter function |
1181 if (fmt->getPixel != NULL) | 1181 if (fmt->format->getPixel != NULL) |
1182 getPixel = fmt->getPixel; | 1182 getPixel = fmt->format->getPixel; |
1183 else | 1183 else |
1184 getPixel = (fmt->type & D64_FMT_MC) ? fmtGetGenericMCPixel : fmtGetGenericSCPixel; | 1184 getPixel = (fmt->format->type & D64_FMT_MC) ? fmtGetGenericMCPixel : fmtGetGenericSCPixel; |
1185 | 1185 |
1186 // Resolution interlaced pics need to halve the source width | 1186 // Resolution interlaced pics need to halve the source width |
1187 int rwidth = src->width; | 1187 int rwidth = src->width; |
1188 if ((src->type & D64_FMT_ILACE) && src->laceType == D64_ILACE_RES) | 1188 if ((src->type & D64_FMT_ILACE) && src->laceType == D64_ILACE_RES) |
1189 rwidth /= 2; | 1189 rwidth /= 2; |
1311 dst->ncolors = C64_NCOLORS; | 1311 dst->ncolors = C64_NCOLORS; |
1312 dst->constpal = TRUE; | 1312 dst->constpal = TRUE; |
1313 dst->pal = dmDefaultC64Palette; | 1313 dst->pal = dmDefaultC64Palette; |
1314 | 1314 |
1315 // Convert | 1315 // Convert |
1316 if (fmt->convertFrom != NULL) | 1316 if (fmt->format->convertFrom != NULL) |
1317 res = fmt->convertFrom(dst, src, fmt); | 1317 res = fmt->format->convertFrom(dst, src, fmt); |
1318 else | 1318 else |
1319 res = dmC64ConvertGenericBMP2Image(dst, src, fmt); | 1319 res = dmC64ConvertGenericBMP2Image(dst, src, fmt); |
1320 | 1320 |
1321 return res; | 1321 return res; |
1322 } | 1322 } |
1390 // Allocate the basic C64 bitmap image structure | 1390 // Allocate the basic C64 bitmap image structure |
1391 if ((*pdst = dst = dmC64ImageAlloc(fmt)) == NULL) | 1391 if ((*pdst = dst = dmC64ImageAlloc(fmt)) == NULL) |
1392 return DMERR_MALLOC; | 1392 return DMERR_MALLOC; |
1393 | 1393 |
1394 // Convert | 1394 // Convert |
1395 if (fmt->convertTo != NULL) | 1395 if (fmt->format->convertTo != NULL) |
1396 res = fmt->convertTo(dst, src, fmt); | 1396 res = fmt->format->convertTo(dst, src, fmt); |
1397 else | 1397 else |
1398 res = dmC64ConvertGenericImage2BMP(dst, src, fmt); | 1398 res = dmC64ConvertGenericImage2BMP(dst, src, fmt); |
1399 | 1399 |
1400 return res; | 1400 return res; |
1401 } | 1401 } |
1472 return scoreMax; | 1472 return scoreMax; |
1473 } | 1473 } |
1474 else | 1474 else |
1475 return DM_PROBE_SCORE_FALSE; | 1475 return DM_PROBE_SCORE_FALSE; |
1476 } | 1476 } |
1477 | |
1478 | |
1479 void dmC64InitializeFormats(void) | |
1480 { | |
1481 for (int i = 0; i < ndmC64ImageFormats; i++) | |
1482 { | |
1483 DMC64ImageFormat *fmt = &dmC64ImageFormats[i]; | |
1484 if (fmt->format == NULL) | |
1485 fmt->format = &fmt->formatDef; | |
1486 } | |
1487 } |