|
|
|
@ -279,8 +279,17 @@ static int stbi__start_write_file(stbi__write_context *s, const char *filename) |
|
|
|
|
{ |
|
|
|
|
FILE *f; |
|
|
|
|
#ifdef STBI_MSC_SECURE_CRT |
|
|
|
|
#ifdef UNICODE |
|
|
|
|
int filenameLength = MultiByteToWideChar(CP_UTF8, 0, filename, -1, NULL, 0); |
|
|
|
|
wchar_t* wFilename = (wchar_t*)STBIW_MALLOC(filenameLength * sizeof(wchar_t)); |
|
|
|
|
MultiByteToWideChar(CP_UTF8, 0, filename, -1, wFilename, filenameLength); |
|
|
|
|
|
|
|
|
|
if (0 != _wfopen_s(&f, wFilename, L"wb")) |
|
|
|
|
f = NULL; |
|
|
|
|
#else |
|
|
|
|
if (fopen_s(&f, filename, "wb")) |
|
|
|
|
f = NULL; |
|
|
|
|
#endif |
|
|
|
|
#else |
|
|
|
|
f = fopen(filename, "wb"); |
|
|
|
|
#endif |
|
|
|
@ -1112,8 +1121,19 @@ STBIWDEF int stbi_write_png(char const *filename, int x, int y, int comp, const |
|
|
|
|
unsigned char *png = stbi_write_png_to_mem((unsigned char *) data, stride_bytes, x, y, comp, &len); |
|
|
|
|
if (png == NULL) return 0; |
|
|
|
|
#ifdef STBI_MSC_SECURE_CRT |
|
|
|
|
#ifdef UNICODE |
|
|
|
|
int filenameLength = MultiByteToWideChar(CP_UTF8, 0, filename, -1, NULL, 0); |
|
|
|
|
wchar_t* wFilename = (wchar_t*)STBIW_MALLOC(filenameLength * sizeof(wchar_t)); |
|
|
|
|
MultiByteToWideChar(CP_UTF8, 0, filename, -1, wFilename, filenameLength); |
|
|
|
|
|
|
|
|
|
if (0 != _wfopen_s(&f, wFilename, L"wb")) |
|
|
|
|
f = NULL; |
|
|
|
|
|
|
|
|
|
STBIW_FREE(wFilename); |
|
|
|
|
#else |
|
|
|
|
if (fopen_s(&f, filename, "wb")) |
|
|
|
|
f = NULL; |
|
|
|
|
#endif |
|
|
|
|
#else |
|
|
|
|
f = fopen(filename, "wb"); |
|
|
|
|
#endif |
|
|
|
@ -1125,6 +1145,18 @@ STBIWDEF int stbi_write_png(char const *filename, int x, int y, int comp, const |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
char* stbiw_convert_wchar_to_utf8(wchar_t* input) { |
|
|
|
|
#ifdef _WINDOWS_ |
|
|
|
|
int outputSizeNeeded = WideCharToMultiByte(CP_UTF8, 0, &input[0], wcslen(input), NULL, 0, NULL, NULL); |
|
|
|
|
char* temp = (char*)STBIW_MALLOC(outputSizeNeeded); |
|
|
|
|
int error = WideCharToMultiByte(65001, 0, input, -1, temp, outputSizeNeeded, NULL, NULL); |
|
|
|
|
temp[outputSizeNeeded] = '\0'; |
|
|
|
|
return temp; |
|
|
|
|
#else |
|
|
|
|
return NULL; |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
STBIWDEF int stbi_write_png_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const void *data, int stride_bytes) |
|
|
|
|
{ |
|
|
|
|
int len; |
|
|
|
|