dmstraker Posted January 20, 2020 Share Posted January 20, 2020 I've been tinkering with conditional expressions in Apply Image. Ideally you'd do something like (conditional-expression?A:B) so if conditional-expression (eg x>0.5) evaluates as true then the result is A otherwise B. But they are not natural, so my current thinking is: roundup(clamp(expression,0,1)) If expression evaluates as negative, then the result is 0 otherwise 1 (including if it is >1), so you then multiply the whole thing by what you want to actually end up with. The 'else' alternative would be found by adding a similar term with the expression reversed. eg. DR=roundup(clamp(SR-0.5,0,1))*SG+roundup(clamp(0.5-SR,0,1))*SB This should set red pixels to equal to green pixel if the red pixel < 0.5, otherwise it should be blue. This, for example, lets you play with DIY blend modes which flip formula either side of 0.5. Untidy, I know. Does it make sense? Any improvements? John Rostron 1 Quote Dave Straker Cameras: Sony A7R2, RX100V Computers: Win10: Chillblast i9 Custom + Philips 40in 4K & Benq 23in; Surface Pro 4 i5; iPad Pro 11" Favourite word: Aha. For me and for others. Link to comment Share on other sites More sharing options...
v_kyr Posted January 20, 2020 Share Posted January 20, 2020 The conditional- or ternary operator is something often found in common prog-languages ... condition ? value1 : value2 // where condition has to be a boolean expression variable = condition ? value1 : value2 int k = i == 10 ? 12 : 5; ... System.out.print(i == 10 ? 12 : 5); Since I'm used to those things from programming it makes sense to me. - Though the way you can only apply/do such things at all in APh is primitive and poor. With some real scripting language support there should be instead much more things possible. Quote ☛ Affinity Designer 1.10.8 ◆ Affinity Photo 1.10.8 ◆ Affinity Publisher 1.10.8 ◆ OSX El Capitan ☛ Affinity V2.3 apps ◆ MacOS Sonoma 14.2 ◆ iPad OS 17.2 Link to comment Share on other sites More sharing options...
dmstraker Posted January 20, 2020 Author Share Posted January 20, 2020 7 hours ago, v_kyr said: The conditional- or ternary operator is something often found in common prog-languages ... condition ? value1 : value2 // where condition has to be a boolean expression variable = condition ? value1 : value2 int k = i == 10 ? 12 : 5; ... System.out.print(i == 10 ? 12 : 5); Since I'm used to those things from programming it makes sense to me. - Though the way you can only apply/do such things at all in APh is primitive and poor. With some real scripting language support there should be instead much more things possible. Yup. I was a programmer too. Assembler, C, ... And good scripting would be fab. Maybe in 2.0? Meanwhile the round/clamp algorithm seems a feasible option (unless anyone cares to shoot in down in flames). v_kyr 1 Quote Dave Straker Cameras: Sony A7R2, RX100V Computers: Win10: Chillblast i9 Custom + Philips 40in 4K & Benq 23in; Surface Pro 4 i5; iPad Pro 11" Favourite word: Aha. For me and for others. Link to comment Share on other sites More sharing options...
v_kyr Posted January 20, 2020 Share Posted January 20, 2020 36 minutes ago, dmstraker said: Yup. I was a programmer too. Assembler, C, ... And good scripting would be fab. Maybe in 2.0? Meanwhile the round/clamp algorithm seems a feasible option (unless anyone cares to shoot in down in flames). Scripting in 2.0, maybe who knows (?). Clamping in graphics Quote In computer graphics, clamping is the process of limiting a position to an area. Unlike wrapping, clamping merely moves the point to the nearest available value. To put clamping into perspective, pseudocode for clamping is as follows: Pseudocode (clamping): function clamp(x, min, max): if (x < min) then x = min; else if (x > max) then x = max; return x; end clamp Uses In general, clamping is used to restrict a value to a given range. For example, in OpenGL the glClearColor function takes four GLfloat values which are then 'clamped' to the range . Y = clamp(X, 1, 5) X Y X < 1 1 1 1 1.5 1.5 2 2 3 3 4 4 5 5 X > 5 5 One of the many uses of clamping in computer graphics is the placing of a detail inside a polygon—for example, a bullet hole on a wall. It can also be used with wrapping to create a variety of effects. - (Note also the right side table there -->) Quote ☛ Affinity Designer 1.10.8 ◆ Affinity Photo 1.10.8 ◆ Affinity Publisher 1.10.8 ◆ OSX El Capitan ☛ Affinity V2.3 apps ◆ MacOS Sonoma 14.2 ◆ iPad OS 17.2 Link to comment Share on other sites More sharing options...
Max P Posted February 8, 2020 Share Posted February 8, 2020 Hi found this description http://www.cplusplus.com/reference/cmath/round/ https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/round.xhtml https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/clamp.xhtml Quote Link to comment Share on other sites More sharing options...
John Rostron Posted February 8, 2020 Share Posted February 8, 2020 @dmstraker, I have used a similar formulation in Filter > Distort > Equations and it does work. I would also like to see some scripting available in Photo. John dmstraker 1 Quote Windows 10, Affinity Photo 1.10.5 Designer 1.10.5 and Publisher 1.10.5 (mainly Photo), now ex-Adobe CC CPU: AMD A6-3670. RAM: 16 GB DDR3 @ 666MHz, Graphics: 2047MB NVIDIA GeForce GT 630 Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.