-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathImagem.java
More file actions
172 lines (138 loc) · 4.48 KB
/
Imagem.java
File metadata and controls
172 lines (138 loc) · 4.48 KB
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
import java.util.Arrays;
public class Imagem {
private CorRGB [][] pixels;
Imagem(int x, int y)
{
pixels = new CorRGB[x][y];
for(int k=0; k<x; k++)
{
for(int w=0; w<y; w++)
{
pixels[k][w]= CorRGB.branca;
}
}
}
public int getLargura()
{
return this.pixels[0].length;
}
public int getAltura()
{
return this.pixels.length;
}
public CorRGB getPixel(int x, int y)
{
return this.pixels[x][y];
}
public String getPixels()
{
String s = "";
for(int k=0; k<this.pixels.length; k++)
{
for(int w=0; w<this.pixels[k].length; w++)
{
s += this.pixels[k][w];
}
}
return s;
}
public void setModificaPixel(int x, int y, CorRGB k)
{
this.pixels[x][y] = k;
}
public void setModificaPixels(int x, int y, int a, int b, int c)
{
this.pixels[x][y].setValorRed(a);
this.pixels[x][y].setValorGreen(b);
this.pixels[x][y].setValorBlue(c);
}
public Imagem imagemCinza() {
int cinza = 0;
Imagem imagem = new Imagem(this.pixels.length,this.pixels[0].length);
for (int x = 0; x < this.pixels.length; x++)
{
for (int y = 0; y < this.pixels[x].length; y++)
{
cinza = (int) this.pixels[x][y].getLuminosidade();
imagem.setModificaPixels(x,y,cinza,cinza,cinza);
}
}
return imagem;
}
public boolean verificarIgualdadeImagem(Imagem x)
{
if(Arrays.deepEquals(this.pixels, x.pixels))
{
return true;
}
else
{
return false;
}
}
private void rotacionar()
{
CorRGB[][] pixelsAuxiliar = new CorRGB[this.pixels[0].length][this.pixels.length];
int cont1Largura, cont1Altura, cont2Largura, cont2Altura;
for(cont1Altura = 0, cont2Largura = this.getAltura() - 1;cont1Altura < this.getAltura();cont1Altura++,cont2Largura--)
{
for(cont1Largura = 0, cont2Altura = 0;cont1Largura < this.getLargura();cont1Largura++,cont2Altura++)
{
pixelsAuxiliar[cont2Altura][cont2Largura] = pixels[cont1Altura][cont1Largura];
}
}
this.pixels = pixelsAuxiliar;
}
private boolean compararFragmentoImagem(Imagem fragmento,int inicioAltura,int inicioLargura)
{
for(int cont1 = inicioAltura,cont1frag = 0;cont1frag < fragmento.getAltura();cont1++,cont1frag++)
{
for(int cont2 = inicioLargura,cont2frag = 0;cont2frag < fragmento.getLargura();cont2++,cont2frag++)
{
if(!this.pixels[cont1][cont2].equals(fragmento.getPixel(cont1frag,cont2frag)))
{
return false;
}
}
}
return true;
}
public boolean isFragmento(Imagem outraImagem)
{
if(outraImagem.getAltura()==1&&outraImagem.getLargura()==1)
{System.out.println("este tamanho nao configura uma imagem");
return false;}
if(outraImagem.getAltura() <= this.getAltura() && outraImagem.getLargura() <= this.getLargura())
{
for(int cont = 0;cont < 4; cont++)
{
for(int correAltura = 0;correAltura + outraImagem.getAltura()<= this.getAltura();correAltura++)
{
for(int correLargura = 0;correLargura + outraImagem.getLargura()<= this.getLargura();correLargura++)
{
if(compararFragmentoImagem(outraImagem,correAltura,correLargura))
{
return true;
}
}
}
outraImagem.rotacionar();
}
}
return false;
}
public String toString() {
String s = "";
for(int k=0; k<pixels.length; k++)
{
for(int w=0; w<pixels[k].length; w++)
{
if(w==0)
{ s += "\n"+ pixels[k][w];}
else
{ s += pixels[k][w];}
}
}
return s;
}
}