1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  * Copyright (C) 2016 Mopria Alliance, Inc.
4  * Copyright (C) 2013 Hewlett-Packard Development Company, L.P.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #include <string.h>
20 #include "wprint_image.h"
21 #include "wprint_mupdf.h"
22 
wprint_image_get_decode_ifc(wprint_image_info_t * image_info)23 const image_decode_ifc_t *wprint_image_get_decode_ifc(wprint_image_info_t *image_info) {
24     if ((image_info != NULL) && (image_info->mime_type != NULL)) {
25         // Only PDF will be provided by upper layer
26         if (strcasecmp(image_info->mime_type, MIME_TYPE_PDF) == 0) {
27             return wprint_mupdf_decode_ifc;
28         }
29     }
30     return NULL;
31 }
32 
wprint_image_init(wprint_image_info_t * image_info,const char * image_url,const int page_num)33 int wprint_image_init(wprint_image_info_t *image_info, const char *image_url, const int page_num) {
34     if (image_info == NULL) return ERROR;
35 
36     image_info->decoder_data.urlPath = image_url;
37     image_info->decoder_data.page = page_num;
38 
39     const image_decode_ifc_t *decode_ifc = wprint_image_get_decode_ifc(image_info);
40     if ((decode_ifc != NULL) && (decode_ifc->init != NULL)) {
41         decode_ifc->init(image_info);
42         image_info->decode_ifc = decode_ifc;
43         return OK;
44     }
45     return ERROR;
46 }