Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void image::cropp(uint32_t x,
- uint32_t y,
- uint32_t new_width_in_pixels,
- uint32_t new_height_in_pixels) {
- auto bytes_in_pixel = bmp_info_header.bit_count / 8;
- std::vector<uint8_t> data_new;
- auto byte_count_per_row = bmp_info_header.width * bytes_in_pixel;
- auto new_padding_bytes =
- (4 - ((new_width_in_pixels * bytes_in_pixel) % 4)) % 4;
- auto new_size_data =
- (bytes_in_pixel * new_width_in_pixels + new_padding_bytes) *
- new_height_in_pixels * bytes_in_pixel;
- data_new.resize(new_size_data);
- auto cur_bytes = 0;
- auto new_width_image_in_bytes = bytes_in_pixel * new_width_in_pixels;
- for (auto cur_line = static_cast<int32_t>(new_height_in_pixels);
- cur_line >= 0; cur_line--) {
- uint32_t cur_x_position =
- (bmp_info_header.height - y - cur_line) * byte_count_per_row +
- bytes_in_pixel * x;
- for (uint32_t i = cur_x_position;
- i < cur_x_position + new_width_image_in_bytes; i++, cur_bytes++) {
- data_new[cur_bytes] = data[i];
- }
- for (uint32_t i = 0; i < new_padding_bytes; i++) {
- data_new[cur_bytes + i] = 0;
- cur_bytes++;
- }
- }
- data.clear();
- data = data_new;
- bmp_info_header.height = static_cast<int>(new_height_in_pixels);
- bmp_info_header.width = static_cast<int>(new_width_in_pixels);
- image::write("out1.bmp");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement