Last change
on this file since 66 was
56,
checked in by Sam Hocevar, 15 years ago
|
- Add licensing terms to most C / C++ files (Ref #5).
|
File size:
2.2 KB
|
Rev | Line | |
---|
[56] | 1 | /* |
---|
| 2 | * Abuse - dark 2D side-scrolling platform game |
---|
| 3 | * Copyright (c) 1995 Crack dot Com |
---|
| 4 | * |
---|
| 5 | * This software was released into the Public Domain. As with most public |
---|
| 6 | * domain software, no warranty is made or implied by Crack dot Com or |
---|
| 7 | * Jonathan Clark. |
---|
| 8 | */ |
---|
| 9 | |
---|
| 10 | #include "config.h" |
---|
| 11 | |
---|
[2] | 12 | #include "image.hpp" |
---|
| 13 | #include "specs.hpp" |
---|
| 14 | |
---|
| 15 | image *load_targa(char *filename, palette *pal) |
---|
| 16 | { |
---|
| 17 | bFILE *fp=open_file(filename,"rb"); |
---|
| 18 | if (!fp) |
---|
| 19 | return 0; |
---|
| 20 | |
---|
| 21 | if (fp->open_failure()) |
---|
| 22 | { |
---|
| 23 | delete fp; |
---|
| 24 | return 0; |
---|
| 25 | } |
---|
| 26 | |
---|
[17] | 27 | uint8_t id,color_map,im_type; |
---|
[2] | 28 | |
---|
[17] | 29 | id=fp->read_uint8(); |
---|
| 30 | color_map=fp->read_uint8(); |
---|
| 31 | im_type=fp->read_uint8(); |
---|
[2] | 32 | |
---|
| 33 | if (color_map!=0) |
---|
| 34 | { |
---|
| 35 | delete fp; |
---|
| 36 | return 0; |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | if (!(im_type==2 || im_type==10)) |
---|
| 40 | { |
---|
| 41 | delete fp; |
---|
| 42 | return 0; |
---|
| 43 | } |
---|
| 44 | |
---|
[17] | 45 | fp->read_uint16(); |
---|
| 46 | fp->read_uint16(); |
---|
| 47 | fp->read_uint8(); |
---|
[2] | 48 | |
---|
[17] | 49 | fp->read_uint16(); |
---|
| 50 | fp->read_uint16(); |
---|
[2] | 51 | |
---|
| 52 | |
---|
[17] | 53 | int w=fp->read_uint16(); |
---|
| 54 | int h=fp->read_uint16(); |
---|
| 55 | uint8_t bpp=fp->read_uint8(); |
---|
[40] | 56 | fp->read_uint8(); // im_des |
---|
[2] | 57 | |
---|
| 58 | if (bpp!=32) |
---|
| 59 | { |
---|
| 60 | delete fp; |
---|
| 61 | return 0; |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | image *im=new image(w,h); |
---|
| 65 | |
---|
| 66 | int x,y; |
---|
[17] | 67 | uint8_t ctrl; |
---|
| 68 | uint8_t bgra[4],*sl,c,lr=0,lg=0,lb=0,ll=0,lc=0; |
---|
[2] | 69 | |
---|
| 70 | |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | if (im_type==10) |
---|
| 74 | { |
---|
| 75 | for (y=0;y<h;y++) |
---|
| 76 | { |
---|
| 77 | sl=im->scan_line(h-y-1); |
---|
| 78 | |
---|
| 79 | for (x=0;x<w;) |
---|
| 80 | { |
---|
[17] | 81 | ctrl=fp->read_uint8(); |
---|
[2] | 82 | if (ctrl&0x80) |
---|
| 83 | { |
---|
| 84 | fp->read(bgra,4); |
---|
| 85 | ctrl&=(~0x80); |
---|
| 86 | ctrl++; |
---|
| 87 | if (bgra[3]) |
---|
| 88 | { |
---|
| 89 | if (ll && lr==bgra[2] && lg==bgra[1] && lb==bgra[0]) |
---|
| 90 | c=lc; |
---|
| 91 | else |
---|
| 92 | { |
---|
| 93 | c=pal->find_closest_non0(bgra[2],bgra[1],bgra[0]); |
---|
| 94 | lr=bgra[2]; |
---|
| 95 | lg=bgra[1]; |
---|
| 96 | lb=bgra[0]; |
---|
| 97 | lc=c; |
---|
| 98 | ll=1; |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | } |
---|
| 102 | else c=0; |
---|
| 103 | |
---|
| 104 | while (ctrl--) |
---|
| 105 | { |
---|
| 106 | *sl=c; |
---|
| 107 | sl++; |
---|
| 108 | x++; |
---|
| 109 | } |
---|
| 110 | } else |
---|
| 111 | { |
---|
| 112 | ctrl++; |
---|
| 113 | while (ctrl--) |
---|
| 114 | { |
---|
| 115 | fp->read(bgra,4); |
---|
| 116 | if (bgra[3]) |
---|
| 117 | { |
---|
| 118 | c=pal->find_closest_non0(bgra[2],bgra[1],bgra[0]); |
---|
| 119 | } |
---|
| 120 | else c=0; |
---|
| 121 | *sl=c; |
---|
| 122 | sl++; |
---|
| 123 | x++; |
---|
| 124 | } |
---|
| 125 | } |
---|
| 126 | } |
---|
| 127 | } |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | |
---|
| 131 | |
---|
| 132 | delete fp; |
---|
| 133 | return im; |
---|
| 134 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.