Skip to content

Commit

Permalink
picture: move to libtrx
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Aug 23, 2024
1 parent 9061c91 commit 84cc44d
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 658 deletions.
2 changes: 0 additions & 2 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ sources = [
'src/game/phase/phase_pause.c',
'src/game/phase/phase_picture.c',
'src/game/phase/phase_stats.c',
'src/game/picture.c',
'src/game/random.c',
'src/game/requester.c',
'src/game/room.c',
Expand Down Expand Up @@ -273,7 +272,6 @@ sources = [
'src/specific/s_fmv.c',
'src/specific/s_input.c',
'src/specific/s_output.c',
'src/specific/s_picture.c',
'src/specific/s_shell.c',
resources,
]
Expand Down
26 changes: 15 additions & 11 deletions src/game/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "game/gamebuf.h"
#include "game/overlay.h"
#include "game/phase/phase.h"
#include "game/picture.h"
#include "game/random.h"
#include "game/viewport.h"
#include "global/const.h"
Expand All @@ -18,6 +17,8 @@
#include "specific/s_output.h"
#include "specific/s_shell.h"

#include <libtrx/engine/image.h>
#include <libtrx/filesystem.h>
#include <libtrx/memory.h>
#include <libtrx/utils.h>

Expand Down Expand Up @@ -59,7 +60,10 @@ static XYZ_32 m_LsVectorView = { 0 };
static int32_t m_LightningCount = 0;
static LIGHTNING m_LightningTable[MAX_LIGHTNINGS];

char *m_BackdropImagePath = NULL;
static char *m_BackdropImagePath = NULL;
static const char *m_ImageExtensions[] = {
".png", ".jpg", ".jpeg", ".pcx", NULL,
};

static void Output_DrawBlackOverlay(uint8_t alpha);

Expand Down Expand Up @@ -950,18 +954,18 @@ void Output_LoadBackdropImage(const char *filename)
}

const char *old_path = m_BackdropImagePath;
m_BackdropImagePath = Memory_DupStr(filename);
m_BackdropImagePath = File_GuessExtension(filename, m_ImageExtensions);
Memory_FreePointer(&old_path);

PICTURE *orig_pic = Picture_CreateFromFile(m_BackdropImagePath);
if (orig_pic) {
PICTURE *scaled_pic = Picture_ScaleSmart(
orig_pic, Viewport_GetWidth(), Viewport_GetHeight());
if (scaled_pic) {
S_Output_DownloadBackdropSurface(scaled_pic);
Picture_Free(scaled_pic);
IMAGE *orig_img = Image_CreateFromFile(m_BackdropImagePath);
if (orig_img) {
IMAGE *scaled_img = Image_ScaleSmart(
orig_img, Viewport_GetWidth(), Viewport_GetHeight());
if (scaled_img) {
S_Output_DownloadBackdropSurface(scaled_img);
Image_Free(scaled_img);
}
Picture_Free(orig_pic);
Image_Free(orig_img);
}
}

Expand Down
84 changes: 0 additions & 84 deletions src/game/picture.c

This file was deleted.

20 changes: 0 additions & 20 deletions src/game/picture.h

This file was deleted.

14 changes: 7 additions & 7 deletions src/gfx/screenshot.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "gfx/screenshot.h"

#include "game/picture.h"
#include "global/types.h"

#include <libtrx/engine/image.h>
#include <libtrx/memory.h>

#include <assert.h>
Expand All @@ -17,17 +17,17 @@ bool GFX_Screenshot_CaptureToFile(const char *path)
GFX_Screenshot_CaptureToBuffer(
NULL, &width, &height, 3, GL_RGB, GL_UNSIGNED_BYTE, true);

PICTURE *pic = Picture_Create(width, height);
assert(pic);
IMAGE *image = Image_Create(width, height);
assert(image);

GFX_Screenshot_CaptureToBuffer(
(uint8_t *)pic->data, &width, &height, 3, GL_RGB, GL_UNSIGNED_BYTE,
(uint8_t *)image->data, &width, &height, 3, GL_RGB, GL_UNSIGNED_BYTE,
true);

ret = Picture_SaveToFile(pic, path);
ret = Image_SaveToFile(image, path);

if (pic) {
Picture_Free(pic);
if (image) {
Image_Free(image);
}
return ret;
}
Expand Down
6 changes: 0 additions & 6 deletions src/global/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1985,12 +1985,6 @@ typedef struct SAMPLE_INFO {
int16_t flags;
} SAMPLE_INFO;

typedef struct PICTURE {
int32_t width;
int32_t height;
RGB_888 *data;
} PICTURE;

typedef union INPUT_STATE {
uint64_t any;
struct {
Expand Down
20 changes: 10 additions & 10 deletions src/specific/s_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -475,9 +475,9 @@ void S_Output_DrawBackdropSurface(void)
GFX_2D_Renderer_Render(m_Renderer2D);
}

void S_Output_DownloadBackdropSurface(const PICTURE *pic)
void S_Output_DownloadBackdropSurface(const IMAGE *const image)
{
if (!pic) {
if (!image) {
if (m_PictureSurface) {
bool result = GFX_2D_Surface_Clear(m_PictureSurface);
S_Output_CheckError(result);
Expand All @@ -490,8 +490,8 @@ void S_Output_DownloadBackdropSurface(const PICTURE *pic)
// first, download the picture directly to a temporary surface
{
GFX_2D_SurfaceDesc surface_desc = {
.width = pic->width,
.height = pic->height,
.width = image->width,
.height = image->height,
};
picture_surface = GFX_2D_Surface_Create(&surface_desc);
}
Expand All @@ -502,8 +502,8 @@ void S_Output_DownloadBackdropSurface(const PICTURE *pic)
S_Output_CheckError(result);

uint32_t *output_ptr = surface_desc.pixels;
RGB_888 *input_ptr = pic->data;
for (int i = 0; i < pic->width * pic->height; i++) {
IMAGE_PIXEL *input_ptr = image->data;
for (int i = 0; i < image->width * image->height; i++) {
uint8_t r = input_ptr->r;
uint8_t g = input_ptr->g;
uint8_t b = input_ptr->b;
Expand All @@ -525,8 +525,8 @@ void S_Output_DownloadBackdropSurface(const PICTURE *pic)

int32_t target_width = m_SurfaceWidth;
int32_t target_height = m_SurfaceHeight;
int32_t source_width = pic->width;
int32_t source_height = pic->height;
int32_t source_width = image->width;
int32_t source_height = image->height;

// keep aspect ratio and fit inside, adding black bars on the sides
const float source_ratio = source_width / (float)source_height;
Expand All @@ -541,8 +541,8 @@ void S_Output_DownloadBackdropSurface(const PICTURE *pic)
GFX_BlitterRect source_rect = {
.left = 0,
.top = 0,
.right = pic->width,
.bottom = pic->height,
.right = image->width,
.bottom = image->height,
};
GFX_BlitterRect target_rect = {
.left = (target_width - new_width) / 2,
Expand Down
5 changes: 3 additions & 2 deletions src/specific/s_output.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#pragma once

#include "game/picture.h"
#include "global/types.h"

#include <libtrx/engine/image.h>

#include <stdbool.h>
#include <stdint.h>

Expand All @@ -27,7 +28,7 @@ RGB_888 S_Output_GetPaletteColor(uint8_t idx);

void S_Output_DownloadTextures(int32_t pages);
void S_Output_SelectTexture(int tex_num);
void S_Output_DownloadBackdropSurface(const PICTURE *pic);
void S_Output_DownloadBackdropSurface(const IMAGE *image);
void S_Output_DrawBackdropSurface(void);

void S_Output_DrawFlatTriangle(
Expand Down
Loading

0 comments on commit 84cc44d

Please sign in to comment.