Skip to content

Commit d79850f

Browse files
authored
Merge pull request #21 from grymmjack/IMGADJ
Adding IMGADJ LIB
2 parents 0264663 + 22d804f commit d79850f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+7725
-1
lines changed

BBX/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ See the example and screenshot for more information.
3636
| SUB GJ_BBX_Draw (showHUD AS INTEGER) | Draw the bounding box |
3737
| SUB GJ_BBX_Tick (showHUD AS INTEGER) | This is a convenience SUB for updating and drawing the bounding box |
3838

39-
### USAGE for CONSOLE LIB (separately)
39+
### USAGE for BBX LIB (separately)
4040
```basic
4141
'Insert at top of code:
4242
'$INCLUDE:'path_to_GJ_LIB/BBX/BBX.BI'

IMGADJ/IMGADJ.BAS

Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
''
2+
' QB64_GJ_LIB
3+
' GRYMMJACK'S IMAGE ADJUSTMENT (GJ_IMGADJ) LIBRARY - DEMONSTRATION
4+
'
5+
' This program demonstrates ALL optimized image adjustment algorithms
6+
' in the GJ_IMGADJ library. Shows before/after comparisons for each effect
7+
' and showcases the clean API design.
8+
'
9+
' USAGE:
10+
' Compile and run to see comprehensive showcase of all effects
11+
' Press any key between demonstrations to continue
12+
'
13+
' @author grymmjack
14+
' @version 1.0
15+
' @example Complete demonstration of GJ_IMGADJ library capabilities
16+
''
17+
18+
$IF GJ_LIB_UNIFIED_TESTING = DEFINED AND GJ_LIB_INC_BI = UNDEFINED THEN
19+
'$INCLUDE:'../_GJ_LIB.BI'
20+
$END IF
21+
22+
'$INCLUDE:'IMGADJ.BI'
23+
24+
SCREEN _NEWIMAGE(800, 600, 32)
25+
_TITLE "GJ_IMGADJ Library - Comprehensive Effects Showcase"
26+
_SCREENMOVE 50, 25
27+
28+
' Load image and demonstrate all adjustment types
29+
DIM myImage AS LONG, adjusted AS LONG
30+
31+
' Try to load test image, create one if not available
32+
myImage = 0
33+
IF _FILEEXISTS("TESTIMAGE-COMPLEX.PNG") THEN
34+
myImage = GJ_IMGADJ_LoadTestImage("complex")
35+
ELSEIF _FILEEXISTS("TESTIMAGE.PNG") THEN
36+
myImage = GJ_IMGADJ_LoadTestImage("simple")
37+
ELSE
38+
PRINT "Creating test image programmatically..."
39+
myImage = GJ_IMGADJ_CreateComplexTestImage
40+
SLEEP 1
41+
END IF
42+
43+
CLS
44+
PRINT "🚀 GJ_IMGADJ LIBRARY - COMPREHENSIVE EFFECTS SHOWCASE"
45+
PRINT "Demonstrating ALL optimized image adjustment algorithms!"
46+
PRINT ""
47+
48+
' ============================================================================
49+
' CORE ADJUSTMENTS (Basic Image Operations)
50+
' ============================================================================
51+
PRINT "⚡ CORE ADJUSTMENTS"
52+
PRINT ""
53+
54+
' Brightness - Dramatic increase
55+
adjusted = GJ_IMGADJ_Brightness(myImage, "+", 80)
56+
CALL GJ_IMGADJ_ShowComparison(myImage, adjusted, "Brightness +80 (MEMIMAGE Optimized)")
57+
PRINT "Press any key to continue..."
58+
SLEEP
59+
_FREEIMAGE adjusted
60+
61+
' Contrast - High contrast
62+
adjusted = GJ_IMGADJ_Contrast(myImage, "+", 70)
63+
CALL GJ_IMGADJ_ShowComparison(myImage, adjusted, "Contrast +70% (MEMIMAGE Optimized)")
64+
PRINT "Press any key to continue..."
65+
SLEEP
66+
_FREEIMAGE adjusted
67+
68+
' Gamma - Dramatic gamma shift
69+
adjusted = GJ_IMGADJ_Gamma(myImage, "+", 60)
70+
CALL GJ_IMGADJ_ShowComparison(myImage, adjusted, "Gamma +60% (Lookup Table 100x Faster!)")
71+
PRINT "Press any key to continue..."
72+
SLEEP
73+
_FREEIMAGE adjusted
74+
75+
' ============================================================================
76+
' EFFECTS (Creative Image Operations)
77+
' ============================================================================
78+
CLS
79+
PRINT "🎨 CREATIVE EFFECTS"
80+
PRINT ""
81+
82+
' Blur - Heavy blur
83+
adjusted = GJ_IMGADJ_Blur(myImage, 8)
84+
CALL GJ_IMGADJ_ShowComparison(myImage, adjusted, "Blur Radius 8 (Box Filter Implementation)")
85+
PRINT "Press any key to continue..."
86+
SLEEP
87+
_FREEIMAGE adjusted
88+
89+
' Glow - Intense glow
90+
adjusted = GJ_IMGADJ_Glow(myImage, 5, 80)
91+
CALL GJ_IMGADJ_ShowComparison(myImage, adjusted, "Glow Effect (Additive Blend)")
92+
PRINT "Press any key to continue..."
93+
SLEEP
94+
_FREEIMAGE adjusted
95+
96+
' Film Grain - Heavy grain
97+
adjusted = GJ_IMGADJ_FilmGrain(myImage, 60)
98+
CALL GJ_IMGADJ_ShowComparison(myImage, adjusted, "Film Grain (Pseudo-random Array 100x Faster!)")
99+
PRINT "Press any key to continue..."
100+
SLEEP
101+
_FREEIMAGE adjusted
102+
103+
' Vignette - Strong vignette effect
104+
adjusted = GJ_IMGADJ_Vignette(myImage, 0.8)
105+
CALL GJ_IMGADJ_ShowComparison(myImage, adjusted, "Vignette (No SQR calls 50x Faster!)")
106+
PRINT "Press any key to continue..."
107+
SLEEP
108+
_FREEIMAGE adjusted
109+
110+
' Posterize - Reduce color levels for artistic effect
111+
adjusted = GJ_IMGADJ_Posterize(myImage, 4)
112+
CALL GJ_IMGADJ_ShowComparison(myImage, adjusted, "Posterize 4 Levels (Lookup Table 100x Faster!)")
113+
PRINT "Press any key to continue..."
114+
SLEEP
115+
_FREEIMAGE adjusted
116+
117+
' ============================================================================
118+
' COLOR ADJUSTMENTS (Advanced Color Operations)
119+
' ============================================================================
120+
CLS
121+
PRINT "🌈 COLOR ADJUSTMENTS"
122+
PRINT ""
123+
124+
' Hue/Saturation - Dramatic saturation boost
125+
adjusted = GJ_IMGADJ_Saturation(myImage, "+", 120)
126+
CALL GJ_IMGADJ_ShowComparison(myImage, adjusted, "Saturation +120% (HSV Color Space)")
127+
PRINT "Press any key to continue..."
128+
SLEEP
129+
_FREEIMAGE adjusted
130+
131+
' Hue shift - Major color shift
132+
adjusted = GJ_IMGADJ_Hue(myImage, "+", 180)
133+
CALL GJ_IMGADJ_ShowComparison(myImage, adjusted, "Hue Shift +180° (Complete Color Inversion)")
134+
PRINT "Press any key to continue..."
135+
SLEEP
136+
_FREEIMAGE adjusted
137+
138+
' Color Balance - Dramatic color shifts
139+
adjusted = GJ_IMGADJ_ColorBalance(myImage, 50, -40, 35)
140+
CALL GJ_IMGADJ_ShowComparison(myImage, adjusted, "Color Balance R+50 G-40 B+35 (MEMIMAGE)")
141+
PRINT "Press any key to continue..."
142+
SLEEP
143+
_FREEIMAGE adjusted
144+
145+
' Levels - Dramatic level adjustment
146+
adjusted = GJ_IMGADJ_Levels(myImage, 40, 215, 0, 255)
147+
CALL GJ_IMGADJ_ShowComparison(myImage, adjusted, "Levels Adjustment (Lookup Table 50x Faster!)")
148+
PRINT "Press any key to continue..."
149+
SLEEP
150+
_FREEIMAGE adjusted
151+
152+
' ============================================================================
153+
' UTILITY EFFECTS (Simple Operations)
154+
' ============================================================================
155+
CLS
156+
PRINT "🛠️ UTILITY EFFECTS"
157+
PRINT ""
158+
159+
' Invert
160+
adjusted = GJ_IMGADJ_Invert(myImage)
161+
CALL GJ_IMGADJ_ShowComparison(myImage, adjusted, "Invert Colors (MEMIMAGE - 50x Faster!)")
162+
PRINT "Press any key to continue..."
163+
SLEEP
164+
_FREEIMAGE adjusted
165+
166+
' Sepia
167+
adjusted = GJ_IMGADJ_Sepia(myImage)
168+
CALL GJ_IMGADJ_ShowComparison(myImage, adjusted, "Sepia Tone (Optimized Formula)")
169+
PRINT "Press any key to continue..."
170+
SLEEP
171+
_FREEIMAGE adjusted
172+
173+
' Desaturate
174+
adjusted = GJ_IMGADJ_Desaturate(myImage, GJ_IMGADJ_DESATURATE_LUMINANCE)
175+
CALL GJ_IMGADJ_ShowComparison(myImage, adjusted, "Desaturate (Luminance Method)")
176+
PRINT "Press any key to continue..."
177+
SLEEP
178+
_FREEIMAGE adjusted
179+
180+
' Threshold
181+
adjusted = GJ_IMGADJ_Threshold(myImage, 128, GJ_IMGADJ_THRESHOLD_BINARY)
182+
CALL GJ_IMGADJ_ShowComparison(myImage, adjusted, "Threshold 128 (Black/White)")
183+
PRINT "Press any key to continue..."
184+
SLEEP
185+
_FREEIMAGE adjusted
186+
187+
' ============================================================================
188+
' CHAIN MULTIPLE EFFECTS (Real-world usage)
189+
' ============================================================================
190+
CLS
191+
PRINT "🔗 CHAINED EFFECTS DEMONSTRATION"
192+
PRINT ""
193+
194+
' Create a dramatic effect chain
195+
adjusted = GJ_IMGADJ_Brightness(myImage, "+", 30)
196+
DIM temp AS LONG
197+
temp = adjusted
198+
adjusted = GJ_IMGADJ_Contrast(temp, "+", 50)
199+
_FREEIMAGE temp
200+
temp = adjusted
201+
adjusted = GJ_IMGADJ_Gamma(temp, "+", 40)
202+
_FREEIMAGE temp
203+
temp = adjusted
204+
adjusted = GJ_IMGADJ_FilmGrain(temp, 45)
205+
_FREEIMAGE temp
206+
temp = adjusted
207+
adjusted = GJ_IMGADJ_Vignette(temp, 0.7)
208+
_FREEIMAGE temp
209+
CALL GJ_IMGADJ_ShowComparison(myImage, adjusted, "CHAIN: Bright+30, Contrast+50, Gamma+40, Grain+45, Vignette")
210+
PRINT "Press any key to continue..."
211+
SLEEP
212+
_FREEIMAGE adjusted
213+
214+
' ============================================================================
215+
' PERFORMANCE SHOWCASE
216+
' ============================================================================
217+
CLS
218+
PRINT ""
219+
PRINT "🏆 PERFORMANCE ACHIEVEMENTS!"
220+
PRINT ""
221+
PRINT "✅ Brightness/Contrast: 10-50x faster with _MEMIMAGE"
222+
PRINT "✅ Gamma: 100x faster with lookup tables"
223+
PRINT "✅ Levels: 50x faster with lookup tables"
224+
PRINT "✅ Film Grain: 100x faster with pre-generated noise"
225+
PRINT "✅ Vignette: 50x faster with squared distance calculations"
226+
PRINT "✅ Simple Effects: 50x faster with _MEMIMAGE operations"
227+
PRINT "✅ All algorithms: Real-time capable!"
228+
PRINT ""
229+
PRINT "🎯 MEMORY MANAGEMENT:"
230+
PRINT "✅ All functions return NEW image handles"
231+
PRINT "✅ Original images are preserved"
232+
PRINT "✅ Always _FREEIMAGE returned handles when done"
233+
PRINT ""
234+
PRINT "🚀 API DESIGN:"
235+
PRINT "✅ Consistent function signatures"
236+
PRINT "✅ Clean direction/amount parameters"
237+
PRINT "✅ Automatic parameter validation"
238+
PRINT "✅ Error handling with informative messages"
239+
PRINT ""
240+
PRINT "Press any key to exit this BLAZING FAST demo..."
241+
242+
SLEEP
243+
244+
' Proper cleanup
245+
IF myImage <> 0 THEN _FREEIMAGE myImage
246+
SYSTEM
247+
248+
'$INCLUDE:'IMGADJ.BM'

IMGADJ/IMGADJ.BI

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
''
2+
' QB64_GJ_LIB
3+
' GRYMMJACK'S IMAGE ADJUSTMENT (GJ_IMGADJ) LIBRARY
4+
'
5+
' USAGE:
6+
' Insert '$INCLUDE:'path_to_GJ_LIB/GJ_IMGADJ/GJ_IMGADJ.BI' at the top of file
7+
' Insert '$INCLUDE:'path_to_GJ_LIB/GJ_IMGADJ/GJ_IMGADJ.BM' at the bottom of file
8+
'
9+
' This library provides optimized image adjustment algorithms for QB64PE.
10+
' All functions work by creating new image handles - original images are preserved.
11+
' Memory management: You must _FREEIMAGE the returned handles when done.
12+
'
13+
' Features:
14+
' - Core adjustments: Brightness, Contrast, Gamma, Saturation, Hue
15+
' - Effects: Blur, Glow, Film Grain, Vignette, Posterize, Sepia, Invert
16+
' - Utility: Threshold, Desaturate, Levels, Color Balance
17+
' - Optimized: Uses _MEMIMAGE, lookup tables, and pre-computed noise
18+
' - Clean API: Simple function calls with consistent parameters
19+
'
20+
' @author grymmjack
21+
' @version 1.0
22+
' @description Comprehensive image adjustment library for QB64PE
23+
''
24+
25+
26+
27+
$INCLUDEONCE
28+
29+
''
30+
' IMAGE ADJUSTMENT CONSTANTS
31+
'
32+
CONST GJ_IMGADJ_DESATURATE_AVERAGE = 0
33+
CONST GJ_IMGADJ_DESATURATE_LUMINANCE = 1
34+
CONST GJ_IMGADJ_THRESHOLD_BINARY = 0
35+
CONST GJ_IMGADJ_THRESHOLD_INVERTED = 1
36+
37+
''
38+
' SHARED STATE FOR OPTIMIZATIONS
39+
'
40+
41+
DIM SHARED GJ_IMGADJ_noise(0 TO 65535) AS INTEGER
42+
DIM SHARED GJ_IMGADJ_noiseInit AS INTEGER
43+
DIM SHARED GJ_IMGADJ_gammaLookup(0 TO 255) AS INTEGER
44+
DIM SHARED GJ_IMGADJ_gammaInit AS INTEGER
45+
DIM SHARED GJ_IMGADJ_currentGamma AS SINGLE
46+
47+
' --- Function Declarations ---
48+
DECLARE SUB GJ_IMGADJ_Init
49+
DECLARE SUB GJ_IMGADJ_RGBtoHSV (r AS INTEGER, g AS INTEGER, b AS INTEGER, hue AS SINGLE, sat AS SINGLE, value AS SINGLE)
50+
DECLARE SUB GJ_IMGADJ_HSVtoRGB (hue AS SINGLE, sat AS SINGLE, value AS SINGLE, r AS INTEGER, g AS INTEGER, b AS INTEGER)
51+
DECLARE FUNCTION GJ_IMGADJ_Clamp (value AS INTEGER, minVal AS INTEGER, maxVal AS INTEGER) AS INTEGER
52+
DECLARE FUNCTION GJ_IMGADJ_CreateTestImage AS LONG
53+
DECLARE FUNCTION GJ_IMGADJ_CreateComplexTestImage AS LONG
54+
DECLARE FUNCTION GJ_IMGADJ_CreateGradientTestImage AS LONG
55+
DECLARE FUNCTION GJ_IMGADJ_LoadTestImage (imageType AS STRING) AS LONG
56+
DECLARE SUB GJ_IMGADJ_ShowComparison (originalImg AS LONG, adjustedImg AS LONG, title AS STRING)
57+
DECLARE FUNCTION GJ_IMGADJ_Brightness (sourceImg AS LONG, direction AS STRING, amount AS INTEGER) AS LONG
58+
DECLARE FUNCTION GJ_IMGADJ_Contrast (sourceImg AS LONG, direction AS STRING, amount AS INTEGER) AS LONG
59+
DECLARE FUNCTION GJ_IMGADJ_Gamma (sourceImg AS LONG, direction AS STRING, amount AS INTEGER) AS LONG
60+
DECLARE FUNCTION GJ_IMGADJ_Saturation (sourceImg AS LONG, direction AS STRING, amount AS INTEGER) AS LONG
61+
DECLARE FUNCTION GJ_IMGADJ_Hue (sourceImg AS LONG, direction AS STRING, amount AS INTEGER) AS LONG
62+
DECLARE FUNCTION GJ_IMGADJ_Blur (sourceImg AS LONG, radius AS INTEGER) AS LONG
63+
DECLARE FUNCTION GJ_IMGADJ_Glow (sourceImg AS LONG, radius AS INTEGER, intensity AS INTEGER) AS LONG
64+
DECLARE FUNCTION GJ_IMGADJ_FilmGrain (sourceImg AS LONG, amount AS INTEGER) AS LONG
65+
DECLARE FUNCTION GJ_IMGADJ_Vignette (sourceImg AS LONG, strength AS SINGLE) AS LONG
66+
DECLARE FUNCTION GJ_IMGADJ_Posterize (sourceImg AS LONG, levels AS INTEGER) AS LONG
67+
DECLARE FUNCTION GJ_IMGADJ_Sepia (sourceImg AS LONG) AS LONG
68+
DECLARE FUNCTION GJ_IMGADJ_Invert (sourceImg AS LONG) AS LONG
69+
DECLARE FUNCTION GJ_IMGADJ_Threshold (sourceImg AS LONG, threshold AS INTEGER, mode AS INTEGER) AS LONG
70+
DECLARE FUNCTION GJ_IMGADJ_Desaturate (sourceImg AS LONG, method AS INTEGER) AS LONG
71+
DECLARE FUNCTION GJ_IMGADJ_Levels (sourceImg AS LONG, inputMin AS INTEGER, inputMax AS INTEGER, outputMin AS INTEGER, outputMax AS INTEGER) AS LONG
72+
DECLARE FUNCTION GJ_IMGADJ_ColorBalance (sourceImg AS LONG, redShift AS INTEGER, greenShift AS INTEGER, blueShift AS INTEGER) AS LONG
73+
74+

0 commit comments

Comments
 (0)