-
Notifications
You must be signed in to change notification settings - Fork 7
Translate pixel format and colorspace macros #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,10 +28,10 @@ | |
| UnixType, | ||
| {$ENDIF} | ||
| {$IFDEF DARWIN} | ||
| CocoaAll; | ||
| {$ELSE} | ||
| X, | ||
| XLib; | ||
| {$ENDIF} | ||
| {$ENDIF} | ||
|
|
||
|
|
@@ -360,5 +360,212 @@ | |
| SDL_CreateThreadWithProperties:=SDL_CreateThreadWithPropertiesRuntime(props,TSDL_FunctionPointer(SDL_BeginThreadFunction),TSDL_FunctionPointer(SDL_EndThreadFunction)); | ||
| end; | ||
|
|
||
| end. | ||
| { Macros from SDL_mouse.h } | ||
| function SDL_BUTTON_MASK(X: TSDL_MouseButtonFlags): TSDL_MouseButtonFlags; | ||
| begin | ||
| Result := TSDL_MouseButtonFlags(1) shl (X-1) | ||
| end; | ||
|
|
||
| { Macros from SDL_stdinc.h} | ||
| function SDL_FOURCC(A, B, C, D: AnsiChar): cuint32; | ||
| begin | ||
| Result := (cuint32(Ord(A)) shl 0) or (cuint32(Ord(B)) shl 8) or (cuint32(Ord(C)) shl 16) or (cuint32(Ord(D)) shl 24) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add semicolon please. |
||
| end; | ||
|
|
||
| { Macros from SDL_pixels.h } | ||
| function SDL_DEFINE_PIXELFOURCC(A, B, C, D: AnsiChar): TSDL_PixelFormat; | ||
| begin | ||
| Result := SDL_FOURCC(A, B, C, D) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All Result lines (applies to all macro functions) should be finished with a semi colon, just to make it clean. |
||
| end; | ||
|
|
||
| function SDL_DEFINE_PIXELFORMAT(type_: TSDL_PixelType; order: Integer; layout: TSDL_PackedLayout; bits, bytes: Integer): TSDL_PixelFormat; | ||
| begin | ||
| Result := (1 shl 28) or (type_ shl 24) or (order shl 20) or (layout shl 16) or (bits shl 8) or (bytes shl 0) | ||
| end; | ||
|
|
||
| function SDL_PIXELFLAG(format: TSDL_PixelFormat): Integer; | ||
| begin | ||
| Result := (format shr 28) and $0F | ||
| end; | ||
|
|
||
| function SDL_PIXELTYPE(format: TSDL_PixelFormat): TSDL_PixelType; | ||
| begin | ||
| Result := (format shr 24) and $0F | ||
| end; | ||
|
|
||
| function SDL_PIXELORDER(format: TSDL_PixelFormat): Integer; | ||
| begin | ||
| Result := (format shr 20) and $0F | ||
| end; | ||
|
|
||
| function SDL_PIXELLAYOUT(format: TSDL_PixelFormat): TSDL_PackedLayout; | ||
| begin | ||
| Result := (format shr 16) and $0F | ||
| end; | ||
|
|
||
| function SDL_BITSPERPIXEL(format: TSDL_PixelFormat): Integer; | ||
| begin | ||
| If SDL_ISPIXELFORMAT_FOURCC(format) then | ||
| Result := 0 | ||
| else | ||
| Result := (format shr 8) and $0F | ||
| end; | ||
|
|
||
| function SDL_BYTESPERPIXEL(format: TSDL_PixelFormat): Integer; | ||
| begin | ||
| If SDL_ISPIXELFORMAT_FOURCC(format) then | ||
| If (format = SDL_PIXELFORMAT_YUY2) or (format = SDL_PIXELFORMAT_UYVY) or (format = SDL_PIXELFORMAT_YVYU) or (format = SDL_PIXELFORMAT_P010) then | ||
| Result := 2 | ||
| else | ||
| Result := 1 | ||
| else | ||
| Result := (format shr 0) and $0F | ||
| end; | ||
|
|
||
| function SDL_ISPIXELFORMAT_INDEXED(format: TSDL_PixelFormat): Boolean; | ||
| begin | ||
| Result := (Not SDL_ISPIXELFORMAT_FOURCC(format)) and | ||
| ( | ||
| (SDL_PIXELTYPE(format) = SDL_PIXELTYPE_INDEX1) or | ||
| (SDL_PIXELTYPE(format) = SDL_PIXELTYPE_INDEX2) or | ||
| (SDL_PIXELTYPE(format) = SDL_PIXELTYPE_INDEX4) or | ||
| (SDL_PIXELTYPE(format) = SDL_PIXELTYPE_INDEX8) | ||
| ) | ||
| end; | ||
|
|
||
| function SDL_ISPIXELFORMAT_PACKED(format: TSDL_PixelFormat): Boolean; | ||
| begin | ||
| Result := (Not SDL_ISPIXELFORMAT_FOURCC(format)) and | ||
| ( | ||
| (SDL_PIXELTYPE(format) = SDL_PIXELTYPE_PACKED8) or | ||
| (SDL_PIXELTYPE(format) = SDL_PIXELTYPE_PACKED16) or | ||
| (SDL_PIXELTYPE(format) = SDL_PIXELTYPE_PACKED32) | ||
| ) | ||
| end; | ||
|
|
||
| function SDL_ISPIXELFORMAT_ARRAY(format: TSDL_PixelFormat): Boolean; | ||
| begin | ||
| Result := (Not SDL_ISPIXELFORMAT_FOURCC(format)) and | ||
| ( | ||
| (SDL_PIXELTYPE(format) = SDL_PIXELTYPE_ARRAYU8) or | ||
| (SDL_PIXELTYPE(format) = SDL_PIXELTYPE_ARRAYU16) or | ||
| (SDL_PIXELTYPE(format) = SDL_PIXELTYPE_ARRAYU32) or | ||
| (SDL_PIXELTYPE(format) = SDL_PIXELTYPE_ARRAYF16) or | ||
| (SDL_PIXELTYPE(format) = SDL_PIXELTYPE_ARRAYF32) | ||
| ) | ||
| end; | ||
|
|
||
| function SDL_ISPIXELFORMAT_10BIT(format: TSDL_PixelFormat): Boolean; | ||
| begin | ||
| Result := (Not SDL_ISPIXELFORMAT_FOURCC(format)) and | ||
| (SDL_PIXELTYPE(format) = SDL_PIXELTYPE_PACKED32) and | ||
| (SDL_PIXELLAYOUT(format) = SDL_PACKEDLAYOUT_2101010) | ||
| end; | ||
|
|
||
| function SDL_ISPIXELFORMAT_FLOAT(format: TSDL_PixelFormat): Boolean; | ||
| begin | ||
| Result := (Not SDL_ISPIXELFORMAT_FOURCC(format)) and | ||
| ((SDL_PIXELTYPE(format) = SDL_PIXELTYPE_ARRAYF16) or (SDL_PIXELTYPE(format) = SDL_PIXELTYPE_ARRAYF32)) | ||
| end; | ||
|
|
||
| function SDL_ISPIXELFORMAT_ALPHA(format: TSDL_PixelFormat): Boolean; | ||
| begin | ||
| Result := | ||
| ( | ||
| ( | ||
| SDL_ISPIXELFORMAT_PACKED(format) and | ||
| ( | ||
| (SDL_PIXELORDER(format) = SDL_PACKEDORDER_ARGB) or | ||
| (SDL_PIXELORDER(format) = SDL_PACKEDORDER_RGBA) or | ||
| (SDL_PIXELORDER(format) = SDL_PACKEDORDER_ABGR) or | ||
| (SDL_PIXELORDER(format) = SDL_PACKEDORDER_BGRA) | ||
| ) | ||
| ) | ||
| or | ||
| ( | ||
| SDL_ISPIXELFORMAT_ARRAY(format) and | ||
| ( | ||
| (SDL_PIXELORDER(format) = SDL_ARRAYORDER_ARGB) or | ||
| (SDL_PIXELORDER(format) = SDL_ARRAYORDER_RGBA) or | ||
| (SDL_PIXELORDER(format) = SDL_ARRAYORDER_ABGR) or | ||
| (SDL_PIXELORDER(format) = SDL_ARRAYORDER_BGRA) | ||
| ) | ||
| ) | ||
| ) | ||
| end; | ||
|
|
||
| function SDL_ISPIXELFORMAT_FOURCC(format: TSDL_PixelFormat): Boolean; | ||
| begin | ||
| (* The flag is set to 1 because 0x1? is not in the printable ASCII range *) | ||
| Result := (format <> 0) and (SDL_PIXELFLAG(format) <> 1) | ||
| end; | ||
|
|
||
| function SDL_DEFINE_COLORSPACE( | ||
| type_: TSDL_ColorType; | ||
| range: TSDL_ColorRange; | ||
| primaries: TSDL_ColorPrimaries; | ||
| transfer: TSDL_TransferCharacteristics; | ||
| matrix: TSDL_MatrixCoefficients; | ||
| chroma: TSDL_ChromaLocation | ||
| ): TSDL_Colorspace; | ||
| begin | ||
| Result := (cuint32(type_) shl 28) or (cuint32(range) shl 24) or (cuint32(chroma) shl 20) or | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All Result lines (applies to all macro functions) should be finished with a semi colon, just to make it clean. |
||
| (cuint32(primaries) shl 10) or (cuint32(transfer) shl 5) or (cuint32(matrix) shl 0) | ||
| end; | ||
|
|
||
| function SDL_COLORSPACETYPE(cspace: TSDL_Colorspace): TSDL_ColorType; | ||
| begin | ||
| Result := (TSDL_ColorType(cspace) shr 28) and $0F | ||
| end; | ||
|
|
||
| function SDL_COLORSPACERANGE(cspace: TSDL_Colorspace): TSDL_ColorRange; | ||
| begin | ||
| Result := (TSDL_ColorRange(cspace) shr 24) and $0F | ||
| end; | ||
|
|
||
| function SDL_COLORSPACECHROMA(cspace: TSDL_Colorspace): TSDL_ChromaLocation; | ||
| begin | ||
| Result := (TSDL_ChromaLocation(cspace) shr 20) and $0F | ||
| end; | ||
|
|
||
| function SDL_COLORSPACEPRIMARIES(cspace: TSDL_Colorspace): TSDL_ColorPrimaries; | ||
| begin | ||
| Result := (TSDL_ColorPrimaries(cspace) shr 10) and $1F | ||
| end; | ||
|
|
||
| function SDL_COLORSPACETRANSFER(cspace: TSDL_Colorspace): TSDL_TransferCharacteristics; | ||
| begin | ||
| Result := (TSDL_TransferCharacteristics(cspace) shr 5) and $1F | ||
| end; | ||
|
|
||
| function SDL_COLORSPACEMATRIX(cspace: TSDL_Colorspace): TSDL_MatrixCoefficients; | ||
| begin | ||
| Result := TSDL_MatrixCoefficients(cspace) and $1F | ||
| end; | ||
|
|
||
| function SDL_ISCOLORSPACE_MATRIX_BT601(cspace: TSDL_Colorspace): Boolean; | ||
| begin | ||
| Result := (SDL_COLORSPACEMATRIX(cspace) = SDL_MATRIX_COEFFICIENTS_BT601) or (SDL_COLORSPACEMATRIX(cspace) = SDL_MATRIX_COEFFICIENTS_BT470BG) | ||
| end; | ||
|
|
||
| function SDL_ISCOLORSPACE_MATRIX_BT709(cspace: TSDL_Colorspace): Boolean; | ||
| begin | ||
| Result := SDL_COLORSPACEMATRIX(cspace) = SDL_MATRIX_COEFFICIENTS_BT709 | ||
| end; | ||
|
|
||
| function SDL_ISCOLORSPACE_MATRIX_BT2020_NCL(cspace: TSDL_Colorspace): Boolean; | ||
| begin | ||
| Result := SDL_COLORSPACEMATRIX(cspace) = SDL_MATRIX_COEFFICIENTS_BT2020_NCL | ||
| end; | ||
|
|
||
| function SDL_ISCOLORSPACE_LIMITED_RANGE(cspace: TSDL_Colorspace): Boolean; | ||
| begin | ||
| Result := SDL_COLORSPACERANGE(cspace) <> SDL_COLOR_RANGE_FULL | ||
| end; | ||
|
|
||
| function SDL_ISCOLORSPACE_FULL_RANGE(cspace: TSDL_Colorspace): Boolean; | ||
| begin | ||
| Result := SDL_COLORSPACERANGE(cspace) = SDL_COLOR_RANGE_FULL | ||
| end; | ||
|
|
||
| end. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -145,16 +145,17 @@ type | |
| PSDL_MouseButtonFlags = ^TSDL_MouseButtonFlags; | ||
| TSDL_MouseButtonFlags = type cuint32; | ||
|
|
||
| function SDL_BUTTON_MASK(X: TSDL_MouseButtonFlags): TSDL_MouseButtonFlags; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be consistent with the original code, this function should be right above SDL_BUTTON_LMASK. I would suggest to move it down and have the following structure: |
||
|
|
||
| const | ||
| SDL_BUTTON_LEFT = TSDL_MouseButtonFlags(1); | ||
| SDL_BUTTON_MIDDLE = TSDL_MouseButtonFlags(2); | ||
| SDL_BUTTON_RIGHT = TSDL_MouseButtonFlags(3); | ||
| SDL_BUTTON_X1 = TSDL_MouseButtonFlags(4); | ||
| SDL_BUTTON_X2 = TSDL_MouseButtonFlags(5); | ||
|
|
||
| {SDL3-for-Pascal: The C macro SDL_BUTTON_MASK is not implemented but the mask | ||
| defines are directly translated. } | ||
| {#define SDL_BUTTON_MASK(X) (1u << ((X)-1)) } | ||
| {SDL3-for-Pascal: FPC does not allow assigning function results to consts, | ||
| so these values are calculated manually. } | ||
| SDL_BUTTON_LMASK = TSDL_MouseButtonFlags(1 shl SDL_BUTTON_LEFT-1); { SDL_BUTTON_MASK(SDL_BUTTON_LEFT) } | ||
| SDL_BUTTON_MMASK = TSDL_MouseButtonFlags(1 shl SDL_BUTTON_MIDDLE-1); { SDL_BUTTON_MASK(SDL_BUTTON_MIDDLE) } | ||
| SDL_BUTTON_RMASK = TSDL_MouseButtonFlags(1 shl SDL_BUTTON_RIGHT-1); { SDL_BUTTON_MASK(SDL_BUTTON_RIGHT) } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add semicolon please.