<commit_before>use decoders::RawImage;
use imageops::OpBuffer;

pub fn convert(img: &RawImage) -> OpBuffer {
  // Calculate the resulting width/height and top-left corner after crops
  let width = img.width - img.crops[1] - img.crops[3];
  let height = img.height - img.crops[0] - img.crops[2];
  let x = img.crops[3];
  let y = img.crops[0];

  if img.cpp == 1 && !img.cfa.is_valid() {
    // We're in a monochrome image so turn it into RGB
    let mut out = OpBuffer::new(width, height, 4);
    out.mutate_lines(&(|line: &mut [f32], row| {
      for (o, i) in line.chunks_mut(4).zip(img.data[img.width*(row+x)+y..].chunks(1)) {
        o[0] = i[0] as f32;
        o[1] = i[0] as f32;
        o[2] = i[0] as f32;
        o[3] = 0.0;
      }
    }));
    out
  } else if img.cpp == 3 {
    // We're in an RGB image, turn it into four channel
    let mut out = OpBuffer::new(width, height, 4);
    out.mutate_lines(&(|line: &mut [f32], row| {
      for (o, i) in line.chunks_mut(4).zip(img.data[img.width*(row+x)+y..].chunks(3)) {
        o[0] = i[0] as f32;
        o[1] = i[1] as f32;
        o[2] = i[2] as f32;
        o[3] = 0.0;
      }
    }));
    out
  } else {
    let mut out = OpBuffer::new(width, height, img.cpp);
    out.mutate_lines(&(|line: &mut [f32], row| {
      for (o, i) in line.chunks_mut(1).zip(img.data[img.width*(row+x)+y..].chunks(1)) {
        o[0] = i[0] as f32;
      }
    }));
    out
  }
}<commit_msg>gofloat: fix broken crop calculations<commit_after>use decoders::RawImage;
use imageops::OpBuffer;

pub fn convert(img: &RawImage) -> OpBuffer {
  // Calculate the resulting width/height and top-left corner after crops
  let width = img.width - img.crops[1] - img.crops[3];
  let height = img.height - img.crops[0] - img.crops[2];
  let x = img.crops[3];
  let y = img.crops[0];

  if img.cpp == 1 && !img.cfa.is_valid() {
    // We're in a monochrome image so turn it into RGB
    let mut out = OpBuffer::new(width, height, 4);
    out.mutate_lines(&(|line: &mut [f32], row| {
      for (o, i) in line.chunks_mut(4).zip(img.data[img.width*(row+y)+x..].chunks(1)) {
        o[0] = i[0] as f32;
        o[1] = i[0] as f32;
        o[2] = i[0] as f32;
        o[3] = 0.0;
      }
    }));
    out
  } else if img.cpp == 3 {
    // We're in an RGB image, turn it into four channel
    let mut out = OpBuffer::new(width, height, 4);
    out.mutate_lines(&(|line: &mut [f32], row| {
      for (o, i) in line.chunks_mut(4).zip(img.data[img.width*(row+y)+x..].chunks(3)) {
        o[0] = i[0] as f32;
        o[1] = i[1] as f32;
        o[2] = i[2] as f32;
        o[3] = 0.0;
      }
    }));
    out
  } else {
    let mut out = OpBuffer::new(width, height, img.cpp);
    out.mutate_lines(&(|line: &mut [f32], row| {
      for (o, i) in line.chunks_mut(1).zip(img.data[img.width*(row+y)+x..].chunks(1)) {
        o[0] = i[0] as f32;
      }
    }));
    out
  }
}
{'fraction_non_alphanumeric': 0.19329183955739973, 'fraction_numerical': 0.03872752420470263, 'mean_word_length': 2.383625730994152, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6055380', 'n_tokens_mistral': 1238, 'n_tokens_neox': 1198, 'n_words': 290}