comparison mupdf-source/source/fitz/transition.c @ 3:2c135c81b16c

MERGE: upstream PyMuPDF 1.26.4 with MuPDF 1.26.7
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:44:09 +0200
parents b50eed0cc0ef
children
comparison
equal deleted inserted replaced
0:6015a75abc2d 3:2c135c81b16c
1 // Copyright (C) 2004-2021 Artifex Software, Inc.
2 //
3 // This file is part of MuPDF.
4 //
5 // MuPDF is free software: you can redistribute it and/or modify it under the
6 // terms of the GNU Affero General Public License as published by the Free
7 // Software Foundation, either version 3 of the License, or (at your option)
8 // any later version.
9 //
10 // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY
11 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU Affero General Public License
16 // along with MuPDF. If not, see <https://www.gnu.org/licenses/agpl-3.0.en.html>
17 //
18 // Alternative licensing terms are available from the licensor.
19 // For commercial licensing, see <https://www.artifex.com/> or contact
20 // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
21 // CA 94129, USA, for further information.
22
23 #include "mupdf/fitz.h"
24
25 #include <string.h>
26
27 /*
28 FIXME: Currently transitions only work with alpha. Our app only
29 uses alpha.
30 */
31
32 static int
33 fade(fz_pixmap *tpix, const fz_pixmap *opix, const fz_pixmap *npix, int time)
34 {
35 unsigned char *t, *o, *n;
36 int size;
37 int h;
38 int tstride, ostride, nstride;
39
40 if (!tpix || !opix || !npix || tpix->w != opix->w || opix->w != npix->w || tpix->h != opix->h || opix->h != npix->h || tpix->n != opix->n || opix->n != npix->n)
41 return 0;
42 h = tpix->h;
43 size = tpix->w * tpix->n;
44 ostride = opix->stride - size;
45 nstride = npix->stride - size;
46 tstride = tpix->stride - size;
47 t = tpix->samples;
48 o = opix->samples;
49 n = npix->samples;
50 while (h--)
51 {
52 int ww = size;
53 while (ww-- > 0)
54 {
55 int op = *o++;
56 int np = *n++;
57 *t++ = ((op<<8) + ((np-op) * time) + 0x80)>>8;
58 }
59 o += ostride;
60 n += nstride;
61 t += tstride;
62 }
63 return 1;
64 }
65
66 static int
67 blind_horiz(fz_pixmap *tpix, fz_pixmap *opix, fz_pixmap *npix, int time)
68 {
69 unsigned char *t, *o, *n;
70 int blind_height, size, position, y;
71 int tstride, ostride, nstride;
72
73 if (!tpix || !opix || !npix || tpix->w != opix->w || opix->w != npix->w || tpix->h != opix->h || opix->h != npix->h || tpix->n != opix->n || opix->n != npix->n)
74 return 0;
75 size = tpix->w * tpix->n;
76 blind_height = (tpix->h+7) / 8;
77 position = blind_height * time / 256;
78 ostride = opix->stride;
79 nstride = npix->stride;
80 tstride = tpix->stride;
81 t = tpix->samples;
82 o = opix->samples;
83 n = npix->samples;
84 for (y = 0; y < tpix->h; y++)
85 {
86 memcpy(t, ((y % blind_height) <= position ? n : o), size);
87 t += tstride;
88 o += ostride;
89 n += nstride;
90 }
91 return 1;
92 }
93
94 static int
95 blind_vertical(fz_pixmap *tpix, fz_pixmap *opix, fz_pixmap *npix, int time)
96 {
97 unsigned char *t, *o, *n;
98 int blind_width, size, position, y;
99 int tstride, ostride, nstride;
100
101 if (!tpix || !opix || !npix || tpix->w != opix->w || opix->w != npix->w || tpix->h != opix->h || opix->h != npix->h || tpix->n != opix->n || opix->n != npix->n)
102 return 0;
103 size = tpix->w * tpix->n;
104 blind_width = (tpix->w+7) / 8;
105 position = blind_width * time / 256;
106 blind_width *= tpix->n;
107 position *= tpix->n;
108 ostride = opix->stride - size;
109 nstride = npix->stride - size;
110 tstride = tpix->stride - size;
111 t = tpix->samples;
112 o = opix->samples;
113 n = npix->samples;
114 for (y = 0; y < tpix->h; y++)
115 {
116 int w, x;
117 x = 0;
118 while ((w = size - x) > 0)
119 {
120 int p;
121 if (w > blind_width)
122 w = blind_width;
123 p = position;
124 if (p > w)
125 p = w;
126 memcpy(t, n, p);
127 memcpy(t+position, o+position, w - p);
128 x += blind_width;
129 t += w;
130 o += w;
131 n += w;
132 }
133 o += ostride;
134 n += nstride;
135 t += tstride;
136 }
137 return 1;
138 }
139
140 static int
141 wipe_tb(fz_pixmap *tpix, fz_pixmap *opix, fz_pixmap *npix, int time)
142 {
143 unsigned char *t, *o, *n;
144 int size, position, y;
145 int tstride, ostride, nstride;
146
147 if (!tpix || !opix || !npix || tpix->w != opix->w || opix->w != npix->w || tpix->h != opix->h || opix->h != npix->h || tpix->n != opix->n || opix->n != npix->n)
148 return 0;
149 size = tpix->w * tpix->n;
150 position = tpix->h * time / 256;
151 ostride = opix->stride;
152 nstride = npix->stride;
153 tstride = tpix->stride;
154 t = tpix->samples;
155 o = opix->samples;
156 n = npix->samples;
157 for (y = 0; y < position; y++)
158 {
159 memcpy(t, n, size);
160 t += tstride;
161 o += ostride;
162 n += nstride;
163 }
164 for (; y < tpix->h; y++)
165 {
166 memcpy(t, o, size);
167 t += tstride;
168 o += ostride;
169 n += nstride;
170 }
171 return 1;
172 }
173
174 static int
175 wipe_lr(fz_pixmap *tpix, fz_pixmap *opix, fz_pixmap *npix, int time)
176 {
177 unsigned char *t, *o, *n;
178 int size, position, y;
179 int tstride, ostride, nstride;
180
181 if (!tpix || !opix || !npix || tpix->w != opix->w || opix->w != npix->w || tpix->h != opix->h || opix->h != npix->h || tpix->n != opix->n || opix->n != npix->n)
182 return 0;
183 size = tpix->w * tpix->n;
184 position = tpix->w * time / 256;
185 position *= tpix->n;
186 ostride = opix->stride;
187 nstride = npix->stride;
188 tstride = tpix->stride;
189 t = tpix->samples;
190 o = opix->samples + position;
191 n = npix->samples;
192 for (y = 0; y < tpix->h; y++)
193 {
194 memcpy(t, n, position);
195 memcpy(t+position, o, size-position);
196 t += tstride;
197 o += ostride;
198 n += nstride;
199 }
200 return 1;
201 }
202
203 int fz_generate_transition(fz_context *ctx, fz_pixmap *tpix, fz_pixmap *opix, fz_pixmap *npix, int time, fz_transition *trans)
204 {
205 switch (trans->type)
206 {
207 default:
208 case FZ_TRANSITION_FADE:
209 return fade(tpix, opix, npix, time);
210 case FZ_TRANSITION_BLINDS:
211 if (trans->vertical)
212 return blind_vertical(tpix, opix, npix, time);
213 else
214 return blind_horiz(tpix, opix, npix, time);
215 case FZ_TRANSITION_WIPE:
216 switch (((trans->direction + 45 + 360) % 360) / 90)
217 {
218 default:
219 case 0: return wipe_lr(tpix, opix, npix, time);
220 case 1: return wipe_tb(tpix, npix, opix, 256-time);
221 case 2: return wipe_lr(tpix, npix, opix, 256-time);
222 case 3: return wipe_tb(tpix, opix, npix, time);
223 }
224 }
225 }