|
1 | 1 | // SPDX-License-Identifier: BSD-3-Clause |
2 | 2 | // Copyright Contributors to the OpenEXR Project. |
3 | 3 |
|
| 4 | +#ifdef _WIN32 |
| 5 | +// windows is very particular about when windows.h is included |
| 6 | +#include <windows.h> |
| 7 | +#include <fileapi.h> |
| 8 | +#include <inttypes.h> |
| 9 | +#include <strsafe.h> |
| 10 | +#else |
| 11 | +#include <unistd.h> |
| 12 | +#endif |
| 13 | + |
4 | 14 | #include "write.h" |
5 | 15 |
|
6 | 16 | #include "test_value.h" |
|
10 | 20 | #include <float.h> |
11 | 21 | #include <limits.h> |
12 | 22 | #include <math.h> |
| 23 | +#include <stdio.h> |
13 | 24 | #include <string.h> |
14 | 25 |
|
15 | 26 | #include <iomanip> |
@@ -1395,3 +1406,80 @@ testWriteMultiPart (const std::string& tempdir) |
1395 | 1406 | EXRCORE_TEST_RVAL (exr_finish (&outf)); |
1396 | 1407 | remove (outfn.c_str ()); |
1397 | 1408 | } |
| 1409 | + |
| 1410 | +void |
| 1411 | +testStartWriteUTF8 (const std::string& tempdir) |
| 1412 | +{ |
| 1413 | + exr_context_t outf; |
| 1414 | + // per google translate, image in Japanese |
| 1415 | + std::string outfn = tempdir + "画像.exr"; |
| 1416 | + int partidx; |
| 1417 | + |
| 1418 | + exr_context_initializer_t cinit = EXR_DEFAULT_CONTEXT_INITIALIZER; |
| 1419 | + cinit.error_handler_fn = &err_cb; |
| 1420 | + cinit.zip_level = 3; |
| 1421 | + cinit.flags |= EXR_CONTEXT_FLAG_WRITE_LEGACY_HEADER; |
| 1422 | + |
| 1423 | + exr_set_default_zip_compression_level (-1); |
| 1424 | + |
| 1425 | + EXRCORE_TEST_RVAL (exr_start_write ( |
| 1426 | + &outf, outfn.c_str (), EXR_WRITE_FILE_DIRECTLY, &cinit)); |
| 1427 | + EXRCORE_TEST_RVAL ( |
| 1428 | + exr_add_part (outf, "beauty", EXR_STORAGE_SCANLINE, &partidx)); |
| 1429 | + EXRCORE_TEST (partidx == 0); |
| 1430 | + EXRCORE_TEST_RVAL (exr_get_count (outf, &partidx)); |
| 1431 | + EXRCORE_TEST (partidx == 1); |
| 1432 | + partidx = 0; |
| 1433 | + |
| 1434 | + int fw = 1; |
| 1435 | + int fh = 1; |
| 1436 | + exr_attr_box2i_t dataW = { {0, 0}, {0, 0} }; |
| 1437 | + |
| 1438 | + EXRCORE_TEST_RVAL ( |
| 1439 | + exr_initialize_required_attr_simple (outf, partidx, fw, fh, EXR_COMPRESSION_NONE)); |
| 1440 | + EXRCORE_TEST_RVAL (exr_set_data_window (outf, partidx, &dataW)); |
| 1441 | + |
| 1442 | + EXRCORE_TEST_RVAL (exr_add_channel ( |
| 1443 | + outf, partidx, "h", EXR_PIXEL_HALF, EXR_PERCEPTUALLY_LOGARITHMIC, 1, 1)); |
| 1444 | + EXRCORE_TEST_RVAL (exr_write_header (outf)); |
| 1445 | + |
| 1446 | + exr_chunk_info_t cinfo; |
| 1447 | + exr_encode_pipeline_t encoder; |
| 1448 | + |
| 1449 | + EXRCORE_TEST_RVAL (exr_write_scanline_chunk_info (outf, 0, 0, &cinfo)); |
| 1450 | + EXRCORE_TEST_RVAL ( |
| 1451 | + exr_encoding_initialize (outf, 0, &cinfo, &encoder)); |
| 1452 | + |
| 1453 | + uint16_t hval[] = { 0x1234, 0 }; |
| 1454 | + for (int c = 0; c < encoder.channel_count; ++c) |
| 1455 | + { |
| 1456 | + encoder.channels[c].encode_from_ptr = (const uint8_t *)hval; |
| 1457 | + encoder.channels[c].user_pixel_stride = 2; |
| 1458 | + encoder.channels[c].user_line_stride = 2; |
| 1459 | + } |
| 1460 | + EXRCORE_TEST_RVAL ( |
| 1461 | + exr_encoding_choose_default_routines (outf, 0, &encoder)); |
| 1462 | + EXRCORE_TEST_RVAL (exr_encoding_run (outf, 0, &encoder)); |
| 1463 | + EXRCORE_TEST_RVAL (exr_encoding_destroy (outf, &encoder)); |
| 1464 | + |
| 1465 | + EXRCORE_TEST_RVAL (exr_finish (&outf)); |
| 1466 | +#ifdef _WIN32 |
| 1467 | + int wcSize = 0, fnlen = 0; |
| 1468 | + wchar_t* wcFn = NULL; |
| 1469 | + |
| 1470 | + fnlen = (int) strlen (outfn.c_str ()); |
| 1471 | + wcSize = MultiByteToWideChar (CP_UTF8, 0, outfn.c_str (), fnlen, NULL, 0); |
| 1472 | + wcFn = (wchar_t*) malloc (sizeof (wchar_t) * (wcSize + 1)); |
| 1473 | + if (wcFn) |
| 1474 | + { |
| 1475 | + MultiByteToWideChar (CP_UTF8, 0, outfn.c_str (), fnlen, wcFn, wcSize); |
| 1476 | + wcFn[wcSize] = 0; |
| 1477 | + } |
| 1478 | + EXRCORE_TEST ( _waccess (wcFn, 0) != -1 ); |
| 1479 | + _wremove (wcFn); |
| 1480 | + free (wcFn); |
| 1481 | +#else |
| 1482 | + EXRCORE_TEST ( access (outfn.c_str (), F_OK) != -1 ); |
| 1483 | + remove (outfn.c_str ()); |
| 1484 | +#endif |
| 1485 | +} |
0 commit comments