do not crash when generating preview of very large sound files, fixes #4123

(cherry picked from commit 9b8f2741ae)
This commit is contained in:
Juan Linietsky 2016-06-20 22:38:31 -03:00 committed by Rémi Verschelde
parent 3318860539
commit 0c71eb8a1e
2 changed files with 12 additions and 12 deletions

View File

@ -637,7 +637,7 @@ Ref<Texture> EditorSamplePreviewPlugin::generate(const RES& p_from) {
for(int j=0;j<h;j++) { for(int j=0;j<h;j++) {
float v = (j/(float)h) * 2.0 - 1.0; float v = (j/(float)h) * 2.0 - 1.0;
uint8_t* imgofs = &imgw[(j*w+i)*3]; uint8_t* imgofs = &imgw[(uint64_t(j)*w+i)*3];
if (v>min[0] && v<max[0]) { if (v>min[0] && v<max[0]) {
imgofs[0]=255; imgofs[0]=255;
imgofs[1]=150; imgofs[1]=150;
@ -655,8 +655,8 @@ Ref<Texture> EditorSamplePreviewPlugin::generate(const RES& p_from) {
float max[2]={-1e10,-1e10}; float max[2]={-1e10,-1e10};
float min[2]={1e10,1e10}; float min[2]={1e10,1e10};
int c=stereo?2:1; int c=stereo?2:1;
int from = i*len/w; int from = uint64_t(i)*len/w;
int to = (i+1)*len/w; int to = (uint64_t(i)+1)*len/w;
if (to>=len) if (to>=len)
to=len-1; to=len-1;
@ -667,7 +667,7 @@ Ref<Texture> EditorSamplePreviewPlugin::generate(const RES& p_from) {
for(int k=from;k<=to;k++) { for(int k=from;k<=to;k++) {
float v = src[k*c+j]/32768.0; float v = src[uint64_t(k)*c+j]/32768.0;
if (v>max[j]) if (v>max[j])
max[j]=v; max[j]=v;
if (v<min[j]) if (v<min[j])
@ -683,7 +683,7 @@ Ref<Texture> EditorSamplePreviewPlugin::generate(const RES& p_from) {
for(int k=from;k<=to;k++) { for(int k=from;k<=to;k++) {
float v = src[k*c+j]/128.0; float v = src[uint64_t(k)*c+j]/128.0;
if (v>max[j]) if (v>max[j])
max[j]=v; max[j]=v;
if (v<min[j]) if (v<min[j])

View File

@ -211,7 +211,7 @@ void SampleEditor::generate_preview_texture(const Ref<Sample>& p_sample,Ref<Imag
for(int j=0;j<h;j++) { for(int j=0;j<h;j++) {
float v = (j/(float)h) * 2.0 - 1.0; float v = (j/(float)h) * 2.0 - 1.0;
uint8_t* imgofs = &imgw[(j*w+i)*3]; uint8_t* imgofs = &imgw[(uint64_t(j)*w+i)*3];
if (v>min[0] && v<max[0]) { if (v>min[0] && v<max[0]) {
imgofs[0]=255; imgofs[0]=255;
imgofs[1]=150; imgofs[1]=150;
@ -229,8 +229,8 @@ void SampleEditor::generate_preview_texture(const Ref<Sample>& p_sample,Ref<Imag
float max[2]={-1e10,-1e10}; float max[2]={-1e10,-1e10};
float min[2]={1e10,1e10}; float min[2]={1e10,1e10};
int c=stereo?2:1; int c=stereo?2:1;
int from = i*len/w; int from = uint64_t(i)*len/w;
int to = (i+1)*len/w; int to = (uint64_t(i)+1)*len/w;
if (to>=len) if (to>=len)
to=len-1; to=len-1;
@ -241,7 +241,7 @@ void SampleEditor::generate_preview_texture(const Ref<Sample>& p_sample,Ref<Imag
for(int k=from;k<=to;k++) { for(int k=from;k<=to;k++) {
float v = src[k*c+j]/32768.0; float v = src[uint64_t(k)*c+j]/32768.0;
if (v>max[j]) if (v>max[j])
max[j]=v; max[j]=v;
if (v<min[j]) if (v<min[j])
@ -257,7 +257,7 @@ void SampleEditor::generate_preview_texture(const Ref<Sample>& p_sample,Ref<Imag
for(int k=from;k<=to;k++) { for(int k=from;k<=to;k++) {
float v = src[k*c+j]/128.0; float v = src[uint64_t(k)*c+j]/128.0;
if (v>max[j]) if (v>max[j])
max[j]=v; max[j]=v;
if (v<min[j]) if (v<min[j])
@ -270,7 +270,7 @@ void SampleEditor::generate_preview_texture(const Ref<Sample>& p_sample,Ref<Imag
if (!stereo) { if (!stereo) {
for(int j=0;j<h;j++) { for(int j=0;j<h;j++) {
float v = (j/(float)h) * 2.0 - 1.0; float v = (j/(float)h) * 2.0 - 1.0;
uint8_t* imgofs = &imgw[(j*w+i)*3]; uint8_t* imgofs = &imgw[(uint64_t(j)*w+i)*3];
if (v>min[0] && v<max[0]) { if (v>min[0] && v<max[0]) {
imgofs[0]=255; imgofs[0]=255;
imgofs[1]=150; imgofs[1]=150;
@ -297,7 +297,7 @@ void SampleEditor::generate_preview_texture(const Ref<Sample>& p_sample,Ref<Imag
v = ((j-(h/2))/(float)(h/2)) * 2.0 - 1.0; v = ((j-(h/2))/(float)(h/2)) * 2.0 - 1.0;
} }
uint8_t* imgofs = &imgw[(j*w+i)*3]; uint8_t* imgofs = &imgw[(uint64_t(j)*w+i)*3];
if (v>min[half] && v<max[half]) { if (v>min[half] && v<max[half]) {
imgofs[0]=255; imgofs[0]=255;
imgofs[1]=150; imgofs[1]=150;