comparison Texture.cpp @ 67:476145dc3441

Слияние
author Ritor1
date Fri, 26 Oct 2012 23:22:41 +0600
parents 05e4b4bd4d64
children b39bdc150e90
comparison
equal deleted inserted replaced
66:5ec98919c8fd 67:476145dc3441
1112 } 1112 }
1113 1113
1114 //----- (0040EAD8) -------------------------------------------------------- 1114 //----- (0040EAD8) --------------------------------------------------------
1115 unsigned int RGBTexture::LoadFromFILE(FILE *pFile, unsigned int mode, unsigned int bCloseFile) 1115 unsigned int RGBTexture::LoadFromFILE(FILE *pFile, unsigned int mode, unsigned int bCloseFile)
1116 { 1116 {
1117 RGBTexture *v4; // esi@1 1117 signed int result; // eax@2
1118 unsigned int result; // eax@2 1118 unsigned char test_byte; // edx@3
1119 unsigned int v6; // ebx@3 1119 //unsigned int read_offset; // ebx@37
1120 unsigned __int16 v7; // cx@5 1120 unsigned int row_position; // edi@40
1121 unsigned __int16 v8; // ax@5 1121 unsigned char value; // cl@63
1122 unsigned int v9; // eax@5 1122 char count; // [sp+50h] [bp-Ch]@43
1123 char v10; // zf@5 1123 unsigned short current_line; // [sp+54h] [bp-8h]@38
1124 signed int v11; // ecx@14 1124 unsigned short *dec_position;
1125 int v12; // ebx@19 1125 unsigned short *temp_dec_position;
1126 signed int v13; // ecx@19 1126 PCXHeader1 psx_head1;
1127 int v14; // ebx@52 1127 PCXHeader2 psx_head2;
1128 unsigned __int16 *v15; // edi@52 1128 short int width, height;
1129 __int16 v16; // ax@54 1129 BYTE color_map[48]; // Colormap for 16-color images
1130 unsigned __int16 *v17; // edi@59 1130
1131 __int16 v18; // ax@61
1132 unsigned __int16 *v19; // edi@66
1133 unsigned __int16 v20; // ax@68
1134 int v21; // eax@73
1135 char DstBuf[60]; // [sp+Ch] [bp-90h]@3
1136 char pColorMap[48]; // [sp+48h] [bp-54h]@3
1137 PCXHeader1 pcxh1; // [sp+78h] [bp-24h]@3
1138 PCXHeader2 pcxh2; // [sp+88h] [bp-14h]@3
1139 int v26; // [sp+90h] [bp-Ch]@51
1140 int v27; // [sp+94h] [bp-8h]@54
1141 unsigned __int8 v28; // [sp+9Bh] [bp-1h]@54
1142
1143 v4 = this;
1144 if (!pFile) 1131 if (!pFile)
1145 return 1; 1132 return 1;
1133
1146 1134
1147 1135 fread(&psx_head1, 1, 16, pFile);
1148 fread(&pcxh1, 1u, 1u, pFile); 1136 fread(&color_map, 1, 48, pFile);
1149 fread(&pcxh1.version, 1u, 1u, pFile); 1137 fread(&psx_head2, 1, 6, pFile);
1150 fread(&pcxh1.encoding, 1u, 1u, pFile); 1138
1151 fread(&pcxh1.bpp, 1u, 1u, pFile); 1139 if (psx_head1.bpp!=8)
1152 v6 = 2; 1140 return 3;
1153 fread(&pcxh1.left, 2u, 1u, pFile); 1141 uWidth=(short int )(psx_head1.right-psx_head1.left+1); // word @ 000014
1154 fread(&pcxh1.up, 2u, 1u, pFile); 1142 uHeight=(short int )(psx_head1.bottom-psx_head1.up+1); // word @ 000016
1155 fread(&pcxh1.right, 2u, 1u, pFile); 1143
1156 fread(&pcxh1.bottom, 2u, 1u, pFile); 1144
1157 fread(&pcxh1.hres, 2u, 1u, pFile); 1145 uNumPixels=uWidth*uHeight; // dword @ 000010
1158 fread(&pcxh1.vres, 2u, 1u, pFile); 1146
1159 fread(pColorMap, 0x30u, 1u, pFile); 1147
1160 fread(&pcxh2, 1u, 1u, pFile); 1148 if ( mode == 0 )
1161 fread(&pcxh2.planes, 1u, 1u, pFile);
1162 fread(&pcxh2.pitch, 2u, 1u, pFile);
1163 fread(&pcxh2.palette_info, 2u, 1u, pFile);
1164 fread(DstBuf, 58u, 1u, pFile);
1165 if ( pcxh1.bpp == 8 )
1166 {
1167 v7 = pcxh1.right - pcxh1.left + 1;
1168 v8 = pcxh1.bottom - pcxh1.up;
1169 v4->uWidth = v7;
1170 ++v8;
1171 v4->uHeight = v8;
1172 v9 = (signed __int16)v7 * (signed __int16)v8;
1173 v10 = mode == 0;
1174 v4->uNumPixels = v9;
1175 if ( v10 )
1176 { 1149 {
1177 if ( v4->pPixels ) 1150 if ( pPixels )
1178 { 1151 {
1179 pAllocator->FreeChunk(v4->pPixels); 1152 pAllocator->FreeChunk(pPixels);
1180 v4->pPixels = 0; 1153 pPixels = 0;
1181 } 1154 }
1182 v4->pPixels = (unsigned __int16 *)pAllocator->AllocNamedChunk( 1155 pPixels = (unsigned __int16 *)pAllocator->AllocNamedChunk(
1183 v4->pPixels, 1156 pPixels,
1184 2 * v4->uNumPixels + 4, 1157 2 * uNumPixels + 4,
1185 v4->pName); 1158 pName);
1186 v6 = 2;
1187 } 1159 }
1188 else 1160 else
1189 { 1161 {
1190 if ( mode != 1 && mode == 2 ) 1162 if ( mode != 1 && mode == 2 )
1191 { 1163 {
1192 operator new(2 * v9 + 4); 1164 pPixels = (unsigned __int16 *)malloc((uNumPixels + 2) * sizeof(unsigned __int16));
1193 v4->pPixels = 0; 1165 field_20 |= 1;
1194 *(unsigned int *)&v4->field_20 |= 1u;
1195 } 1166 }
1196 } 1167 }
1197 if ( v4->pPixels ) 1168
1169
1170
1171
1172 auto pOutPixels = pPixels;
1173
1174 memset(pOutPixels, 0, uNumPixels * sizeof(__int16));
1175
1176 short i=1;
1177 while ( (1<<i) !=uWidth)
1178 {
1179 ++i;
1180 if (i >= 15)
1181 break;
1182 }
1183 field_18=i;
1184 short i_=1;
1185 while ( (1<<i_) !=uHeight)
1186 {
1187 ++i_;
1188 if (i_ >= 15)
1189 break;
1190 }
1191 field_1A=i_;
1192 switch (field_18)
1193 {
1194 case 2: field_1C = 3; break;
1195 case 3: field_1C = 7; break;
1196 case 4: field_1C = 15; break;
1197 case 5: field_1C = 31; break;
1198 case 6: field_1C = 63; break;
1199 case 7: field_1C = 127; break;
1200 case 8: field_1C = 255; break;
1201 case 9: field_1C = 511; break;
1202 case 10: field_1C = 1023; break;
1203 case 11: field_1C = 2047; break;
1204 case 12: field_1C = 4095; break;
1205 }
1206
1207 switch (field_1A)
1208 {
1209 case 2: field_1E = 3; break;
1210 case 3: field_1E = 7; break;
1211 case 4: field_1E = 15; break;
1212 case 5: field_1E = 31; break;
1213 case 6: field_1E = 63; break;
1214 case 7: field_1E = 127; break;
1215 case 8: field_1E = 255; break;
1216 case 9: field_1E = 511; break;
1217 case 10: field_1E = 1023; break;
1218 case 11: field_1E = 2047; break;
1219 case 12: field_1E = 4095; break;
1220 }
1221
1222
1223 fseek(pFile, 128 - 70, SEEK_CUR);
1224
1225
1226 for (uint y = 0; y < uHeight; ++y)
1227 {
1228 unsigned __int16 *pDst = pPixels + y * uWidth;
1229
1230 uint x = 0;
1231 do
1232 {
1233 uint ctrl = 0;
1234 fread(&ctrl, 1, 1, pFile);
1235 if ((ctrl & 0xC0) == 0xC0)
1198 { 1236 {
1199 v11 = 1; 1237 uint uNumPixels = ctrl & 0x3F;
1200 while ( 1 << v11 != v4->uWidth ) 1238 uint clr = 0;
1201 { 1239 fread(&clr, 1, 1, pFile);
1202 ++v11; 1240 for (uint i = 0; i < uNumPixels; ++i)
1203 if ( v11 >= 15 ) 1241 pDst[x++] = pRenderer->uTargetRMask & (clr << (pRenderer->uTargetGBits +
1204 goto LABEL_19; 1242 pRenderer->uTargetRBits +
1205 } 1243 pRenderer->uTargetBBits - 8));
1206 v4->field_18 = v11;
1207 LABEL_19:
1208 v12 = v4->uHeight;
1209 v13 = 1;
1210 while ( 1 << v13 != v12 )
1211 {
1212 ++v13;
1213 if ( v13 >= 15 )
1214 goto LABEL_24;
1215 }
1216 v4->field_1A = v13;
1217 LABEL_24:
1218 switch ( v4->field_18 )
1219 {
1220 case 2:
1221 v4->field_1C = 3;
1222 break;
1223 case 3:
1224 v4->field_1C = 7;
1225 break;
1226 case 4:
1227 v4->field_1C = 15;
1228 break;
1229 case 5:
1230 v4->field_1C = 31;
1231 break;
1232 case 6:
1233 v4->field_1C = 63;
1234 break;
1235 case 7:
1236 v4->field_1C = 127;
1237 break;
1238 case 8:
1239 v4->field_1C = 255;
1240 break;
1241 case 9:
1242 v4->field_1C = 511;
1243 break;
1244 case 10:
1245 v4->field_1C = 1023;
1246 break;
1247 case 11:
1248 v4->field_1C = 2047;
1249 break;
1250 case 12:
1251 v4->field_1C = 4095;
1252 break;
1253 default:
1254 break;
1255 }
1256 switch ( v4->field_1A )
1257 {
1258 case 2:
1259 v4->field_1E = 3;
1260 break;
1261 case 3:
1262 v4->field_1E = 7;
1263 break;
1264 case 4:
1265 v4->field_1E = 15;
1266 break;
1267 case 5:
1268 v4->field_1E = 31;
1269 break;
1270 case 6:
1271 v4->field_1E = 63;
1272 break;
1273 case 7:
1274 v4->field_1E = 127;
1275 break;
1276 case 8:
1277 v4->field_1E = 255;
1278 break;
1279 case 9:
1280 v4->field_1E = 511;
1281 break;
1282 case 10:
1283 v4->field_1E = 1023;
1284 break;
1285 case 11:
1286 v4->field_1E = 2047;
1287 break;
1288 case 12:
1289 v4->field_1E = 4095;
1290 break;
1291 default:
1292 break;
1293 }
1294 if ( pcxh2.planes == 1 )
1295 Abortf("24bit PCX Only!");
1296 if ( pcxh2.planes == 3 )
1297 {
1298 v26 = 0;
1299 if ( v12 > 0 )
1300 {
1301 do
1302 {
1303 v14 = 0;
1304 v15 = &v4->pPixels[v26 * v4->uWidth];
1305 if ( pcxh2.pitch )
1306 {
1307 do
1308 {
1309 fread((char *)&mode + 3, 1u, 1u, pFile);
1310 if ( (BYTE3(mode) & 0xC0) == -64 )
1311 {
1312 BYTE3(mode) &= 0x3Fu;
1313 fread(&v28, 1u, 1u, pFile);
1314 v27 = 0;
1315 v16 = v28;
1316 if ( BYTE3(mode) )
1317 {
1318 do
1319 {
1320 ++v14;
1321 *v15 = LOWORD(pRenderer->uTargetRMask) & (v16 << (pRenderer->uTargetGBits
1322 + pRenderer->uTargetRBits
1323 + pRenderer->uTargetBBits
1324 - 8));
1325 ++v15;
1326 ++v27;
1327 }
1328 while ( v27 < BYTE3(mode) );
1329 }
1330 }
1331 else
1332 {
1333 ++v14;
1334 *v15 = LOWORD(pRenderer->uTargetRMask) & (BYTE3(mode) << (pRenderer->uTargetGBits
1335 + pRenderer->uTargetRBits
1336 + pRenderer->uTargetBBits
1337 - 8));
1338 ++v15;
1339 }
1340 }
1341 while ( v14 < (unsigned __int16)pcxh2.pitch );
1342 }
1343 v17 = &v4->pPixels[v26 * v4->uWidth];
1344 while ( v14 < 2 * (unsigned __int16)pcxh2.pitch )
1345 {
1346 fread((char *)&mode + 3, 1u, 1u, pFile);
1347 if ( (BYTE3(mode) & 0xC0) == -64 )
1348 {
1349 BYTE3(mode) &= 0x3Fu;
1350 fread(&v28, 1u, 1u, pFile);
1351 v27 = 0;
1352 v18 = v28;
1353 if ( BYTE3(mode) )
1354 {
1355 do
1356 {
1357 *v17 |= pRenderer->uTargetGMask & (unsigned __int16)(v18 << (pRenderer->uTargetGBits
1358 + pRenderer->uTargetBBits
1359 - 8));
1360 ++v14;
1361 ++v17;
1362 ++v27;
1363 }
1364 while ( v27 < BYTE3(mode) );
1365 }
1366 }
1367 else
1368 {
1369 *v17 |= pRenderer->uTargetGMask & (unsigned __int16)(BYTE3(mode) << (pRenderer->uTargetGBits
1370 + pRenderer->uTargetBBits
1371 - 8));
1372 ++v14;
1373 ++v17;
1374 }
1375 }
1376 v19 = &v4->pPixels[v26 * v4->uWidth];
1377 while ( v14 < 3 * (unsigned __int16)pcxh2.pitch )
1378 {
1379 fread((char *)&mode + 3, 1u, 1u, pFile);
1380 if ( (BYTE3(mode) & 0xC0) == -64 )
1381 {
1382 BYTE3(mode) &= 0x3Fu;
1383 fread(&v28, 1u, 1u, pFile);
1384 v27 = 0;
1385 v20 = v28;
1386 if ( BYTE3(mode) )
1387 {
1388 do
1389 {
1390 *v19 |= v20 >> (8 - pRenderer->uTargetBBits);
1391 ++v14;
1392 ++v19;
1393 ++v27;
1394 }
1395 while ( v27 < BYTE3(mode) );
1396 }
1397 }
1398 else
1399 {
1400 *v19 |= BYTE3(mode) >> (8 - pRenderer->uTargetBBits);
1401 ++v14;
1402 ++v19;
1403 }
1404 }
1405 v21 = v4->uHeight;
1406 ++v26;
1407 }
1408 while ( v26 < v21 );
1409 }
1410 }
1411 if ( bCloseFile )
1412 fclose(pFile);
1413 result = 0;
1414 } 1244 }
1415 else 1245 else
1416 { 1246 {
1417 result = v6; 1247 pDst[x++] = pRenderer->uTargetRMask & (ctrl << (pRenderer->uTargetGBits +
1248 pRenderer->uTargetRBits +
1249 pRenderer->uTargetBBits - 8));
1418 } 1250 }
1419 } 1251 } while (x < psx_head2.pitch);
1420 else 1252
1421 { 1253
1422 result = 3; 1254
1423 } 1255
1424 1256
1425 return result; 1257 x = 0;
1258 do
1259 {
1260 uint ctrl = 0;
1261 fread(&ctrl, 1, 1, pFile);
1262 if ((ctrl & 0xC0) == 0xC0)
1263 {
1264 uint uNumPixels = ctrl & 0x3F;
1265 uint clr = 0;
1266 fread(&clr, 1, 1, pFile);
1267 for (uint i = 0; i < uNumPixels; ++i)
1268 pDst[x++] |= pRenderer->uTargetGMask & (clr << (pRenderer->uTargetGBits +
1269 pRenderer->uTargetBBits - 8));
1270 }
1271 else
1272 {
1273 pDst[x++] |= pRenderer->uTargetGMask & (ctrl << (pRenderer->uTargetGBits +
1274 pRenderer->uTargetBBits - 8));
1275 }
1276 } while (x < psx_head2.pitch);
1277
1278
1279
1280
1281
1282 x = 0;
1283 do
1284 {
1285 uint ctrl = 0;
1286 fread(&ctrl, 1, 1, pFile);
1287 if ((ctrl & 0xC0) == 0xC0)
1288 {
1289 uint uNumPixels = ctrl & 0x3F;
1290 uint clr = 0;
1291 fread(&clr, 1, 1, pFile);
1292 for (uint i = 0; i < uNumPixels; ++i)
1293 pDst[x++] |= pRenderer->uTargetBMask & (clr >> (8 - pRenderer->uTargetBBits));
1294 }
1295 else
1296 {
1297 pDst[x++] |= pRenderer->uTargetBMask & (ctrl >> (8 - pRenderer->uTargetRBits));
1298 }
1299 } while (x < psx_head2.pitch);
1300 }
1301
1302 if (bCloseFile)
1303 fclose(pFile);
1304 return 0;
1426 } 1305 }
1427 1306
1428 //----- (0040E51F) -------------------------------------------------------- 1307 //----- (0040E51F) --------------------------------------------------------
1429 void RGBTexture::Release() 1308 void RGBTexture::Release()
1430 { 1309 {