public CachedTextureResampled(CachedTexture cachedTexture) { cachedTextureOriginal = cachedTexture; ResampleInfo resampleInfo = new ResampleInfo(cachedTexture.width, cachedTexture.height, cachedTexture); resampleInfos.AddLast(resampleInfo); }
private CachedTexture resampleTexture(int width, int height) { if (resampleInfos.Count >= 5 && VideoEngine.log_Renamed.InfoEnabled) { VideoEngine.log_Renamed.info(string.Format("Resampling texture from ({0:D},{1:D}) to ({2:D},{3:D}), pixelFormat={4:D}, resampled {5:D} times", cachedTextureOriginal.width, cachedTextureOriginal.height, width, height, cachedTextureOriginal.pixelFormat, resampleInfos.Count)); } else if (VideoEngine.log_Renamed.DebugEnabled) { VideoEngine.log_Renamed.debug(string.Format("Resampling texture from ({0:D},{1:D}) to ({2:D},{3:D}), pixelFormat={4:D}, resampled {5:D} times", cachedTextureOriginal.width, cachedTextureOriginal.height, width, height, cachedTextureOriginal.pixelFormat, resampleInfos.Count)); } RESoftware.textureResamplingStatistics.start(); int widthPow2 = makePow2(width); int heightPow2 = makePow2(height); int[] buffer = new int[widthPow2 * heightPow2]; int widthSkipEOL = widthPow2 - width; if (cachedTextureOriginal.width == (width << 1) && cachedTextureOriginal.height == (height << 1)) { // Optimized common case: minimize texture by a factor of 2 resampleTextureMinimize2(buffer, width, height, widthSkipEOL); } else if ((cachedTextureOriginal.width << 1) == width && (cachedTextureOriginal.height << 1) == height) { // Optimized common case: magnify texture by a factor of 2 resampleTextureMagnify2(buffer, width, height, widthSkipEOL); } else { // Generic case: magnify/minimize by arbitrary factors float widthFactor = cachedTextureOriginal.width / (float)width; float heightFactor = cachedTextureOriginal.height / (float)height; resampleTexture(buffer, width, height, widthSkipEOL, widthFactor, heightFactor); } CachedTexture cachedTextureResampled = new CachedTexturePow2(widthPow2, heightPow2, width, height, GeCommands.TPSM_PIXEL_STORAGE_MODE_32BIT_ABGR8888); cachedTextureResampled.setBuffer(buffer, 0, buffer.Length); ResampleInfo resampleInfo = new ResampleInfo(width, height, cachedTextureResampled); resampleInfos.AddLast(resampleInfo); RESoftware.textureResamplingStatistics.end(); return(cachedTextureResampled); }