| 350 | } |
| 351 | |
| 352 | Vec4B Image::get(Vec2U const& pos) const { |
| 353 | Vec4B c; |
| 354 | if (pos[0] >= m_width || pos[1] >= m_height) { |
| 355 | throw ImageException(strf("{} out of range in Image::get", pos)); |
| 356 | } else if (bytesPerPixel() == 4) { |
| 357 | size_t offset = pos[1] * m_width * 4 + pos[0] * 4; |
| 358 | c[0] = m_data[offset]; |
| 359 | c[1] = m_data[offset + 1]; |
| 360 | c[2] = m_data[offset + 2]; |
| 361 | c[3] = m_data[offset + 3]; |
| 362 | } else if (bytesPerPixel() == 3) { |
| 363 | size_t offset = pos[1] * m_width * 3 + pos[0] * 3; |
| 364 | c[0] = m_data[offset]; |
| 365 | c[1] = m_data[offset + 1]; |
| 366 | c[2] = m_data[offset + 2]; |
| 367 | c[3] = 255; |
| 368 | } |
| 369 | return c; |
| 370 | } |
| 371 | |
| 372 | void Image::setrgb(Vec2U const& pos, Vec4B const& c) { |
| 373 | if (m_pixelFormat == PixelFormat::BGR24 || m_pixelFormat == PixelFormat::BGRA32) |
no test coverage detected