Atlas - SDL_render_ops.cpp
Home / ext / SDL / src / render / ngage Lines: 1 | Size: 5023 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)][FILE BEGIN]1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2025 Sam Lantinga <[email protected]> 4 5 This software is provided 'as-is', without any express or implied 6 warranty. In no event will the authors be held liable for any damages 7 arising from the use of this software. 8 9 Permission is granted to anyone to use this software for any purpose, 10 including commercial applications, and to alter it and redistribute it 11 freely, subject to the following restrictions: 12 13 1. The origin of this software must not be misrepresented; you must not 14 claim that you wrote the original software. If you use this software 15 in a product, an acknowledgment in the product documentation would be 16 appreciated but is not required. 17 2. Altered source versions must be plainly marked as such, and must not be 18 misrepresented as being the original software. 19 3. This notice may not be removed or altered from any source distribution. 20*/ 21#include "SDL_internal.h" 22 23#include <3dtypes.h> 24#include "SDL_render_ops.hpp" 25 26void ApplyColorMod(void *dest, void *source, int pitch, int width, int height, SDL_FColor color) 27{ 28 TUint16 *src_pixels = static_cast<TUint16 *>(source); 29 TUint16 *dst_pixels = static_cast<TUint16 *>(dest); 30 31 TFixed rf = Real2Fix(color.r); 32 TFixed gf = Real2Fix(color.g); 33 TFixed bf = Real2Fix(color.b); 34 35 for (int y = 0; y < height; ++y) 36 { 37 for (int x = 0; x < width; ++x) 38 { 39 TUint16 pixel = src_pixels[y * pitch / 2 + x]; 40 TUint8 r = (pixel & 0xF800) >> 8; 41 TUint8 g = (pixel & 0x07E0) >> 3; 42 TUint8 b = (pixel & 0x001F) << 3; 43 r = FixMul(r, rf); 44 g = FixMul(g, gf); 45 b = FixMul(b, bf); 46 dst_pixels[y * pitch / 2 + x] = (r << 8) | (g << 3) | (b >> 3); 47 } 48 } 49} 50 51void ApplyFlip(void *dest, void *source, int pitch, int width, int height, SDL_FlipMode flip) 52{ 53 TUint16 *src_pixels = static_cast<TUint16 *>(source); 54 TUint16 *dst_pixels = static_cast<TUint16 *>(dest); 55 56 for (int y = 0; y < height; ++y) 57 { 58 for (int x = 0; x < width; ++x) 59 { 60 int src_x = x; 61 int src_y = y; 62 63 if (flip & SDL_FLIP_HORIZONTAL) 64 { 65 src_x = width - 1 - x; 66 } 67 68 if (flip & SDL_FLIP_VERTICAL) 69 { 70 src_y = height - 1 - y; 71 } 72 73 dst_pixels[y * pitch / 2 + x] = src_pixels[src_y * pitch / 2 + src_x]; 74 } 75 } 76} 77 78void ApplyRotation(void *dest, void *source, int pitch, int width, int height, TFixed center_x, TFixed center_y, TFixed angle) 79{ 80 TUint16 *src_pixels = static_cast<TUint16 *>(source); 81 TUint16 *dst_pixels = static_cast<TUint16 *>(dest); 82 83 TFixed cos_angle = 0; 84 TFixed sin_angle = 0; 85 86 if (angle != 0) 87 { 88 FixSinCos(angle, sin_angle, cos_angle); 89 } 90 91 for (int y = 0; y < height; ++y) 92 { 93 for (int x = 0; x < width; ++x) 94 { 95 // Translate point to origin. 96 TFixed translated_x = Int2Fix(x) - center_x; 97 TFixed translated_y = Int2Fix(y) - center_y; 98 99 // Rotate point (clockwise). 100 TFixed rotated_x = FixMul(translated_x, cos_angle) + FixMul(translated_y, sin_angle); 101 TFixed rotated_y = FixMul(translated_y, cos_angle) - FixMul(translated_x, sin_angle); 102 103 // Translate point back. 104 int final_x = Fix2Int(rotated_x + center_x); 105 int final_y = Fix2Int(rotated_y + center_y); 106 107 // Check bounds. 108 if (final_x >= 0 && final_x < width && final_y >= 0 && final_y < height) 109 { 110 dst_pixels[y * pitch / 2 + x] = src_pixels[final_y * pitch / 2 + final_x]; 111 } 112 else 113 { 114 dst_pixels[y * pitch / 2 + x] = 0; 115 } 116 } 117 } 118} 119 120void ApplyScale(void *dest, void *source, int pitch, int width, int height, TFixed center_x, TFixed center_y, TFixed scale_x, TFixed scale_y) 121{ 122 TUint16 *src_pixels = static_cast<TUint16 *>(source); 123 TUint16 *dst_pixels = static_cast<TUint16 *>(dest); 124 125 for (int y = 0; y < height; ++y) 126 { 127 for (int x = 0; x < width; ++x) 128 { 129 // Translate point to origin. 130 TFixed translated_x = Int2Fix(x) - center_x; 131 TFixed translated_y = Int2Fix(y) - center_y; 132 133 // Scale point. 134 TFixed scaled_x = FixDiv(translated_x, scale_x); 135 TFixed scaled_y = FixDiv(translated_y, scale_y); 136 137 // Translate point back. 138 int final_x = Fix2Int(scaled_x + center_x); 139 int final_y = Fix2Int(scaled_y + center_y); 140 141 // Check bounds. 142 if (final_x >= 0 && final_x < width && final_y >= 0 && final_y < height) 143 { 144 dst_pixels[y * pitch / 2 + x] = src_pixels[final_y * pitch / 2 + final_x]; 145 } 146 else 147 { 148 dst_pixels[y * pitch / 2 + x] = 0; 149 } 150 } 151 } 152} 153[FILE END](C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.