comparison tools/lib64gfx.c @ 940:ff18d2511843

Remove the doubleMC madness completely. Should be replaced with x/y aspect ratio information for display purposes.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 25 Feb 2015 22:01:23 +0200
parents 5e820addd035
children 8eacbc38b043
comparison
equal deleted inserted replaced
939:5e820addd035 940:ff18d2511843
1010 } 1010 }
1011 1011
1012 1012
1013 // Convert a generic "C64" format bitmap in DMC64Image struct to 1013 // Convert a generic "C64" format bitmap in DMC64Image struct to
1014 // a indexed/paletted bitmap image. 1014 // a indexed/paletted bitmap image.
1015 int dmC64ConvertGenericBMP2Image(DMImage *dst, const DMC64Image *src, const BOOL doubleMC) 1015 int dmC64ConvertGenericBMP2Image(DMImage *dst, const DMC64Image *src)
1016 { 1016 {
1017 Uint8 *dp = dst->data; 1017 Uint8 *dp = dst->data;
1018 const int wdivisor = doubleMC ? 2 : 1;
1019 int yc; 1018 int yc;
1020 1019
1021 // Sanity check arguments 1020 // Sanity check arguments
1022 if (dst == NULL || src == NULL) 1021 if (dst == NULL || src == NULL)
1023 return DMERR_NULLPTR; 1022 return DMERR_NULLPTR;
1052 else 1051 else
1053 *d++ = src->bgcolor; 1052 *d++ = src->bgcolor;
1054 } 1053 }
1055 else 1054 else
1056 // Multicolor variants 1055 // Multicolor variants
1057 for (xc = 0; xc < src->width / wdivisor; xc++) 1056 for (xc = 0; xc < src->width; xc++)
1058 { 1057 {
1059 const int x = xc / 4; 1058 const int x = xc / 4;
1060 const int scroffs = scroffsy + x; 1059 const int scroffs = scroffsy + x;
1061 const int chr = src->screen[0][scroffs]; 1060 const int chr = src->screen[0][scroffs];
1062 const int v = 6 - ((xc * 2) & 6); 1061 const int v = 6 - ((xc * 2) & 6);
1069 case 2: c = src->d023; break; 1068 case 2: c = src->d023; break;
1070 case 3: c = src->color[0][scroffs]; 1069 case 3: c = src->color[0][scroffs];
1071 } 1070 }
1072 1071
1073 *d++ = c; 1072 *d++ = c;
1074 if (doubleMC)
1075 *d++ = c;
1076 } 1073 }
1077 } 1074 }
1078 else 1075 else
1079 { 1076 {
1080 // Perform generic BITMAP conversion 1077 // Perform generic BITMAP conversion
1081 const int bmoffsy = y * src->width; 1078 const int bmoffsy = y * src->ch_width * 8 + yb;
1082 1079
1083 if ((src->type & D64_FMT_MC) == D64_FMT_HIRES) 1080 if ((src->type & D64_FMT_MC) == D64_FMT_HIRES)
1084 // Hi-res bitmap 1081 // Hi-res bitmap
1085 for (xc = 0; xc < src->width; xc++) 1082 for (xc = 0; xc < src->width; xc++)
1086 { 1083 {
1087 const int x = xc / 8; 1084 const int x = xc / 8;
1088 const int scroffs = scroffsy + x; 1085 const int scroffs = scroffsy + x;
1089 const int bmoffs = bmoffsy + (x * 8) + yb; 1086 const int bmoffs = bmoffsy + (x * 8);
1090 const int v = 7 - (xc & 7); 1087 const int v = 7 - (xc & 7);
1091 1088
1092 if ((src->bitmap[0][bmoffs] >> v) & 1) 1089 if ((src->bitmap[0][bmoffs] >> v) & 1)
1093 *d++ = src->screen[0][scroffs] >> 4; 1090 *d++ = src->screen[0][scroffs] >> 4;
1094 else 1091 else
1095 *d++ = src->screen[0][scroffs] & 15; 1092 *d++ = src->screen[0][scroffs] & 15;
1096 } 1093 }
1097 else 1094 else
1098 // Multicolor bitmap and variants 1095 // Multicolor bitmap and variants
1099 for (xc = 0; xc < src->width / wdivisor; xc++) 1096 for (xc = 0; xc < src->width; xc++)
1100 { 1097 {
1101 const int x = xc / 4; 1098 const int x = xc / 4;
1102 const int scroffs = scroffsy + x; 1099 const int scroffs = scroffsy + x;
1103 const int bmoffs = bmoffsy + (x * 8) + yb; 1100 const int bmoffs = bmoffsy + (x * 8);
1104 const int v = 6 - ((xc * 2) & 6); 1101 const int v = 6 - ((xc * 2) & 6);
1105 Uint8 c; 1102 Uint8 c;
1106 1103
1107 if (src->type & D64_FMT_FLI) 1104 if (src->type & D64_FMT_FLI)
1108 { 1105 {
1119 vbank = yb; 1116 vbank = yb;
1120 break; 1117 break;
1121 } 1118 }
1122 c = dmC64GetMCColor(src, (src->bitmap[0][bmoffs] >> v) & 3, 0, vbank, scroffs); 1119 c = dmC64GetMCColor(src, (src->bitmap[0][bmoffs] >> v) & 3, 0, vbank, scroffs);
1123 *d++ = c; 1120 *d++ = c;
1124 if (doubleMC)
1125 *d++ = c;
1126 } 1121 }
1127 else 1122 else
1128 if (src->type & D64_FMT_ILACE) 1123 if (src->type & D64_FMT_ILACE)
1129 { 1124 {
1130 *d++ = dmC64GetMCColor(src, (src->bitmap[0][bmoffs] >> v) & 3, 0, src->laceBank1, scroffs); 1125 *d++ = dmC64GetMCColor(src, (src->bitmap[0][bmoffs] >> v) & 3, 0, src->laceBank1, scroffs);
1131 if (doubleMC) 1126 *d++ = dmC64GetMCColor(src, (src->bitmap[1][bmoffs] >> v) & 3, 0, src->laceBank2, scroffs);
1132 *d++ = dmC64GetMCColor(src, (src->bitmap[1][bmoffs] >> v) & 3, 0, src->laceBank2, scroffs);
1133 } 1127 }
1134 else 1128 else
1135 { 1129 {
1136 c = dmC64GetMCColor(src, (src->bitmap[0][bmoffs] >> v) & 3, 0, 0, scroffs); 1130 c = dmC64GetMCColor(src, (src->bitmap[0][bmoffs] >> v) & 3, 0, 0, scroffs);
1137 *d++ = c; 1131 *d++ = c;
1138 if (doubleMC)
1139 *d++ = c;
1140 } 1132 }
1141 } 1133 }
1142 } 1134 }
1143 dp += dst->pitch; 1135 dp += dst->pitch;
1144 } 1136 }
1145 1137
1146 return DMERR_OK; 1138 return DMERR_OK;
1147 } 1139 }
1148 1140
1149 1141
1150 int dmC64ConvertBMP2Image(DMImage **pdst, const DMC64Image *src, const DMC64ImageFormat *fmt, const BOOL doubleMC) 1142 int dmC64ConvertBMP2Image(DMImage **pdst, const DMC64Image *src, const DMC64ImageFormat *fmt)
1151 { 1143 {
1152 int width, res; 1144 int res;
1153 DMImage *dst; 1145 DMImage *dst;
1154 1146
1155 if (pdst == NULL || src == NULL) 1147 if (pdst == NULL || src == NULL)
1156 return DMERR_NULLPTR; 1148 return DMERR_NULLPTR;
1157 1149
1158 // Calculate output image width
1159 if ((src->type & D64_FMT_MC) && !doubleMC)
1160 width = C64_SCR_WIDTH / 2;
1161 else
1162 width = C64_SCR_WIDTH;
1163
1164 // Allocate image structure 1150 // Allocate image structure
1165 if ((*pdst = dst = dmImageAlloc(width, C64_SCR_HEIGHT)) == NULL) 1151 if ((*pdst = dst = dmImageAlloc(src->width, src->height)) == NULL)
1166 return DMERR_MALLOC; 1152 return DMERR_MALLOC;
1167 1153
1168 // Set palette 1154 // Set palette
1169 dst->pal = (DMColor *) &dmC64Palette; 1155 dst->pal = (DMColor *) &dmC64Palette;
1170 dst->ncolors = C64_NCOLORS; 1156 dst->ncolors = C64_NCOLORS;
1171 dst->constpal = TRUE; 1157 dst->constpal = TRUE;
1172 1158
1173 // Convert 1159 // Convert
1174 if (fmt->convertFrom != NULL) 1160 if (fmt->convertFrom != NULL)
1175 res = fmt->convertFrom(dst, src, doubleMC); 1161 res = fmt->convertFrom(dst, src);
1176 else 1162 else
1177 res = dmC64ConvertGenericBMP2Image(dst, src, doubleMC); 1163 res = dmC64ConvertGenericBMP2Image(dst, src);
1178 1164
1179 return res; 1165 return res;
1180 } 1166 }
1181 1167
1182 1168