This commit is contained in:
UnknownShadow200 2018-11-29 01:46:54 +11:00
parent 39d9e40b68
commit 69770cf93a
3 changed files with 4 additions and 2 deletions

View File

@ -619,6 +619,7 @@ static void Png_EncodeRow(const BitmapCol* src, uint8_t* cur, uint8_t* prior, ui
best[0] = bestFilter;
}
static int Png_SelectRow(Bitmap* bmp, int y) { return y; }
ReturnCode Png_Encode(Bitmap* bmp, struct Stream* stream, Png_RowSelector selectRow) {
uint8_t tmp[32];
uint8_t prevLine[PNG_MAX_DIMS * 3], curLine[PNG_MAX_DIMS * 3];
@ -630,6 +631,7 @@ ReturnCode Png_Encode(Bitmap* bmp, struct Stream* stream, Png_RowSelector select
int y, lineSize;
ReturnCode res;
if (!selectRow) selectRow = Png_SelectRow;
if ((res = Stream_Write(stream, png_sig, PNG_SIG_SIZE))) return res;
Bitmap_Crc32Stream(&chunk, stream);

View File

@ -47,6 +47,7 @@ typedef int (*Png_RowSelector)(Bitmap* bmp, int row);
*/
ReturnCode Png_Decode(Bitmap* bmp, struct Stream* stream);
/* Encodes a bitmap in PNG format. */
/* selectRow is optional. Can be used to modify how rows are encoded. (e.g. flip image) */
/* NOTE: Always saves as RGB, alpha channel is discarded. */
ReturnCode Png_Encode(Bitmap* bmp, struct Stream* stream, Png_RowSelector selectRow);
#endif

View File

@ -860,7 +860,6 @@ void Gfx_CalcPerspectiveMatrix(float fov, float aspect, float zNear, float zFar,
/*########################################################################################################################*
*-----------------------------------------------------------Misc----------------------------------------------------------*
*#########################################################################################################################*/
static int D3D9_SelectRow(Bitmap* bmp, int y) { return y; }
ReturnCode Gfx_TakeScreenshot(struct Stream* output, int width, int height) {
IDirect3DSurface9* backbuffer = NULL;
IDirect3DSurface9* temp = NULL;
@ -878,7 +877,7 @@ ReturnCode Gfx_TakeScreenshot(struct Stream* output, int width, int height) {
if (res) goto finished;
{
Bitmap bmp; Bitmap_Create(&bmp, width, height, rect.pBits);
res = Png_Encode(&bmp, output, D3D9_SelectRow);
res = Png_Encode(&bmp, output, NULL);
if (res) { IDirect3DSurface9_UnlockRect(temp); goto finished; }
}
res = IDirect3DSurface9_UnlockRect(temp);