Subversion Repositories SvarDOS

Rev

Rev 1360 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1360 Rev 1542
Line 2... Line 2...
2
 * PCX-loading routines
2
 * PCX-loading routines
3
 *
3
 *
4
 * This file is part of the Mateusz' DOS Routines (MDR): http://mdr.osdn.io
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.
5
 * Published under the terms of the MIT License, as stated below.
6
 *
6
 *
7
 * Copyright (C) 2022 Mateusz Viste
7
 * Copyright (C) 2022-2023 Mateusz Viste
8
 *
8
 *
9
 * Permission is hereby granted, free of charge, to any person obtaining a copy
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
10
 * of this software and associated documentation files (the "Software"), to
11
 * deal in the Software without restriction, including without limitation the
11
 * deal in the Software without restriction, including without limitation the
12
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
Line 26... Line 26...
26
 */
26
 */
27
 
27
 
28
#ifndef MDR_PCX_H
28
#ifndef MDR_PCX_H
29
#define MDR_PCX_H
29
#define MDR_PCX_H
30
 
30
 
-
 
31
#include <stdio.h> /* FILE */
-
 
32
 
31
struct pcx_hdr {
33
struct pcx_hdr {
32
  unsigned char rle;
34
  unsigned char rle;
33
  unsigned char bpp;
35
  unsigned char bpp;
34
  unsigned short max_x;
36
  unsigned short max_x;
35
  unsigned short max_y;
37
  unsigned short max_y;
Line 39... Line 41...
39
    unsigned char g;
41
    unsigned char g;
40
    unsigned char b;
42
    unsigned char b;
41
  } pal[256];
43
  } pal[256];
42
};
44
};
43
 
45
 
-
 
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. */
44
int pcx_anal(struct pcx_hdr *h, FILE *fd, unsigned long offset, unsigned short len);
52
int mdr_pcx_anal(struct pcx_hdr *h, FILE *fd, unsigned long offset, unsigned long len);
-
 
53
 
-
 
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);
-
 
60
 
-
 
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. */
45
int pcx_load(void *ptr, size_t ptrsz, const struct pcx_hdr *h, FILE *fd, unsigned long offset);
66
int mdr_pcx_load(void *ptr, const struct pcx_hdr *h, FILE *fd);
46
 
67
 
47
/* convert img to 8bpp if needed (ie unpack 2 and 4bpp data to 8bpp) */
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 */
48
int pcx_convto8bpp(void *img, const struct pcx_hdr *h);
75
int mdr_pcx_to8bpp(void *img, const struct pcx_hdr *h, unsigned char rowflag);
49
 
76
 
50
#endif
77
#endif