36{
39 }
40
41 NSCParameterAssert(height > 0);
42
43 height *= 2;
48
50 uint32_t* pixel = outPixMap.
pixels;
51 float fheight = height;
52 float rheight = 1.0f / fheight;
53
54 float halfSize = (sourcePixMap.
width - 1) * 0.5f;
55 uint8_t* srcBytes = sourcePixMap.
pixels;
56
57
58 float sinTable[width];
59 float cosTable[width];
60 for (
x = 0;
x < width;
x++) {
61 float lon = ((float)
x * rheight) *
kPiF;
62 sinTable[
x] = sin(lon);
63 cosTable[
x] = cos(lon);
64 }
65
66 for (
y = 0;
y < height;
y++) {
67
68
69
70
71
72
73
74
75
76
77 float cy = -sinTable[width * 3 / 4 -
y];
78 float lac = -cosTable[width * 3 / 4 -
y];
79 float ay = fabs(cy);
80
81 for (
x = 0;
x < width;
x++) {
82 float cx = sinTable[
x] * lac;
83 float cz = cosTable[
x] * lac;
84
85 float ax = fabs(cx);
86 float az = fabs(cz);
87
88
90
91
93
94
95 if (ax >= ay && ax >= az) {
98 r = ax;
99 if (0.0f < cx) {
100 yOffset = 0;
101 } else {
103 yOffset = 1;
104 }
105 } else if (ay >= ax && ay >= az) {
108 r = ay;
109 if (0.0f < cy) {
111 yOffset = 2;
112 } else {
113 yOffset = 3;
114 }
115 } else {
118 r = az;
119 if (0.0f < cz) {
121 yOffset = 5;
122 } else {
123 yOffset = 4;
124 }
125 }
126
127
128 r = 1.0f / r;
131
132#ifndef NDEBUG
133 assert(ix < sourcePixMap.
width && iy < sourcePixMap.
width);
134#endif
135
136
137 iy += sourcePixMap.
width * yOffset;
138
139 uint32_t* row = (uint32_t*)(srcBytes + iy * sourcePixMap.
rowBytes);
140 *pixel++ = row[ix];
141 }
142 }
143
144
145 return OOScalePixMap(outPixMap, width / 2, height / 2, leaveSpaceForMipMaps);
146}
uint32_t OOPixMapDimension
const OOPixMap kOONullPixMap
OOPixMap OOAllocatePixMap(OOPixMapDimension width, OOPixMapDimension height, OOPixMapFormat format, size_t rowBytes, size_t bufferSize)
BOOL OOIsValidPixMap(OOPixMap pixMap)
OOPixMap OOScalePixMap(OOPixMap srcPixMap, OOPixMapDimension dstWidth, OOPixMapDimension dstHeight, BOOL leaveSpaceForMipMaps)