mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-04-26 01:04:17 +00:00
Simplified SDL_Surface
SDL_Surface has been simplified and internal details are no longer in the public structure. The `format` member of SDL_Surface is now an enumerated pixel format value. You can get the full details of the pixel format by calling `SDL_GetPixelFormatDetails(surface->format)`. You can get the palette associated with the surface by calling SDL_GetSurfacePalette(). You can get the clip rectangle by calling SDL_GetSurfaceClipRect(). SDL_PixelFormat has been renamed SDL_PixelFormatDetails and just describes the pixel format, it does not include a palette for indexed pixel types. SDL_PixelFormatEnum has been renamed SDL_PixelFormat and is used instead of Uint32 for API functions that refer to pixel format by enumerated value. SDL_MapRGB(), SDL_MapRGBA(), SDL_GetRGB(), and SDL_GetRGBA() take an optional palette parameter for indexed color lookups.
This commit is contained in:
@@ -84,7 +84,7 @@ char *SDL_GetCameraThreadName(SDL_CameraDevice *device, char *buf, size_t buflen
|
||||
return buf;
|
||||
}
|
||||
|
||||
int SDL_AddCameraFormat(CameraFormatAddData *data, SDL_PixelFormatEnum format, SDL_Colorspace colorspace, int w, int h, int framerate_numerator, int framerate_denominator)
|
||||
int SDL_AddCameraFormat(CameraFormatAddData *data, SDL_PixelFormat format, SDL_Colorspace colorspace, int w, int h, int framerate_numerator, int framerate_denominator)
|
||||
{
|
||||
SDL_assert(data != NULL);
|
||||
if (data->allocated_specs <= data->num_specs) {
|
||||
@@ -130,7 +130,7 @@ static size_t GetFrameBufLen(const SDL_CameraSpec *spec)
|
||||
const size_t w = (const size_t) spec->width;
|
||||
const size_t h = (const size_t) spec->height;
|
||||
const size_t wxh = w * h;
|
||||
const SDL_PixelFormatEnum fmt = spec->format;
|
||||
const SDL_PixelFormat fmt = spec->format;
|
||||
|
||||
switch (fmt) {
|
||||
// Some YUV formats have a larger Y plane than their U or V planes.
|
||||
@@ -367,8 +367,8 @@ static int SDLCALL CameraSpecCmp(const void *vpa, const void *vpb)
|
||||
SDL_assert(b->width > 0);
|
||||
SDL_assert(b->height > 0);
|
||||
|
||||
const SDL_PixelFormatEnum afmt = a->format;
|
||||
const SDL_PixelFormatEnum bfmt = b->format;
|
||||
const SDL_PixelFormat afmt = a->format;
|
||||
const SDL_PixelFormat bfmt = b->format;
|
||||
if (SDL_ISPIXELFORMAT_FOURCC(afmt) && !SDL_ISPIXELFORMAT_FOURCC(bfmt)) {
|
||||
return -1;
|
||||
} else if (!SDL_ISPIXELFORMAT_FOURCC(afmt) && SDL_ISPIXELFORMAT_FOURCC(bfmt)) {
|
||||
@@ -879,8 +879,8 @@ SDL_bool SDL_CameraThreadIterate(SDL_CameraDevice *device)
|
||||
if (device->needs_conversion) {
|
||||
SDL_Surface *dstsurf = (device->needs_scaling == 1) ? device->conversion_surface : output_surface;
|
||||
SDL_ConvertPixels(srcsurf->w, srcsurf->h,
|
||||
srcsurf->format->format, srcsurf->pixels, srcsurf->pitch,
|
||||
dstsurf->format->format, dstsurf->pixels, dstsurf->pitch);
|
||||
srcsurf->format, srcsurf->pixels, srcsurf->pitch,
|
||||
dstsurf->format, dstsurf->pixels, dstsurf->pitch);
|
||||
srcsurf = dstsurf;
|
||||
}
|
||||
if (device->needs_scaling == 1) { // upscaling? Do it last. -1: downscale, 0: no scaling, 1: upscale
|
||||
@@ -1005,8 +1005,8 @@ static void ChooseBestCameraSpec(SDL_CameraDevice *device, const SDL_CameraSpec
|
||||
SDL_assert(closest->height > 0);
|
||||
|
||||
// okay, we have what we think is the best resolution, now we just need the best format that supports it...
|
||||
const SDL_PixelFormatEnum wantfmt = spec->format;
|
||||
SDL_PixelFormatEnum best_format = SDL_PIXELFORMAT_UNKNOWN;
|
||||
const SDL_PixelFormat wantfmt = spec->format;
|
||||
SDL_PixelFormat best_format = SDL_PIXELFORMAT_UNKNOWN;
|
||||
SDL_Colorspace best_colorspace = SDL_COLORSPACE_UNKNOWN;
|
||||
for (int i = 0; i < num_specs; i++) {
|
||||
const SDL_CameraSpec *thisspec = &device->all_specs[i];
|
||||
@@ -1124,7 +1124,7 @@ SDL_Camera *SDL_OpenCameraDevice(SDL_CameraDeviceID instance_id, const SDL_Camer
|
||||
|
||||
device->needs_conversion = (closest.format != device->spec.format);
|
||||
|
||||
device->acquire_surface = SDL_CreateSurfaceFrom(NULL, closest.width, closest.height, 0, closest.format);
|
||||
device->acquire_surface = SDL_CreateSurfaceFrom(closest.width, closest.height, closest.format, NULL, 0);
|
||||
if (!device->acquire_surface) {
|
||||
ClosePhysicalCameraDevice(device);
|
||||
ReleaseCameraDevice(device);
|
||||
@@ -1136,7 +1136,7 @@ SDL_Camera *SDL_OpenCameraDevice(SDL_CameraDeviceID instance_id, const SDL_Camer
|
||||
if (device->needs_scaling && device->needs_conversion) {
|
||||
const SDL_bool downsampling_first = (device->needs_scaling < 0);
|
||||
const SDL_CameraSpec *s = downsampling_first ? &device->spec : &closest;
|
||||
const SDL_PixelFormatEnum fmt = downsampling_first ? closest.format : device->spec.format;
|
||||
const SDL_PixelFormat fmt = downsampling_first ? closest.format : device->spec.format;
|
||||
device->conversion_surface = SDL_CreateSurface(s->width, s->height, fmt);
|
||||
if (!device->conversion_surface) {
|
||||
ClosePhysicalCameraDevice(device);
|
||||
@@ -1160,7 +1160,7 @@ SDL_Camera *SDL_OpenCameraDevice(SDL_CameraDeviceID instance_id, const SDL_Camer
|
||||
if (device->needs_scaling || device->needs_conversion) {
|
||||
surf = SDL_CreateSurface(device->spec.width, device->spec.height, device->spec.format);
|
||||
} else {
|
||||
surf = SDL_CreateSurfaceFrom(NULL, device->spec.width, device->spec.height, 0, device->spec.format);
|
||||
surf = SDL_CreateSurfaceFrom(device->spec.width, device->spec.height, device->spec.format, NULL, 0);
|
||||
}
|
||||
if (!surf) {
|
||||
ClosePhysicalCameraDevice(device);
|
||||
|
||||
@@ -64,7 +64,7 @@ typedef struct CameraFormatAddData
|
||||
int allocated_specs;
|
||||
} CameraFormatAddData;
|
||||
|
||||
int SDL_AddCameraFormat(CameraFormatAddData *data, SDL_PixelFormatEnum format, SDL_Colorspace colorspace, int w, int h, int framerate_numerator, int framerate_denominator);
|
||||
int SDL_AddCameraFormat(CameraFormatAddData *data, SDL_PixelFormat format, SDL_Colorspace colorspace, int w, int h, int framerate_numerator, int framerate_denominator);
|
||||
|
||||
typedef struct SurfaceList
|
||||
{
|
||||
|
||||
@@ -252,7 +252,7 @@ static void DestroyCameraManager(void)
|
||||
}
|
||||
}
|
||||
|
||||
static void format_android_to_sdl(Uint32 fmt, SDL_PixelFormatEnum *format, SDL_Colorspace *colorspace)
|
||||
static void format_android_to_sdl(Uint32 fmt, SDL_PixelFormat *format, SDL_Colorspace *colorspace)
|
||||
{
|
||||
switch (fmt) {
|
||||
#define CASE(x, y, z) case x: *format = y; *colorspace = z; return
|
||||
@@ -274,7 +274,7 @@ static void format_android_to_sdl(Uint32 fmt, SDL_PixelFormatEnum *format, SDL_C
|
||||
*colorspace = SDL_COLORSPACE_UNKNOWN;
|
||||
}
|
||||
|
||||
static Uint32 format_sdl_to_android(SDL_PixelFormatEnum fmt)
|
||||
static Uint32 format_sdl_to_android(SDL_PixelFormat fmt)
|
||||
{
|
||||
switch (fmt) {
|
||||
#define CASE(x, y) case y: return x
|
||||
@@ -632,7 +632,7 @@ static void GatherCameraSpecs(const char *devid, CameraFormatAddData *add_data,
|
||||
const int w = (int) i32ptr[1];
|
||||
const int h = (int) i32ptr[2];
|
||||
const int32_t type = i32ptr[3];
|
||||
SDL_PixelFormatEnum sdlfmt = SDL_PIXELFORMAT_UNKNOWN;
|
||||
SDL_PixelFormat sdlfmt = SDL_PIXELFORMAT_UNKNOWN;
|
||||
SDL_Colorspace colorspace = SDL_COLORSPACE_UNKNOWN;
|
||||
|
||||
if (type == ACAMERA_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_INPUT) {
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
* <key>com.apple.security.device.camera</key> <true/>
|
||||
*/
|
||||
|
||||
static void CoreMediaFormatToSDL(FourCharCode fmt, SDL_PixelFormatEnum *pixel_format, SDL_Colorspace *colorspace)
|
||||
static void CoreMediaFormatToSDL(FourCharCode fmt, SDL_PixelFormat *pixel_format, SDL_Colorspace *colorspace)
|
||||
{
|
||||
switch (fmt) {
|
||||
#define CASE(x, y, z) case x: *pixel_format = y; *colorspace = z; return
|
||||
@@ -260,7 +260,7 @@ static int COREMEDIA_OpenDevice(SDL_CameraDevice *device, const SDL_CameraSpec *
|
||||
NSArray<AVCaptureDeviceFormat *> *formats = [avdevice formats];
|
||||
for (AVCaptureDeviceFormat *format in formats) {
|
||||
CMFormatDescriptionRef formatDescription = [format formatDescription];
|
||||
SDL_PixelFormatEnum device_format = SDL_PIXELFORMAT_UNKNOWN;
|
||||
SDL_PixelFormat device_format = SDL_PIXELFORMAT_UNKNOWN;
|
||||
SDL_Colorspace device_colorspace = SDL_COLORSPACE_UNKNOWN;
|
||||
CoreMediaFormatToSDL(CMFormatDescriptionGetMediaSubType(formatDescription), &device_format, &device_colorspace);
|
||||
if (device_format != spec->format || device_colorspace != spec->colorspace) {
|
||||
@@ -384,7 +384,7 @@ static void GatherCameraSpecs(AVCaptureDevice *device, CameraFormatAddData *add_
|
||||
}
|
||||
|
||||
//NSLog(@"Available camera format: %@\n", fmt);
|
||||
SDL_PixelFormatEnum device_format = SDL_PIXELFORMAT_UNKNOWN;
|
||||
SDL_PixelFormat device_format = SDL_PIXELFORMAT_UNKNOWN;
|
||||
SDL_Colorspace device_colorspace = SDL_COLORSPACE_UNKNOWN;
|
||||
CoreMediaFormatToSDL(CMFormatDescriptionGetMediaSubType(fmt.formatDescription), &device_format, &device_colorspace);
|
||||
if (device_format == SDL_PIXELFORMAT_UNKNOWN) {
|
||||
|
||||
@@ -85,7 +85,7 @@ SDL_DEFINE_MEDIATYPE_GUID(MFVideoFormat_NV21, FCC('NV21'));
|
||||
static const struct
|
||||
{
|
||||
const GUID *guid;
|
||||
SDL_PixelFormatEnum format;
|
||||
SDL_PixelFormat format;
|
||||
SDL_Colorspace colorspace;
|
||||
} fmtmappings[] = {
|
||||
// This is not every possible format, just popular ones that SDL can reasonably handle.
|
||||
@@ -281,7 +281,7 @@ static SDL_Colorspace GetMediaTypeColorspace(IMFMediaType *mediatype, SDL_Colors
|
||||
return colorspace;
|
||||
}
|
||||
|
||||
static void MediaTypeToSDLFmt(IMFMediaType *mediatype, SDL_PixelFormatEnum *format, SDL_Colorspace *colorspace)
|
||||
static void MediaTypeToSDLFmt(IMFMediaType *mediatype, SDL_PixelFormat *format, SDL_Colorspace *colorspace)
|
||||
{
|
||||
HRESULT ret;
|
||||
GUID type;
|
||||
@@ -300,7 +300,7 @@ static void MediaTypeToSDLFmt(IMFMediaType *mediatype, SDL_PixelFormatEnum *form
|
||||
*colorspace = SDL_COLORSPACE_UNKNOWN;
|
||||
}
|
||||
|
||||
static const GUID *SDLFmtToMFVidFmtGuid(SDL_PixelFormatEnum format)
|
||||
static const GUID *SDLFmtToMFVidFmtGuid(SDL_PixelFormat format)
|
||||
{
|
||||
for (size_t i = 0; i < SDL_arraysize(fmtmappings); i++) {
|
||||
if (fmtmappings[i].format == format) {
|
||||
@@ -930,7 +930,7 @@ static void GatherCameraSpecs(IMFMediaSource *source, CameraFormatAddData *add_d
|
||||
GUID type;
|
||||
ret = IMFMediaType_GetGUID(mediatype, &SDL_MF_MT_MAJOR_TYPE, &type);
|
||||
if (SUCCEEDED(ret) && WIN_IsEqualGUID(&type, &SDL_MFMediaType_Video)) {
|
||||
SDL_PixelFormatEnum sdlfmt = SDL_PIXELFORMAT_UNKNOWN;
|
||||
SDL_PixelFormat sdlfmt = SDL_PIXELFORMAT_UNKNOWN;
|
||||
SDL_Colorspace colorspace = SDL_COLORSPACE_UNKNOWN;
|
||||
MediaTypeToSDLFmt(mediatype, &sdlfmt, &colorspace);
|
||||
if (sdlfmt != SDL_PIXELFORMAT_UNKNOWN) {
|
||||
|
||||
@@ -357,7 +357,7 @@ static void param_update(struct spa_list *param_list, struct spa_list *pending_l
|
||||
}
|
||||
|
||||
static struct sdl_video_format {
|
||||
SDL_PixelFormatEnum format;
|
||||
SDL_PixelFormat format;
|
||||
SDL_Colorspace colorspace;
|
||||
uint32_t id;
|
||||
} sdl_video_formats[] = {
|
||||
@@ -389,7 +389,7 @@ static struct sdl_video_format {
|
||||
#endif
|
||||
};
|
||||
|
||||
static uint32_t sdl_format_to_id(SDL_PixelFormatEnum format)
|
||||
static uint32_t sdl_format_to_id(SDL_PixelFormat format)
|
||||
{
|
||||
struct sdl_video_format *f;
|
||||
SPA_FOR_EACH_ELEMENT(sdl_video_formats, f) {
|
||||
@@ -399,7 +399,7 @@ static uint32_t sdl_format_to_id(SDL_PixelFormatEnum format)
|
||||
return SPA_VIDEO_FORMAT_UNKNOWN;
|
||||
}
|
||||
|
||||
static void id_to_sdl_format(uint32_t id, SDL_PixelFormatEnum *format, SDL_Colorspace *colorspace)
|
||||
static void id_to_sdl_format(uint32_t id, SDL_PixelFormat *format, SDL_Colorspace *colorspace)
|
||||
{
|
||||
struct sdl_video_format *f;
|
||||
SPA_FOR_EACH_ELEMENT(sdl_video_formats, f) {
|
||||
@@ -603,7 +603,7 @@ static void PIPEWIRECAMERA_ReleaseFrame(SDL_CameraDevice *device, SDL_Surface *f
|
||||
PIPEWIRE_pw_thread_loop_unlock(hotplug.loop);
|
||||
}
|
||||
|
||||
static void collect_rates(CameraFormatAddData *data, struct param *p, SDL_PixelFormatEnum sdlfmt, SDL_Colorspace colorspace, const struct spa_rectangle *size)
|
||||
static void collect_rates(CameraFormatAddData *data, struct param *p, SDL_PixelFormat sdlfmt, SDL_Colorspace colorspace, const struct spa_rectangle *size)
|
||||
{
|
||||
const struct spa_pod_prop *prop;
|
||||
struct spa_pod * values;
|
||||
@@ -636,7 +636,7 @@ static void collect_rates(CameraFormatAddData *data, struct param *p, SDL_PixelF
|
||||
}
|
||||
}
|
||||
|
||||
static void collect_size(CameraFormatAddData *data, struct param *p, SDL_PixelFormatEnum sdlfmt, SDL_Colorspace colorspace)
|
||||
static void collect_size(CameraFormatAddData *data, struct param *p, SDL_PixelFormat sdlfmt, SDL_Colorspace colorspace)
|
||||
{
|
||||
const struct spa_pod_prop *prop;
|
||||
struct spa_pod * values;
|
||||
@@ -670,7 +670,7 @@ static void collect_size(CameraFormatAddData *data, struct param *p, SDL_PixelFo
|
||||
static void collect_format(CameraFormatAddData *data, struct param *p)
|
||||
{
|
||||
const struct spa_pod_prop *prop;
|
||||
SDL_PixelFormatEnum sdlfmt;
|
||||
SDL_PixelFormat sdlfmt;
|
||||
SDL_Colorspace colorspace;
|
||||
struct spa_pod * values;
|
||||
uint32_t i, n_vals, choice, *ids;
|
||||
|
||||
@@ -391,7 +391,7 @@ static int AllocBufferUserPtr(SDL_CameraDevice *device, size_t buffer_size)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void format_v4l2_to_sdl(Uint32 fmt, SDL_PixelFormatEnum *format, SDL_Colorspace *colorspace)
|
||||
static void format_v4l2_to_sdl(Uint32 fmt, SDL_PixelFormat *format, SDL_Colorspace *colorspace)
|
||||
{
|
||||
switch (fmt) {
|
||||
#define CASE(x, y, z) case x: *format = y; *colorspace = z; return
|
||||
@@ -407,7 +407,7 @@ static void format_v4l2_to_sdl(Uint32 fmt, SDL_PixelFormatEnum *format, SDL_Colo
|
||||
*colorspace = SDL_COLORSPACE_UNKNOWN;
|
||||
}
|
||||
|
||||
static Uint32 format_sdl_to_v4l2(SDL_PixelFormatEnum fmt)
|
||||
static Uint32 format_sdl_to_v4l2(SDL_PixelFormat fmt)
|
||||
{
|
||||
switch (fmt) {
|
||||
#define CASE(y, x) case x: return y
|
||||
@@ -645,7 +645,7 @@ static SDL_bool FindV4L2CameraDeviceByBusInfoCallback(SDL_CameraDevice *device,
|
||||
return (SDL_strcmp(handle->bus_info, (const char *) userdata) == 0);
|
||||
}
|
||||
|
||||
static int AddCameraFormat(const int fd, CameraFormatAddData *data, SDL_PixelFormatEnum sdlfmt, SDL_Colorspace colorspace, Uint32 v4l2fmt, int w, int h)
|
||||
static int AddCameraFormat(const int fd, CameraFormatAddData *data, SDL_PixelFormat sdlfmt, SDL_Colorspace colorspace, Uint32 v4l2fmt, int w, int h)
|
||||
{
|
||||
struct v4l2_frmivalenum frmivalenum;
|
||||
SDL_zero(frmivalenum);
|
||||
@@ -729,7 +729,7 @@ static void MaybeAddDevice(const char *path)
|
||||
SDL_zero(fmtdesc);
|
||||
fmtdesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
while (ioctl(fd, VIDIOC_ENUM_FMT, &fmtdesc) == 0) {
|
||||
SDL_PixelFormatEnum sdlfmt = SDL_PIXELFORMAT_UNKNOWN;
|
||||
SDL_PixelFormat sdlfmt = SDL_PIXELFORMAT_UNKNOWN;
|
||||
SDL_Colorspace colorspace = SDL_COLORSPACE_UNKNOWN;
|
||||
format_v4l2_to_sdl(fmtdesc.pixelformat, &sdlfmt, &colorspace);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user