Compare commits
	
		
			1 Commits
		
	
	
		
			64e693fe4a
			...
			main
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 89352198d4 | 
							
								
								
									
										28
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								README.md
									
									
									
									
									
								
							@ -2,12 +2,24 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
Shaders for Avidemux with OpenGL support
 | 
					Shaders for Avidemux with OpenGL support
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## GoPro fisheye removal
 | 
					## GoPro fisheye removal v2.0
 | 
				
			||||||
 | 
					
 | 
				
			||||||

 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### gopro_8:7 - Fisheye removal for GoPro 11+, 8:7 ratio, 4K, HyperSmooth off
 | 
					### gopro_8:7 - Fisheye removal for GoPro 11+, 8:7 ratio, 4K, HyperSmooth off
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#### What's new
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- New method based on sensor size and focal length
 | 
				
			||||||
 | 
					- Accurate frame widening
 | 
				
			||||||
 | 
					- Fisheye aware subsampling
 | 
				
			||||||
 | 
					- Rec.709 colorspace conversion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#### Content
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- avidemux.patch  
 | 
				
			||||||
 | 
					Optional patch to use GL_NEAREST instead of GL_LINEAR for the luminance channel (the shader is implementing bilinear interpolation with colorspace conversion).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- unfish_gopro_8:7.py  
 | 
					- unfish_gopro_8:7.py  
 | 
				
			||||||
Script to compute the parameters
 | 
					Script to compute the parameters
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -15,9 +27,9 @@ Script to compute the parameters
 | 
				
			|||||||
Shader for fisheye removal
 | 
					Shader for fisheye removal
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- preset_gopro_8:7.py  
 | 
					- preset_gopro_8:7.py  
 | 
				
			||||||
Preset for mp4, 4K, high quality
 | 
					Preset for mp4, 4K, high quality compression
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### Installation for BSD/GNU-Linux systems:
 | 
					#### Installation for BSD/GNU-Linux systems:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Copy the preset into ~/.avidemux6/custom or ~/.local/share/avidemux6/custom
 | 
					- Copy the preset into ~/.avidemux6/custom or ~/.local/share/avidemux6/custom
 | 
				
			||||||
- Copy the shader into /opt/rk/avidemux (or edit the preset to set the path)  
 | 
					- Copy the shader into /opt/rk/avidemux (or edit the preset to set the path)  
 | 
				
			||||||
@ -26,9 +38,15 @@ Or just run the script install_gopro_8:7.sh
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
_For commercial OS's, figure out the paths yourself, then edit the preset to fix the path to the .glsl file_
 | 
					_For commercial OS's, figure out the paths yourself, then edit the preset to fix the path to the .glsl file_
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### Usage:
 | 
					#### Usage:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Load and edit video(s)
 | 
					- Load and edit video(s)
 | 
				
			||||||
- Select "Custom/preset_gopro_8:7" in the menu
 | 
					- Select "Custom/preset_gopro_8:7" in the menu
 | 
				
			||||||
- Modify and/or add filters
 | 
					- Modify and/or add filters
 | 
				
			||||||
- Save the video
 | 
					- Save the video
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#### Shader options
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- #define color_conversion: comment out to disable gamma correction for the luminance channel
 | 
				
			||||||
 | 
					- #define texture_filtering: comment out to disable custom bilinear filtering for the luminance channel
 | 
				
			||||||
 | 
					- #define rotate_180: uncomment to rotate the image by 180 degrees
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										28
									
								
								gopro_8:7/avidemux.patch
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								gopro_8:7/avidemux.patch
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,28 @@
 | 
				
			|||||||
 | 
					From 42e283d8b7c5d950ff81cff788398665410bcd6b Mon Sep 17 00:00:00 2001
 | 
				
			||||||
 | 
					Message-Id: <42e283d8b7c5d950ff81cff788398665410bcd6b.1759271917.git.roz@rozk.net>
 | 
				
			||||||
 | 
					From: Roz K <roz@rozk.net>
 | 
				
			||||||
 | 
					Date: Wed, 1 Oct 2025 00:38:19 +0200
 | 
				
			||||||
 | 
					Subject: [PATCH] OpenGL: use nearest interpolation filter for Y texture
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					---
 | 
				
			||||||
 | 
					 avidemux/qt4/ADM_openGL/src/ADM_openGl.cpp | 4 ++--
 | 
				
			||||||
 | 
					 1 file changed, 2 insertions(+), 2 deletions(-)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					diff --git a/avidemux/qt4/ADM_openGL/src/ADM_openGl.cpp b/avidemux/qt4/ADM_openGL/src/ADM_openGl.cpp
 | 
				
			||||||
 | 
					index ea389a1e6..b97a2034f 100644
 | 
				
			||||||
 | 
					--- a/avidemux/qt4/ADM_openGL/src/ADM_openGl.cpp
 | 
				
			||||||
 | 
					+++ b/avidemux/qt4/ADM_openGL/src/ADM_openGl.cpp
 | 
				
			||||||
 | 
					@@ -236,8 +236,8 @@ void ADM_coreQtGl::uploadAllPlanes(ADMImage *image)
 | 
				
			||||||
 | 
					         glBindTexture(GL_TEXTURE_RECTANGLE_NV, texName[xplane]); // Use tex engine "texNum"
 | 
				
			||||||
 | 
					         glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
 | 
				
			||||||
 | 
					         glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
 | 
				
			||||||
 | 
					-        glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 | 
				
			||||||
 | 
					-        glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 | 
				
			||||||
 | 
					+        glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, plane == PLANAR_Y ? GL_NEAREST : GL_LINEAR);
 | 
				
			||||||
 | 
					+        glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, plane == PLANAR_Y ? GL_NEAREST : GL_LINEAR);
 | 
				
			||||||
 | 
					         glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					         int pitch = (nbComponents == 1)? image->GetPitch(plane) : ALIGNX(image->GetWidth(plane),16); // ???
 | 
				
			||||||
 | 
					-- 
 | 
				
			||||||
 | 
					2.39.5
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -1,6 +1,20 @@
 | 
				
			|||||||
#PY  <- Needed to identify #
 | 
					#PY  <- Needed to identify #
 | 
				
			||||||
# RozK
 | 
					
 | 
				
			||||||
# Custom preset for GoPro, 8:7 ratio, without hypersmooth, output widened scaled to 4K (2160p), high bitrate
 | 
					# Fisheye removal for GoPro 11+, 8:7 ratio, without hypersmooth
 | 
				
			||||||
 | 
					# Copyright (C) 2025 Roz K <roz@rozk.net>
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# This program is free software: you can redistribute it and/or modify
 | 
				
			||||||
 | 
					# it under the terms of the GNU Affero General Public License as
 | 
				
			||||||
 | 
					# published by the Free Software Foundation, either version 3 of the
 | 
				
			||||||
 | 
					# License, or (at your option) any later version.
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# This program is distributed in the hope that it will be useful,
 | 
				
			||||||
 | 
					# but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
				
			||||||
 | 
					# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
				
			||||||
 | 
					# GNU Affero General Public License for more details.
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# You should have received a copy of the GNU Affero General Public License
 | 
				
			||||||
 | 
					# along with this program.  If not, see <https://www.gnu.org/licenses/>.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
adm = Avidemux()
 | 
					adm = Avidemux()
 | 
				
			||||||
adm.videoCodec(
 | 
					adm.videoCodec(
 | 
				
			||||||
@ -88,12 +102,19 @@ adm.videoCodec(
 | 
				
			|||||||
adm.addVideoFilter(
 | 
					adm.addVideoFilter(
 | 
				
			||||||
    "shaderLoader", "shaderFile=/opt/rk/avidemux/unfish_gopro_8:7.glsl")
 | 
					    "shaderLoader", "shaderFile=/opt/rk/avidemux/unfish_gopro_8:7.glsl")
 | 
				
			||||||
adm.addVideoFilter(
 | 
					adm.addVideoFilter(
 | 
				
			||||||
    "swscale", "width=2792", "height=2160", "algo=2", "sourceAR=0", "targetAR=0", "lockAR=False", "roundup=0")
 | 
					    "swscale",
 | 
				
			||||||
 | 
					    "width=2468",
 | 
				
			||||||
 | 
					    "height=2160",
 | 
				
			||||||
 | 
					    "algo=2",
 | 
				
			||||||
 | 
					    "sourceAR=0",
 | 
				
			||||||
 | 
					    "targetAR=0",
 | 
				
			||||||
 | 
					    "lockAR=False",
 | 
				
			||||||
 | 
					    "roundup=0")
 | 
				
			||||||
adm.audioClearTracks()
 | 
					adm.audioClearTracks()
 | 
				
			||||||
if adm.audioTotalTracksCount() <= 0:
 | 
					if adm.audioTotalTracksCount() <= 0:
 | 
				
			||||||
    raise("Cannot add audio track 0, total tracks: " + str(adm.audioTotalTracksCount()))
 | 
					    raise("Cannot add audio track 0, total tracks: " + str(adm.audioTotalTracksCount()))
 | 
				
			||||||
adm.audioAddTrack(0)
 | 
					adm.audioAddTrack(0)
 | 
				
			||||||
adm.audioCodec(0, "LavAAC", "bitrate=128")
 | 
					adm.audioCodec(0, "LavAAC", "bitrate=192")
 | 
				
			||||||
adm.audioSetDrc2(0, 1, 1, 0.001, 0.2, 1, 2, -12)
 | 
					adm.audioSetDrc2(0, 1, 1, 0.001, 0.2, 1, 2, -12)
 | 
				
			||||||
adm.audioSetEq(0, 0, 0, 0, 0, 880, 5000)
 | 
					adm.audioSetEq(0, 0, 0, 0, 0, 880, 5000)
 | 
				
			||||||
adm.audioSetChannelGains(0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
 | 
					adm.audioSetChannelGains(0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
 | 
				
			||||||
 | 
				
			|||||||
@ -1,6 +1,7 @@
 | 
				
			|||||||
#version 130
 | 
					#version 130
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Fisheye removal for GoPro 11+, 8:7 ratio, without hypersmooth
 | 
					// Fisheye removal for GoPro 11+, 8:7 ratio, without hypersmooth
 | 
				
			||||||
// Copyright (C) 2025 Jean-Baptiste Berlioz
 | 
					// Copyright (C) 2025 Roz K <roz@rozk.net>
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
// This program is free software: you can redistribute it and/or modify
 | 
					// This program is free software: you can redistribute it and/or modify
 | 
				
			||||||
// it under the terms of the GNU Affero General Public License as
 | 
					// it under the terms of the GNU Affero General Public License as
 | 
				
			||||||
@ -17,14 +18,16 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#extension GL_ARB_texture_rectangle: enable
 | 
					#extension GL_ARB_texture_rectangle: enable
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define non_linear_decoding
 | 
					#define color_conversion
 | 
				
			||||||
#define rotate_180
 | 
					#define texture_filtering
 | 
				
			||||||
 | 
					//#define rotate_180
 | 
				
			||||||
//#define debug_borders
 | 
					//#define debug_borders
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#undef highp // defined by Qt-OpenGl
 | 
					#undef highp // defined by Qt-OpenGl
 | 
				
			||||||
precision highp float;
 | 
					precision highp float;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// uniforms
 | 
					// uniforms
 | 
				
			||||||
 | 
					
 | 
				
			||||||
uniform sampler2DRect myTextureY;
 | 
					uniform sampler2DRect myTextureY;
 | 
				
			||||||
uniform sampler2DRect myTextureU;
 | 
					uniform sampler2DRect myTextureU;
 | 
				
			||||||
uniform sampler2DRect myTextureV;
 | 
					uniform sampler2DRect myTextureV;
 | 
				
			||||||
@ -32,84 +35,127 @@ uniform vec2 myResolution;
 | 
				
			|||||||
uniform float pts;
 | 
					uniform float pts;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// parameters
 | 
					// parameters
 | 
				
			||||||
const vec2 sensor_size = vec2(5.949440, 5.205760);
 | 
					
 | 
				
			||||||
const float equidistant_focal_length = 2.970000;
 | 
					const vec2  sensor_size              = vec2(5.949440, 5.205760);
 | 
				
			||||||
const float rectilinear_focal_length = 2.167601;
 | 
					const float equidistant_focal_length = 2.920000;
 | 
				
			||||||
 | 
					const float rectilinear_focal_length = 2.102263;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// constants
 | 
					// constants
 | 
				
			||||||
const int subsampling = 4;
 | 
					
 | 
				
			||||||
const vec2 subsampling_step = vec2(1.0 / float(subsampling));
 | 
					const int   subsampling       = 8;
 | 
				
			||||||
const vec2 subsampling_start = subsampling_step * 0.5 - vec2(0.5);
 | 
					const vec2  subsampling_step  = vec2(1.0 / float(subsampling));
 | 
				
			||||||
 | 
					const vec2  subsampling_start = subsampling_step * 0.5 - vec2(0.5);
 | 
				
			||||||
const float subsampling_scale = 1.0 / float(subsampling * subsampling);
 | 
					const float subsampling_scale = 1.0 / float(subsampling * subsampling);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// variables
 | 
					// reprojection
 | 
				
			||||||
 | 
					
 | 
				
			||||||
vec2 texture_center;
 | 
					vec2 texture_center;
 | 
				
			||||||
vec2 texture_to_sensor;
 | 
					vec2 texture_to_sensor;
 | 
				
			||||||
vec2 sensor_to_texture;
 | 
					vec2 sensor_to_texture;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void initialize() {
 | 
					void initialize() {
 | 
				
			||||||
    texture_center = myResolution * 0.5;
 | 
					    texture_center = myResolution * 0.5;
 | 
				
			||||||
    texture_to_sensor = sensor_size / myResolution;
 | 
					    texture_to_sensor = (sensor_size / myResolution);
 | 
				
			||||||
#ifdef rotate_180
 | 
					#ifdef rotate_180
 | 
				
			||||||
    texture_to_sensor *= -1.0;
 | 
					    texture_to_sensor *= -1.0;
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
    sensor_to_texture = myResolution / sensor_size;
 | 
					    sensor_to_texture = myResolution / sensor_size;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
vec2 equidistant_to_rectilinear(const in vec2 coord) {
 | 
					vec2 equidistant_to_rectilinear(const in vec2 equidistant) {
 | 
				
			||||||
    float rectilinear_radius = length(coord);
 | 
					    float rectilinear_radius = length(equidistant);
 | 
				
			||||||
    float rectilinear_angle = atan(rectilinear_radius / rectilinear_focal_length);
 | 
					    float rectilinear_angle = atan(rectilinear_radius / rectilinear_focal_length);
 | 
				
			||||||
    float equidistant_radius = rectilinear_angle * equidistant_focal_length;
 | 
					    float equidistant_radius = rectilinear_angle * equidistant_focal_length;
 | 
				
			||||||
    return coord * (equidistant_radius / rectilinear_radius);
 | 
					    return equidistant * (equidistant_radius / (rectilinear_radius > 0.0 ? rectilinear_radius : 1.0));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
vec3 sample_texture(const in vec2 coord) {
 | 
					// color space (https://en.wikipedia.org/wiki/Rec._709)
 | 
				
			||||||
    vec2 rectilinear = equidistant_to_rectilinear((coord - texture_center) * texture_to_sensor);
 | 
					
 | 
				
			||||||
    vec2 y_coord = texture_center + rectilinear * sensor_to_texture;
 | 
					#ifdef color_conversion
 | 
				
			||||||
#ifdef debug_borders
 | 
					
 | 
				
			||||||
    if (y_coord.x < 0.0 || y_coord.y < 0.0 || y_coord.x > myResolution.x || y_coord.y > myResolution.y) {
 | 
					const float luminance_min   =  16.0 / 255.0;
 | 
				
			||||||
        return vec3(1.0);
 | 
					const float luminance_max   = 235.0 / 255.0;
 | 
				
			||||||
    }
 | 
					const float luminance_range = luminance_max - luminance_min;
 | 
				
			||||||
#endif
 | 
					
 | 
				
			||||||
    vec2 uv_coord = y_coord * 0.5;
 | 
					float decode_luminance(const in float x) {
 | 
				
			||||||
    return vec3(
 | 
					    float y = (x - luminance_min) / luminance_range;
 | 
				
			||||||
        texture2DRect(myTextureY, y_coord).x,
 | 
					    return (y < 0.081) ? (y / 4.5) : pow((y + 0.099) / 1.099, 1.0 / 0.45);
 | 
				
			||||||
        texture2DRect(myTextureU, uv_coord).x,
 | 
					 | 
				
			||||||
        texture2DRect(myTextureV, uv_coord).x);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef non_linear_decoding
 | 
					float encode_luminance(const in float l) {
 | 
				
			||||||
 | 
					    float x = (l < 0.018) ? (l * 4.5) : (pow(l, 0.45) * 1.099 - 0.099);
 | 
				
			||||||
// https://en.wikipedia.org/wiki/Rec._709
 | 
					    return x * luminance_range + luminance_min;
 | 
				
			||||||
 | 
					 | 
				
			||||||
#define y_min    ( 16.0 / 255.0)
 | 
					 | 
				
			||||||
#define y_max    (235.0 / 255.0)
 | 
					 | 
				
			||||||
#define uv_min   ( 16.0 / 255.0)
 | 
					 | 
				
			||||||
#define uv_max   (240.0 / 255.0)
 | 
					 | 
				
			||||||
#define y_range  (y_max - y_min)
 | 
					 | 
				
			||||||
#define uv_range (uv_max - uv_min)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
const vec3 yuv_min = vec3(y_min, uv_min, uv_min);
 | 
					 | 
				
			||||||
const vec3 yuv_range = vec3(y_range, uv_range, uv_range);
 | 
					 | 
				
			||||||
const vec3 yuv_center = vec3(0.0, 0.5, 0.5);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
vec3 decode_pixel(const in vec3 pixel) {
 | 
					 | 
				
			||||||
    vec3 color = (pixel - yuv_min) / yuv_range - yuv_center;
 | 
					 | 
				
			||||||
    float l = (color.x < 0.081) ? (color.x / 4.5) : pow((color.x + 0.099) / 1.099, 1.0 / 0.45);
 | 
					 | 
				
			||||||
    return vec3(l, color.yz);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
vec3 encode_pixel(const in vec3 color) {
 | 
					vec3 decode_ycbcr(const in vec3 pixel) {
 | 
				
			||||||
    float y = (color.x < 0.018) ? (color.x * 4.5) : (pow(color.x, 0.45) * 1.099 - 0.099);
 | 
					    return vec3(decode_luminance(pixel.x), pixel.yz);
 | 
				
			||||||
    return (vec3(y, color.yz) + yuv_center) * yuv_range + yuv_min;
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					vec3 encode_ycbcr(const in vec3 color) {
 | 
				
			||||||
 | 
					    return vec3(encode_luminance(color.x), color.yz);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define decode_pixel(_color) _color
 | 
					#define decode_luminance(_x) (_x)
 | 
				
			||||||
#define encode_pixel(_color) _color
 | 
					#define encode_luminance(_l) (_l)
 | 
				
			||||||
 | 
					#define decode_ycbcr(_pixel) (_pixel)
 | 
				
			||||||
 | 
					#define encode_ycbcr(_color) (_color)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif // non_linear_decoding
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// texture filtering
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef texture_filtering
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const vec2 half_pixel = vec2(0.5);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const vec2 corner_a = vec2(0.0, 0.0) + half_pixel;
 | 
				
			||||||
 | 
					const vec2 corner_b = vec2(1.0, 0.0) + half_pixel;
 | 
				
			||||||
 | 
					const vec2 corner_c = vec2(0.0, 1.0) + half_pixel;
 | 
				
			||||||
 | 
					const vec2 corner_d = vec2(1.0, 1.0) + half_pixel;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					vec3 texture_filter(const in vec2 y_coord) {
 | 
				
			||||||
 | 
					    vec2 i, f = modf(y_coord - half_pixel, i);
 | 
				
			||||||
 | 
					    float luminance = mix(
 | 
				
			||||||
 | 
					        mix(
 | 
				
			||||||
 | 
					            decode_luminance(texture2DRect(myTextureY, i + corner_a).x),
 | 
				
			||||||
 | 
					            decode_luminance(texture2DRect(myTextureY, i + corner_b).x),
 | 
				
			||||||
 | 
					            f.x),
 | 
				
			||||||
 | 
					        mix(
 | 
				
			||||||
 | 
					            decode_luminance(texture2DRect(myTextureY, i + corner_c).x),
 | 
				
			||||||
 | 
					            decode_luminance(texture2DRect(myTextureY, i + corner_d).x),
 | 
				
			||||||
 | 
					            f.x),
 | 
				
			||||||
 | 
					        f.y);
 | 
				
			||||||
 | 
					    vec2 uv_coord = y_coord * 0.5;
 | 
				
			||||||
 | 
					    return vec3(luminance, texture2DRect(myTextureU, uv_coord).x, texture2DRect(myTextureV, uv_coord).x);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					vec3 texture_filter(const in vec2 y_coord) {
 | 
				
			||||||
 | 
					    vec2 uv_coord = y_coord * 0.5;
 | 
				
			||||||
 | 
					    return decode_ycbcr(vec3(
 | 
				
			||||||
 | 
					        texture2DRect(myTextureY, y_coord).x,
 | 
				
			||||||
 | 
					        texture2DRect(myTextureU, uv_coord).x,
 | 
				
			||||||
 | 
					        texture2DRect(myTextureV, uv_coord).x));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					vec3 texture_sample(const in vec2 equidistant) {
 | 
				
			||||||
 | 
					    vec2 rectilinear = texture_center + sensor_to_texture *
 | 
				
			||||||
 | 
					        equidistant_to_rectilinear((equidistant - texture_center) * texture_to_sensor);
 | 
				
			||||||
 | 
					#ifdef debug_borders
 | 
				
			||||||
 | 
					    if (rectilinear.x < 0.0 || rectilinear.y < 0.0 ||
 | 
				
			||||||
 | 
					        rectilinear.x > myResolution.x || rectilinear.y > myResolution.y) {
 | 
				
			||||||
 | 
					        return vec3(235.0 / 255.0, 240.0 / 255.0, 240.0 / 255.0);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					    return texture_filter(rectilinear);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void main() {
 | 
					void main() {
 | 
				
			||||||
    initialize();
 | 
					    initialize();
 | 
				
			||||||
@ -118,8 +164,8 @@ void main() {
 | 
				
			|||||||
    for (int y = 0; y < subsampling; y++) {
 | 
					    for (int y = 0; y < subsampling; y++) {
 | 
				
			||||||
        for (int x = 0; x < subsampling; x++) {
 | 
					        for (int x = 0; x < subsampling; x++) {
 | 
				
			||||||
            vec2 offset = subsampling_start + subsampling_step * vec2(x, y);
 | 
					            vec2 offset = subsampling_start + subsampling_step * vec2(x, y);
 | 
				
			||||||
            color += decode_pixel(sample_texture(coord + offset));
 | 
					            color += texture_sample(coord + offset);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    gl_FragColor = vec4(encode_pixel(color * subsampling_scale), 1.0);
 | 
					    gl_FragColor = vec4(encode_ycbcr(color * subsampling_scale), 1.0);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -1,5 +1,5 @@
 | 
				
			|||||||
# Fisheye removal for GoPro 11+, 8:7 ratio, without hypersmooth
 | 
					# Fisheye removal for GoPro 11+, 8:7 ratio, without hypersmooth
 | 
				
			||||||
# Copyright (C) 2025 Jean-Baptiste Berlioz
 | 
					# Copyright (C) 2025 Roz K <roz@rozk.net>
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
# This program is free software: you can redistribute it and/or modify
 | 
					# This program is free software: you can redistribute it and/or modify
 | 
				
			||||||
# it under the terms of the GNU Affero General Public License as
 | 
					# it under the terms of the GNU Affero General Public License as
 | 
				
			||||||
@ -27,6 +27,9 @@ sensor_pixel_size = 1.12 * 0.001 # mm
 | 
				
			|||||||
gopro_array_horizontal = 5312 # p
 | 
					gopro_array_horizontal = 5312 # p
 | 
				
			||||||
gopro_array_vertical   = 4648 # p
 | 
					gopro_array_vertical   = 4648 # p
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					gopro_texture_horizontal = 3840 # p
 | 
				
			||||||
 | 
					gopro_texture_vertical   = 3360 # p
 | 
				
			||||||
 | 
					
 | 
				
			||||||
gopro_size_horizontal = gopro_array_horizontal * sensor_pixel_size
 | 
					gopro_size_horizontal = gopro_array_horizontal * sensor_pixel_size
 | 
				
			||||||
gopro_size_vertical   = gopro_array_vertical   * sensor_pixel_size
 | 
					gopro_size_vertical   = gopro_array_vertical   * sensor_pixel_size
 | 
				
			||||||
gopro_size_diagonal   = math.hypot(gopro_size_horizontal, gopro_size_vertical)
 | 
					gopro_size_diagonal   = math.hypot(gopro_size_horizontal, gopro_size_vertical)
 | 
				
			||||||
@ -38,7 +41,7 @@ print("gopro  size : horizontal = %7.3f, vertical = %7.3f, diagonal = %7.3f (mm)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
# https://thinglabs.io/gopro-focal-length-guide
 | 
					# https://thinglabs.io/gopro-focal-length-guide
 | 
				
			||||||
 | 
					
 | 
				
			||||||
gopro_focal_length = 2.97 # mm
 | 
					gopro_focal_length = 2.92
 | 
				
			||||||
 | 
					
 | 
				
			||||||
gopro_radius_horizontal = gopro_size_horizontal * 0.5
 | 
					gopro_radius_horizontal = gopro_size_horizontal * 0.5
 | 
				
			||||||
gopro_radius_vertical   = gopro_size_vertical   * 0.5
 | 
					gopro_radius_vertical   = gopro_size_vertical   * 0.5
 | 
				
			||||||
@ -57,7 +60,7 @@ print("gopro  fov  : horizontal = %7.3f, vertical = %7.3f, diagonal = %7.3f (deg
 | 
				
			|||||||
    gopro_fov_vertical,
 | 
					    gopro_fov_vertical,
 | 
				
			||||||
    gopro_fov_diagonal))
 | 
					    gopro_fov_diagonal))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
print("\n--- rectilinear re-projection, preserving vertical fov ---\n")
 | 
					print("\n--- rectilinear re-projection ---\n")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
rectilinear_focal_length = lambda radius: radius * math.tan(math.radians(90.0 - equidistant_angle(radius)))
 | 
					rectilinear_focal_length = lambda radius: radius * math.tan(math.radians(90.0 - equidistant_angle(radius)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -70,22 +73,22 @@ print("linear focal: horizontal = %7.3f, vertical = %7.3f, diagonal = %7.3f (mm)
 | 
				
			|||||||
    rectilinear_focal_length_vertical,
 | 
					    rectilinear_focal_length_vertical,
 | 
				
			||||||
    rectilinear_focal_length_diagonal))
 | 
					    rectilinear_focal_length_diagonal))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
rectilinear_radius = lambda angle,  focal_length: focal_length * math.tan(math.radians(angle))
 | 
					rectilinear_radius = lambda angle:  rectilinear_focal_length_vertical * math.tan(math.radians(angle))
 | 
				
			||||||
rectilinear_angle  = lambda radius, focal_length: math.degrees(math.atan(radius / focal_length))
 | 
					rectilinear_angle  = lambda radius: math.degrees(math.atan(radius / rectilinear_focal_length_vertical))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
preserved_fov_horizontal = 2.0 * rectilinear_angle(gopro_radius_horizontal, rectilinear_focal_length_vertical)
 | 
					rectilinear_fov_horizontal = 2.0 * rectilinear_angle(gopro_radius_horizontal)
 | 
				
			||||||
preserved_fov_vertical   = 2.0 * rectilinear_angle(gopro_radius_vertical,   rectilinear_focal_length_vertical)
 | 
					rectilinear_fov_vertical   = 2.0 * rectilinear_angle(gopro_radius_vertical)
 | 
				
			||||||
preserved_fov_diagonal   = 2.0 * rectilinear_angle(gopro_radius_diagonal,   rectilinear_focal_length_vertical)
 | 
					rectilinear_fov_diagonal   = 2.0 * rectilinear_angle(gopro_radius_diagonal)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
print("linear fov  : horizontal = %7.3f, vertical = %7.3f, diagonal = %7.3f (deg)" % (
 | 
					print("linear fov  : horizontal = %7.3f, vertical = %7.3f, diagonal = %7.3f (deg)" % (
 | 
				
			||||||
    preserved_fov_horizontal,
 | 
					    rectilinear_fov_horizontal,
 | 
				
			||||||
    preserved_fov_vertical,
 | 
					    rectilinear_fov_vertical,
 | 
				
			||||||
    preserved_fov_diagonal))
 | 
					    rectilinear_fov_diagonal))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
print("\n--- shader parameters ---\n")
 | 
					print("\n--- shader parameters ---\n")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
print("""// parameters
 | 
					print("""// parameters\n
 | 
				
			||||||
const vec2 sensor_size = vec2(%.6f, %.6f);
 | 
					const vec2  sensor_size              = vec2(%.6f, %.6f);
 | 
				
			||||||
const float equidistant_focal_length = %.6f;
 | 
					const float equidistant_focal_length = %.6f;
 | 
				
			||||||
const float rectilinear_focal_length = %.6f;""" % (
 | 
					const float rectilinear_focal_length = %.6f;""" % (
 | 
				
			||||||
    gopro_size_horizontal, gopro_size_vertical,
 | 
					    gopro_size_horizontal, gopro_size_vertical,
 | 
				
			||||||
@ -93,13 +96,13 @@ const float rectilinear_focal_length = %.6f;""" % (
 | 
				
			|||||||
    rectilinear_focal_length_vertical)
 | 
					    rectilinear_focal_length_vertical)
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
print("\n--- filter parameters 4K ---\n")
 | 
					print("\n--- output size ---\n")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
width_scale = rectilinear_focal_length_vertical / rectilinear_focal_length_horizontal
 | 
					def print_output_array(array_vertical):
 | 
				
			||||||
 | 
					    array_horizontal = (array_vertical / gopro_array_vertical) * gopro_array_horizontal
 | 
				
			||||||
 | 
					    print("resize: width = %d, height = %d" % (
 | 
				
			||||||
 | 
					        round(array_horizontal / 4.0) * 4,
 | 
				
			||||||
 | 
					        array_vertical))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
output_height = 2160
 | 
					print_output_array(2160)
 | 
				
			||||||
output_width  = int(round((output_height / 7.0) * 8.0 * width_scale))
 | 
					print_output_array(1080)
 | 
				
			||||||
 | 
					 | 
				
			||||||
print("resize: width = %d, height = %d" % (
 | 
					 | 
				
			||||||
    output_width,
 | 
					 | 
				
			||||||
    output_height))
 | 
					 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user