1 /*
2 * Copyright (c) 2018 Dirk Farin <farin@struktur.de>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #include "HeifError.h"
21
22
setHeifError(KisDocument * document,heif::Error error)23 KisImportExportErrorCode setHeifError(KisDocument* document,
24 heif::Error error)
25 {
26 switch (error.get_code()) {
27 case heif_error_Ok:
28 return ImportExportCodes::OK;
29
30 case heif_error_Input_does_not_exist:
31 // this should never happen because we do not read from file names
32 KIS_ASSERT_RECOVER_RETURN_VALUE(true, ImportExportCodes::InternalError);
33 return ImportExportCodes::InternalError;
34
35 case heif_error_Invalid_input:
36 case heif_error_Decoder_plugin_error:
37 return ImportExportCodes::FileFormatIncorrect;
38
39 case heif_error_Unsupported_filetype:
40 case heif_error_Unsupported_feature:
41 return ImportExportCodes::FormatFeaturesUnsupported;
42
43 case heif_error_Usage_error:
44 case heif_error_Encoder_plugin_error:
45 // this should never happen if we use libheif in the correct way
46 KIS_ASSERT_RECOVER_RETURN_VALUE(true, ImportExportCodes::InternalError);
47 return ImportExportCodes::InternalError;
48
49 case heif_error_Memory_allocation_error:
50 document->setErrorMessage(i18n("Could not allocate memory."));
51 return ImportExportCodes::InsufficientMemory;
52
53 case heif_error_Encoding_error:
54 document->setErrorMessage(i18n("Could not encode or write image."));
55 return ImportExportCodes::NoAccessToWrite;
56
57 default:
58 // we only get here when we forgot to handle an error ID
59 document->setErrorMessage(i18n("Unknown error."));
60 return ImportExportCodes::Failure;
61 }
62 }
63