1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
|
/*
This code does smooth scaling of a pixmap.
This function returns a new pixmap representing the area starting at (0,0)
given by taking the source pixmap src, scaling it to width w, and height h,
and then positioning it at (frac(x),frac(y)).
This is a cut-down version of draw_scale.c that only copes with filters
that return values strictly in the 0..1 range, and uses bytes for
intermediate results rather than ints.
*/
#include "fitz.h"
/* Do we special case handling of single pixel high/wide images? The
* 'purest' handling is given by not special casing them, but certain
* files that use such images 'stack' them to give full images. Not
* special casing them results in then being fainter and giving noticable
* rounding errors.
*/
#define SINGLE_PIXEL_SPECIALS
/* If we're compiling as thumb code, then we need to tell the compiler
* to enter and exit ARM mode around our assembly sections. If we move
* the ARM functions to a separate file and arrange for it to be compiled
* without thumb mode, we can save some time on entry.
*/
#ifdef ARCH_ARM
#ifdef ARCH_THUMB
#define ENTER_ARM ".balign 4\nmov r12,pc\nbx r12\n0:.arm\n"
#define ENTER_THUMB "9:.thumb\n"
#else
#define ENTER_ARM
#define ENTER_THUMB
#endif
#endif
#ifdef DEBUG_SCALING
#ifdef WIN32
#include <windows.h>
static void debug_print(const char *fmt, ...)
{
va_list args;
char text[256];
va_start(args, fmt);
vsprintf(text, fmt, args);
va_end(args);
OutputDebugStringA(text);
printf(text);
}
#else
static void debug_print(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
vfprintf(stderr, fmt, args);
va_end(args);
}
#endif
#endif
#ifdef DEBUG_SCALING
#define DBUG(A) debug_print A
#else
#define DBUG(A) do {} while(0==1)
#endif
/*
Consider a row of source samples, src, of width src_w, positioned at x,
scaled to width dst_w.
src[i] is centred at: x + (i + 0.5)*dst_w/src_w
Therefore the distance between the centre of the jth output pixel and
the centre of the ith source sample is:
dist[j,i] = j + 0.5 - (x + (i + 0.5)*dst_w/src_w)
When scaling up, therefore:
dst[j] = SUM(filter(dist[j,i]) * src[i])
(for all ints i)
This can be simplified by noticing that filters are only non zero within
a given filter width (henceforth called W). So:
dst[j] = SUM(filter(dist[j,i]) * src[i])
(for ints i, s.t. (j*src_w/dst_w)-W < i < (j*src_w/dst_w)+W)
When scaling down, each filtered source sample is stretched to be wider
to avoid aliasing issues. This effectively reduces the distance between
centres.
dst[j] = SUM(filter(dist[j,i] * F) * F * src[i])
(where F = dst_w/src_w)
(for ints i, s.t. (j-W)/F < i < (j+W)/F)
*/
typedef struct fz_scale_filter_s fz_scale_filter;
struct fz_scale_filter_s
{
int width;
float (*fn)(fz_scale_filter *, float);
};
/* Image scale filters */
static float
triangle(fz_scale_filter *filter, float f)
{
if (f >= 1)
return 0;
return 1-f;
}
static float
box(fz_scale_filter *filter, float f)
{
if (f >= 0.5f)
return 0;
return 1;
}
static float
simple(fz_scale_filter *filter, float x)
{
if (x >= 1)
return 0;
return 1 + (2*x - 3)*x*x;
}
fz_scale_filter fz_scale_filter_box = { 1, box };
fz_scale_filter fz_scale_filter_triangle = { 1, triangle };
fz_scale_filter fz_scale_filter_simple = { 1, simple };
/*
We build ourselves a set of tables to contain the precalculated weights
for a given set of scale settings.
The first dst_w entries in index are the index into index of the
sets of weight for each destination pixel.
Each of the sets of weights is a set of values consisting of:
the minimum source pixel index used for this destination pixel
the number of weights used for this destination pixel
the weights themselves
So to calculate dst[i] we do the following:
weights = &index[index[i]];
min = *weights++;
len = *weights++;
dst[i] = 0;
while (--len > 0)
dst[i] += src[min++] * *weights++
in addition, we guarantee that at the end of this process weights will now
point to the weights value for dst pixel i+1.
In the simplest version of this algorithm, we would scale the whole image
horizontally first into a temporary buffer, then scale that temporary
buffer again vertically to give us our result. Using such a simple
algorithm would mean that could use the same style of weights for both
horizontal and vertical scaling.
Unfortunately, this would also require a large temporary buffer,
particularly in the case where we are scaling up.
We therefore modify the algorithm as follows; we scale scanlines from the
source image horizontally into a temporary buffer, until we have all the
contributors for a given output scanline. We then produce that output
scanline from the temporary buffer. In this way we restrict the height
of the temporary buffer to a small fraction of the final size.
Unfortunately, this means that the pseudo code for recombining a
scanline of fully scaled pixels is as follows:
weights = &index[index[y]];
min = *weights++;
len = *weights++;
for (x=0 to dst_w)
min2 = min
len2 = len
weights2 = weights
dst[x] = 0;
while (--len2 > 0)
dst[x] += temp[x][(min2++) % tmp_buf_height] * *weights2++
i.e. it requires a % operation for every source pixel - this is typically
expensive.
To avoid this, we alter the order in which vertical weights are stored,
so that they are ordered in the same order as the temporary buffer lines
would appear. This simplifies the algorithm to:
weights = &index[index[y]];
min = *weights++;
len = *weights++;
for (x=0 to dst_w)
min2 = 0
len2 = len
weights2 = weights
dst[x] = 0;
while (--len2 > 0)
dst[x] += temp[i][min2++] * *weights2++
This means that len may be larger than it needs to be (due to the
possible inclusion of a zero weight row or two), but in practise this
is only an increase of 1 or 2 at worst.
We implement this by generating the weights as normal (but ensuring we
leave enough space) and then reordering afterwards.
*/
typedef struct fz_weights_s fz_weights;
struct fz_weights_s
{
int flip;
int count;
int max_len;
int n;
int new_line;
int index[1];
};
static fz_weights *
new_weights(fz_context *ctx, fz_scale_filter *filter, int src_w, float dst_w, int dst_w_i, int n, int flip)
{
int max_len;
fz_weights *weights;
if (src_w > dst_w)
{
/* Scaling down, so there will be a maximum of
* 2*filterwidth*src_w/dst_w src pixels
* contributing to each dst pixel. */
max_len = (int)ceilf((2 * filter->width * src_w)/dst_w);
if (max_len > src_w)
max_len = src_w;
}
else
{
/* Scaling up, so there will be a maximum of
* 2*filterwidth src pixels contributing to each dst pixel.
*/
max_len = 2 * filter->width;
}
/* We need the size of the struct,
* plus dst_w*sizeof(int) for the index
* plus (2+max_len)*sizeof(int) for the weights
* plus room for an extra set of weights for reordering.
*/
weights = fz_malloc(ctx, sizeof(*weights)+(max_len+3)*(dst_w_i+1)*sizeof(int));
if (!weights)
return NULL;
weights->count = -1;
weights->max_len = max_len;
weights->index[0] = dst_w_i;
weights->n = n;
weights->flip = flip;
return weights;
}
static void
init_weights(fz_weights *weights, int j)
{
int index;
assert(weights->count == j-1);
weights->count++;
weights->new_line = 1;
if (j == 0)
index = weights->index[0];
else
{
index = weights->index[j-1];
index += 2 + weights->index[index+1];
}
weights->index[j] = index; /* row pointer */
weights->index[index] = 0; /* min */
weights->index[index+1] = 0; /* len */
}
static void
add_weight(fz_weights *weights, int j, int i, fz_scale_filter *filter,
float x, float F, float G, int src_w, float dst_w)
{
float dist = j - x + 0.5f - ((i + 0.5f)*dst_w/src_w);
float f;
int min, len, index, weight;
dist *= G;
if (dist < 0)
dist = -dist;
f = filter->fn(filter, dist)*F;
weight = (int)(256*f+0.5f);
if (weight == 0)
return;
/* Ensure i is in range */
if (i < 0)
{
i = 0;
weight = 0;
}
else if (i >= src_w)
{
i = src_w-1;
weight = 0;
}
if (weight == 0)
return;
DBUG(("add_weight[%d][%d] = %d(%g) dist=%g\n",j,i,weight,f,dist));
if (weights->new_line)
{
/* New line */
weights->new_line = 0;
index = weights->index[j]; /* row pointer */
weights->index[index] = i; /* min */
weights->index[index+1] = 0; /* len */
}
index = weights->index[j];
min = weights->index[index++];
len = weights->index[index++];
while (i < min)
{
/* This only happens in rare cases, but we need to insert
* one earlier. In exceedingly rare cases we may need to
* insert more than one earlier. */
int k;
for (k = len; k > 0; k--)
{
weights->index[index+k] = weights->index[index+k-1];
}
weights->index[index] = 0;
min--;
len++;
weights->index[index-2] = min;
weights->index[index-1] = len;
}
if (i-min >= len)
{
/* The usual case */
while (i-min >= ++len)
{
weights->index[index+len-1] = 0;
}
assert(len-1 == i-min);
weights->index[index+i-min] = weight;
weights->index[index-1] = len;
assert(len <= weights->max_len);
}
else
{
/* Infrequent case */
weights->index[index+i-min] += weight;
}
}
static void
reorder_weights(fz_weights *weights, int j, int src_w)
{
int idx = weights->index[j];
int min = weights->index[idx++];
int len = weights->index[idx++];
int max = weights->max_len;
int tmp = idx+max;
int i, off;
/* Copy into the temporary area */
memcpy(&weights->index[tmp], &weights->index[idx], sizeof(int)*len);
/* Pad out if required */
assert(len <= max);
assert(min+len <= src_w);
off = 0;
if (len < max)
{
memset(&weights->index[tmp+len], 0, sizeof(int)*(max-len));
len = max;
if (min + len > src_w)
{
off = min + len - src_w;
min = src_w - len;
weights->index[idx-2] = min;
}
weights->index[idx-1] = len;
}
/* Copy back into the proper places */
for (i = 0; i < len; i++)
{
weights->index[idx+((min+i+off) % max)] = weights->index[tmp+i];
}
}
/* Due to rounding and edge effects, the sums for the weights sometimes don't
* add up to 256. This causes visible rendering effects. Therefore, we take
* pains to ensure that they 1) never exceed 256, and 2) add up to exactly
* 256 for all pixels that are completely covered. See bug #691629. */
static void
check_weights(fz_weights *weights, int j, int w, float x, float wf)
{
int idx, len;
int sum = 0;
int max = -256;
int maxidx = 0;
int i;
idx = weights->index[j];
idx++; /* min */
len = weights->index[idx++];
for(i=0; i < len; i++)
{
int v = weights->index[idx++];
sum += v;
if (v > max)
{
max = v;
maxidx = idx;
}
}
/* If we aren't the first or last pixel, OR if the sum is too big
* then adjust it. */
if (((j != 0) && (j != w-1)) || (sum > 256))
weights->index[maxidx-1] += 256-sum;
/* Otherwise, if we are the first pixel, and it's fully covered, then
* adjust it. */
else if ((j == 0) && (x < 0.0001F) && (sum != 256))
weights->index[maxidx-1] += 256-sum;
/* Finally, if we are the last pixel, and it's fully covered, then
* adjust it. */
else if ((j == w-1) && ((float)w-wf < 0.0001F) && (sum != 256))
weights->index[maxidx-1] += 256-sum;
DBUG(("total weight %d = %d\n", j, sum));
}
static fz_weights *
make_weights(fz_context *ctx, int src_w, float x, float dst_w, fz_scale_filter *filter, int vertical, int dst_w_int, int n, int flip)
{
fz_weights *weights;
float F, G;
float window;
int j;
if (dst_w < src_w)
{
/* Scaling down */
F = dst_w / src_w;
G = 1;
}
else
{
/* Scaling up */
F = 1;
G = src_w / dst_w;
}
window = filter->width / F;
DBUG(("make_weights src_w=%d x=%g dst_w=%g dst_w_int=%d F=%g window=%g\n", src_w, x, dst_w, dst_w_int, F, window));
weights = new_weights(ctx, filter, src_w, dst_w, dst_w_int, n, flip);
if (!weights)
return NULL;
for (j = 0; j < dst_w_int; j++)
{
/* find the position of the centre of dst[j] in src space */
float centre = (j - x + 0.5f)*src_w/dst_w - 0.5f;
int l, r;
l = ceilf(centre - window);
r = floorf(centre + window);
DBUG(("%d: centre=%g l=%d r=%d\n", j, centre, l, r));
init_weights(weights, j);
for (; l <= r; l++)
{
add_weight(weights, j, l, filter, x, F, G, src_w, dst_w);
}
check_weights(weights, j, dst_w_int, x, dst_w);
if (vertical)
{
reorder_weights(weights, j, src_w);
}
}
weights->count++; /* weights->count = dst_w_int now */
return weights;
}
static void
scale_row_to_temp(unsigned char *dst, unsigned char *src, fz_weights *weights)
{
int *contrib = &weights->index[weights->index[0]];
int len, i, j, n;
unsigned char *min;
int tmp[FZ_MAX_COLORS];
int *t = tmp;
n = weights->n;
for (j = 0; j < n; j++)
tmp[j] = 128;
if (weights->flip)
{
dst += (weights->count-1)*n;
for (i=weights->count; i > 0; i--)
{
min = &src[n * *contrib++];
len = *contrib++;
while (len-- > 0)
{
for (j = n; j > 0; j--)
*t++ += *min++ * *contrib;
t -= n;
contrib++;
}
for (j = n; j > 0; j--)
{
*dst++ = (unsigned char)(*t>>8);
*t++ = 128;
}
t -= n;
dst -= n*2;
}
}
else
{
for (i=weights->count; i > 0; i--)
{
min = &src[n * *contrib++];
len = *contrib++;
while (len-- > 0)
{
for (j = n; j > 0; j--)
*t++ += *min++ * *contrib;
t -= n;
contrib++;
}
for (j = n; j > 0; j--)
{
*dst++ = (unsigned char)(*t>>8);
*t++ = 128;
}
t -= n;
}
}
}
#ifdef ARCH_ARM
static void
scale_row_to_temp1(unsigned char *dst, unsigned char *src, fz_weights *weights)
__attribute__((naked));
static void
scale_row_to_temp2(unsigned char *dst, unsigned char *src, fz_weights *weights)
__attribute__((naked));
static void
scale_row_to_temp4(unsigned char *dst, unsigned char *src, fz_weights *weights)
__attribute__((naked));
static void
scale_row_from_temp(unsigned char *dst, unsigned char *src, fz_weights *weights, int width, int row)
__attribute__((naked));
static void
scale_row_to_temp1(unsigned char *dst, unsigned char *src, fz_weights *weights)
{
/* possible optimisation in here; unroll inner loops to avoid stall. */
asm volatile(
ENTER_ARM
"stmfd r13!,{r4-r5,r9,r14} \n"
"@ r0 = dst \n"
"@ r1 = src \n"
"@ r2 = weights \n"
"ldr r12,[r2],#4 @ r12= flip \n"
"ldr r3, [r2],#16 @ r3 = count r2 = &index\n"
"ldr r4, [r2] @ r4 = index[0] \n"
"cmp r12,#0 @ if (flip) \n"
"beq 4f @ { \n"
"add r2, r2, r4, LSL #2 @ r2 = &index[index[0]] \n"
"add r0, r0, r3 @ dst += count \n"
"1: \n"
"ldr r4, [r2], #4 @ r4 = *contrib++ \n"
"ldr r9, [r2], #4 @ r9 = len = *contrib++ \n"
"mov r5, #128 @ r5 = a = 128 \n"
"add r4, r1, r4 @ r4 = min = &src[r4] \n"
"cmp r9, #0 @ while (len-- > 0) \n"
"beq 3f @ { \n"
"2: \n"
"ldr r12,[r2], #4 @ r12 = *contrib++ \n"
"ldrb r14,[r4], #1 @ r14 = *min++ \n"
"subs r9, r9, #1 @ r9 = len-- \n"
"@stall on r14 \n"
"mla r5, r12,r14,r5 @ g += r14 * r12 \n"
"bgt 2b @ } \n"
"3: \n"
"mov r5, r5, lsr #8 @ g >>= 8 \n"
"strb r5,[r0, #-1]! @ *--dst=a \n"
"subs r3, r3, #1 @ i-- \n"
"bgt 1b @ \n"
"ldmfd r13!,{r4-r5,r9,PC} @ pop, return to thumb \n"
"4:"
"add r2, r2, r4, LSL #2 @ r2 = &index[index[0]] \n"
"5:"
"ldr r4, [r2], #4 @ r4 = *contrib++ \n"
"ldr r9, [r2], #4 @ r9 = len = *contrib++ \n"
"mov r5, #128 @ r5 = a = 128 \n"
"add r4, r1, r4 @ r4 = min = &src[r4] \n"
"cmp r9, #0 @ while (len-- > 0) \n"
"beq 7f @ { \n"
"6: \n"
"ldr r12,[r2], #4 @ r12 = *contrib++ \n"
"ldrb r14,[r4], #1 @ r14 = *min++ \n"
"subs r9, r9, #1 @ r9 = len-- \n"
"@stall on r14 \n"
"mla r5, r12,r14,r5 @ a += r14 * r12 \n"
"bgt 6b @ } \n"
"7: \n"
"mov r5, r5, LSR #8 @ a >>= 8 \n"
"strb r5, [r0], #1 @ *dst++=a \n"
"subs r3, r3, #1 @ i-- \n"
"bgt 5b @ \n"
"ldmfd r13!,{r4-r5,r9,PC} @ pop, return to thumb \n"
ENTER_THUMB
);
}
static void
scale_row_to_temp2(unsigned char *dst, unsigned char *src, fz_weights *weights)
{
asm volatile(
ENTER_ARM
"stmfd r13!,{r4-r6,r9-r11,r14} \n"
"@ r0 = dst \n"
"@ r1 = src \n"
"@ r2 = weights \n"
"ldr r12,[r2],#4 @ r12= flip \n"
"ldr r3, [r2],#16 @ r3 = count r2 = &index\n"
"ldr r4, [r2] @ r4 = index[0] \n"
"cmp r12,#0 @ if (flip) \n"
"beq 4f @ { \n"
"add r2, r2, r4, LSL #2 @ r2 = &index[index[0]] \n"
"add r0, r0, r3, LSL #1 @ dst += 2*count \n"
"1: \n"
"ldr r4, [r2], #4 @ r4 = *contrib++ \n"
"ldr r9, [r2], #4 @ r9 = len = *contrib++ \n"
"mov r5, #128 @ r5 = g = 128 \n"
"mov r6, #128 @ r6 = a = 128 \n"
"add r4, r1, r4, LSL #1 @ r4 = min = &src[2*r4] \n"
"cmp r9, #0 @ while (len-- > 0) \n"
"beq 3f @ { \n"
"2: \n"
"ldr r14,[r2], #4 @ r14 = *contrib++ \n"
"ldrb r11,[r4], #1 @ r11 = *min++ \n"
"ldrb r12,[r4], #1 @ r12 = *min++ \n"
"subs r9, r9, #1 @ r9 = len-- \n"
"mla r5, r14,r11,r5 @ g += r11 * r14 \n"
"mla r6, r14,r12,r6 @ a += r12 * r14 \n"
"bgt 2b @ } \n"
"3: \n"
"mov r5, r5, lsr #8 @ g >>= 8 \n"
"mov r6, r6, lsr #8 @ a >>= 8 \n"
"strb r5, [r0, #-2]! @ *--dst=a \n"
"strb r6, [r0, #1] @ *--dst=g \n"
"subs r3, r3, #1 @ i-- \n"
"bgt 1b @ \n"
"ldmfd r13!,{r4-r6,r9-r11,PC} @ pop, return to thumb \n"
"4:"
"add r2, r2, r4, LSL #2 @ r2 = &index[index[0]] \n"
"5:"
"ldr r4, [r2], #4 @ r4 = *contrib++ \n"
"ldr r9, [r2], #4 @ r9 = len = *contrib++ \n"
"mov r5, #128 @ r5 = g = 128 \n"
"mov r6, #128 @ r6 = a = 128 \n"
"add r4, r1, r4, LSL #1 @ r4 = min = &src[2*r4] \n"
"cmp r9, #0 @ while (len-- > 0) \n"
"beq 7f @ { \n"
"6: \n"
"ldr r14,[r2], #4 @ r10 = *contrib++ \n"
"ldrb r11,[r4], #1 @ r11 = *min++ \n"
"ldrb r12,[r4], #1 @ r12 = *min++ \n"
"subs r9, r9, #1 @ r9 = len-- \n"
"mla r5, r14,r11,r5 @ g += r11 * r14 \n"
"mla r6, r14,r12,r6 @ a += r12 * r14 \n"
"bgt 6b @ } \n"
"7: \n"
"mov r5, r5, lsr #8 @ g >>= 8 \n"
"mov r6, r6, lsr #8 @ a >>= 8 \n"
"strb r5, [r0], #1 @ *dst++=g \n"
"strb r6, [r0], #1 @ *dst++=a \n"
"subs r3, r3, #1 @ i-- \n"
"bgt 5b @ \n"
"ldmfd r13!,{r4-r6,r9-r11,PC} @ pop, return to thumb \n"
ENTER_THUMB
);
}
static void
scale_row_to_temp4(unsigned char *dst, unsigned char *src, fz_weights *weights)
{
asm volatile(
ENTER_ARM
"stmfd r13!,{r4-r11,r14} \n"
"@ r0 = dst \n"
"@ r1 = src \n"
"@ r2 = weights \n"
"ldr r12,[r2],#4 @ r12= flip \n"
"ldr r3, [r2],#16 @ r3 = count r2 = &index\n"
"ldr r4, [r2] @ r4 = index[0] \n"
"ldr r5,=0x00800080 @ r5 = rounding \n"
"ldr r6,=0x00FF00FF @ r7 = 0x00FF00FF \n"
"cmp r12,#0 @ if (flip) \n"
"beq 4f @ { \n"
"add r2, r2, r4, LSL #2 @ r2 = &index[index[0]] \n"
"add r0, r0, r3, LSL #2 @ dst += 4*count \n"
"1: \n"
"ldr r4, [r2], #4 @ r4 = *contrib++ \n"
"ldr r9, [r2], #4 @ r9 = len = *contrib++ \n"
"mov r7, r5 @ r7 = b = rounding \n"
"mov r8, r5 @ r8 = a = rounding \n"
"add r4, r1, r4, LSL #2 @ r4 = min = &src[4*r4] \n"
"cmp r9, #0 @ while (len-- > 0) \n"
"beq 3f @ { \n"
"2: \n"
"ldr r11,[r4], #4 @ r11 = *min++ \n"
"ldr r10,[r2], #4 @ r10 = *contrib++ \n"
"subs r9, r9, #1 @ r9 = len-- \n"
"and r12,r6, r11 @ r12 = __22__00 \n"
"and r11,r6, r11,LSR #8 @ r11 = __33__11 \n"
"mla r7, r10,r12,r7 @ b += r14 * r10 \n"
"mla r8, r10,r11,r8 @ a += r11 * r10 \n"
"bgt 2b @ } \n"
"3: \n"
"and r7, r6, r7, lsr #8 @ r7 = __22__00 \n"
"bic r8, r8, r6 @ r8 = 33__11__ \n"
"orr r7, r7, r8 @ r7 = 33221100 \n"
"str r7, [r0, #-4]! @ *--dst=r \n"
"subs r3, r3, #1 @ i-- \n"
"bgt 1b @ \n"
"ldmfd r13!,{r4-r11,PC} @ pop, return to thumb \n"
"4: \n"
"add r2, r2, r4, LSL #2 @ r2 = &index[index[0]] \n"
"5: \n"
"ldr r4, [r2], #4 @ r4 = *contrib++ \n"
"ldr r9, [r2], #4 @ r9 = len = *contrib++ \n"
"mov r7, r5 @ r7 = b = rounding \n"
"mov r8, r5 @ r8 = a = rounding \n"
"add r4, r1, r4, LSL #2 @ r4 = min = &src[4*r4] \n"
"cmp r9, #0 @ while (len-- > 0) \n"
"beq 7f @ { \n"
"6: \n"
"ldr r11,[r4], #4 @ r11 = *min++ \n"
"ldr r10,[r2], #4 @ r10 = *contrib++ \n"
"subs r9, r9, #1 @ r9 = len-- \n"
"and r12,r6, r11 @ r12 = __22__00 \n"
"and r11,r6, r11,LSR #8 @ r11 = __33__11 \n"
"mla r7, r10,r12,r7 @ b += r14 * r10 \n"
"mla r8, r10,r11,r8 @ a += r11 * r10 \n"
"bgt 6b @ } \n"
"7: \n"
"and r7, r6, r7, lsr #8 @ r7 = __22__00 \n"
"bic r8, r8, r6 @ r8 = 33__11__ \n"
"orr r7, r7, r8 @ r7 = 33221100 \n"
"str r7, [r0], #4 @ *dst++=r \n"
"subs r3, r3, #1 @ i-- \n"
"bgt 5b @ \n"
"ldmfd r13!,{r4-r11,PC} @ pop, return to thumb \n"
ENTER_THUMB
);
}
static void
scale_row_from_temp(unsigned char *dst, unsigned char *src, fz_weights *weights, int width, int row)
{
asm volatile(
ENTER_ARM
"ldr r12,[r13] @ r12= row \n"
"add r2, r2, #20 @ r2 = weights->index \n"
"stmfd r13!,{r4-r11,r14} \n"
"@ r0 = dst \n"
"@ r1 = src \n"
"@ r2 = &weights->index[0] \n"
"@ r3 = width \n"
"@ r12= row \n"
"ldr r4, [r2, r12, LSL #2] @ r4 = index[row] \n"
"add r2, r2, #4 @ r2 = &index[1] \n"
"subs r6, r3, #4 @ r6 = x = width-4 \n"
"ldr r14,[r2, r4, LSL #2]! @ r2 = contrib = index[index[row]+1]\n"
" @ r14= len = *contrib \n"
"blt 4f @ while (x >= 0) { \n"
#ifndef ARCH_ARM_CAN_LOAD_UNALIGNED
"tst r3, #3 @ if (r3 & 3) \n"
"blt 4f @ can't do fast code\n"
#endif
"ldr r9, =0x00FF00FF @ r9 = 0x00FF00FF \n"
"1: \n"
"ldr r5, =0x00800080 @ r5 = val0 = round \n"
"stmfd r13!,{r1,r2} @ stash r1,r2,r14 \n"
" @ r1 = min = src \n"
" @ r2 = contrib2-4 \n"
"movs r8, r14 @ r8 = len2 = len \n"
"mov r7, r5 @ r7 = val1 = round \n"
"ble 3f @ while (len2-- > 0) { \n"
"2: \n"
"ldr r12,[r1], r3 @ r12 = *min r5 = min += width\n"
"ldr r10,[r2, #4]! @ r10 = *contrib2++ \n"
"subs r8, r8, #1 @ len2-- \n"
"and r11,r9, r12 @ r11= __22__00 \n"
"and r12,r9, r12,LSR #8 @ r12= __33__11 \n"
"mla r5, r10,r11,r5 @ r5 = val0 += r11 * r10\n"
"mla r7, r10,r12,r7 @ r7 = val1 += r12 * r10\n"
"bgt 2b @ } \n"
"3: \n"
"ldmfd r13!,{r1,r2} @ restore r1,r2,r14 \n"
"and r5, r9, r5, LSR #8 @ r5 = __22__00 \n"
"and r7, r7, r9, LSL #8 @ r7 = 33__11__ \n"
"orr r5, r5, r7 @ r5 = 33221100 \n"
"subs r6, r6, #4 @ x-- \n"
"add r1, r1, #4 @ src++ \n"
"str r5, [r0], #4 @ *dst++ = val \n"
"bge 1b @ \n"
"4: @ } (Less than 4 to go) \n"
"adds r6, r6, #4 @ r6 = x += 4 \n"
"beq 8f @ if (x == 0) done \n"
"5: \n"
"mov r5, r1 @ r5 = min = src \n"
"mov r7, #128 @ r7 = val = 128 \n"
"movs r8, r14 @ r8 = len2 = len \n"
"add r9, r2, #4 @ r9 = contrib2 \n"
"ble 7f @ while (len2-- > 0) { \n"
"6: \n"
"ldr r10,[r9], #4 @ r10 = *contrib2++ \n"
"ldrb r12,[r5], r3 @ r12 = *min r5 = min += width\n"
"subs r8, r8, #1 @ len2-- \n"
"@ stall r12 \n"
"mla r7, r10,r12,r7 @ val += r12 * r10 \n"
"bgt 6b @ } \n"
"7: \n"
"mov r7, r7, asr #8 @ r7 = val >>= 8 \n"
"subs r6, r6, #1 @ x-- \n"
"add r1, r1, #1 @ src++ \n"
"strb r7, [r0], #1 @ *dst++ = val \n"
"bgt 5b @ \n"
"8: \n"
"ldmfd r13!,{r4-r11,PC} @ pop, return to thumb \n"
ENTER_THUMB
);
}
#else
static void
scale_row_to_temp1(unsigned char *dst, unsigned char *src, fz_weights *weights)
{
int *contrib = &weights->index[weights->index[0]];
int len, i;
unsigned char *min;
assert(weights->n == 1);
if (weights->flip)
{
dst += weights->count;
for (i=weights->count; i > 0; i--)
{
int val = 128;
min = &src[*contrib++];
len = *contrib++;
while (len-- > 0)
{
val += *min++ * *contrib++;
}
*--dst = (unsigned char)(val>>8);
}
}
else
{
for (i=weights->count; i > 0; i--)
{
int val = 128;
min = &src[*contrib++];
len = *contrib++;
while (len-- > 0)
{
val += *min++ * *contrib++;
}
*dst++ = (unsigned char)(val>>8);
}
}
}
static void
scale_row_to_temp2(unsigned char *dst, unsigned char *src, fz_weights *weights)
{
int *contrib = &weights->index[weights->index[0]];
int len, i;
unsigned char *min;
assert(weights->n == 2);
if (weights->flip)
{
dst += 2*weights->count;
for (i=weights->count; i > 0; i--)
{
int c1 = 128;
int c2 = 128;
min = &src[2 * *contrib++];
len = *contrib++;
while (len-- > 0)
{
c1 += *min++ * *contrib;
c2 += *min++ * *contrib++;
}
*--dst = (unsigned char)(c2>>8);
*--dst = (unsigned char)(c1>>8);
}
}
else
{
for (i=weights->count; i > 0; i--)
{
int c1 = 128;
int c2 = 128;
min = &src[2 * *contrib++];
len = *contrib++;
while (len-- > 0)
{
c1 += *min++ * *contrib;
c2 += *min++ * *contrib++;
}
*dst++ = (unsigned char)(c1>>8);
*dst++ = (unsigned char)(c2>>8);
}
}
}
static void
scale_row_to_temp4(unsigned char *dst, unsigned char *src, fz_weights *weights)
{
int *contrib = &weights->index[weights->index[0]];
int len, i;
unsigned char *min;
assert(weights->n == 4);
if (weights->flip)
{
dst += 4*weights->count;
for (i=weights->count; i > 0; i--)
{
int r = 128;
int g = 128;
int b = 128;
int a = 128;
min = &src[4 * *contrib++];
len = *contrib++;
while (len-- > 0)
{
r += *min++ * *contrib;
g += *min++ * *contrib;
b += *min++ * *contrib;
a += *min++ * *contrib++;
}
*--dst = (unsigned char)(a>>8);
*--dst = (unsigned char)(b>>8);
*--dst = (unsigned char)(g>>8);
*--dst = (unsigned char)(r>>8);
}
}
else
{
for (i=weights->count; i > 0; i--)
{
int r = 128;
int g = 128;
int b = 128;
int a = 128;
min = &src[4 * *contrib++];
len = *contrib++;
while (len-- > 0)
{
r += *min++ * *contrib;
g += *min++ * *contrib;
b += *min++ * *contrib;
a += *min++ * *contrib++;
}
*dst++ = (unsigned char)(r>>8);
*dst++ = (unsigned char)(g>>8);
*dst++ = (unsigned char)(b>>8);
*dst++ = (unsigned char)(a>>8);
}
}
}
static void
scale_row_from_temp(unsigned char *dst, unsigned char *src, fz_weights *weights, int width, int row)
{
int *contrib = &weights->index[weights->index[row]];
int len, x;
contrib++; /* Skip min */
len = *contrib++;
for (x=width; x > 0; x--)
{
unsigned char *min = src;
int val = 128;
int len2 = len;
int *contrib2 = contrib;
while (len2-- > 0)
{
val += *min * *contrib2++;
min += width;
}
*dst++ = (unsigned char)(val>>8);
src++;
}
}
#endif
#ifdef SINGLE_PIXEL_SPECIALS
static void
duplicate_single_pixel(unsigned char *dst, unsigned char *src, int n, int w, int h)
{
int i;
for (i = n; i > 0; i--)
*dst++ = *src++;
for (i = (w*h-1)*n; i > 0; i--)
{
*dst = dst[-n];
dst++;
}
}
static void
scale_single_row(unsigned char *dst, unsigned char *src, fz_weights *weights, int src_w, int h)
{
int *contrib = &weights->index[weights->index[0]];
int min, len, i, j, n;
int tmp[FZ_MAX_COLORS];
n = weights->n;
/* Scale a single row */
for (j = 0; j < n; j++)
tmp[j] = 128;
if (weights->flip)
{
dst += (weights->count-1)*n;
for (i=weights->count; i > 0; i--)
{
min = *contrib++;
len = *contrib++;
min *= n;
while (len-- > 0)
{
for (j = 0; j < n; j++)
tmp[j] += src[min++] * *contrib;
contrib++;
}
for (j = 0; j < n; j++)
{
*dst++ = (unsigned char)(tmp[j]>>8);
tmp[j] = 128;
}
dst -= 2*n;
}
dst += n * (weights->count+1);
}
else
{
for (i=weights->count; i > 0; i--)
{
min = *contrib++;
len = *contrib++;
min *= n;
while (len-- > 0)
{
for (j = 0; j < n; j++)
tmp[j] += src[min++] * *contrib;
contrib++;
}
for (j = 0; j < n; j++)
{
*dst++ = (unsigned char)(tmp[j]>>8);
tmp[j] = 128;
}
}
}
/* And then duplicate it h times */
n *= weights->count;
while (--h > 0)
{
memcpy(dst, dst-n, n);
dst += n;
}
}
static void
scale_single_col(unsigned char *dst, unsigned char *src, fz_weights *weights, int src_w, int n, int w, int flip_y)
{
int *contrib = &weights->index[weights->index[0]];
int min, len, i, j;
int tmp[FZ_MAX_COLORS];
for (j = 0; j < n; j++)
tmp[j] = 128;
if (flip_y)
{
src_w = (src_w-1)*n;
w = (w-1)*n;
for (i=weights->count; i > 0; i--)
{
/* Scale the next pixel in the column */
min = *contrib++;
len = *contrib++;
min = src_w-min*n;
while (len-- > 0)
{
for (j = 0; j < n; j++)
tmp[j] += src[src_w-min+j] * *contrib;
contrib++;
}
for (j = 0; j < n; j++)
{
*dst++ = (unsigned char)(tmp[j]>>8);
tmp[j] = 128;
}
/* And then duplicate it across the row */
for (j = w; j > 0; j--)
{
*dst = dst[-n];
dst++;
}
}
}
else
{
w = (w-1)*n;
for (i=weights->count; i > 0; i--)
{
/* Scale the next pixel in the column */
min = *contrib++;
len = *contrib++;
min *= n;
while (len-- > 0)
{
for (j = 0; j < n; j++)
tmp[j] += src[min++] * *contrib;
contrib++;
}
for (j = 0; j < n; j++)
{
*dst++ = (unsigned char)(tmp[j]>>8);
tmp[j] = 128;
}
/* And then duplicate it across the row */
for (j = w; j > 0; j--)
{
*dst = dst[-n];
dst++;
}
}
}
}
#endif /* SINGLE_PIXEL_SPECIALS */
fz_pixmap *
fz_scale_pixmap(fz_context *ctx, fz_pixmap *src, float x, float y, float w, float h)
{
fz_scale_filter *filter = &fz_scale_filter_simple;
fz_weights *contrib_rows = NULL;
fz_weights *contrib_cols = NULL;
fz_pixmap *output = NULL;
unsigned char *temp = NULL;
int max_row, temp_span, temp_rows, row;
int dst_w_int, dst_h_int, dst_x_int, dst_y_int;
int flip_x, flip_y;
fz_var(contrib_cols);
fz_var(contrib_rows);
DBUG(("Scale: (%d,%d) to (%g,%g) at (%g,%g)\n",src->w,src->h,w,h,x,y));
/* Find the destination bbox, width/height, and sub pixel offset,
* allowing for whether we're flipping or not. */
/* Note that the x and y sub pixel offsets here are different.
* The (x,y) position given describes where the bottom left corner
* of the source image should be mapped to (i.e. where (0,h) in image
* space ends up, not the more logical and sane (0,0)). Also there
* are differences in the way we scale horizontally and vertically.
* When scaling rows horizontally, we always read forwards through
* the source, and store either forwards or in reverse as required.
* When scaling vertically, we always store out forwards, but may
* feed source rows in in a different order.
*
* Consider the image rectange 'r' to which the image is mapped,
* and the (possibly) larger rectangle 'R', given by expanding 'r' to
* complete pixels.
*
* x can either be r.xmin-R.xmin or R.xmax-r.xmax depending on whether
* the image is x flipped or not. Whatever happens 0 <= x < 1.
* y is always R.ymax - r.ymax.
*/
/* dst_x_int is calculated to be the left of the scaled image, and
* x (the sub_pixel_offset) is the distance in from either the left
* or right pixel expanded edge. */
flip_x = (w < 0);
if (flip_x)
{
float tmp;
w = -w;
dst_x_int = floor(x-w);
tmp = ceilf(x);
dst_w_int = (int)tmp;
x = tmp - x;
dst_w_int -= dst_x_int;
}
else
{
dst_x_int = floor(x);
x -= (float)dst_x_int;
dst_w_int = (int)ceilf(x + w);
}
flip_y = (h < 0);
/* dst_y_int is calculated to be the bottom of the scaled image, but
* y (the sub pixel offset) has to end up being the value at the top.
*/
if (flip_y)
{
h = -h;
dst_y_int = floor(y-h);
dst_h_int = (int)ceilf(y) - dst_y_int;
} else {
dst_y_int = floor(y);
y += h;
dst_h_int = (int)ceilf(y) - dst_y_int;
}
/* y is the top edge position in floats. We want it to be the
* distance down from the next pixel boundary. */
y = ceilf(y) - y;
DBUG(("Result image: (%d,%d) at (%d,%d) (subpix=%g,%g)\n", dst_w_int, dst_h_int, dst_x_int, dst_y_int, x, y));
fz_try(ctx)
{
/* Step 1: Calculate the weights for columns and rows */
#ifdef SINGLE_PIXEL_SPECIALS
if (src->w == 1)
contrib_cols = NULL;
else
#endif /* SINGLE_PIXEL_SPECIALS */
contrib_cols = make_weights(ctx, src->w, x, w, filter, 0, dst_w_int, src->n, flip_x);
#ifdef SINGLE_PIXEL_SPECIALS
if (src->h == 1)
contrib_rows = NULL;
else
#endif /* SINGLE_PIXEL_SPECIALS */
contrib_rows = make_weights(ctx, src->h, y, h, filter, 1, dst_h_int, src->n, flip_y);
output = fz_new_pixmap(ctx, src->colorspace, dst_w_int, dst_h_int);
}
fz_catch(ctx)
{
fz_free(ctx, contrib_cols);
fz_free(ctx, contrib_rows);
fz_rethrow(ctx);
}
output->x = dst_x_int;
output->y = dst_y_int;
/* Step 2: Apply the weights */
#ifdef SINGLE_PIXEL_SPECIALS
if (!contrib_rows)
{
/* Only 1 source pixel high. */
if (!contrib_cols)
{
/* Only 1 pixel in the entire image! */
duplicate_single_pixel(output->samples, src->samples, src->n, dst_w_int, dst_h_int);
}
else
{
/* Scale the row once, then copy it. */
scale_single_row(output->samples, src->samples, contrib_cols, src->w, dst_h_int);
}
}
else if (!contrib_cols)
{
/* Only 1 source pixel wide. Scale the col and duplicate. */
scale_single_col(output->samples, src->samples, contrib_rows, src->h, src->n, dst_w_int, flip_y);
}
else
#endif /* SINGLE_PIXEL_SPECIALS */
{
void (*row_scale)(unsigned char *dst, unsigned char *src, fz_weights *weights);
temp_span = contrib_cols->count * src->n;
temp_rows = contrib_rows->max_len;
if (temp_span <= 0 || temp_rows > INT_MAX / temp_span)
goto cleanup;
fz_try(ctx)
{
temp = fz_calloc(ctx, temp_span*temp_rows, sizeof(unsigned char));
}
fz_catch(ctx)
{
fz_drop_pixmap(ctx, output);
fz_free(ctx, contrib_cols);
fz_free(ctx, contrib_rows);
fz_rethrow(ctx);
}
switch (src->n)
{
default:
row_scale = scale_row_to_temp;
break;
case 1: /* Image mask case */
row_scale = scale_row_to_temp1;
break;
case 2: /* Greyscale with alpha case */
row_scale = scale_row_to_temp2;
break;
case 4: /* RGBA */
row_scale = scale_row_to_temp4;
break;
}
max_row = 0;
for (row = 0; row < contrib_rows->count; row++)
{
/*
Which source rows do we need to have scaled into the
temporary buffer in order to be able to do the final
scale?
*/
int row_index = contrib_rows->index[row];
int row_min = contrib_rows->index[row_index++];
int row_len = contrib_rows->index[row_index++];
while (max_row < row_min+row_len)
{
/* Scale another row */
assert(max_row < src->h);
DBUG(("scaling row %d to temp\n", max_row));
(*row_scale)(&temp[temp_span*(max_row % temp_rows)], &src->samples[(flip_y ? (src->h-1-max_row): max_row)*src->w*src->n], contrib_cols);
max_row++;
}
DBUG(("scaling row %d from temp\n", row));
scale_row_from_temp(&output->samples[row*output->w*output->n], temp, contrib_rows, temp_span, row);
}
fz_free(ctx, temp);
}
cleanup:
fz_free(ctx, contrib_rows);
fz_free(ctx, contrib_cols);
return output;
}
|