private void createMatrices(){
  final int w=(int)(current_image.getWidth() / scaling);
  final int h=(int)(current_image.getHeight() / scaling);
  Trm=new float[3][3];
  Trm[0][0]=(CTM[0][0] / w);
  Trm[0][1]=(CTM[0][1] / w);
  Trm[0][2]=0;
  Trm[1][0]=(CTM[1][0] / h);
  Trm[1][1]=(CTM[1][1] / h);
  Trm[1][2]=0;
  Trm[2][0]=CTM[2][0];
  Trm[2][1]=CTM[2][1];
  Trm[2][2]=1;
  for (int y=0; y < 3; y++) {
    for (int x=0; x < 3; x++) {
      if ((Trm[x][y] > .99) & (Trm[x][y] < 1)) {
        Trm[x][y]=1;
      }
    }
  }
  Trm1=new float[3][3];
  Trm2=new float[3][3];
  float x1, x2, y1, y2;
  x1=CTM[0][0];
  if (x1 < 0) {
    x1=-x1;
  }
  x2=CTM[0][1];
  if (x2 < 0) {
    x2=-x2;
  }
  y1=CTM[1][1];
  if (y1 < 0) {
    y1=-y1;
  }
  y2=CTM[1][0];
  if (y2 < 0) {
    y2=-y2;
  }
  if (CTM[0][0] == 0.0 || CTM[1][1] == 0.0) {
    Trm1=Trm;
  }
 else   if ((CTM[0][1] == 0.0) && (CTM[1][0] == 0.0)) {
    Trm1[0][0]=w / (CTM[0][0]);
    Trm1[0][1]=0;
    Trm1[0][2]=0;
    Trm1[1][0]=0;
    Trm1[1][1]=h / (CTM[1][1]);
    Trm1[1][2]=0;
    Trm1[2][0]=0;
    Trm1[2][1]=0;
    Trm1[2][2]=1;
    Trm1=Matrix.multiply(Trm,Trm1);
    for (int y=0; y < 3; y++) {
      for (int x=0; x < 3; x++) {
        if ((Trm1[x][y] > .99) & (Trm1[x][y] < 1)) {
          Trm1[x][y]=1;
        }
      }
    }
    if (Trm1[2][0] < 0 && Trm1[0][0] > 0 && CTM[0][0] < 0) {
      Trm1[2][0]=0;
      Trm1[0][0]=-1f;
    }
    if (Trm1[2][1] < 0 && Trm1[1][1] > 0 && CTM[1][1] < 0 && CTM[0][0] < 0) {
      Trm1[2][1]=0;
      Trm1[1][1]=-1f;
    }
  }
 else {
    if (x1 > x2) {
      Trm1[0][0]=w / (CTM[0][0]);
    }
 else {
      Trm1[0][0]=w / (CTM[0][1]);
    }
    if (Trm1[0][0] < 0) {
      Trm1[0][0]=-Trm1[0][0];
    }
    Trm1[0][1]=0;
    Trm1[0][2]=0;
    Trm1[1][0]=0;
    if (y1 > y2) {
      Trm1[1][1]=h / (CTM[1][1]);
    }
 else {
      Trm1[1][1]=h / (CTM[1][0]);
    }
    if (Trm1[1][1] < 0) {
      Trm1[1][1]=-Trm1[1][1];
    }
    Trm1[1][2]=0;
    Trm1[2][0]=0;
    Trm1[2][1]=0;
    Trm1[2][2]=1;
    Trm1=Matrix.multiply(Trm,Trm1);
    for (int y=0; y < 3; y++) {
      for (int x=0; x < 3; x++) {
        if ((Trm1[x][y] > .99) & (Trm1[x][y] < 1)) {
          Trm1[x][y]=1;
        }
      }
    }
  }
  if (x1 > x2) {
    Trm2[0][0]=(CTM[0][0] / w);
  }
 else {
    Trm2[0][0]=(CTM[0][1] / w);
  }
  if (Trm2[0][0] < 0) {
    Trm2[0][0]=-Trm2[0][0];
  }
  Trm2[0][1]=0;
  Trm2[0][2]=0;
  Trm2[1][0]=0;
  if (y1 > y2) {
    Trm2[1][1]=(CTM[1][1] / h);
  }
 else {
    Trm2[1][1]=(CTM[1][0] / h);
  }
  if (Trm2[1][1] < 0) {
    Trm2[1][1]=-Trm2[1][1];
  }
  Trm2[1][2]=0;
  Trm2[2][0]=0;
  Trm2[2][1]=0;
  Trm2[2][2]=1;
  for (int y=0; y < 3; y++) {
    for (int x=0; x < 3; x++) {
      if ((Trm2[x][y] > .99) & (Trm2[x][y] < 1)) {
        Trm2[x][y]=1;
      }
    }
  }
}

private void createMatrices ( ) { final int w = ( int ) ( current_image . getWidth ( ) / scaling ) ; final int h = ( int ) ( current_image . getHeight ( ) / scaling ) ; Trm = new float [ 3 ] [ 3 ] ; Trm [ 0 ] [ 0 ] = ( CTM [ 0 ] [ 0 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= 0 ; y < 3 ; y ++ ) { for ( int x = 0 ; x < 3 ; x ++ ) { if ( ( Trm1 [ x ] [ y ] > .99 ) & ( Trm1 [ x ] [ y ] < 1 ) ) { Trm1 [ x ] [ y ] = 1 ; } } } } if ( x1 > x2 ) { Trm2 [ 0 ] [ 0 ] = ( CTM [ 0 ] [ 0 ] / w ) ; } else { Trm2 [ 0 ] [ 0 ] = ( CTM [ 0 ] [ 1 ] / w ) ; } if ( Trm2 [ 0 ] [ 0 ] < 0 ) { Trm2 [ 0 ] [ 0 ] = - Trm2 [ 0 ] [ 0 ] ; } Trm2 [ 0 ] [ 1 ] = 0 ; Trm2 [ 0 ] [ 2 ] = 0 ; Trm2 [ 1 ] [ 0 ] = 0 ; if ( y1 > y2 ) { Trm2 [ 1 ] [ 1 ] = ( CTM [ 1 ] [ 1 ] / h ) ; } else { Trm2 [ 1 ] [ 1 ] = ( CTM [ 1 ] [ 0 ] / h ) ; } if ( Trm2 [ 1 ] [ 1 ] < 0 ) { Trm2 [ 1 ] [ 1 ] = - Trm2 [ 1 ] [ 1 ] ; } Trm2 [ 1 ] [ 2 ] = 0 ; Trm2 [ 2 ] [ 0 ] = 0 ; Trm2 [ 2 ] [ 1 ] = 0 ; Trm2 [ 2 ] [ 2 ] = 1 ; for ( int y = 0 ; y < 3 ; y ++ ) { for ( int x = 0 ; x < 3 ; x ++ ) { if ( ( Trm2 [ x ] [ y ] > .99 ) & ( Trm2 [ x ] [ y ] < 1 ) ) { Trm2 [ x ] [ y ] = 1 ; } } } }
workout the transformation as 1 or 2 transformations
