Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Starbuck5 committed Oct 5, 2023
1 parent 1e80409 commit 8b8da40
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions src_c/surface.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,6 @@ static void
_release_buffer(Py_buffer *view_p);
static PyObject *
_raise_get_view_ndim_error(int bitsize, SurfViewKind kind);
static PyObject *
_raise_create_surface_error(void);
static SDL_Surface *
pg_DisplayFormatAlpha(SDL_Surface *surface);
static SDL_Surface *
Expand Down Expand Up @@ -717,13 +715,19 @@ surface_init(pgSurfaceObject *self, PyObject *args, PyObject *kwds)
}
}

surface = PG_CreateSurface(
width, height,
SDL_MasksToPixelFormatEnum(bpp, Rmask, Gmask, Bmask, Amask));
Uint32 pxformat =
SDL_MasksToPixelFormatEnum(bpp, Rmask, Gmask, Bmask, Amask);
if (pxformat == SDL_PIXELFORMAT_UNKNOWN) {
PyErr_SetString(PyExc_ValueError, "Invalid mask values");
return -1;
}

surface = PG_CreateSurface(width, height, pxformat);
if (!surface) {
_raise_create_surface_error();
PyErr_SetString(pgExc_SDLError, SDL_GetError());
return -1;
}

if (!(flags & PGS_SRCALPHA)) {
/* We ignore the error if any. */
SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_NONE);
Expand Down Expand Up @@ -763,16 +767,6 @@ surface_init(pgSurfaceObject *self, PyObject *args, PyObject *kwds)
return 0;
}

static PyObject *
_raise_create_surface_error(void)
{
const char *msg = SDL_GetError();

if (strcmp(msg, "Unknown pixel format") == 0)
return RAISE(PyExc_ValueError, "Invalid mask values");
return RAISE(pgExc_SDLError, msg);
}

/* surface object methods */
static PyObject *
surf_get_at(PyObject *self, PyObject *position)
Expand Down Expand Up @@ -2681,7 +2675,7 @@ surf_subsurface(PyObject *self, PyObject *args)
pgSurface_Unlock((pgSurfaceObject *)self);

if (!sub)
return _raise_create_surface_error();
return RAISE(pgExc_SDLError, SDL_GetError());

/* copy the colormap if we need it */
if (SDL_ISPIXELFORMAT_INDEXED(surf->format->format) &&
Expand Down

0 comments on commit 8b8da40

Please sign in to comment.