7 s16 posY, u16 clipULx, u16 clipULy, u16 clipLRx, u16 clipRLy, u8 opacity) {
16 gDPSetRenderMode(
gMainGfxPos++, G_RM_TEX_EDGE, G_RM_TEX_EDGE2);
17 gDPSetCombineMode(
gMainGfxPos++, G_CC_DECALRGBA, G_CC_DECALRGBA);
18 }
else if (opacity == 0) {
21 gDPSetRenderMode(
gMainGfxPos++, G_RM_XLU_SURF, G_RM_XLU_SURF2);
23 gDPSetPrimColor(
gMainGfxPos++, 0, 0, 0, 0, 0, opacity);
26 if (fmt == G_IM_FMT_CI) {
28 if (bitDepth == G_IM_SIZ_4b) {
36 ret =
draw_image_with_clipping(raster, width, height, fmt, bitDepth, posX, posY, clipULx, clipULy, clipLRx, clipRLy);
51 u16 clipWidth, u16 clipHeight) {
58 u16 texOffsetX, texOffsetY;
60 if (posX >= clipX + clipWidth || posY >= clipY + clipHeight) {
63 if (clipX >= (s16)(posX + width)) {
66 if (clipY >= (s16)(posY + height)) {
75 texRect.
lry = texRect.
uly + 31;
76 drawRect.
lry = drawRect.
uly + 32;
78 if (drawRect.
lry <= clipY) {
81 drawRect.
uly = drawRect.
lry;
83 }
while (drawRect.
lry < clipY);
84 texRect.
lry = texRect.
uly + 31;
87 if (drawRect.
uly < clipY) {
88 texOffsetY = abs(posY - clipY);
92 if (drawRect.
lry >= clipY + clipHeight) {
93 texRect.
lry = clipY + clipHeight - posY - 1;
95 drawRect.
lry = clipY + clipHeight;
98 if (texRect.
lry + 1 >= height) {
99 texRect.
lry = height - 1;
100 drawRect.
lry = texRect.
lry + posY + 1;
106 stopDrawingLine = FALSE;
109 texRect.
lrx = texRect.
ulx + 63;
110 drawRect.
lrx = drawRect.
ulx + 64;
113 if (drawRect.
lrx <= clipX) {
116 drawRect.
ulx = drawRect.
lrx;
118 }
while (drawRect.
lrx < clipX);
119 texRect.
lrx = texRect.
ulx + 63;
122 if (drawRect.
ulx < clipX) {
123 texOffsetX = abs(posX - clipX);
124 drawRect.
ulx = clipX;
127 if (drawRect.
lrx >= clipX + clipWidth) {
128 texRect.
lrx = clipX + clipWidth - posX - 1;
129 stopDrawingLine = TRUE;
130 drawRect.
lrx = clipX + clipWidth;
133 if (texRect.
lrx + 1 >= width) {
134 texRect.
lrx = width - 1;
135 drawRect.
lrx = texRect.
lrx + posX + 1;
136 stopDrawingLine = TRUE;
139 if (bitDepth == G_IM_SIZ_4b) {
140 gDPLoadTextureTile_4b(
gMainGfxPos++, raster, fmt, width, height,
142 G_TX_WRAP, G_TX_WRAP, 6, 5, G_TX_NOLOD, G_TX_NOLOD);
143 }
else if (bitDepth == G_IM_SIZ_16b) {
144 gDPLoadTextureTile(
gMainGfxPos++, raster, fmt, G_IM_SIZ_16b, width, height,
146 G_TX_WRAP, G_TX_WRAP, 6, 5, G_TX_NOLOD, G_TX_NOLOD);
147 }
else if (bitDepth == G_IM_SIZ_8b) {
148 gDPLoadTextureTile(
gMainGfxPos++, raster, fmt, G_IM_SIZ_8b, width, height,
150 G_TX_WRAP, G_TX_WRAP, 6, 5, G_TX_NOLOD, G_TX_NOLOD);
154 0, texOffsetX * 32, texOffsetY * 32, 1024, 1024);
156 if (stopDrawingLine) {
160 drawRect.
ulx = drawRect.
lrx;
167 drawRect.
uly = drawRect.
lry;
175 u16 clipX, u16 clipY, u16 clipWidth, u16 clipHeight,
176 f32 scaleX, f32 scaleY) {
180 s32 texOffsetX, texOffsetY;
184 if (scaleX < 0.01 || scaleY < 0.01) {
188 if (posX >= clipX + clipWidth || posY >= clipY + clipHeight) {
192 if (clipX >= (s16)(posX + width * scaleX)) {
196 if (clipY >= (s16)(posY + height * scaleY)) {
203 dsdx = 1.0f / scaleX * 1024.0f;
204 dtdy = 1.0f / scaleY * 1024.0f;
206 texRect.
lry = texRect.
uly + 31;
207 drawRect.
lry = drawRect.
uly + (scaleY * 32.0 + 0.5);
209 if (drawRect.
lry <= clipY) {
212 drawRect.
uly = drawRect.
lry;
213 drawRect.
lry += scaleY * 32.0f;
214 }
while (drawRect.
lry < clipY);
215 texRect.
lry = texRect.
uly + 31;
218 if (drawRect.
uly < clipY) {
219 drawRect.
uly = clipY;
220 texOffsetY = abs(posY - clipY) / scaleY * 32.0f;
223 if ((u32)(texRect.
lry + 1) >= height) {
224 texRect.
lry = height - 1;
226 drawRect.
lry = posY + (s16)(texRect.
lry * scaleY);
227 drawRect.
lry += scaleY;
230 if (drawRect.
lry > clipY + clipHeight) {
231 drawRect.
lry = clipY + clipHeight;
233 drawRect.
lry = clipY + clipHeight;
242 texRect.
lrx = texRect.
ulx + 63;
243 drawRect.
lrx = drawRect.
ulx + (scaleX * 64.0 + 0.3);
246 if (drawRect.
lrx <= clipX) {
249 drawRect.
ulx = drawRect.
lrx;
250 drawRect.
lrx += scaleX * 64.0f;
251 }
while (drawRect.
lrx < clipX);
252 texRect.
lrx = texRect.
ulx + 63;
255 if (drawRect.
ulx < clipX) {
256 drawRect.
ulx = clipX;
257 texOffsetX = abs(posX - clipX) / scaleX * 32.0f;
260 if ((u32)(texRect.
lrx + 1) >= width) {
261 texRect.
lrx = width - 1;
262 stopDrawingLine = TRUE;
263 drawRect.
lrx = posX + (s16)(texRect.
lrx * scaleX);
264 drawRect.
lrx = drawRect.
lrx + scaleX + 0.3;
267 if (drawRect.
lrx > clipX + clipWidth) {
268 drawRect.
lrx = clipX + clipWidth;
269 stopDrawingLine = TRUE;
272 if (bitDepth == G_IM_SIZ_16b) {
273 gDPLoadTextureTile(
gMainGfxPos++, raster, fmt, G_IM_SIZ_16b, width, height,
275 G_TX_WRAP, G_TX_WRAP, 6, 5, G_TX_NOLOD, G_TX_NOLOD);
276 }
else if (bitDepth == G_IM_SIZ_4b) {
277 gDPLoadTextureTile_4b(
gMainGfxPos++, raster, fmt, width, height,
279 G_TX_WRAP, G_TX_WRAP, 6, 5, G_TX_NOLOD, G_TX_NOLOD);
282 gSPTextureRectangle(
gMainGfxPos++, drawRect.
ulx * 4, drawRect.
uly * 4, (drawRect.
lrx - stopDrawingLine) * 4, drawRect.
lry * 4,
283 0, texOffsetX, texOffsetY, dsdx, dtdy);
285 if (stopDrawingLine) {
289 drawRect.
ulx = drawRect.
lrx;
296 drawRect.
uly = drawRect.
lry;
318 u16 clipX, u16 clipY, u16 clipWidth, u16 clipHeight,
319 f32 scaleX, f32 scaleY) {
324 s32 texOffsetX, texOffsetY;
334 if (scaleX < 0.01 || scaleY < 0.01) {
338 if (posX >= clipX + clipWidth || posY >= clipY + clipHeight) {
342 if (clipX >= (s16)(posX + width * scaleX)) {
346 if (clipY >= (s16)(posY + height * scaleY)) {
349 if (bitDepth == G_IM_SIZ_4b) {
350 if (fmt == G_IM_FMT_IA || fmt == G_IM_FMT_I) {
352 }
else if (fmt == G_IM_FMT_CI) {
357 }
else if (bitDepth == G_IM_SIZ_8b) {
358 if (fmt == G_IM_FMT_IA || fmt == G_IM_FMT_I) {
360 }
else if (fmt == G_IM_FMT_CI) {
365 }
else if (bitDepth == G_IM_SIZ_16b) {
366 if (fmt == G_IM_FMT_RGBA) {
368 }
else if (fmt == G_IM_FMT_IA) {
373 }
else if (bitDepth == G_IM_SIZ_32b) {
374 if (fmt == G_IM_FMT_RGBA) {
383 dsdx = 1.0f / scaleX * 1024.0f;
384 dtdy = 1.0f / scaleY * 1024.0f;
385 lineHeight = texelNum / width;
386 if (lineHeight > height) {
388 }
else if (lineHeight <= 1) {
408 texRect.
lrx = width - 1;
409 texRect.
lry = texRect.
uly + lineHeight - 1;
410 drawRect.
lry = drawRect.
uly + lineHeight * scaleY;
411 drawRect.
lrx = (s16)(drawRect.
ulx + width * scaleX);
414 texOffsetX = texOffsetY = 0;
416 if (drawRect.
lry <= clipY) {
418 texRect.
uly += lineHeight;
419 drawRect.
uly = drawRect.
lry;
420 drawRect.
lry += lineHeight * scaleY;
421 }
while (drawRect.
lry < clipY);
422 texRect.
lry = texRect.
uly + lineHeight - 1;
425 if (drawRect.
uly < clipY) {
426 drawRect.
uly = clipY;
427 temp = abs(posY - clipY);
429 texOffsetY = temp * 32.0f;
431 if (texRect.
lry + 1 == height){
433 }
else if (height < texRect.
lry + 1) {
435 texRect.
lry = height - 1;
436 temp = height * scaleY;
438 drawRect.
lry = drawRect.
uly + temp;
441 if (drawRect.
lry >= clipY + clipHeight) {
443 drawRect.
lry = clipY + clipHeight;
445 }
else if (drawRect.
lry > clipY + clipHeight) {
446 drawRect.
lry = clipY + clipHeight;
449 if (drawRect.
ulx < clipX) {
450 drawRect.
ulx = clipX;
451 temp = abs(posX - clipX);
453 texOffsetX = temp * 32.0f;
455 if (drawRect.
lrx >= clipX + clipWidth) {
456 drawRect.
lrx = clipX + clipWidth;
459 if (bitDepth == G_IM_SIZ_4b) {
460 gDPLoadTextureTile_4b(
gMainGfxPos++, raster, fmt, width, height,
462 G_TX_WRAP, G_TX_WRAP, masks, maskt, G_TX_NOLOD, G_TX_NOLOD);
463 }
else if (bitDepth == G_IM_SIZ_8b) {
464 gDPLoadTextureTile(
gMainGfxPos++, raster, fmt, G_IM_SIZ_8b, width, height,
466 G_TX_WRAP, G_TX_WRAP, masks, maskt, G_TX_NOLOD, G_TX_NOLOD);
467 }
else if (bitDepth == G_IM_SIZ_16b) {
468 gDPLoadTextureTile(
gMainGfxPos++, raster, fmt, G_IM_SIZ_16b, width, height,
470 G_TX_WRAP, G_TX_WRAP, masks, maskt, G_TX_NOLOD, G_TX_NOLOD);
471 }
else if (bitDepth == G_IM_SIZ_32b) {
472 gDPLoadTextureTile(
gMainGfxPos++, raster, fmt, G_IM_SIZ_32b, width, height,
474 G_TX_WRAP, G_TX_WRAP, masks, maskt, G_TX_NOLOD, G_TX_NOLOD);
477 0, texOffsetX, texOffsetY, dsdx, dtdy);
483 texRect.
uly += lineHeight - overlap;
484 drawRect.
uly = drawRect.
lry - overlap * scaleY;
s32 draw_image_with_clipping(IMG_PTR raster, u32 width, u32 height, s32 fmt, s32 bitDepth, s16 posX, s16 posY, u16 clipX, u16 clipY, u16 clipWidth, u16 clipHeight)
s32 draw_tiled_image(IMG_PTR raster, u32 width, u32 height, u8 fmt, u8 bitDepth, s16 posX, s16 posY, u16 clipX, u16 clipY, u16 clipWidth, u16 clipHeight, f32 scaleX, f32 scaleY)
s32 draw_adjustable_tiled_image(IMG_PTR raster, u32 width, u32 height, u8 fmt, u8 bitDepth, s16 posX, s16 posY, u16 clipX, u16 clipY, u16 clipWidth, u16 clipHeight, f32 scaleX, f32 scaleY)
s32 draw_ci_image_with_clipping(IMG_PTR raster, s32 width, s32 height, s32 fmt, s32 bitDepth, PAL_PTR palette, s16 posX, s16 posY, u16 clipULx, u16 clipULy, u16 clipLRx, u16 clipRLy, u8 opacity)