1360 |
mateusz.vi |
1 |
/*
|
|
|
2 |
* PCX-loading routines
|
|
|
3 |
*
|
|
|
4 |
* This file is part of the Mateusz' DOS Routines (MDR): http://mdr.osdn.io
|
|
|
5 |
* Published under the terms of the MIT License, as stated below.
|
|
|
6 |
*
|
1542 |
mateusz.vi |
7 |
* Copyright (C) 2022-2023 Mateusz Viste
|
1360 |
mateusz.vi |
8 |
*
|
|
|
9 |
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
10 |
* of this software and associated documentation files (the "Software"), to
|
|
|
11 |
* deal in the Software without restriction, including without limitation the
|
|
|
12 |
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
|
13 |
* sell copies of the Software, and to permit persons to whom the Software is
|
|
|
14 |
* furnished to do so, subject to the following conditions:
|
|
|
15 |
*
|
|
|
16 |
* The above copyright notice and this permission notice shall be included in
|
|
|
17 |
* all copies or substantial portions of the Software.
|
|
|
18 |
*
|
|
|
19 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
20 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
21 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
22 |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
23 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
24 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
25 |
* IN THE SOFTWARE.
|
|
|
26 |
*/
|
|
|
27 |
|
|
|
28 |
#ifndef MDR_PCX_H
|
|
|
29 |
#define MDR_PCX_H
|
|
|
30 |
|
1542 |
mateusz.vi |
31 |
#include <stdio.h> /* FILE */
|
|
|
32 |
|
1360 |
mateusz.vi |
33 |
struct pcx_hdr {
|
|
|
34 |
unsigned char rle;
|
|
|
35 |
unsigned char bpp;
|
|
|
36 |
unsigned short max_x;
|
|
|
37 |
unsigned short max_y;
|
|
|
38 |
unsigned short bytes_per_scanline;
|
|
|
39 |
struct {
|
|
|
40 |
unsigned char r;
|
|
|
41 |
unsigned char g;
|
|
|
42 |
unsigned char b;
|
|
|
43 |
} pal[256];
|
|
|
44 |
};
|
|
|
45 |
|
1542 |
mateusz.vi |
46 |
/* analyzes the header of a PCX file and fills the pcx_hdr struct accordingly.
|
|
|
47 |
* fd must be a valid (open) file descriptor.
|
|
|
48 |
* offset is the address inside the file where the PCX data is located
|
|
|
49 |
* (usually 0, unless the file is some kind of container).
|
|
|
50 |
* len is the total length of the PCX data. len=0 means "same as file size"
|
|
|
51 |
* returns 0 on success, non-zero otherwise. */
|
|
|
52 |
int mdr_pcx_anal(struct pcx_hdr *h, FILE *fd, unsigned long offset, unsigned long len);
|
1360 |
mateusz.vi |
53 |
|
1542 |
mateusz.vi |
54 |
/* this function should be called to load the next row of a PCX file into a
|
|
|
55 |
* buffer pointed at by bufptr. you will typically want to call this function
|
|
|
56 |
* h->max_y times. ptr must be at least (h->max_x + 1) bytes large for 8bpp.
|
|
|
57 |
* the pcx_hdr struct must have been produced by pcx_anal().
|
|
|
58 |
* returns 0 on success, non-zero otherwise. */
|
|
|
59 |
int mdr_pcx_loadrow(void *bufptr, const struct pcx_hdr *h, FILE *fd);
|
1360 |
mateusz.vi |
60 |
|
1542 |
mateusz.vi |
61 |
/* load an entire PCX file into a pixel buffer. the PCX data must have been
|
|
|
62 |
* previously analyzed by pcx_anal() and the fd file pointer must not have been
|
|
|
63 |
* modified since then. the destination buffer must be large enough to hold all
|
|
|
64 |
* pixels, ie. (h->max_x + 1) * (h->max_y + 1) for 8 bpp.
|
|
|
65 |
* returns 0 on success, non-zero otherwise. */
|
|
|
66 |
int mdr_pcx_load(void *ptr, const struct pcx_hdr *h, FILE *fd);
|
|
|
67 |
|
|
|
68 |
/* convert img to 8bpp if needed (ie unpack 2 and 4bpp data to 8bpp).
|
|
|
69 |
* the conversion is performed in-place, make sure the img buffer is large
|
|
|
70 |
* enough to accomodate the size of the data after conversion (ie. twice as
|
|
|
71 |
* big on 4bpp source, 4x times as big on 2bpp source and 8x as big on 1bpp
|
|
|
72 |
* source).
|
|
|
73 |
* if rowflag is set to a non-zero value, then the routine assumes img
|
|
|
74 |
* contains only a single row of pixels */
|
|
|
75 |
int mdr_pcx_to8bpp(void *img, const struct pcx_hdr *h, unsigned char rowflag);
|
|
|
76 |
|
1360 |
mateusz.vi |
77 |
#endif
|