|
2 | 2 | "cells": [
|
3 | 3 | {
|
4 | 4 | "cell_type": "code",
|
5 |
| - "execution_count": 2, |
| 5 | + "execution_count": 1, |
6 | 6 | "metadata": {},
|
7 | 7 | "outputs": [],
|
8 | 8 | "source": [
|
|
128 | 128 | },
|
129 | 129 | {
|
130 | 130 | "cell_type": "code",
|
131 |
| - "execution_count": 5, |
| 131 | + "execution_count": 2, |
132 | 132 | "metadata": {},
|
133 | 133 | "outputs": [
|
134 | 134 | {
|
135 | 135 | "name": "stdout",
|
136 | 136 | "output_type": "stream",
|
137 | 137 | "text": [
|
138 |
| - "[-0.18104345 0.54372042 -0.14186212]\n" |
| 138 | + "[0.70985258 0.20630107 0.06283242]\n" |
139 | 139 | ]
|
140 | 140 | }
|
141 | 141 | ],
|
|
147 | 147 | "print(eval_sh(deg, sh, dirs))\n"
|
148 | 148 | ]
|
149 | 149 | },
|
| 150 | + { |
| 151 | + "cell_type": "code", |
| 152 | + "execution_count": 3, |
| 153 | + "metadata": {}, |
| 154 | + "outputs": [], |
| 155 | + "source": [ |
| 156 | + "import struct\n", |
| 157 | + "import numpy as np\n", |
| 158 | + "\n", |
| 159 | + "def unpackHalf2x16(value):\n", |
| 160 | + " \"\"\"The first float is the least significant 16bits, the second is the most significant 16bits.\"\"\"\n", |
| 161 | + " # Convert int32 to its binary representation\n", |
| 162 | + " binary = format(value, '032b')\n", |
| 163 | + " \n", |
| 164 | + " # Split the binary string into two 16-bit parts\n", |
| 165 | + " binary1 = binary[:16]\n", |
| 166 | + " binary2 = binary[16:]\n", |
| 167 | + " \n", |
| 168 | + " # Convert each 16-bit binary string to an integer\n", |
| 169 | + " int1 = int(binary1, 2)\n", |
| 170 | + " int2 = int(binary2, 2)\n", |
| 171 | + " \n", |
| 172 | + " # Use numpy to convert uint16 to float16\n", |
| 173 | + " float1 = np.frombuffer(struct.pack('H', int1), dtype=np.float16)[0]\n", |
| 174 | + " float2 = np.frombuffer(struct.pack('H', int2), dtype=np.float16)[0]\n", |
| 175 | + " \n", |
| 176 | + " return float1, float2\n", |
| 177 | + "\n", |
| 178 | + "def int32_to_rgba(value):\n", |
| 179 | + " # Ensure the input is a 32-bit integer\n", |
| 180 | + " value = int(value) & 0xFFFFFFFF\n", |
| 181 | + " \n", |
| 182 | + " # Extract each 8-bit piece\n", |
| 183 | + " r = (value >> 24) & 0xFF\n", |
| 184 | + " g = (value >> 16) & 0xFF\n", |
| 185 | + " b = (value >> 8) & 0xFF\n", |
| 186 | + " a = value & 0xFF\n", |
| 187 | + " \n", |
| 188 | + " return r / 255.0, g / 255.0, b / 255.0, a / 255.0" |
| 189 | + ] |
| 190 | + }, |
| 191 | + { |
| 192 | + "cell_type": "code", |
| 193 | + "execution_count": 4, |
| 194 | + "metadata": {}, |
| 195 | + "outputs": [ |
| 196 | + { |
| 197 | + "data": { |
| 198 | + "text/plain": [ |
| 199 | + "(0.803, 0.8213)" |
| 200 | + ] |
| 201 | + }, |
| 202 | + "execution_count": 4, |
| 203 | + "metadata": {}, |
| 204 | + "output_type": "execute_result" |
| 205 | + } |
| 206 | + ], |
| 207 | + "source": [ |
| 208 | + "unpackHalf2x16(980236946)" |
| 209 | + ] |
| 210 | + }, |
| 211 | + { |
| 212 | + "cell_type": "code", |
| 213 | + "execution_count": 5, |
| 214 | + "metadata": {}, |
| 215 | + "outputs": [ |
| 216 | + { |
| 217 | + "data": { |
| 218 | + "text/plain": [ |
| 219 | + "(-0.00319, 0.786)" |
| 220 | + ] |
| 221 | + }, |
| 222 | + "execution_count": 5, |
| 223 | + "metadata": {}, |
| 224 | + "output_type": "execute_result" |
| 225 | + } |
| 226 | + ], |
| 227 | + "source": [ |
| 228 | + "unpackHalf2x16(2592619082)" |
| 229 | + ] |
| 230 | + }, |
| 231 | + { |
| 232 | + "cell_type": "code", |
| 233 | + "execution_count": 4, |
| 234 | + "metadata": {}, |
| 235 | + "outputs": [ |
| 236 | + { |
| 237 | + "data": { |
| 238 | + "text/plain": [ |
| 239 | + "(0.3686274509803922,\n", |
| 240 | + " 0.7215686274509804,\n", |
| 241 | + " 0.7254901960784313,\n", |
| 242 | + " 0.7294117647058823)" |
| 243 | + ] |
| 244 | + }, |
| 245 | + "execution_count": 4, |
| 246 | + "metadata": {}, |
| 247 | + "output_type": "execute_result" |
| 248 | + } |
| 249 | + ], |
| 250 | + "source": [ |
| 251 | + "int32_to_rgba(1589164474)" |
| 252 | + ] |
| 253 | + }, |
| 254 | + { |
| 255 | + "cell_type": "code", |
| 256 | + "execution_count": 5, |
| 257 | + "metadata": {}, |
| 258 | + "outputs": [ |
| 259 | + { |
| 260 | + "data": { |
| 261 | + "application/vnd.jupyter.widget-view+json": { |
| 262 | + "model_id": "c3317264494f4ea997d61191fa24a3c5", |
| 263 | + "version_major": 2, |
| 264 | + "version_minor": 0 |
| 265 | + }, |
| 266 | + "text/plain": [ |
| 267 | + "VBox(children=(FloatSlider(value=0.8212358, description='Red:', max=1.0, step=0.01), FloatSlider(value=0.80300…" |
| 268 | + ] |
| 269 | + }, |
| 270 | + "metadata": {}, |
| 271 | + "output_type": "display_data" |
| 272 | + } |
| 273 | + ], |
| 274 | + "source": [ |
| 275 | + "import ipywidgets as widgets\n", |
| 276 | + "from IPython.display import display, HTML\n", |
| 277 | + "import matplotlib.colors as mcolors\n", |
| 278 | + "\n", |
| 279 | + "def color_picker(r=0.5, g=0.5, b=0.5):\n", |
| 280 | + " def update_color(r, g, b):\n", |
| 281 | + " color = mcolors.to_hex([r, g, b])\n", |
| 282 | + " color_display.value = f'<div style=\"width: 100px; height: 100px; background-color: {color};\"></div>'\n", |
| 283 | + " rgb_display.value = f'RGB: ({r:.2f}, {g:.2f}, {b:.2f})'\n", |
| 284 | + " hex_display.value = f'Hex: {color}'\n", |
| 285 | + "\n", |
| 286 | + " r_slider = widgets.FloatSlider(value=r, min=0, max=1, step=0.01, description='Red:')\n", |
| 287 | + " g_slider = widgets.FloatSlider(value=g, min=0, max=1, step=0.01, description='Green:')\n", |
| 288 | + " b_slider = widgets.FloatSlider(value=b, min=0, max=1, step=0.01, description='Blue:')\n", |
| 289 | + "\n", |
| 290 | + " color_display = widgets.HTML()\n", |
| 291 | + " rgb_display = widgets.Label()\n", |
| 292 | + " hex_display = widgets.Label()\n", |
| 293 | + "\n", |
| 294 | + " widgets.interactive(update_color, r=r_slider, g=g_slider, b=b_slider)\n", |
| 295 | + "\n", |
| 296 | + " display(widgets.VBox([r_slider, g_slider, b_slider, color_display, rgb_display, hex_display]))\n", |
| 297 | + "\n", |
| 298 | + "# Usage\n", |
| 299 | + "color_picker(0.8212358, 0.8030037, 0.78623223) # You can change these initial values" |
| 300 | + ] |
| 301 | + }, |
| 302 | + { |
| 303 | + "cell_type": "code", |
| 304 | + "execution_count": 6, |
| 305 | + "metadata": {}, |
| 306 | + "outputs": [ |
| 307 | + { |
| 308 | + "data": { |
| 309 | + "application/vnd.jupyter.widget-view+json": { |
| 310 | + "model_id": "49ebcdf479814f618fab56eb4f17427b", |
| 311 | + "version_major": 2, |
| 312 | + "version_minor": 0 |
| 313 | + }, |
| 314 | + "text/plain": [ |
| 315 | + "VBox(children=(FloatSlider(value=0.3686274509803922, description='Red:', max=1.0, step=0.01), FloatSlider(valu…" |
| 316 | + ] |
| 317 | + }, |
| 318 | + "metadata": {}, |
| 319 | + "output_type": "display_data" |
| 320 | + } |
| 321 | + ], |
| 322 | + "source": [ |
| 323 | + "color_picker(0.3686274509803922, 0.7215686274509804, 0.7254901960784313)" |
| 324 | + ] |
| 325 | + }, |
150 | 326 | {
|
151 | 327 | "cell_type": "code",
|
152 | 328 | "execution_count": null,
|
|
0 commit comments