| 302 | // --- ConvertPixels --- |
| 303 | |
| 304 | bool ConvertPixels(const void* src, void* dst, int width, int height, PixelFormat srcFmt, PixelFormat dstFmt) |
| 305 | { |
| 306 | if (srcFmt == dstFmt) |
| 307 | { |
| 308 | std::memcpy(dst, src, ComputeDataSize(width, height, srcFmt)); |
| 309 | return true; |
| 310 | } |
| 311 | |
| 312 | const auto* srcBytes = static_cast<const uint8_t*>(src); |
| 313 | auto* dstBytes = static_cast<uint8_t*>(dst); |
| 314 | |
| 315 | // If source is RGBA8888, encode directly |
| 316 | if (srcFmt == PixelFormat::RGBA8888) |
| 317 | { |
| 318 | switch (dstFmt) |
| 319 | { |
| 320 | case PixelFormat::ARGB4444: |
| 321 | rgbaToARGB4444(srcBytes, dstBytes, width, height); |
| 322 | return true; |
| 323 | case PixelFormat::ARGB1555: |
| 324 | rgbaToARGB1555(srcBytes, dstBytes, width, height); |
| 325 | return true; |
| 326 | case PixelFormat::RGB565: |
| 327 | rgbaToRGB565(srcBytes, dstBytes, width, height); |
| 328 | return true; |
| 329 | case PixelFormat::AI88: |
| 330 | rgbaToAI88(srcBytes, dstBytes, width, height); |
| 331 | return true; |
| 332 | case PixelFormat::ARGB8888: |
| 333 | rgbaToARGB8888(srcBytes, dstBytes, width, height); |
| 334 | return true; |
| 335 | case PixelFormat::DXT1: |
| 336 | { |
| 337 | auto compressed = DXTCompressor::CompressDXT1(srcBytes, width, height); |
| 338 | std::memcpy(dstBytes, compressed.data(), compressed.size()); |
| 339 | return true; |
| 340 | } |
| 341 | case PixelFormat::DXT5: |
| 342 | { |
| 343 | auto compressed = DXTCompressor::CompressDXT5(srcBytes, width, height); |
| 344 | std::memcpy(dstBytes, compressed.data(), compressed.size()); |
| 345 | return true; |
| 346 | } |
| 347 | default: |
| 348 | return false; |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | // If destination is RGBA8888, decode directly |
| 353 | if (dstFmt == PixelFormat::RGBA8888) |
| 354 | { |
| 355 | switch (srcFmt) |
| 356 | { |
| 357 | case PixelFormat::ARGB4444: |
| 358 | argb4444ToRGBA(srcBytes, dstBytes, width, height); |
| 359 | return true; |
| 360 | case PixelFormat::ARGB1555: |
| 361 | argb1555ToRGBA(srcBytes, dstBytes, width, height); |
no test coverage detected