| 654 | //============================== |
| 655 | |
| 656 | CMP_ERROR stb_load(const char* SourceFile, MipSet* MipSetIn) |
| 657 | { |
| 658 | int Width, Height, ComponentCount; |
| 659 | unsigned char* pTempData = stbi_load(SourceFile, &Width, &Height, &ComponentCount, STBI_rgb_alpha); |
| 660 | |
| 661 | if (pTempData == NULL) |
| 662 | { |
| 663 | return CMP_ERR_UNSUPPORTED_SOURCE_FORMAT; |
| 664 | } |
| 665 | |
| 666 | CMP_CMIPS CMips; |
| 667 | |
| 668 | memset(MipSetIn, 0, sizeof(MipSet)); |
| 669 | if (!CMips.AllocateMipSet(MipSetIn, CF_8bit, TDT_ARGB, TT_2D, Width, Height, 1)) |
| 670 | { |
| 671 | return CMP_ERR_MEM_ALLOC_FOR_MIPSET; |
| 672 | } |
| 673 | |
| 674 | if (!CMips.AllocateMipLevelData(CMips.GetMipLevel(MipSetIn, 0), Width, Height, CF_8bit, TDT_ARGB)) |
| 675 | { |
| 676 | return CMP_ERR_MEM_ALLOC_FOR_MIPSET; |
| 677 | } |
| 678 | |
| 679 | MipSetIn->m_nMipLevels = 1; |
| 680 | MipSetIn->m_format = CMP_FORMAT_RGBA_8888; |
| 681 | |
| 682 | CMP_BYTE* pData = CMips.GetMipLevel(MipSetIn, 0)->m_pbData; |
| 683 | |
| 684 | // RGBA : 8888 = 4 bytes |
| 685 | CMP_DWORD dwPitch = (4 * MipSetIn->m_nWidth); |
| 686 | CMP_DWORD dwSize = dwPitch * MipSetIn->m_nHeight; |
| 687 | |
| 688 | memcpy(pData, pTempData, dwSize); |
| 689 | |
| 690 | // Assign miplevel 0 to MipSetin pData ref |
| 691 | // both miplevel pData and mipset pData will point to the same location |
| 692 | // Typically mipset pData is assign a pointer to the current miplevel data been processed at run time |
| 693 | MipSetIn->pData = pData; |
| 694 | MipSetIn->dwDataSize = dwSize; |
| 695 | |
| 696 | stbi_image_free(pTempData); |
| 697 | return CMP_OK; |
| 698 | } |
| 699 | |
| 700 | void CMP_API CMP_FreeMipSet(CMP_MipSet* MipSetIn) |
| 701 | { |
no test coverage detected