Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkAndshark committed Dec 10, 2024
1 parent 767d431 commit 84ded8f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions martin/src/cog/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,22 +427,23 @@ fn rgb_to_png(
let pixels = if nodata.is_some() || need_add_alpha || is_padded {
let mut result_vec = vec![default_value; (tile_width * tile_height * 4) as usize];
for row in 0..data_height {
for col in 0..data_width {
'outer: for col in 0..data_width {
let idx_chunk =
row * data_width * chunk_components_count + col * chunk_components_count;
let idx_result = row * tile_width * 4 + col * 4;
let mut is_nodata = false;
for component_idx in 0..chunk_components_count {
if nodata.eq(&Some(vec[(idx_chunk + component_idx) as usize])) {
is_nodata = true;
//This pixel is nodata, just make it transparent and skip it then
let alpha_idx = (idx_result + 3) as usize;
result_vec[alpha_idx] = 0;
continue 'outer;
}
result_vec[(idx_result + component_idx) as usize] =
vec[(idx_chunk + component_idx) as usize];
}
if is_nodata || need_add_alpha {
if need_add_alpha {
let alpha_idx = (idx_result + 3) as usize;
let value = if is_nodata { 0 } else { 255 };
result_vec[alpha_idx] = value;
result_vec[alpha_idx] = 255;
}
}
}
Expand Down
Binary file modified tests/expected/auto/rgba_u8_nodata_0_0_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/expected/auto/rgba_u8_nodata_1_0_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 84ded8f

Please sign in to comment.