3 (*
5 SDL2_framerate.h: framerate manager
6 SDL2_gfxPrimitives.h: graphics primitives for SDL
7 SDL2_imageFilter.h: byte-image "filter" routines
8 SDL2_rotozoom.h: rotozoomer, zoomer and shrinker for 32bit or 8bit surfaces
10 Copyright (C) 2001-2012 Andreas Schiffler
12 This software is provided 'as-is', without any express or implied
13 warranty. In no event will the authors be held liable for any damages
14 arising from the use of this software.
16 Permission is granted to anyone to use this software for any purpose,
17 including commercial applications, and to alter it and redistribute it
18 freely, subject to the following restrictions:
20 1. The origin of this software must not be misrepresented; you must not
21 claim that you wrote the original software. If you use this software
22 in a product, an acknowledgment in the product documentation would be
23 appreciated but is not required.
25 2. Altered source versions must be plainly marked as such, and must not be
26 misrepresented as being the original software.
28 3. This notice may not be removed or altered from any source
29 distribution.
31 Andreas Schiffler -- aschiffler at ferzkopp dot net
33 *)
35 {$INCLUDE jedi.inc}
37 interface
40 const
41 {$IFDEF WINDOWS}
43 {$ENDIF}
45 {$IFDEF UNIX}
46 {$IFDEF DARWIN}
48 {$ELSE}
49 {$IFDEF FPC}
51 {$ELSE}
53 {$ENDIF}
54 {$ENDIF}
55 {$ENDIF}
57 {$IFDEF MACOS}
59 {$IFDEF FPC}
60 {$linklib libSDL2_gfx}
61 {$ENDIF}
62 {$ENDIF}
64 {$IF DEFINED(DELPHI) AND DEFINED(MACOS)}
65 {$DEFINE DELMAC}
66 {$ENDIF}
70 {---< SDL2_framerate.h >---}
72 Const
73 {*!
74 \brief Highest possible rate supported by framerate controller in Hz (1/s).
75 *}
78 {*!
79 \brief Lowest possible rate supported by framerate controller in Hz (1/s).
80 *}
83 {*!
84 \brief Default rate of framerate controller in Hz (1/s).
85 *}
88 Type
89 {*!
90 \brief Structure holding the state and timing information of the framerate controller.
91 *}
119 {---< SDL2_gfxPrimitives.h >---}
121 Const
126 (* Note: all ___Color routines expect the colour to be in format 0xRRGGBBAA *)
129 {* Pixel *}
137 { Horizontal line }
145 { Vertical line }
150 Function vlineRGBA(renderer: PSDL_Renderer; x, y1, y2: sInt16; r, g, b, a: uInt8):sInt32; cdecl;
153 { Rectangle }
155 Function rectangleColor(renderer: PSDL_Renderer; x1, y1, x2, y2: sInt16; colour: uInt32):sInt32; cdecl;
158 Function rectangleRGBA(renderer: PSDL_Renderer; x1, y1, x2, y2: sInt16; r, g, b, a: uInt8):sInt32; cdecl;
161 { Rounded-Corner Rectangle }
163 Function roundedRectangleColor(renderer: PSDL_Renderer; x1, y1, x2, y2, rad: sInt16; colour: uInt32):sInt32; cdecl;
166 Function roundedRectangleRGBA(renderer: PSDL_Renderer; x1, y1, x2, y2, rad: sInt16; r, g, b, a: uInt8):sInt32; cdecl;
169 { Filled rectangle (Box) }
171 Function boxColor(renderer: PSDL_Renderer; x1, y1, x2, y2: sInt16; colour: uInt32):sInt32; cdecl;
174 Function boxRGBA(renderer: PSDL_Renderer; x1, y1, x2, y2: sInt16; r, g, b, a: uInt8):sInt32; cdecl;
177 { Rounded-Corner Filled rectangle (Box) }
179 Function roundedBoxColor(renderer: PSDL_Renderer; x1, y1, x2, y2, rad: sInt16; colour: uInt32):sInt32; cdecl;
182 Function roundedBoxRGBA(renderer: PSDL_Renderer; x1, y1, x2, y2, rad: sInt16; r, g, b, a: uInt8):sInt32; cdecl;
185 { Line }
187 Function lineColor(renderer: PSDL_Renderer; x1, y1, x2, y2: sInt16; colour: uInt32):sInt32; cdecl;
190 Function lineRGBA(renderer: PSDL_Renderer; x1, y1, x2, y2: sInt16; r, g, b, a: uInt8):sInt32; cdecl;
193 { AA Line }
195 Function aalineColor(renderer: PSDL_Renderer; x1, y1, x2, y2: sInt16; colour: uInt32):sInt32; cdecl;
198 Function aalineRGBA(renderer: PSDL_Renderer; x1, y1, x2, y2: sInt16; r, g, b, a: uInt8):sInt32; cdecl;
201 { Thick Line }
202 Function thickLineColor(renderer: PSDL_Renderer; x1, y1, x2, y2: sInt16; width: uInt8; colour: uInt32):sInt32; cdecl;
205 Function thickLineRGBA(renderer: PSDL_Renderer; x1, y1, x2, y2: sInt16; width, r, g, b, a: uInt8):sInt32; cdecl;
208 { Circle }
213 Function circleRGBA(renderer: PSDL_Renderer; x, y, rad: sInt16; r, g, b, a: uInt8):sInt32; cdecl;
216 { Arc }
218 Function arcColor(renderer: PSDL_Renderer; x, y, rad, start, finish: sInt16; colour: uInt32):sInt32; cdecl;
221 Function arcRGBA(renderer: PSDL_Renderer; x, y, rad, start, finish: sInt16; r, g, b, a: uInt8):sInt32; cdecl;
224 { AA Circle }
226 Function aacircleColor(renderer: PSDL_Renderer; x, y, rad: sInt16; colour: uInt32):sInt32; cdecl;
229 Function aacircleRGBA(renderer: PSDL_Renderer; x, y, rad: sInt16; r, g, b, a: uInt8):sInt32; cdecl;
232 { Filled Circle }
234 Function filledCircleColor(renderer: PSDL_Renderer; x, y, rad: sInt16; colour: uInt32):sInt32; cdecl;
237 Function filledCircleRGBA(renderer: PSDL_Renderer; x, y, rad: sInt16; r, g, b, a: uInt8):sInt32; cdecl;
240 { Ellipse }
242 Function ellipseColor(renderer: PSDL_Renderer; x, y, rx, ry: sInt16; colour: uInt32):sInt32; cdecl;
245 Function ellipseRGBA(renderer: PSDL_Renderer; x, y, rx, ry: sInt16; r, g, b, a: uInt8):sInt32; cdecl;
248 { AA Ellipse }
250 Function aaellipseColor(renderer: PSDL_Renderer; x, y, rx, ry: sInt16; colour: uInt32):sInt32; cdecl;
253 Function aaellipseRGBA(renderer: PSDL_Renderer; x, y, rx, ry: sInt16; r, g, b, a: uInt8):sInt32; cdecl;
256 { Filled Ellipse }
258 Function filledEllipseColor(renderer: PSDL_Renderer; x, y, rx, ry: sInt16; colour: uInt32):sInt32; cdecl;
261 Function filledEllipseRGBA(renderer: PSDL_Renderer; x, y, rx, ry: sInt16; r, g, b, a: uInt8):sInt32; cdecl;
264 { Pie }
266 Function pieColor(renderer: PSDL_Renderer; x, y, rad, start, finish: sInt16; colour: uInt32):sInt32; cdecl;
269 Function pieRGBA(renderer: PSDL_Renderer; x, y, rad, start, finish: sInt16; r, g, b, a: uInt8):sInt32; cdecl;
272 { Filled Pie }
274 Function filledPieColor(renderer: PSDL_Renderer; x, y, rad, start, finish: sInt16; colour: uInt32):sInt32; cdecl;
277 Function filledPieRGBA(renderer: PSDL_Renderer; x, y, rad, start, finish: sInt16; r, g, b, a: uInt8):sInt32; cdecl;
280 { Trigon }
282 Function trigonColor(renderer: PSDL_Renderer; x1, y1, x2, y2, x3, y3: sInt16; colour: uInt32):sInt32; cdecl;
285 Function trigonRGBA(renderer: PSDL_Renderer; x1, y1, x2, y2, x3, y3: sInt16; r, g, b, a: uInt8):sInt32; cdecl;
288 { AA-Trigon }
290 Function aatrigonColor(renderer: PSDL_Renderer; x1, y1, x2, y2, x3, y3: sInt16; colour: uInt32):sInt32; cdecl;
293 Function aatrigonRGBA(renderer: PSDL_Renderer; x1, y1, x2, y2, x3, y3: sInt16; r, g, b, a: uInt8):sInt32; cdecl;
296 { Filled Trigon }
298 Function filledTrigonColor(renderer: PSDL_Renderer; x1, y1, x2, y2, x3, y3: sInt16; colour: uInt32):sInt32; cdecl;
301 Function filledTrigonRGBA(renderer: PSDL_Renderer; x1, y1, x2, y2, x3, y3: sInt16; r, g, b, a: uInt8):sInt32; cdecl;
304 { Polygon }
306 Function polygonColor(renderer: PSDL_Renderer; Const vx, vy: PsInt16; n: sInt32; colour: uInt32):sInt32; cdecl;
309 Function polygonRGBA(renderer: PSDL_Renderer; Const vx, vy: PsInt16; n: sInt32; r, g, b, a: uInt8):sInt32; cdecl;
312 { AA-Polygon }
314 Function aapolygonColor(renderer: PSDL_Renderer; Const vx, vy: PsInt16; n: sInt32; colour: uInt32):sInt32; cdecl;
317 Function aapolygonRGBA(renderer: PSDL_Renderer; Const vx, vy: PsInt16; n: sInt32; r, g, b, a: uInt8):sInt32; cdecl;
320 { Filled Polygon }
322 Function filledPolygonColor(renderer: PSDL_Renderer; Const vx, vy: PsInt16; n: sInt32; colour: uInt32):sInt32; cdecl;
325 Function filledPolygonRGBA(renderer: PSDL_Renderer; Const vx, vy: PsInt16; n: sInt32; r, g, b, a: uInt8):sInt32; cdecl;
328 { Textured Polygon }
330 Function texturedPolygon(renderer: PSDL_Renderer; Const vx, vy: PsInt16; n: sInt32; texture: PSDL_Surface; texture_dx, texture_dy: sInt32):sInt32; cdecl;
333 { Bezier }
335 Function bezierColor(renderer: PSDL_Renderer; Const vx, vy: PsInt16; n, s: sInt32; colour: uInt32):sInt32; cdecl;
338 Function bezierRGBA(renderer: PSDL_Renderer; Const vx, vy: PsInt16; n, s: sInt32; r, g, b, a: uInt8):sInt32; cdecl;
341 { Characters/Strings }
350 Function characterColor(renderer: PSDL_Renderer; x, y: sInt16; c: Char; colour: uInt32):sInt32; cdecl;
353 Function characterRGBA(renderer: PSDL_Renderer; x, y: sInt16; c: Char; r, g, b, a: uInt8):sInt32; cdecl;
357 Function stringColor(renderer: PSDL_Renderer; x, y: sInt16; Const str: PChar; colour: uInt32):sInt32; cdecl;
360 Function stringRGBA(renderer: PSDL_Renderer; x, y: sInt16; Const syt: PChar; r, g, b, a: uInt8):sInt32; cdecl;
365 {---< SDL2_imageFilter.h >---}
367 (* Comments: *
368 * 1.) MMX functions work best if all data blocks are aligned on a 32 bytes boundary. *
369 * 2.) Data that is not within an 8 byte boundary is processed using the C routine. *
370 * 3.) Convolution routines do not have C routines at this time. *)
372 // Detect MMX capability in CPU
376 // Force use of MMX off (or turn possible use back on)
384 // SDL_imageFilterAdd: D = saturation255(S1 + S2)
388 // SDL_imageFilterMean: D = S1/2 + S2/2
392 // SDL_imageFilterSub: D = saturation0(S1 - S2)
396 // SDL_imageFilterAbsDiff: D = | S1 - S2 |
401 // SDL_imageFilterMult: D = saturation(S1 * S2)
405 // SDL_imageFilterMultNor: D = S1 * S2 (non-MMX)
409 // SDL_imageFilterMultDivby2: D = saturation255(S1/2 * S2)
413 // SDL_imageFilterMultDivby4: D = saturation255(S1/2 * S2/2)
418 // SDL_imageFilterBitAnd: D = S1 & S2
422 // SDL_imageFilterBitOr: D = S1 | S2
427 // SDL_imageFilterDiv: D = S1 / S2 (non-MMX)
431 // SDL_imageFilterBitNegation: D = !S
436 // SDL_imageFilterAddByte: D = saturation255(S + C)
440 // SDL_imageFilterAddUsInt32: D = saturation255(S + (usInt32)C)
441 Function SDL_imageFilterAddUsInt32(Src1, Dest : PuInt8; Length:uInt32; C : uInt32):Sint32; cdecl;
444 // SDL_imageFilterAddByteToHalf: D = saturation255(S/2 + C)
445 Function SDL_imageFilterAddByteToHalf(Src1, Dest : PuInt8; Length:uInt32; C : uInt8):Sint32; cdecl;
449 // SDL_imageFilterSubByte: D = saturation0(S - C)
453 // SDL_imageFilterSubUsInt32: D = saturation0(S - (usInt32)C)
454 Function SDL_imageFilterSubUsInt32(Src1, Dest : PuInt8; Length:uInt32; C : uInt32):Sint32; cdecl;
458 // SDL_imageFilterShiftRight: D = saturation0(S >> N)
459 Function SDL_imageFilterShiftRight(Src1, Dest : PuInt8; Length:uInt32; N : uInt8):Sint32; cdecl;
462 // SDL_imageFilterShiftRightUsInt32: D = saturation0((usInt32)S >> N)
463 Function SDL_imageFilterShiftRightUsInt32(Src1, Dest : PuInt8; Length:uInt32; N : uInt8):Sint32; cdecl;
467 // SDL_imageFilterMultByByte: D = saturation255(S * C)
468 Function SDL_imageFilterMultByByte(Src1, Dest : PuInt8; Length:uInt32; C : uInt8):Sint32; cdecl;
471 // SDL_imageFilterShiftRightAndMultByByte: D = saturation255((S >> N) * C)
472 Function SDL_imageFilterShiftRightAndMultByByte(Src1, Dest : PuInt8; Length:uInt32; N, C : uInt8):Sint32; cdecl;
476 // SDL_imageFilterShiftLeftByte: D = (S << N)
477 Function SDL_imageFilterShiftLeftByte(Src1, Dest : PuInt8; Length:uInt32; N: uInt8):Sint32; cdecl;
480 // SDL_imageFilterShiftLeftUsInt32: D = ((usInt32)S << N)
481 Function SDL_imageFilterShiftLeftUsInt32(Src1, Dest : PuInt8; Length:uInt32; N:uInt8):Sint32; cdecl;
484 // SDL_imageFilterShiftLeft: D = saturation255(S << N)
489 // SDL_imageFilterBinarizeUsingThreshold: D = S >= T ? 255:0
490 Function SDL_imageFilterBinarizeUsingThreshold(Src1, Dest : PuInt8; Length:uInt32; T: uInt8):Sint32; cdecl;
493 // SDL_imageFilterClipToRange: D = (S >= Tmin) & (S <= Tmax) 255:0
494 Function SDL_imageFilterClipToRange(Src1, Dest : PuInt8; Length:uInt32; Tmin, Tmax: uInt8):Sint32; cdecl;
497 // SDL_imageFilterNormalizeLinear: D = saturation255((Nmax - Nmin)/(Cmax - Cmin)*(S - Cmin) + Nmin)
498 Function SDL_imageFilterNormalizeLinear(Src, Dest: PuInt8; Length, Cmin, Cmax, Nmin, Nmax: sInt32):Sint32; cdecl;
502 {---< SDL2_rotozoom.h >---}
504 Const
505 {*!
506 \brief Disable anti-aliasing (no smoothing).
507 *}
510 {*!
511 \brief Enable anti-aliasing (smoothing).
512 *}
515 { Rotozoom functions }
517 Function rotozoomSurface(src: PSDL_Surface; angle, zoom: Double; smooth: sInt32):PSDL_Surface; cdecl;
520 Function rotozoomSurfaceXY(src: PSDL_Surface; angle, zoomx, zoomy: Double; smooth: sInt32):PSDL_Surface; cdecl;
524 Procedure rotozoomSurfaceSize(width, height: sInt32; angle, zoom: Double; dstwidth, dstheight: PuInt32); cdecl;
527 Procedure rotozoomSurfaceSizeXY(width, height: sInt32; angle, zoomx, zoomy: Double; dstwidth, dstheight:PuInt32); cdecl;
531 { Zooming functions }
533 Function zoomSurface(src: PSDL_Surface; zoomx, zoomy: Double; smooth: sInt32):PSDL_Surface; cdecl;
536 Procedure zoomSurfaceSize(width, height: sInt32; zoomx, zoomy: Double; dstwidth, dstheight: PuInt32); cdecl;
539 { Shrinking functions }
544 { Specialized rotation functions }
546 Function rotateSurface90Degrees(src: PSDL_Surface; numClockwiseTurns: sInt32):PSDL_Surface; cdecl;
550 implementation
553 begin