-------------------------------------------------------------------------------------- Description: Starts saving TGA image. Opens a file and writes out a header. Arguments: path - Res or physical path to output TGA image width - Width of the image height - Height of the image pixelFormat - Image pixel format Return Value: AL result of operation ----------------------------------------------------
| 43 | // AL result of operation |
| 44 | // -------------------------------------------------------------------------------------- |
| 45 | ALResult Tr2StreamingBitmapSaver::StartSaving( |
| 46 | const wchar_t* path, |
| 47 | uint32_t width, |
| 48 | uint32_t height, |
| 49 | Tr2RenderContextEnum::PixelFormat pixelFormat ) |
| 50 | { |
| 51 | if( IsSaving() ) |
| 52 | { |
| 53 | CR_RETURN_HR( EndSaving() ); |
| 54 | } |
| 55 | |
| 56 | if( !ImageIO::Tga::IsSaveSupported( m_format ) ) |
| 57 | { |
| 58 | CCP_LOGWARN( |
| 59 | "Tr2StreamingBitmapSaver::StartSaving unsupported image format (%i)", |
| 60 | pixelFormat ); |
| 61 | return E_INVALIDARG; |
| 62 | } |
| 63 | |
| 64 | if( !width || !height ) |
| 65 | { |
| 66 | CCP_LOGWARN( |
| 67 | "Tr2StreamingBitmapSaver::StartSaving invalid image dimensions (%u x %u)", |
| 68 | width, |
| 69 | height ); |
| 70 | return E_INVALIDARG; |
| 71 | } |
| 72 | |
| 73 | Be::Clsid resFileClsid( "blue", "ResFile" ); |
| 74 | IResFilePtr stream( resFileClsid ); |
| 75 | if( !( stream->FileExistsW( path ) ? stream->OpenW( path, false ) : stream->CreateW( path ) ) ) |
| 76 | { |
| 77 | CCP_LOGWARN( |
| 78 | "Tr2StreamingBitmapSaver::StartSaving failed to open Blue stream (%ls)", |
| 79 | path ); |
| 80 | return E_FAIL; |
| 81 | } |
| 82 | |
| 83 | if( !ImageIO::Tga::SaveHeader( width, height, pixelFormat, *stream ) ) |
| 84 | { |
| 85 | CCP_LOGWARN( |
| 86 | "Tr2StreamingBitmapSaver::StartSaving failed to write TGA header (%ls)", |
| 87 | path ); |
| 88 | return E_FAIL; |
| 89 | } |
| 90 | |
| 91 | m_output = stream; |
| 92 | |
| 93 | m_width = width; |
| 94 | m_height = height; |
| 95 | m_format = pixelFormat; |
| 96 | m_bytesPerPixel = Tr2RenderContextEnum::GetBytesPerPixel( m_format ); |
| 97 | m_currentOffset = m_height; |
| 98 | |
| 99 | return S_OK; |
| 100 | } |
| 101 | |
| 102 | // -------------------------------------------------------------------------------------- |
no outgoing calls
no test coverage detected