4 * Copyright 2012 Samsung Electronics Co., Ltd
6 * Licensed under the Flora License, Version 1.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
10 * http://floralicense.org/license/
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.
22 #include <page_preview.h>
23 #include <page_preview_thread.h>
24 #include <previewgen.h>
26 #include "pts_debug.h"
27 #include "preview_engine.h"
29 int init_preview_engine(struct preview_engine *engine)
32 PTS_RETV_IF(engine == NULL, -1, "engine is NULL");
34 /*engine->fname = NULL;
35 DBG("preview_engine: fname = %s", fname);*/
37 engine->state = PREVIEW_ENGINE_STATE_INITIAL;
38 engine->initial_thread = NULL;
39 engine->next_preview_data = NULL;
41 memset(&(engine->p_model), 0, sizeof(struct preview_model));
43 if (init_preview_task_model(&(engine->task_model), engine) < 0) {
47 /*if (init_preview_model(&(engine->p_model)) < 0)
50 /*engine->preview_data.pages_count = -1;
51 engine->preview_data.fname = strdup(fname);*/
53 engine->page_ready_event_type = ecore_event_type_new();
59 /* TODO: engine destruction */
60 int preview_engine_init_done(struct preview_engine *engine,
61 const struct preview_conf *conf)
64 if (conf->pages_count > 0) {
65 engine->state = PREVIEW_ENGINE_STATE_READY;
66 if (init_preview_model(&(engine->p_model),
68 PTS_DEBUG("ERROR in preview model initialization");
69 engine->state = PREVIEW_ENGINE_STATE_ERROR;
70 preview_engine_send_page_message(engine,
71 PREVIEW_ENGINE_EVENT_INITIAL_ERROR, -1);
75 preview_engine_send_page_message(engine,
76 PREVIEW_ENGINE_EVENT_INITIAL_READY, 0);
81 PTS_DEBUG("ERROR: no pages");
82 engine->state = PREVIEW_ENGINE_STATE_ERROR;
83 preview_engine_send_page_message(engine,
84 PREVIEW_ENGINE_EVENT_INITIAL_ERROR, -1);
89 int process_preview_engine_file(struct preview_engine *engine,
92 const struct paper_size_pts *paper_size,
93 const struct size_px *max_available_size_px,
94 enum page_orientation orientation, int n_up,
95 const struct page_scale *scale, int is_grayscale)
98 PTS_RETV_IF(NULL == engine ||
101 NULL == paper_size ||
103 NULL == max_available_size_px
104 , -1 , "Invalid argument");
106 struct initial_preview_data *data;
108 data = malloc(sizeof(struct initial_preview_data));
109 PTS_RETV_IF(data == NULL, -1, "Insufficient memory");
111 data->conf.initial_fname = strdup(fname);
112 data->conf.ppd = strdup(ppd);
113 data->conf.fname = strdup(TEMP_PDFTOPDF_FNAME);
114 data->conf.paper_size = *paper_size;
115 data->conf.paper_size.name = strdup(paper_size->name);
116 data->conf.max_available_size_px = *max_available_size_px;
117 data->conf.orientation = orientation;
118 data->conf.n_up = n_up;
119 data->conf.scale = *scale;
120 data->conf.is_grayscale = is_grayscale;
121 data->engine = engine;
123 //careful memory release:
124 if (data->conf.initial_fname == NULL || data->conf.ppd == NULL ||
125 data->conf.fname == NULL || data->conf.paper_size.name == NULL) {
126 PTS_IF_FREE_MEM(data->conf.initial_fname);
127 PTS_IF_FREE_MEM(data->conf.ppd);
128 PTS_IF_FREE_MEM(data->conf.fname);
129 PTS_IF_FREE_MEM(data->conf.paper_size.name);
130 PTS_IF_FREE_MEM(data);
131 PTS_RETV_IF(1, -1, "Insufficient memory");
134 engine->state = PREVIEW_ENGINE_STATE_PROCESSING;
135 add_preview_task_initial(&(engine->task_model), &(data->conf));
136 PTS_IF_FREE_MEM(data);
142 void preview_engine_send_page_message(struct preview_engine *engine,
143 enum preview_engine_event_status status, int page)
145 PTS_RET_IF(engine == NULL, "engine is NULL");
147 struct preview_engine_event *event_data = malloc(sizeof(*event_data));
150 PTS_DEBUG("Send event: [%d, %d]", page, status);
152 /* TODO: check for active preview model */
153 event_data->page = page;
154 event_data->status = status;
155 ecore_event_add(engine->page_ready_event_type, event_data, NULL, NULL);