Esempio n. 1
0
  public static int getFormat(CapabilitiesImmutable rCaps) {
    int fmt = PixelFormat.UNKNOWN;

    if (!rCaps.isBackgroundOpaque()) {
      fmt = PixelFormat.TRANSLUCENT;
    } else if (rCaps.getRedBits() <= 5
        && rCaps.getGreenBits() <= 6
        && rCaps.getBlueBits() <= 5
        && rCaps.getAlphaBits() == 0) {
      fmt = PixelFormat.RGB_565;
    }
    /* else if(rCaps.getRedBits()<=5 &&
       rCaps.getGreenBits()<=5 &&
       rCaps.getBlueBits()<=5 &&
       rCaps.getAlphaBits()==1) {
        fmt = PixelFormat.RGBA_5551; // FIXME: Supported ?
    } */
    else {
      fmt = PixelFormat.RGBA_8888;
    }
    Log.d(MD.TAG, "getFormat: requested: " + rCaps);
    Log.d(MD.TAG, "getFormat:  returned: " + fmt);

    return fmt;
  }
Esempio n. 2
0
  public static CapabilitiesImmutable fixCaps(
      boolean matchFormatPrecise, int format, CapabilitiesImmutable rCaps) {
    PixelFormat pf = new PixelFormat();
    PixelFormat.getPixelFormatInfo(format, pf);
    final CapabilitiesImmutable res;
    int r, g, b, a;

    switch (format) {
      case PixelFormat.RGBA_8888:
        r = 8;
        g = 8;
        b = 8;
        a = 8;
        break;
      case PixelFormat.RGBX_8888:
        r = 8;
        g = 8;
        b = 8;
        a = 0;
        break;
      case PixelFormat.RGB_888:
        r = 8;
        g = 8;
        b = 8;
        a = 0;
        break;
      case PixelFormat.RGB_565:
        r = 5;
        g = 6;
        b = 5;
        a = 0;
        break;
      case PixelFormat.RGBA_5551:
        r = 5;
        g = 5;
        b = 5;
        a = 1;
        break;
      case PixelFormat.RGBA_4444:
        r = 4;
        g = 4;
        b = 4;
        a = 4;
        break;
      case PixelFormat.RGB_332:
        r = 3;
        g = 3;
        b = 2;
        a = 0;
        break;
      default:
        throw new InternalError("Unhandled pixelformat: " + format);
    }
    final boolean change =
        matchFormatPrecise
            || rCaps.getRedBits() > r
                && rCaps.getGreenBits() > g
                && rCaps.getBlueBits() > b
                && rCaps.getAlphaBits() > a;

    if (change) {
      Capabilities nCaps = (Capabilities) rCaps.cloneMutable();
      nCaps.setRedBits(r);
      nCaps.setGreenBits(g);
      nCaps.setBlueBits(b);
      nCaps.setAlphaBits(a);
      res = nCaps;
    } else {
      res = rCaps;
    }
    Log.d(MD.TAG, "fixCaps:    format: " + format);
    Log.d(MD.TAG, "fixCaps: requested: " + rCaps);
    Log.d(MD.TAG, "fixCaps:    chosen: " + res);

    return res;
  }