summaryrefslogtreecommitdiffstats
path: root/tools/render-test/png-serialize-util.cpp
blob: a7f6aa83a8d4e884575235442e3d463c3d2e3bcc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// png-serialize-util.cpp
#define _CRT_SECURE_NO_WARNINGS

#include "png-serialize-util.h"

#include <stdlib.h>
#include <stdio.h>

#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "external/stb/stb_image_write.h"

namespace renderer_test {
using namespace Slang;

/* static */Slang::Result PngSerializeUtil::write(const char* filename, const Surface& surface)
{
    int numComps = 0;
    switch (surface.m_format)
    {
        case Format::RGBA_Unorm_UInt8:
        {
            numComps = 4;
            break;
        }
        default: break;
    }

    if (numComps <= 0)
    {
        return SLANG_FAIL;
    }

    int stbResult = stbi_write_png(filename, surface.m_width, surface.m_height, numComps, surface.m_data, surface.m_rowStrideInBytes);

    return stbResult ? SLANG_OK : SLANG_FAIL;
}

} // renderer_test