public Bitmap CreateImageFromCpc(int length, Param par, bool isSprite = false) { if (!isSprite) { if (bmpCpc[0] == 'M' && bmpCpc[1] == 'J' && bmpCpc[2] == 'H') { DepactOCP(); } else if (bmpCpc[0] == 'P' && bmpCpc[1] == 'K' && (bmpCpc[2] == 'O' || bmpCpc[2] == 'V' || bmpCpc[2] == 'S')) { DepactPK(); } else { if (!InitDatas()) { if (length == 16384) { nbCol = 80; nbLig = 200; } else if (length < 32000) { int l = PackDepack.Depack(bmpCpc, 0, bufTmp); Array.Copy(bufTmp, bmpCpc, l); if (!InitDatas()) { cpcPlus = false; nbCol = maxColsCpc; nbLig = maxLignesCpc; SetPalette(bmpCpc, 0x600, cpcPlus); } } else { if (length > 0x4000) { nbCol = maxColsCpc; nbLig = maxLignesCpc; } } } } } par.cpcPlus = cpcPlus; // Rendu dans un bitmap PC DirectBitmap loc = new DirectBitmap(nbCol << 3, nbLig * 2); for (int y = 0; y < nbLig << 1; y += 2) { int mode = (modeVirtuel >= 5 ? 1 : modeVirtuel >= 3 ? (y & 2) == 0 ? modeVirtuel - 2 : modeVirtuel - 3 : modeVirtuel); int adrCPC = isSprite ? nbCol * (y >> 1) : GetAdrCpc(y); int xBitmap = 0; for (int x = 0; x < nbCol; x++) { byte octet = bmpCpc[adrCPC + x]; switch (mode) { case 0: loc.SetHorLineDouble(xBitmap, y, 4, GetPalCPC(Palette[(octet >> 7) + ((octet & 0x20) >> 3) + ((octet & 0x08) >> 2) + ((octet & 0x02) << 2)])); loc.SetHorLineDouble(xBitmap + 4, y, 4, GetPalCPC(Palette[((octet & 0x40) >> 6) + ((octet & 0x10) >> 2) + ((octet & 0x04) >> 1) + ((octet & 0x01) << 3)])); xBitmap += 8; break; case 1: loc.SetHorLineDouble(xBitmap, y, 2, GetPalCPC(Palette[((octet >> 7) & 1) + ((octet >> 2) & 2)])); loc.SetHorLineDouble(xBitmap + 2, y, 2, GetPalCPC(Palette[((octet >> 6) & 1) + ((octet >> 1) & 2)])); loc.SetHorLineDouble(xBitmap + 4, y, 2, GetPalCPC(Palette[((octet >> 5) & 1) + ((octet >> 0) & 2)])); loc.SetHorLineDouble(xBitmap + 6, y, 2, GetPalCPC(Palette[((octet >> 4) & 1) + ((octet << 1) & 2)])); xBitmap += 8; break; case 2: for (int i = 8; i-- > 0;) { loc.SetPixel(xBitmap, y, GetPalCPC(Palette[(octet >> i) & 1])); loc.SetPixel(xBitmap++, y + 1, GetPalCPC(Palette[(octet >> i) & 1])); } break; } } } return(loc.Bitmap); }
private void DepactPK() { byte[] Palette = new byte[0x100]; // Valeurs par défaut cpcPlus = false; nbCol = 80; nbLig = 200; // //PKSL -> 320x200 STD //PKS3 -> 320x200 Mode 3 //PKSP -> 320x200 PLUS //PKVL -> Overscan STD //PKVP -> Overscan PLUS // cpcPlus = (bmpCpc[3] == 'P') || (bmpCpc[2] == 'O'); bool Overscan = (bmpCpc[2] == 'V') || (bmpCpc[3] == 'V'); bool Std = (bmpCpc[2] == 'S' && bmpCpc[3] == 'L'); if (Std) { for (int i = 0; i < 17; i++) { Palette[i] = bmpCpc[i + 4]; } } int l = PackDepack.Depack(bmpCpc, Std ? 21 : 4, bufTmp); if (Std) { int i = 0; for (int x = 0; x < 80; x++) { for (int y = 0; y < 200; y++) { bmpCpc[x + GetAdrCpc(y << 1)] = bufTmp[i++]; } } } else { Array.Copy(bufTmp, bmpCpc, l); } if (Overscan) { nbCol = maxColsCpc; nbLig = maxLignesCpc; SetPalette(bmpCpc, 0x600, cpcPlus); } else { if (Std) { SetPalette(Palette, 0, cpcPlus); } else { SetPalette(bmpCpc, 0x17D0, cpcPlus); } } }