Clamping texture sizes
This commit is contained in:
parent
943a8cd1d9
commit
3c780c7290
@ -253,15 +253,27 @@ static int refresh_texture(struct ResManRes *res) {
|
|||||||
|
|
||||||
int w, h, origN;
|
int w, h, origN;
|
||||||
unsigned char *data = stbi_load(namebuf, &w, &h, &origN, n);
|
unsigned char *data = stbi_load(namebuf, &w, &h, &origN, n);
|
||||||
int stbifree = 1;
|
|
||||||
|
|
||||||
if(TextureResolutionReduction && data) {
|
int newW = w, newH = h;
|
||||||
int newW = w >> TextureResolutionReduction;
|
|
||||||
int newH = h >> TextureResolutionReduction;
|
|
||||||
|
|
||||||
if(newW <= 4) newW = 4;
|
if(TextureResolutionReduction) {
|
||||||
if(newH <= 4) newH = 4;
|
newW = newW >> TextureResolutionReduction;
|
||||||
|
newH = newH >> TextureResolutionReduction;
|
||||||
|
}
|
||||||
|
if(newW > k3TexSzMax()) {
|
||||||
|
newW = k3TexSzMax();
|
||||||
|
}
|
||||||
|
if(newH > k3TexSzMax()) {
|
||||||
|
newH = k3TexSzMax();
|
||||||
|
}
|
||||||
|
if(newW < 4) {
|
||||||
|
newW = 4;
|
||||||
|
}
|
||||||
|
if(newH < 4) {
|
||||||
|
newH = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(newW != w || newH != h) {
|
||||||
unsigned char *data2 = malloc(newW * newH * n);
|
unsigned char *data2 = malloc(newW * newH * n);
|
||||||
int success = stbir_resize_uint8_generic(data, w, h, 0, data2, newW, newH, 0, n, n == 4 ? 3 : -1, 0, STBIR_EDGE_WRAP, STBIR_FILTER_DEFAULT, gamma ? STBIR_COLORSPACE_SRGB : STBIR_COLORSPACE_LINEAR, NULL);
|
int success = stbir_resize_uint8_generic(data, w, h, 0, data2, newW, newH, 0, n, n == 4 ? 3 : -1, 0, STBIR_EDGE_WRAP, STBIR_FILTER_DEFAULT, gamma ? STBIR_COLORSPACE_SRGB : STBIR_COLORSPACE_LINEAR, NULL);
|
||||||
|
|
||||||
@ -271,7 +283,6 @@ static int refresh_texture(struct ResManRes *res) {
|
|||||||
w = newW;
|
w = newW;
|
||||||
h = newH;
|
h = newH;
|
||||||
data = data2;
|
data = data2;
|
||||||
stbifree = 0;
|
|
||||||
} else {
|
} else {
|
||||||
free(data2);
|
free(data2);
|
||||||
}
|
}
|
||||||
@ -283,14 +294,9 @@ static int refresh_texture(struct ResManRes *res) {
|
|||||||
|
|
||||||
if(data) {
|
if(data) {
|
||||||
k3TexUpdate(res->thing, type, 0, w, h, data);
|
k3TexUpdate(res->thing, type, 0, w, h, data);
|
||||||
|
|
||||||
if(stbifree) {
|
|
||||||
stbi_image_free(data);
|
|
||||||
} else {
|
|
||||||
free(data);
|
free(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user