Exemplo n.º 1
0
        private IVisualization2d GenerateBitmap(ReadOnlyDictionary <string, object> parms)
        {
            int  offset      = Util.GetFromObjDict(parms, P_OFFSET, 0);
            int  width       = Util.GetFromObjDict(parms, P_WIDTH, 1);
            int  height      = Util.GetFromObjDict(parms, P_HEIGHT, 1);
            bool showInvalid = Util.GetFromObjDict(parms, P_SHOWINVALID, false);

            // Check parameters.
            int lastAddress = offset + width * height - 1;

            if ((offset < 0) || (lastAddress >= this.mFileData.Length))
            {
                this.mAppRef.ReportError("Invalid parameter");
                return(null);
            }

            // Set palette.
            PaletteBitmap bitmap = new PaletteBitmap((uint)width, (uint)height);

            bitmap.AddColor(0x00000000);                                        // Transparent
            for (int i = 0; i < NesPalette.Length; i++)
            {
                UInt32 color = 0xFF000000U | (UInt32)NesPalette[i];
                bitmap.AddColor((int)color);                    // Palette color (1 shift)
            }

            // Convert to pixels.
            for (uint y = 0; y < (uint)height; y++)
            {
                for (uint x = 0; x < (uint)width; x++)
                {
                    uint index = y * (uint)width + x;

                    byte palette = this.mFileData[offset + index];
                    if (!showInvalid & ((int)palette > NesPalette.Length))
                    {
                        // Transparent invalid color.
                        bitmap.SetPixel(x, y, 0);
                        continue;
                    }

                    palette = (byte)((palette % NesPalette.Length) + 1);
                    bitmap.SetPixel(x, y, palette);
                }
            }

            return(bitmap.Bitmap);
        }
Exemplo n.º 2
0
 private void GenerateTile(PaletteBitmap bitmap, ChrMapper mapper, uint row, uint col, byte tile)
 {
     for (uint tileY = 0; tileY < 8; tileY++)
     {
         uint drawY = (uint)(row * 8 + tileY);
         for (uint tileX = 0; tileX < 8; tileX++)
         {
             uint drawX = col * 8 + tileX;
             byte color = mapper.GetPixel(tile, tileX, tileY);
             bitmap.SetPixel(drawX, drawY, (byte)(color + 1));
         }
     }
 }
Exemplo n.º 3
0
        private void GenerateTile(PaletteBitmap bitmap, int width, int row, int col, int offset)
        {
            int baseAddr = offset + (row * width + col) * 16;

            for (int tileY = 0; tileY < 8; tileY++)
            {
                uint drawY = (uint)(row * 8 + tileY);
                byte high  = this.mFileData[baseAddr + tileY + 8];
                byte low   = this.mFileData[baseAddr + tileY];
                for (int tileX = 0; tileX < 8; tileX++)
                {
                    uint drawX   = (uint)(col * 8 + tileX);
                    int  shift   = 7 - tileX;
                    int  highBit = ((high >> shift) & 0x01) << 1;
                    int  lowBit  = ((low >> shift) & 0x01);
                    int  pColor  = highBit | lowBit;
                    bitmap.SetPixel(drawX, drawY, (byte)(pColor + 1));
                }
            }
        }