SourceForge: jmec64/jmec64: changeset 363:d0e4e40483c4
some performance improvements for scaled displays
authorjoergjahnke
Sat Oct 24 13:07:24 2009 +0200 (4 weeks ago)
changeset 363d0e4e40483c4
parent 3620165357b167f
child 364ae0030d9525b
some performance improvements for scaled displays
src/de/joergjahnke/c64/smalldisplays/ScalableVIC6569.java
src/de/joergjahnke/c64/smalldisplays/SmoothingScalableVIC6569.java
     1.1 --- a/src/de/joergjahnke/c64/smalldisplays/ScalableVIC6569.java	Wed Oct 21 23:37:52 2009 +0200
     1.2 +++ b/src/de/joergjahnke/c64/smalldisplays/ScalableVIC6569.java	Sat Oct 24 13:07:24 2009 +0200
     1.3 @@ -26,7 +26,7 @@
     1.4      /**
     1.5       * this is the multiplier we reach using the bit shifting
     1.6       */
     1.7 -    protected final static int MULTIPLIER = 1 << MULTIPLIER_BITS;
     1.8 +    protected final static int MULTIPLIER = 1024;//1 << MULTIPLIER_BITS;
     1.9      /**
    1.10       * scaling factor for devices with a resolution < 320x200 pixels
    1.11       */
    1.12 @@ -64,6 +64,10 @@
    1.13       */
    1.14      protected int savedYFraction;
    1.15      /**
    1.16 +     * do we set more than one pixel in the scaled display when one pixel needs to be painted?
    1.17 +     */
    1.18 +    protected final boolean isScaledUp;
    1.19 +    /**
    1.20       * this many pixels we set when painting a pixel
    1.21       */
    1.22      protected final int pixelsPerPaint;
    1.23 @@ -85,7 +89,8 @@
    1.24          // this is the value we increase the video memory for each pixel per line
    1.25          this.memInc = (int) (getScaling() * MULTIPLIER);
    1.26          // this many pixels we set when painting a pixel
    1.27 -        this.pixelsPerPaint = (int)Math.floor(scaling + 0.99);
    1.28 +        this.pixelsPerPaint = (int) Math.floor(scaling + 0.99);
    1.29 +        this.isScaledUp = this.pixelsPerPaint >= 2;
    1.30      }
    1.31  
    1.32      public void initScreenMemory() {
    1.33 @@ -126,10 +131,19 @@
    1.34          this.borderWidth = (int) (super.getBorderWidth() * getScaling());
    1.35      }
    1.36  
    1.37 +    /**
    1.38 +     * Set the fraction of an y-increment
    1.39 +     *
    1.40 +     * @param yFraction new fraction value
    1.41 +     */
    1.42 +    protected void setYFraction(final int yFraction) {
    1.43 +        this.yFraction = yFraction;
    1.44 +    }
    1.45 +
    1.46      public void gotoPixel(final int x, final int y) {
    1.47          // recalculate variables involved in painting scaled pixels
    1.48          this.nextScaledPixel = (int) ((Math.floor(y * getScaling()) * getBorderWidth() + x * getScaling()) * MULTIPLIER);
    1.49 -        this.yFraction = (int) (y * getScaling() * MULTIPLIER) % MULTIPLIER;
    1.50 +        setYFraction((int) (y * getScaling() * MULTIPLIER) % MULTIPLIER);
    1.51          this.isPaintLine = (y + 1) * getScaling() % 1.0 < getScaling();
    1.52  
    1.53          super.gotoPixel(x, y);
    1.54 @@ -144,19 +158,22 @@
    1.55      }
    1.56  
    1.57      protected void setNextPixel(final int color) {
    1.58 +        // we have to paint this line?
    1.59          if (this.isPaintLine) {
    1.60              // set pixel color
    1.61 -            if(this.pixelsPerPaint == 1) {
    1.62 -                this.scaledPixels[this.nextScaledPixel >> MULTIPLIER_BITS] = color;
    1.63 -            } else {
    1.64 +            if (this.isScaledUp) {
    1.65                  final int pixelsPerPaint_ = this.pixelsPerPaint;
    1.66                  final int borderWidth_ = this.borderWidth;
    1.67 +                final int[] scaledPixels_ = this.scaledPixels;
    1.68 +                final int pos = this.nextScaledPixel >> MULTIPLIER_BITS;
    1.69  
    1.70 -                for(int y = 0 ; y < pixelsPerPaint_ ; ++y) {
    1.71 -                    for(int x = 0 ; x < pixelsPerPaint_ ; ++x) {
    1.72 -                        this.scaledPixels[(this.nextScaledPixel >> MULTIPLIER_BITS) + x + y * borderWidth_] = color;
    1.73 +                for (int y = 0, yy = 0; y < pixelsPerPaint_; ++y, yy += borderWidth_) {
    1.74 +                    for (int x = 0; x < pixelsPerPaint_; ++x) {
    1.75 +                        scaledPixels_[pos + x + yy] = color;
    1.76                      }
    1.77                  }
    1.78 +            } else {
    1.79 +                this.scaledPixels[this.nextScaledPixel >> MULTIPLIER_BITS] = color;
    1.80              }
    1.81          }
    1.82  
    1.83 @@ -177,7 +194,7 @@
    1.84      }
    1.85  
    1.86      protected void restoreSavedPixelPosition() {
    1.87 -        this.yFraction = this.savedYFraction;
    1.88 +        setYFraction(this.savedYFraction);
    1.89          this.nextScaledPixel = this.savedScaledPosition;
    1.90          super.restoreSavedPixelPosition();
    1.91      }
    1.92 @@ -216,7 +233,7 @@
    1.93          this.memInc = in.readInt();
    1.94          this.borderWidth = in.readInt();
    1.95          this.nextScaledPixel = in.readInt();
    1.96 -        this.yFraction = in.readInt();
    1.97 +        setYFraction(in.readInt());
    1.98          this.savedScaledPosition = in.readInt();
    1.99          this.savedYFraction = in.readInt();
   1.100      }
     2.1 --- a/src/de/joergjahnke/c64/smalldisplays/SmoothingScalableVIC6569.java	Wed Oct 21 23:37:52 2009 +0200
     2.2 +++ b/src/de/joergjahnke/c64/smalldisplays/SmoothingScalableVIC6569.java	Sat Oct 24 13:07:24 2009 +0200
     2.3 @@ -23,6 +23,10 @@
     2.4       * saved information whether we have to paint the current line
     2.5       */
     2.6      protected boolean savedPaintLine;
     2.7 +    /**
     2.8 +     * used in calculating the correct color value, needs to be updated when yFraction gets updated
     2.9 +     */
    2.10 +    protected int fracY = 0;
    2.11  
    2.12      /**
    2.13       * Creates a new instance of ScalableVIC6569
    2.14 @@ -43,30 +47,38 @@
    2.15          this.scaledPixels = new int[getBorderWidth() * getBorderHeight()];
    2.16      }
    2.17  
    2.18 +    protected void setYFraction(final int yFraction) {
    2.19 +        super.setYFraction(yFraction);
    2.20 +        this.fracY = (MULTIPLIER - (this.yFraction % MULTIPLIER));
    2.21 +    }
    2.22 +
    2.23      protected void setNextPixel(final int color) {
    2.24 +        final int nextPixel_ = this.nextPixel;
    2.25 +        final int[] pixels_ = this.pixels;
    2.26 +        final int nextScaledPixel_ = this.nextScaledPixel;
    2.27 +
    2.28          // we paint a pixel only if a full line or column has been finished
    2.29 -        if (this.isPaintLine && (this.nextScaledPixel + this.memInc) % 1024 < this.nextScaledPixel % 1024) {
    2.30 +        if (this.isPaintLine && (nextScaledPixel_ + this.memInc) % MULTIPLIER < nextScaledPixel_ % MULTIPLIER) {
    2.31              // index in pixels array of superclass for pixel1
    2.32 -            final int abovePixelIndex = this.nextPixel - TOTAL_WIDTH;
    2.33 +            final int abovePixelIndex = nextPixel_ - TOTAL_WIDTH;
    2.34  
    2.35              // mix colors and set pixel
    2.36 -            final int fracX = (1024 - (this.nextScaledPixel % 1024));
    2.37 -            final int fracY = (1024 - (this.yFraction % 1024));
    2.38 -            final int fraction22 = (fracX * fracY) >> 10;
    2.39 -            final int fraction21 = ((1024 - fracX) * fracY) >> 10;
    2.40 -            final int fraction12 = (fracX * (1024 - fracY)) >> 10;
    2.41 -            final int fraction11 = ((1024 - fracX) * (1024 - fracY)) >> 10;
    2.42 +            final int fracX = (MULTIPLIER - (nextScaledPixel_ % MULTIPLIER));
    2.43 +            final int fraction22 = (fracX * fracY) >> MULTIPLIER_BITS;
    2.44 +            final int fraction21 = ((MULTIPLIER - fracX) * fracY) >> MULTIPLIER_BITS;
    2.45 +            final int fraction12 = (fracX * (MULTIPLIER - fracY)) >> MULTIPLIER_BITS;
    2.46 +            final int fraction11 = ((MULTIPLIER - fracX) * (MULTIPLIER - fracY)) >> MULTIPLIER_BITS;
    2.47  
    2.48 -            this.scaledPixels[this.nextScaledPixel >> MULTIPLIER_BITS] = Color.mix(this.pixels[abovePixelIndex - 1], fraction11, this.pixels[abovePixelIndex], fraction12, this.pixels[this.nextPixel - 1], fraction21, color, fraction22);
    2.49 +            this.scaledPixels[nextScaledPixel_ >> MULTIPLIER_BITS] = Color.mix(pixels_[abovePixelIndex - 1], fraction11, pixels_[abovePixelIndex], fraction12, pixels_[nextPixel_ - 1], fraction21, color, fraction22);
    2.50          }
    2.51  
    2.52          // invalidate the pixel below and to the right of the current pixel as it might need a repaint
    2.53 -        if (color != this.pixels[this.nextPixel]) {
    2.54 +        if (color != pixels_[nextPixel_]) {
    2.55              this.lastPainted[this.paintY + 1][this.hashCol] = -1;
    2.56          }
    2.57  
    2.58          // set pixel in unscaled memory
    2.59 -        this.pixels[this.nextPixel] = color;
    2.60 +        pixels_[nextPixel_] = color;
    2.61  
    2.62          // proceed to next pixel
    2.63          skipPixels(1);