1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
|
public void addTexture(Image _texture, Point _pGHaut, Point _pDHaut, int _yBas, boolean _transform)
{
if(_pGHaut.getX()>_pDHaut.getX())
{
Point BufPoint = _pDHaut;
_pDHaut = _pGHaut;
_pGHaut = BufPoint;
_texture = Image.createImage(_texture, 0, 0, _texture.getWidth(), _texture.getHeight(), Sprite.TRANS_MIRROR);
}
if(_pGHaut.getY()>=_yBas || _pDHaut.getY()>_yBas || _yBas > this.__height)
{
return;
}
else
{
if(_transform==true)
_texture = Image.createImage(_texture, 0, 0, _texture.getWidth(), _texture.getHeight(), Sprite.TRANS_MIRROR);
Image textDeforme = deformerImage(_texture, _pDHaut.getX()-_pGHaut.getX(), _yBas-_pGHaut.getY(), _yBas-_pDHaut.getY());
int x = _pGHaut.getX();
int y = 0;
if(_pGHaut.getY()>_pDHaut.getY())
y = _pDHaut.getY();
else
y = _pGHaut.getY();
afficherImage(textDeforme, x, y);
}
}
public Image deformerImage(Image _image, int _largeur, int _hauteur1, int _hauteur2)
{
int oldWidth = _image.getWidth();
int oldHeight = _image.getHeight();
int[] oldImage = readImage(_image);
int cas = 0;
double dy = 0.0;
int air = 0;
int larg = 0;
if(_hauteur1>_hauteur2)
{
cas = 1;
dy = ((double)_hauteur1-(double)_hauteur2)/(double)oldWidth;
air = oldWidth*_hauteur1;
larg = (oldWidth*(_hauteur1-1));
}
else
{
dy = ((double)_hauteur2-(double)_hauteur1)/(double)oldWidth;
air = oldWidth*_hauteur2;
larg = (oldWidth*(_hauteur2-1));
}
int lon = (oldWidth*(oldHeight-1));
double newHauteur = (double)_hauteur1;
int[] newImage = new int[air];
int[] bufImTab = null;
Image newIMAGE = null;
for(int i=0; i<oldWidth; i++)
{
bufImTab = new int[oldHeight];
//recupe tout une bande de hauteur
for(int j=0;j<oldHeight;j++)
bufImTab[j] = oldImage[i+lon -(j*oldWidth)];
//On la redimensionne
bufImTab = readImage(redimImage(Image.createRGBImage(bufImTab, 1, oldHeight, true), 1, (int)newHauteur));
//On la place dans la nouvelle image
for(int k=0;k<(int)newHauteur;k++)
{
if(newImage[k]==0)
newImage[k] = defineColor(0,0,0,0);
newImage[i+larg-(k*oldWidth)] = bufImTab[k];
}
if(cas == 0)
newHauteur +=dy;
else
newHauteur -=dy;
}
if(cas==1)
{
return redimImage(Image.createRGBImage(newImage, oldWidth, _hauteur1, true),_largeur, _hauteur1);
}
else
{
return redimImage(Image.createRGBImage(newImage, oldWidth, _hauteur2, true),_largeur, _hauteur2);
}
}
public Image redimImage(Image _image, int _longueur, int _hauteur)
{
int sourceWidth = _image.getWidth();
int sourceHeight = _image.getHeight();
int redimWidth = _longueur;
int redimHeight = _hauteur;
int[] oldImage = readImage(_image);
int[] newImage = new int[redimWidth*redimHeight];
int compteur =0;
Image redimImage = Image.createImage(redimWidth, redimHeight);
if(redimWidth > __width)
redimWidth = __width;
if(redimHeight > __height)
redimHeight = __height;
if (redimHeight < 0)
redimHeight = redimWidth * sourceHeight / sourceWidth;
for (int y = 0; y < redimHeight; y++)
{
for (int x = 0; x < redimWidth; x++)
{
int dx = x * sourceWidth / redimWidth;
int dy = y * sourceHeight / redimHeight;
newImage[compteur] = oldImage[dx+dy*sourceWidth];
compteur++;
}
}
redimImage = Image.createRGBImage(newImage, redimWidth, redimHeight, true);
return redimImage;
}
public void afficherImage(Image _image, int _x, int _y)
{
int[] imData = readImage(_image);
int width = _image.getWidth();
int height = _image.getHeight();
int compteurX = 0;
int compteurY = 0;
for(int i=_y;i<(height+_y);i++)
{
for(int j=_x;j<(width+_x);j++)
{
if(0 <= j && j <= this.__width && 0 <= i && i <= this.__height)
this.__tabJeux[j+(i*this.__width)] = imData[compteurX+compteurY*width];
compteurX++;
}
compteurX = 0;
compteurY++;
}
}
public int[] readImage(Image _image)
{
int[] argbdata = new int[_image.getWidth()*_image.getHeight()];
_image.getRGB( argbdata, 0, _image.getWidth(), 0, 0, _image.getWidth(), _image.getHeight());
return argbdata;
} |