PDA

View Full Version : Application crash when saving the image



Astrologer
3rd May 2010, 14:33
Hi there. I keep receiving application crash when saving an image (line 44). But the problem is that it appears every now and then. May you have a look at the snippet? Thank you so much.



void MainWindow::algorithm(QString image_name)
{

int counter = 0;

QImage initial_image_tmp(image_name);
int height_of_image = initial_image_tmp.height();
initial_image_tmp.~QImage();

double NDN = 889000;//should be defined
double height = 830000;//should be defined
//int height_of_image = 2384;
int delta_r = 240; // should be defined
//----------------------------------------//

double NDK = NDN + delta_r * height_of_image;// estimate far slant distance
double delta_R = NDK - NDN; // estimate pixel slant range step

std::vector<double> slant_initial_vec;// define initial slant range vector

double near_horiz_distance, far_horiz_distance, L_spheric;//define horizontal distances

slant2range(NDN, height, near_horiz_distance);// slant to range distance convertion (near)
slant2range(NDK, height, far_horiz_distance);// slant to range distance convertion(far)

L_spheric = far_horiz_distance - near_horiz_distance;//define arc length which
//corresponds to slant range

double size_tmp = L_spheric / delta_r;//define step at horiaontal range
int size_of_output_array = (int)ceil(size_tmp);//compute size of output array (new image height)

for (int i = 0; i < height_of_image; i++) slant_initial_vec.push_back(NDN + delta_r * i);//fill in initial slant vector

std::vector<double> slant_vec;//horiaontal distances vector

for (int i = 0; i < size_of_output_array; i++)//fill in resampled slant vector
{
double tmp_horiz = near_horiz_distance + i * delta_r;
double tmp_slant;
range2slant(tmp_horiz, height, tmp_slant);

//-----------------------------------------//
int counter = 100 * i /size_of_output_array;
emit signal_update(counter);
//-----------------------------------------//

slant_vec.push_back(tmp_slant);
}

counter = 0;

std::vector<int> indexes_lower, indexes_higher;//define indexes and delta vectors
std::vector<double> delta_s;

for (int i = 0; i < size_of_output_array; i++)
{
double out_slant_range, in_slant_range;

out_slant_range = slant_vec[i];
std::vector<double>::iterator range_iterator =
std::lower_bound
(slant_initial_vec.begin(),
slant_initial_vec.end(),
out_slant_range);
in_slant_range = *range_iterator;

int val = (int)(range_iterator - slant_initial_vec.begin());
delta_s.push_back((out_slant_range - in_slant_range)/delta_r);
indexes_lower.push_back(val);
if (val >=height_of_image) indexes_higher.push_back(val);
else indexes_higher.push_back(val + 1);

int counter = 100 * i /size_of_output_array;
emit signal_update(counter);
}

counter = 0;

//----start processing-----------------------------//
QImage initial_image(image_name);
QString bmp_name = image_name + ".bmp";
QImage initial_bmp = initial_image.copy(0,0, initial_image.width(), initial_image.height());
initial_bmp.save(bmp_name);

int initial_width = initial_image.width();
int initial_height = initial_image.height();

initial_image.~QImage();
initial_bmp.~QImage();

QImage image_resampled(initial_width, size_of_output_array, QImage::Format_ARGB32);
image_resampled.fill(0);
QString name_of_output_jpg = image_name + "_resampled.jpg";
std::vector<double>
input_green_vector,
input_red_vector,
input_blue_vector;

//--------------------------//

QImage tmp_bmp_image(bmp_name);

//--------------------------//

QRgb output_rgb_value;

for (int j = 0;
j < initial_width;
j++)
{
get_current_column(//bmp_name,
tmp_bmp_image,
j,
input_red_vector,
input_green_vector,
input_blue_vector);

for (int i = 0; i < size_of_output_array; i++)
{
double val_green = input_green_vector[indexes_lower[i]] *
(1- abs(delta_s[i])) +
input_green_vector[indexes_higher[i]] * abs(delta_s[i]);

double val_red = input_red_vector[indexes_lower[i]] *
(1- abs(delta_s[i])) +
input_red_vector[indexes_higher[i]] * abs(delta_s[i]);

double val_blue = input_blue_vector[indexes_lower[i]] *
(1- abs(delta_s[i])) +
input_blue_vector[indexes_higher[i]] * abs(delta_s[i]);

//output_green_vector.push_back(val_green);
//output_red_vector.push_back(val_red);
//output_blue_vector.push_back(val_blue);

output_rgb_value = qRgb(val_red, val_green, val_blue);

image_resampled.setPixel(j, i, output_rgb_value);
}
int counter = 100 * j /initial_width;
emit signal_update(counter);
}

image_resampled.save(name_of_output_jpg);//save the image

emit end_of_calculating();

}

Astrologer
10th May 2010, 09:52
Solved. I deleted all explicitly used destructors and it worked just fine.