Exemple #1
0
        public BitmapSource RenderImageSource(ILUT lut)
        {
            bool render = false;

            if (_bitmap == null)
            {
                _pixels = new PinnedIntArray(ScaledData.Width * ScaledData.Height);
                _bitmap = new WriteableBitmap(ScaledData.Width, ScaledData.Height);
                render  = true;
            }
            if (_applyLut && lut != null && !lut.IsValid)
            {
                lut.Recalculate();
                render = true;
            }
            if (render)
            {
                ScaledData.Render((_applyLut ? lut : null), _pixels.Data);
            }

            MultiThread.For(0, _pixels.Count, delegate(int i) { _bitmap.Pixels[i] = _pixels.Data[i]; });
            _bitmap.Rotate(_rotation);
            if (_flipX)
            {
                _bitmap.Flip(WriteableBitmapExtensions.FlipMode.Horizontal);
            }
            if (_flipY)
            {
                _bitmap.Flip(WriteableBitmapExtensions.FlipMode.Vertical);
            }

            _bitmap.Invalidate();

            return(_bitmap);
        }
Exemple #2
0
        public void Render(int[] pixels, int width, int height)
        {
            byte[] data = null;

            if (_scaledData == null)
            {
                if (_scale == 1.0)
                {
                    _scaledData = _originalData;
                }
                else
                {
                    int w = (int)(_originalData.Width * _scale);
                    int h = (int)(_originalData.Height * _scale);
                    data        = BilinearInterpolation.RescaleGrayscale(_originalData.Data, _originalData.Width, _originalData.Height, w, h);
                    _scaledData = new GrayscalePixelDataU8(w, h, data);
                }
            }

            data = _scaledData.Data;

            int ox = (int)(_offsetX * _scale);
            int oy = (int)(_offsetY * _scale);

            MultiThread.For(0, _scaledData.Height, y => {
                for (int i = _scaledData.Width * y, e = i + _scaledData.Width; i < e; i++)
                {
                    if (data[i] > 0)
                    {
                        int p     = (oy * width) + ox + i;
                        pixels[p] = _color;
                    }
                }
            });
        }
        public static byte[] RescaleColor32(byte[] input, int inputWidth, int inputHeight, int outputWidth, int outputHeight)
        {
            byte[] output = new byte[outputWidth * outputHeight * 4];

            double xF = (double)inputWidth / (double)outputWidth;
            double yF = (double)inputHeight / (double)outputHeight;

            int xMax = inputWidth - 1;
            int yMax = inputHeight - 1;

            unchecked {
                MultiThread.For(0, outputHeight, 1, delegate(int y) {
                    double oy0 = y * yF;
                    int oy1    = (int)oy0;                  // rounds down
                    int oy2    = (oy1 == yMax) ? oy1 : oy1 + 1;

                    double dy1 = oy0 - oy1;
                    double dy2 = 1.0 - dy1;

                    int yo0 = outputWidth * y * 4;
                    int yo1 = inputWidth * oy1 * 4;
                    int yo2 = inputWidth * oy2 * 4;

                    double ox0, dx1, dx2;
                    int ox1, ox2;

                    for (int x = 0, px = 0; x < outputWidth; x++)
                    {
                        ox0 = x * xF;
                        ox1 = (int)ox0;
                        ox2 = (ox1 == xMax) ? ox1 : ox1 + 1;

                        dx1 = ox0 - ox1;
                        dx2 = 1.0 - dx1;

                        output[yo0 + px] =
                            (byte)((dy2 * ((dx2 * input[yo1 + ox1]) + (dx1 * input[yo1 + ox2]))) +
                                   (dy1 * ((dx2 * input[yo2 + ox1]) + (dx1 * input[yo2 + ox2]))));
                        px++; ox1++; ox2++;

                        output[yo0 + px] =
                            (byte)((dy2 * ((dx2 * input[yo1 + ox1]) + (dx1 * input[yo1 + ox2]))) +
                                   (dy1 * ((dx2 * input[yo2 + ox1]) + (dx1 * input[yo2 + ox2]))));
                        px++; ox1++; ox2++;

                        output[yo0 + px] =
                            (byte)((dy2 * ((dx2 * input[yo1 + ox1]) + (dx1 * input[yo1 + ox2]))) +
                                   (dy1 * ((dx2 * input[yo2 + ox1]) + (dx1 * input[yo2 + ox2]))));
                        px++; ox1++; ox2++;

                        output[yo0 + px] =
                            (byte)((dy2 * ((dx2 * input[yo1 + ox1]) + (dx1 * input[yo1 + ox2]))) +
                                   (dy1 * ((dx2 * input[yo2 + ox1]) + (dx1 * input[yo2 + ox2]))));
                        px++; ox1++; ox2++;
                    }
                });
            }

            return(output);
        }
Exemple #4
0
    public static IGTResults IGTCheckParallel <Gb>(Gb[] gbs, RbyIntroSequence intro, int numIgts, Func <GameBoy, bool> fn = null, int ss = 0, int ssOverwrite = -1) where Gb : Rby
    {
        intro.ExecuteUntilIGT(gbs[0]);
        byte[]   igtState = gbs[0].SaveState();
        byte[][] states   = new byte[numIgts][];
        MultiThread.For(numIgts, gbs, (gb, i) => {
            states[i] = gb.MakeIGTState(intro, igtState, i);
        });

        return(IGTCheckParallel(gbs, states, fn, ss, ssOverwrite));
    }
Exemple #5
0
    public static IGTResults IGTCheckParallel <Gb>(Gb[] gbs, int timesec, GscIntroSequence intro, int numIgts, Func <Gb, bool> fn = null, int ss = 0, int igtOffset = 0) where Gb : Gsc
    {
        gbs[0].SetTimeSec(timesec);
        intro.ExecuteUntilIGT(gbs[0]);
        byte[]     igtState    = gbs[0].SaveState();
        IGTResults introStates = new IGTResults(numIgts);

        MultiThread.For(numIgts, gbs, (gb, i) => {
            introStates[i] = gb.MakeIGTState(intro, igtState, i + igtOffset);
        });

        return(IGTCheckParallel(gbs, introStates, x => fn == null || fn((Gb)x), ss));
    }
Exemple #6
0
        public static short[] RescaleGrayscale(short[] input, int inputWidth, int inputHeight, int outputWidth, int outputHeight)
        {
            short[] output = new short[outputWidth * outputHeight];

            double xF = (double)inputWidth / (double)outputWidth;
            double yF = (double)inputHeight / (double)outputHeight;

            int xMax = inputWidth - 1;
            int yMax = inputHeight - 1;

            unchecked
            {
                MultiThread.For(0, outputHeight, y =>
                {
                    double oy0 = y * yF;
                    int oy1    = (int)oy0; // rounds down
                    int oy2    = (oy1 == yMax) ? oy1 : oy1 + 1;

                    double dy1 = oy0 - oy1;
                    double dy2 = 1.0 - dy1;

                    int yo0 = outputWidth * y;
                    int yo1 = inputWidth * oy1;
                    int yo2 = inputWidth * oy2;

                    double ox0, dx1, dx2;
                    int ox1, ox2;

                    for (int x = 0; x < outputWidth; x++)
                    {
                        ox0 = x * xF;
                        ox1 = (int)ox0;
                        ox2 = (ox1 == xMax) ? ox1 : ox1 + 1;

                        dx1 = ox0 - ox1;
                        dx2 = 1.0 - dx1;

                        output[yo0 + x] =
                            (short)((dy2 * ((dx2 * input[yo1 + ox1]) + (dx1 * input[yo1 + ox2]))) +
                                    (dy1 * ((dx2 * input[yo2 + ox1]) + (dx1 * input[yo2 + ox2]))));
                    }
                });
            }

            return(output);
        }
Exemple #7
0
 public void Render(ILUT lut, int[] output)
 {
     if (lut == null)
     {
         MultiThread.For(0, Height, delegate(int y) {
             for (int i = Width * y, e = i + Width; i < e; i++)
             {
                 output[i] = _data[i];
             }
         });
     }
     else
     {
         MultiThread.For(0, Height, delegate(int y) {
             for (int i = Width * y, e = i + Width; i < e; i++)
             {
                 output[i] = lut[_data[i]];
             }
         });
     }
 }
Exemple #8
0
 public void Render(ILUT lut, int[] output)
 {
     if (lut == null)
     {
         MultiThread.For(0, Height, delegate(int y) {
             for (int i = Width * y, e = i + Width, p = i * 3; i < e; i++)
             {
                 output[i] = (_data[p++] << 16) | (_data[p++] << 8) | _data[p++];
             }
         });
     }
     else
     {
         MultiThread.For(0, Height, delegate(int y) {
             for (int i = Width * y, e = i + Width, p = i * 3; i < e; i++)
             {
                 output[i] = (lut[_data[p++]] << 16) | (lut[_data[p++]] << 8) | lut[_data[p++]];
             }
         });
     }
 }