Browse Source

engine: common: imagelib: split imagelib.h.

pull/2/head
Andrey Akhmichin 5 years ago
parent
commit
248c8a745c
  1. 214
      engine/common/imagelib/imagelib.h
  2. 1
      engine/common/imagelib/img_bmp.c
  3. 51
      engine/common/imagelib/img_bmp.h
  4. 1
      engine/common/imagelib/img_dds.c
  5. 116
      engine/common/imagelib/img_dds.h
  6. 1
      engine/common/imagelib/img_png.c
  7. 73
      engine/common/imagelib/img_png.h
  8. 1
      engine/common/imagelib/img_tga.c
  9. 42
      engine/common/imagelib/img_tga.h

214
engine/common/imagelib/imagelib.h

@ -98,220 +98,6 @@ typedef struct imglib_s
qboolean custom_palette; // custom palette was installed qboolean custom_palette; // custom palette was installed
} imglib_t; } imglib_t;
/*
========================================================================
.BMP image format
========================================================================
*/
#define BI_SIZE 40 // size of bitmap info header.
#if !defined(BI_RGB)
#define BI_RGB 0 // uncompressed RGB bitmap(defined in wingdi.h)
#endif
#pragma pack( 1 )
typedef struct
{
char id[2]; // bmfh.bfType
dword fileSize; // bmfh.bfSize
dword reserved0; // bmfh.bfReserved1 + bmfh.bfReserved2
dword bitmapDataOffset; // bmfh.bfOffBits
dword bitmapHeaderSize; // bmih.biSize
int width; // bmih.biWidth
int height; // bmih.biHeight
word planes; // bmih.biPlanes
word bitsPerPixel; // bmih.biBitCount
dword compression; // bmih.biCompression
dword bitmapDataSize; // bmih.biSizeImage
dword hRes; // bmih.biXPelsPerMeter
dword vRes; // bmih.biYPelsPerMeter
dword colors; // bmih.biClrUsed
dword importantColors; // bmih.biClrImportant
} bmp_t;
#pragma pack( )
/*
========================================================================
.TGA image format (Truevision Targa)
========================================================================
*/
#pragma pack( 1 )
typedef struct tga_s
{
byte id_length;
byte colormap_type;
byte image_type;
word colormap_index;
word colormap_length;
byte colormap_size;
word x_origin;
word y_origin;
word width;
word height;
byte pixel_size;
byte attributes;
} tga_t;
#pragma pack( )
/*
========================================================================
.PNG image format (Portable Network Graphics)
========================================================================
*/
enum
{
PNG_CT_GREY,
PNG_CT_PALLETE = BIT(0),
PNG_CT_RGB = BIT(1),
PNG_CT_ALPHA = BIT(2),
PNG_CT_RGBA = (PNG_CT_RGB|PNG_CT_ALPHA)
} png_colortype;
enum
{
PNG_F_NONE,
PNG_F_SUB,
PNG_F_UP,
PNG_F_AVERAGE,
PNG_F_PAETH
} png_filter;
#pragma pack( push, 1 )
typedef struct png_ihdr_s
{
uint width;
uint height;
byte bitdepth;
byte colortype;
byte compression;
byte filter;
byte interlace;
} png_ihdr_t;
typedef struct png_s
{
byte sign[8];
uint ihdr_len;
byte ihdr_sign[4];
png_ihdr_t ihdr_chunk;
uint ihdr_crc32;
} png_t;
#pragma pack( pop )
typedef struct png_footer_s
{
uint idat_crc32;
uint iend_len;
byte iend_sign[4];
uint iend_crc32;
} png_footer_t;
/*
========================================================================
.DDS image format
========================================================================
*/
#define DDSHEADER ((' '<<24)+('S'<<16)+('D'<<8)+'D') // little-endian "DDS "
// various four-cc types
#define TYPE_DXT1 (('1'<<24)+('T'<<16)+('X'<<8)+'D') // little-endian "DXT1"
#define TYPE_DXT2 (('2'<<24)+('T'<<16)+('X'<<8)+'D') // little-endian "DXT2"
#define TYPE_DXT3 (('3'<<24)+('T'<<16)+('X'<<8)+'D') // little-endian "DXT3"
#define TYPE_DXT4 (('4'<<24)+('T'<<16)+('X'<<8)+'D') // little-endian "DXT4"
#define TYPE_DXT5 (('5'<<24)+('T'<<16)+('X'<<8)+'D') // little-endian "DXT5"
#define TYPE_ATI1 (('1'<<24)+('I'<<16)+('T'<<8)+'A') // little-endian "ATI1"
#define TYPE_ATI2 (('2'<<24)+('I'<<16)+('T'<<8)+'A') // little-endian "ATI2"
#define TYPE_RXGB (('B'<<24)+('G'<<16)+('X'<<8)+'R') // little-endian "RXGB" doom3 normalmaps
#define TYPE_$ (('\0'<<24)+('\0'<<16)+('\0'<<8)+'$') // little-endian "$"
#define TYPE_o (('\0'<<24)+('\0'<<16)+('\0'<<8)+'o') // little-endian "o"
#define TYPE_p (('\0'<<24)+('\0'<<16)+('\0'<<8)+'p') // little-endian "p"
#define TYPE_q (('\0'<<24)+('\0'<<16)+('\0'<<8)+'q') // little-endian "q"
#define TYPE_r (('\0'<<24)+('\0'<<16)+('\0'<<8)+'r') // little-endian "r"
#define TYPE_s (('\0'<<24)+('\0'<<16)+('\0'<<8)+'s') // little-endian "s"
#define TYPE_t (('\0'<<24)+('\0'<<16)+('\0'<<8)+'t') // little-endian "t"
// dwFlags1
#define DDS_CAPS 0x00000001L
#define DDS_HEIGHT 0x00000002L
#define DDS_WIDTH 0x00000004L
#define DDS_PITCH 0x00000008L
#define DDS_PIXELFORMAT 0x00001000L
#define DDS_MIPMAPCOUNT 0x00020000L
#define DDS_LINEARSIZE 0x00080000L
#define DDS_DEPTH 0x00800000L
// dwFlags2
#define DDS_ALPHAPIXELS 0x00000001L
#define DDS_ALPHA 0x00000002L
#define DDS_FOURCC 0x00000004L
#define DDS_RGB 0x00000040L
#define DDS_RGBA 0x00000041L // (DDS_RGB|DDS_ALPHAPIXELS)
#define DDS_LUMINANCE 0x00020000L
#define DDS_DUDV 0x00080000L
// dwCaps1
#define DDS_COMPLEX 0x00000008L
#define DDS_TEXTURE 0x00001000L
#define DDS_MIPMAP 0x00400000L
// dwCaps2
#define DDS_CUBEMAP 0x00000200L
#define DDS_CUBEMAP_POSITIVEX 0x00000400L
#define DDS_CUBEMAP_NEGATIVEX 0x00000800L
#define DDS_CUBEMAP_POSITIVEY 0x00001000L
#define DDS_CUBEMAP_NEGATIVEY 0x00002000L
#define DDS_CUBEMAP_POSITIVEZ 0x00004000L
#define DDS_CUBEMAP_NEGATIVEZ 0x00008000L
#define DDS_CUBEMAP_ALL_SIDES 0x0000FC00L
#define DDS_VOLUME 0x00200000L
typedef struct dds_pf_s
{
uint dwSize;
uint dwFlags;
uint dwFourCC;
uint dwRGBBitCount;
uint dwRBitMask;
uint dwGBitMask;
uint dwBBitMask;
uint dwABitMask;
} dds_pixf_t;
// DDCAPS2
typedef struct dds_caps_s
{
uint dwCaps1;
uint dwCaps2;
uint dwCaps3; // currently unused
uint dwCaps4; // currently unused
} dds_caps_t;
typedef struct dds_s
{
uint dwIdent; // must matched with DDSHEADER
uint dwSize;
uint dwFlags; // determines what fields are valid
uint dwHeight;
uint dwWidth;
uint dwLinearSize; // Formless late-allocated optimized surface size
uint dwDepth; // depth if a volume texture
uint dwMipMapCount; // number of mip-map levels requested
uint dwAlphaBitDepth; // depth of alpha buffer requested
uint dwReserved1[10]; // reserved for future expansions
dds_pixf_t dsPixelFormat;
dds_caps_t dsCaps;
uint dwTextureStage;
} dds_t;
// imagelib definitions // imagelib definitions
#define IMAGE_MAXWIDTH 8192 #define IMAGE_MAXWIDTH 8192
#define IMAGE_MAXHEIGHT 8192 #define IMAGE_MAXHEIGHT 8192

1
engine/common/imagelib/img_bmp.c

@ -15,6 +15,7 @@ GNU General Public License for more details.
#include "imagelib.h" #include "imagelib.h"
#include "mathlib.h" #include "mathlib.h"
#include "img_bmp.h"
/* /*
============= =============

51
engine/common/imagelib/img_bmp.h

@ -0,0 +1,51 @@
/*
img_bmp.h - bmp format reference
Copyright (C) 2007 Uncle Mike
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#ifndef IMG_BMP_H
#define IMG_BMP_H
/*
========================================================================
.BMP image format
========================================================================
*/
#define BI_SIZE 40 // size of bitmap info header.
#if !defined(BI_RGB)
#define BI_RGB 0 // uncompressed RGB bitmap(defined in wingdi.h)
#endif
#pragma pack( push, 1 )
typedef struct
{
char id[2]; // bmfh.bfType
dword fileSize; // bmfh.bfSize
dword reserved0; // bmfh.bfReserved1 + bmfh.bfReserved2
dword bitmapDataOffset; // bmfh.bfOffBits
dword bitmapHeaderSize; // bmih.biSize
int width; // bmih.biWidth
int height; // bmih.biHeight
word planes; // bmih.biPlanes
word bitsPerPixel; // bmih.biBitCount
dword compression; // bmih.biCompression
dword bitmapDataSize; // bmih.biSizeImage
dword hRes; // bmih.biXPelsPerMeter
dword vRes; // bmih.biYPelsPerMeter
dword colors; // bmih.biClrUsed
dword importantColors; // bmih.biClrImportant
} bmp_t;
#pragma pack( pop )
#endif // IMG_BMP_H

1
engine/common/imagelib/img_dds.c

@ -15,6 +15,7 @@ GNU General Public License for more details.
#include "imagelib.h" #include "imagelib.h"
#include "mathlib.h" #include "mathlib.h"
#include "img_dds.h"
qboolean Image_CheckDXT3Alpha( dds_t *hdr, byte *fin ) qboolean Image_CheckDXT3Alpha( dds_t *hdr, byte *fin )
{ {

116
engine/common/imagelib/img_dds.h

@ -0,0 +1,116 @@
/*
img_dds.h - dds format reference
Copyright (C) 2015 Uncle Mike
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#ifndef IMG_DDS_H
#define IMG_DDS_H
/*
========================================================================
.DDS image format
========================================================================
*/
#define DDSHEADER ((' '<<24)+('S'<<16)+('D'<<8)+'D') // little-endian "DDS "
// various four-cc types
#define TYPE_DXT1 (('1'<<24)+('T'<<16)+('X'<<8)+'D') // little-endian "DXT1"
#define TYPE_DXT2 (('2'<<24)+('T'<<16)+('X'<<8)+'D') // little-endian "DXT2"
#define TYPE_DXT3 (('3'<<24)+('T'<<16)+('X'<<8)+'D') // little-endian "DXT3"
#define TYPE_DXT4 (('4'<<24)+('T'<<16)+('X'<<8)+'D') // little-endian "DXT4"
#define TYPE_DXT5 (('5'<<24)+('T'<<16)+('X'<<8)+'D') // little-endian "DXT5"
#define TYPE_ATI1 (('1'<<24)+('I'<<16)+('T'<<8)+'A') // little-endian "ATI1"
#define TYPE_ATI2 (('2'<<24)+('I'<<16)+('T'<<8)+'A') // little-endian "ATI2"
#define TYPE_RXGB (('B'<<24)+('G'<<16)+('X'<<8)+'R') // little-endian "RXGB" doom3 normalmaps
#define TYPE_$ (('\0'<<24)+('\0'<<16)+('\0'<<8)+'$') // little-endian "$"
#define TYPE_o (('\0'<<24)+('\0'<<16)+('\0'<<8)+'o') // little-endian "o"
#define TYPE_p (('\0'<<24)+('\0'<<16)+('\0'<<8)+'p') // little-endian "p"
#define TYPE_q (('\0'<<24)+('\0'<<16)+('\0'<<8)+'q') // little-endian "q"
#define TYPE_r (('\0'<<24)+('\0'<<16)+('\0'<<8)+'r') // little-endian "r"
#define TYPE_s (('\0'<<24)+('\0'<<16)+('\0'<<8)+'s') // little-endian "s"
#define TYPE_t (('\0'<<24)+('\0'<<16)+('\0'<<8)+'t') // little-endian "t"
// dwFlags1
#define DDS_CAPS 0x00000001L
#define DDS_HEIGHT 0x00000002L
#define DDS_WIDTH 0x00000004L
#define DDS_PITCH 0x00000008L
#define DDS_PIXELFORMAT 0x00001000L
#define DDS_MIPMAPCOUNT 0x00020000L
#define DDS_LINEARSIZE 0x00080000L
#define DDS_DEPTH 0x00800000L
// dwFlags2
#define DDS_ALPHAPIXELS 0x00000001L
#define DDS_ALPHA 0x00000002L
#define DDS_FOURCC 0x00000004L
#define DDS_RGB 0x00000040L
#define DDS_RGBA 0x00000041L // (DDS_RGB|DDS_ALPHAPIXELS)
#define DDS_LUMINANCE 0x00020000L
#define DDS_DUDV 0x00080000L
// dwCaps1
#define DDS_COMPLEX 0x00000008L
#define DDS_TEXTURE 0x00001000L
#define DDS_MIPMAP 0x00400000L
// dwCaps2
#define DDS_CUBEMAP 0x00000200L
#define DDS_CUBEMAP_POSITIVEX 0x00000400L
#define DDS_CUBEMAP_NEGATIVEX 0x00000800L
#define DDS_CUBEMAP_POSITIVEY 0x00001000L
#define DDS_CUBEMAP_NEGATIVEY 0x00002000L
#define DDS_CUBEMAP_POSITIVEZ 0x00004000L
#define DDS_CUBEMAP_NEGATIVEZ 0x00008000L
#define DDS_CUBEMAP_ALL_SIDES 0x0000FC00L
#define DDS_VOLUME 0x00200000L
typedef struct dds_pf_s
{
uint dwSize;
uint dwFlags;
uint dwFourCC;
uint dwRGBBitCount;
uint dwRBitMask;
uint dwGBitMask;
uint dwBBitMask;
uint dwABitMask;
} dds_pixf_t;
// DDCAPS2
typedef struct dds_caps_s
{
uint dwCaps1;
uint dwCaps2;
uint dwCaps3; // currently unused
uint dwCaps4; // currently unused
} dds_caps_t;
typedef struct dds_s
{
uint dwIdent; // must matched with DDSHEADER
uint dwSize;
uint dwFlags; // determines what fields are valid
uint dwHeight;
uint dwWidth;
uint dwLinearSize; // Formless late-allocated optimized surface size
uint dwDepth; // depth if a volume texture
uint dwMipMapCount; // number of mip-map levels requested
uint dwAlphaBitDepth; // depth of alpha buffer requested
uint dwReserved1[10]; // reserved for future expansions
dds_pixf_t dsPixelFormat;
dds_caps_t dsCaps;
uint dwTextureStage;
} dds_t;
#endif // IMG_DDS_H

1
engine/common/imagelib/img_png.c

@ -17,6 +17,7 @@ GNU General Public License for more details.
#include "miniz.h" #include "miniz.h"
#include "imagelib.h" #include "imagelib.h"
#include "mathlib.h" #include "mathlib.h"
#include "img_png.h"
#if defined(XASH_NO_NETWORK) #if defined(XASH_NO_NETWORK)
#include "platform/stub/net_stub.h" #include "platform/stub/net_stub.h"

73
engine/common/imagelib/img_png.h

@ -0,0 +1,73 @@
/*
img_png.h - png format reference
Copyright (C) 2019 Andrey Akhmichin
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#ifndef IMG_PNG_H
#define IMG_PNG_H
/*
========================================================================
.PNG image format (Portable Network Graphics)
========================================================================
*/
enum
{
PNG_CT_GREY,
PNG_CT_PALLETE = BIT(0),
PNG_CT_RGB = BIT(1),
PNG_CT_ALPHA = BIT(2),
PNG_CT_RGBA = (PNG_CT_RGB|PNG_CT_ALPHA)
} png_colortype;
enum
{
PNG_F_NONE,
PNG_F_SUB,
PNG_F_UP,
PNG_F_AVERAGE,
PNG_F_PAETH
} png_filter;
#pragma pack( push, 1 )
typedef struct png_ihdr_s
{
uint width;
uint height;
byte bitdepth;
byte colortype;
byte compression;
byte filter;
byte interlace;
} png_ihdr_t;
typedef struct png_s
{
byte sign[8];
uint ihdr_len;
byte ihdr_sign[4];
png_ihdr_t ihdr_chunk;
uint ihdr_crc32;
} png_t;
#pragma pack( pop )
typedef struct png_footer_s
{
uint idat_crc32;
uint iend_len;
byte iend_sign[4];
uint iend_crc32;
} png_footer_t;
#endif // IMG_PNG_H

1
engine/common/imagelib/img_tga.c

@ -15,6 +15,7 @@ GNU General Public License for more details.
#include "imagelib.h" #include "imagelib.h"
#include "mathlib.h" #include "mathlib.h"
#include "img_tga.h"
/* /*
============= =============

42
engine/common/imagelib/img_tga.h

@ -0,0 +1,42 @@
/*
img_tga.h - tga format reference
Copyright (C) 2007 Uncle Mike
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#ifndef IMG_TGA_H
#define IMG_TGA_H
/*
========================================================================
.TGA image format (Truevision Targa)
========================================================================
*/
#pragma pack( push, 1 )
typedef struct tga_s
{
byte id_length;
byte colormap_type;
byte image_type;
word colormap_index;
word colormap_length;
byte colormap_size;
word x_origin;
word y_origin;
word width;
word height;
byte pixel_size;
byte attributes;
} tga_t;
#pragma pack( pop )
#endif // IMG_TGA_H
Loading…
Cancel
Save