tga.c

filter: Statementstmt 77.6% 348 / 448 Branchbran 68.7% 158 / 230 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 74.6% 506 / 678 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« scale.im ↑ Summary rubthru.im »
1 #include "imageri.h"
2 #include "log.h"
3 #include "iolayer.h"
4  
5 #include <stdlib.h>
6 #include <errno.h>
7  
8  
9 /*
10 =head1 NAME
11  
12 tga.c - implements reading and writing targa files, uses io layer.
13  
14 =head1 SYNOPSIS
15  
16 io_glue *ig = io_new_fd( fd );
17 i_img *im = i_readtga_wiol(ig, -1); // no limit on how much is read
18 // or
19 io_glue *ig = io_new_fd( fd );
20 return_code = i_writetga_wiol(im, ig);
21  
22 =head1 DESCRIPTION
23  
24 tga.c implements the basic functions to read and write portable targa
25 files. It uses the iolayer and needs either a seekable source or an
26 entire memory mapped buffer.
27  
28 =head1 FUNCTION REFERENCE
29  
30 Some of these functions are internal.
31  
32 =over
33  
34 =cut
35 */
36  
37  
38  
39  
40 typedef struct {
41 unsigned char idlength;
42 char colourmaptype;
43 char datatypecode;
44 unsigned colourmaporigin;
45 unsigned colourmaplength;
46 unsigned char colourmapdepth;
47 unsigned x_origin;
48 unsigned y_origin;
49 int width;
50 int height;
51 char bitsperpixel;
52 char imagedescriptor;
53 } tga_header;
54  
55  
56 typedef enum { NoInit, Raw, Rle } rle_state;
57  
58 typedef struct {
59 int compressed;
60 size_t bytepp;
61 rle_state state;
62 unsigned char cval[4];
63 int len;
64 unsigned char hdr;
65 io_glue *ig;
66 } tga_source;
67  
68  
69 typedef struct {
70 int compressed;
71 int bytepp;
72 io_glue *ig;
73 } tga_dest;
74  
75 #define TGA_MAX_DIM 0xFFFF
76  
77 /*
78 =item bpp_to_bytes(bpp)
79  
80 Convert bits per pixel into bytes per pixel
81  
82 bpp - bits per pixel
83  
84 =cut
85 */
86  
87  
88 static
89 size_t
90 63 bpp_to_bytes(unsigned int bpp) {
91 63 switch (bpp) {
92 0 case 8:
93 0 return 1;
94 7 case 15:
95 case 16:
96 7 return 2;
97 56 case 24:
98 56 return 3;
99 0 case 32:
100 0 return 4;
101 }
102 0 return 0;
103 }
104  
105  
106  
107 /*
108 =item bpp_to_channels(bpp)
109  
110 Convert bits per pixel and the number of attribute bits into channels
111 in the image
112  
113 bpp - bits per pixel
114 attr_bit_count - number of attribute bits
115  
116 =cut
117 */
118  
119 static
120 int
121 27 bpp_to_channels(unsigned int bpp, int attr_bit_count) {
122 27 switch (bpp) {
123 0 case 8:
124 0 return 1;
125 2 case 16:
126 2 ▶ if (attr_bit_count == 1)
Branch: 1 branch
BranchTrueFalseTotal
if (attr_bit_count == 1) 2 0 2
127 2 return 4;
128 /* FALLTHROUGH */
129 case 15:
130 0 return 3;
131 0 case 32:
132 0 ▶ if (attr_bit_count == 8)
Branch: 1 branch
BranchTrueFalseTotal
if (attr_bit_count == 8) 0 0 0
133 0 return 4;
134 /* FALLTHROUGH */
135 case 24:
136 25 return 3;
137 }
138 0 return 0;
139 }
140  
141  
142  
143 /*
144 * Packing functions - used for (un)packing
145 * datastructures into raw bytes.
146 */
147  
148  
149 /*
150 =item color_unpack(buf, bytepp, val)
151  
152 Unpacks bytes into colour structures, for 2 byte type the first byte
153 coming from the file will actually be GGGBBBBB, and the second will be
154 ARRRRRGG. "A" represents an attribute bit. The 3 byte entry contains
155 1 byte each of blue, green, and red. The 4 byte entry contains 1 byte
156 each of blue, green, red, and attribute.
157  
158 buf - pointer to data
159 bytepp - bytes per pixel
160 val - pointer to color to store to
161  
162 =cut
163 */
164  
165 static
166 void
167 484024 color_unpack(unsigned char *buf, int bytepp, i_color *val) {
168 484024 switch (bytepp) {
169 0 case 1:
170 0 val->gray.gray_color = buf[0];
171 0 break;
172 800 case 2:
173 800 val->rgba.r = (buf[1] & 0x7c) << 1;
174 800 val->rgba.g = ((buf[1] & 0x03) << 6) | ((buf[0] & 0xe0) >> 2);
175 800 val->rgba.b = (buf[0] & 0x1f) << 3;
176 800 ▶ val->rgba.a = (buf[1] & 0x80) ? 0 : 255;
Branch: 1 branch
BranchTrueFalseTotal
val->rgba.a = (buf[1] & 0x80) ? 0 : 255; 400 400 800
177 800 val->rgba.r |= val->rgba.r >> 5;
178 800 val->rgba.g |= val->rgba.g >> 5;
179 800 val->rgba.b |= val->rgba.b >> 5;
180 800 break;
181 483224 case 3:
182 483224 val->rgb.b = buf[0];
183 483224 val->rgb.g = buf[1];
184 483224 val->rgb.r = buf[2];
185 483224 break;
186 0 case 4:
187 0 val->rgba.b = buf[0];
188 0 val->rgba.g = buf[1];
189 0 val->rgba.r = buf[2];
190 0 val->rgba.a = buf[3];
191 0 break;
192 }
193 484024 }
194  
195  
196  
197 /*
198 =item color_pack
199  
200 Packs a colour into an array of bytes, for 2 byte type the first byte
201 will be GGGBBBBB, and the second will be ARRRRRGG. "A" represents an
202 attribute bit. The 3 byte entry contains 1 byte each of blue, green,
203 and red. The 4 byte entry contains 1 byte each of blue, green, red,
204 and attribute.
205  
206 buf - destination buffer
207 bitspp - bits per pixel
208 val - color to pack
209  
210 =cut
211 */
212  
213 static
214 void
215 497084 color_pack(unsigned char *buf, int bitspp, i_color *val) {
216 497084 switch (bitspp) {
217 0 case 8:
218 0 buf[0] = val->gray.gray_color;
219 0 break;
220 400 case 16:
221 400 buf[0] = (val->rgba.b >> 3);
222 400 buf[0] |= (val->rgba.g & 0x38) << 2;
223 400 buf[1] = (val->rgba.r & 0xf8)>> 1;
224 400 buf[1] |= (val->rgba.g >> 6);
225 400 ▶ buf[1] |= val->rgba.a > 0x7f ? 0 : 0x80;
Branch: 1 branch
BranchTrueFalseTotal
buf[1] |= val->rgba.a > 0x7f ? 0 : 0x80; 200 200 400
226 400 break;
227 45432 case 15:
228 45432 buf[0] = (val->rgba.b >> 3);
229 45432 buf[0] |= (val->rgba.g & 0x38) << 2;
230 45432 buf[1] = (val->rgba.r & 0xf8)>> 1;
231 45432 buf[1] |= (val->rgba.g >> 6);
232 45432 break;
233 451252 case 24:
234 451252 buf[0] = val->rgb.b;
235 451252 buf[1] = val->rgb.g;
236 451252 buf[2] = val->rgb.r;
237 451252 break;
238 0 case 32:
239 0 buf[0] = val->rgba.b;
240 0 buf[1] = val->rgba.g;
241 0 buf[2] = val->rgba.r;
242 0 buf[3] = val->rgba.a;
243 0 break;
244 }
245 497084 }
246  
247  
248 /*
249 =item find_repeat
250  
251 Helper function for rle compressor to find the next triple repeat of the
252 same pixel value in buffer.
253  
254 buf - buffer
255 length - number of pixel values in buffer
256 bytepp - number of bytes in a pixel value
257  
258 =cut
259 */
260  
261 static
262 int
263 132482 find_repeat(unsigned char *buf, int length, int bytepp) {
264 132482 int i = 0;
265
266 193399 ▶ while(i<length-1) {
Branch: 1 branch
BranchTrueFalseTotal
while(i<length-1) { 86904 106495 193399
267 86904 ▶ if(memcmp(buf+i*bytepp, buf+(i+1)*bytepp, bytepp) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if(memcmp(buf+i*bytepp, buf+(i+1)*bytepp, bytepp) == 0) { 29883 57021 86904
268 29883 ▶ if (i == length-2) return -1;
Branch: 1 branch
BranchTrueFalseTotal
if (i == length-2) return -1; 0 29883 29883
269 29883 ▶ if (memcmp(buf+(i+1)*bytepp, buf+(i+2)*bytepp,bytepp) == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (memcmp(buf+(i+1)*bytepp, buf+(i+2)*bytepp,bytepp) == 0) 25987 3896 29883
270 25987 return i;
271 3896 else i++;
272 }
273 60917 i++;
274 }
275 106495 return -1;
276 }
277  
278  
279 /*
280 =item find_span
281  
282 Helper function for rle compressor to find the length of a span where
283 the same pixel value is in the buffer.
284  
285 buf - buffer
286 length - number of pixel values in buffer
287 bytepp - number of bytes in a pixel value
288  
289 =cut
290 */
291  
292 static
293 int
294 25987 find_span(unsigned char *buf, int length, int bytepp) {
295 25987 int i = 0;
296 440669 ▶ while(i<length) {
Branch: 1 branch
BranchTrueFalseTotal
while(i<length) { 438247 2422 440669
297 438247 ▶ if(memcmp(buf, buf+(i*bytepp), bytepp) != 0) return i;
Branch: 1 branch
BranchTrueFalseTotal
if(memcmp(buf, buf+(i*bytepp), bytepp) != 0) return i; 23565 414682 438247
298 414682 i++;
299 }
300 2422 return length;
301 }
302  
303  
304 /*
305 =item tga_header_unpack(header, headbuf)
306  
307 Unpacks the header structure into from buffer and stores
308 in the header structure.
309  
310 header - header structure
311 headbuf - buffer to unpack from
312  
313 =cut
314 */
315  
316 static
317 void
318 71 tga_header_unpack(tga_header *header, unsigned char headbuf[18]) {
319 71 header->idlength = headbuf[0];
320 71 header->colourmaptype = headbuf[1];
321 71 header->datatypecode = headbuf[2];
322 71 header->colourmaporigin = (headbuf[4] << 8) + headbuf[3];
323 71 header->colourmaplength = (headbuf[6] << 8) + headbuf[5];
324 71 header->colourmapdepth = headbuf[7];
325 71 header->x_origin = (headbuf[9] << 8) + headbuf[8];
326 71 header->y_origin = (headbuf[11] << 8) + headbuf[10];
327 71 header->width = (headbuf[13] << 8) + headbuf[12];
328 71 header->height = (headbuf[15] << 8) + headbuf[14];
329 71 header->bitsperpixel = headbuf[16];
330 71 header->imagedescriptor = headbuf[17];
331 71 }
332  
333  
334 /* this function should never produce diagnostics to stdout, maybe to the logfile */
335 int
336 44 tga_header_verify(unsigned char headbuf[18]) {
337 tga_header header;
338 44 tga_header_unpack(&header, headbuf);
339 44 switch (header.datatypecode) {
340 3 default:
341 /*printf("bad typecode!\n");*/
342 3 return 0;
343 17 case 1: /* Uncompressed, color-mapped images */
344 case 3: /* Uncompressed, grayscale images */
345 case 9: /* Compressed, color-mapped images */
346 case 11: /* Compressed, grayscale images */
347 17 ▶ if (header.bitsperpixel != 8)
Branch: 1 branch
BranchTrueFalseTotal
if (header.bitsperpixel != 8) 17 0 17
348 17 return 0;
349 0 break;
350 24 case 0:
351 case 2: /* Uncompressed, rgb images */
352 case 10: /* Compressed, rgb images */
353 24 ▶ if (header.bitsperpixel != 15 && header.bitsperpixel != 16
Branch: 2 branches
BranchTrueFalseTotal
if (header.bitsperpixel != 15 && header.bitsperpixel != 16 24 0 24
if (header.bitsperpixel != 15 && header.bitsperpixel != 16 22 2 24
354 22 ▶ && header.bitsperpixel != 24 && header.bitsperpixel != 32)
Branch: 2 branches
BranchTrueFalseTotal
&& header.bitsperpixel != 24 && header.bitsperpixel != 32) 7 15 22
&& header.bitsperpixel != 24 && header.bitsperpixel != 32) 6 1 7
355 6 return 0;
356 18 break;
357 }
358  
359 18 switch (header.colourmaptype) {
360 0 default:
361 /*printf("bad colourmaptype!\n");*/
362 0 return 0;
363 0 case 1:
364 0 ▶ if (header.datatypecode != 1 && header.datatypecode != 9)
Branch: 2 branches
BranchTrueFalseTotal
if (header.datatypecode != 1 && header.datatypecode != 9) 0 0 0
if (header.datatypecode != 1 && header.datatypecode != 9) 0 0 0
365 0 return 0; /* only get a color map on a color mapped image */
366 case 0:
367 18 break;
368 }
369  
370 18 ▶ switch (header.colourmapdepth) {
Branch: 1 branch
BranchTrueFalseTotal
switch (header.colourmapdepth) { 0 18 18
371 0 default:
372 0 return 0;
373 18 case 0: /* can be 0 if no colour map */
374 case 15:
375 case 16:
376 case 24:
377 case 32:
378 18 break;
379 }
380
381 18 return 1;
382 }
383  
384  
385 /*
386 =item tga_header_pack(header, headbuf)
387  
388 Packs header structure into buffer for writing.
389  
390 header - header structure
391 headbuf - buffer to pack into
392  
393 =cut
394 */
395  
396 static
397 void
398 23 tga_header_pack(tga_header *header, unsigned char headbuf[18]) {
399 23 headbuf[0] = header->idlength;
400 23 headbuf[1] = header->colourmaptype;
401 23 headbuf[2] = header->datatypecode;
402 23 headbuf[3] = header->colourmaporigin & 0xff;
403 23 headbuf[4] = header->colourmaporigin >> 8;
404 23 headbuf[5] = header->colourmaplength & 0xff;
405 23 headbuf[6] = header->colourmaplength >> 8;
406 23 headbuf[7] = header->colourmapdepth;
407 23 headbuf[8] = header->x_origin & 0xff;
408 23 headbuf[9] = header->x_origin >> 8;
409 23 headbuf[10] = header->y_origin & 0xff;
410 23 headbuf[11] = header->y_origin >> 8;
411 23 headbuf[12] = header->width & 0xff;
412 23 headbuf[13] = header->width >> 8;
413 23 headbuf[14] = header->height & 0xff;
414 23 headbuf[15] = header->height >> 8;
415 23 headbuf[16] = header->bitsperpixel;
416 23 headbuf[17] = header->imagedescriptor;
417 23 }
418  
419  
420 /*
421 =item tga_source_read(s, buf, pixels)
422  
423 Reads pixel number of pixels from source s into buffer buf. Takes
424 care of decompressing the stream if needed.
425  
426 s - data source
427 buf - destination buffer
428 pixels - number of pixels to put into buffer
429  
430 =cut
431 */
432  
433 static
434 int
435 108789 tga_source_read(tga_source *s, unsigned char *buf, size_t pixels) {
436 108789 size_t cp = 0;
437 size_t j, k;
438 108789 ▶ if (!s->compressed) {
Branch: 1 branch
BranchTrueFalseTotal
if (!s->compressed) { 900 107889 108789
439 900 if ((size_t)i_io_read(s->ig, buf, pixels*s->bytepp)
440 900 ▶ != pixels*s->bytepp) return 0;
Branch: 1 branch
BranchTrueFalseTotal
!= pixels*s->bytepp) return 0; 0 900 900
441 900 return 1;
442 }
443
444 478928 ▶ while(cp < pixels) {
Branch: 1 branch
BranchTrueFalseTotal
while(cp < pixels) { 263150 107889 371039
445 size_t ml;
446 263150 ▶ if (s->len == 0) s->state = NoInit;
Branch: 1 branch
BranchTrueFalseTotal
if (s->len == 0) s->state = NoInit; 131575 131575 263150
447 263150 switch (s->state) {
448 131575 case NoInit:
449 131575 ▶ if (i_io_read(s->ig, &s->hdr, 1) != 1) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (i_io_read(s->ig, &s->hdr, 1) != 1) return 0; 0 131575 131575
450  
451 131575 s->len = (s->hdr &~(1<<7))+1;
452 131575 ▶ s->state = (s->hdr & (1<<7)) ? Rle : Raw;
Branch: 1 branch
BranchTrueFalseTotal
s->state = (s->hdr & (1<<7)) ? Rle : Raw; 21876 109699 131575
453 {
454 /*
455 static cnt = 0;
456 printf("%04d %s: %d\n", cnt++, s->state==Rle?"RLE":"RAW", s->len);
457 */
458 }
459 131575 ▶ if (s->state == Rle
Branch: 1 branch
BranchTrueFalseTotal
if (s->state == Rle 21876 109699 131575
460 21876 ▶ && (size_t)i_io_read(s->ig, s->cval, s->bytepp) != s->bytepp) {
Branch: 1 branch
BranchTrueFalseTotal
&& (size_t)i_io_read(s->ig, s->cval, s->bytepp) != s->bytepp) { 0 21876 21876
461 0 return 0;
462 }
463  
464 131575 break;
465 21876 case Rle:
466 21876 ml = i_min(s->len, pixels-cp);
467 1113728 ▶ for(k=0; k<ml; k++) for(j=0; j < s->bytepp; j++)
Branch: 2 branches
BranchTrueFalseTotal
for(k=0; k<ml; k++) for(j=0; j < s->bytepp; j++) 796713 295139 1091852
for(k=0; k<ml; k++) for(j=0; j < s->bytepp; j++) 295139 21876 317015
468 796713 buf[(cp+k)*s->bytepp+j] = s->cval[j];
469 21876 cp += ml;
470 21876 s->len -= ml;
471 21876 break;
472 109699 case Raw:
473 109699 ml = i_min(s->len, pixels-cp);
474 109699 if ((size_t)i_io_read(s->ig, buf+cp*s->bytepp, ml*s->bytepp)
475 109699 ▶ != ml*s->bytepp) {
Branch: 1 branch
BranchTrueFalseTotal
!= ml*s->bytepp) { 0 109699 109699
476 0 return 0;
477 }
478 109699 cp += ml;
479 109699 s->len -= ml;
480 109699 break;
481 }
482 }
483 107889 return 1;
484 }
485  
486  
487  
488  
489 /*
490 =item tga_dest_write(s, buf, pixels)
491  
492 Writes pixels from buf to destination s. Takes care of compressing if the
493 destination is compressed.
494  
495 s - data destination
496 buf - source buffer
497 pixels - number of pixels to put write to destination
498  
499 =cut
500 */
501  
502 static
503 int
504 109067 tga_dest_write(tga_dest *s, unsigned char *buf, size_t pixels) {
505 109067 size_t cp = 0;
506  
507 109067 ▶ if (!s->compressed) {
Branch: 1 branch
BranchTrueFalseTotal
if (!s->compressed) { 150 108917 109067
508 150 if ((size_t)i_io_write(s->ig, buf, pixels*s->bytepp)
509 150 ▶ != pixels*s->bytepp) {
Branch: 1 branch
BranchTrueFalseTotal
!= pixels*s->bytepp) { 0 150 150
510 0 return 0;
511 }
512 150 return 1;
513 }
514
515 134904 ▶ while(cp < pixels) {
Branch: 1 branch
BranchTrueFalseTotal
while(cp < pixels) { 132482 2422 134904
516 int tlen;
517 132482 int nxtrip = find_repeat(buf+cp*s->bytepp, pixels-cp, s->bytepp);
518 132482 ▶ tlen = (nxtrip == -1) ? (int)(pixels-cp) : nxtrip;
Branch: 1 branch
BranchTrueFalseTotal
tlen = (nxtrip == -1) ? (int)(pixels-cp) : nxtrip; 106495 25987 132482
519 245801 ▶ while(tlen) {
Branch: 1 branch
BranchTrueFalseTotal
while(tlen) { 113319 132482 245801
520 113319 unsigned char clen = (tlen>128) ? 128 : tlen;
521 113319 clen--;
522 113319 ▶ if (i_io_write(s->ig, &clen, 1) != 1) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (i_io_write(s->ig, &clen, 1) != 1) return 0; 0 113319 113319
523 113319 clen++;
524 113319 ▶ if (i_io_write(s->ig, buf+cp*s->bytepp, clen*s->bytepp) != clen*s->bytepp) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (i_io_write(s->ig, buf+cp*s->bytepp, clen*s->bytepp) != clen*s->bytepp) return 0; 0 113319 113319
525 113319 tlen -= clen;
526 113319 cp += clen;
527 }
528 132482 ▶ if (cp >= pixels) break;
Branch: 1 branch
BranchTrueFalseTotal
if (cp >= pixels) break; 106495 25987 132482
529 25987 tlen = find_span(buf+cp*s->bytepp, pixels-cp, s->bytepp);
530 25987 ▶ if (tlen <3) continue;
Branch: 1 branch
BranchTrueFalseTotal
if (tlen <3) continue; 0 25987 25987
531 52881 ▶ while (tlen) {
Branch: 1 branch
BranchTrueFalseTotal
while (tlen) { 26894 25987 52881
532 26894 unsigned char clen = (tlen>128) ? 128 : tlen;
533 26894 clen = (clen - 1) | 0x80;
534 26894 ▶ if (i_io_write(s->ig, &clen, 1) != 1) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (i_io_write(s->ig, &clen, 1) != 1) return 0; 0 26894 26894
535 26894 clen = (clen & ~0x80) + 1;
536 26894 ▶ if (i_io_write(s->ig, buf+cp*s->bytepp, s->bytepp) != s->bytepp) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (i_io_write(s->ig, buf+cp*s->bytepp, s->bytepp) != s->bytepp) return 0; 0 26894 26894
537 26894 tlen -= clen;
538 26894 cp += clen;
539 }
540 }
541 108917 return 1;
542 }
543  
544  
545  
546  
547  
548  
549 /*
550 =item tga_palette_read(ig, img, bytepp, colourmaplength)
551  
552 Reads the colormap from a tga file and stores in the paletted image
553 structure.
554  
555 ig - iolayer data source
556 img - image structure
557 bytepp - bytes per pixel
558 colourmaplength - number of colours in colourmap
559  
560 =cut
561 */
562  
563 static
564 int
565 5 tga_palette_read(io_glue *ig, i_img *img, int bytepp,
566 unsigned colourmaporigin, unsigned colourmaplength) {
567 unsigned i;
568 size_t palbsize;
569 unsigned char *palbuf;
570 i_color val;
571 5 unsigned colourmapusable = colourmaplength;
572  
573 5 ▶ if (colourmaporigin > 255) {
Branch: 1 branch
BranchTrueFalseTotal
if (colourmaporigin > 255) { 0 5 5
574 0 i_push_errorf(0, "colourmaporigin %u not supported", colourmaporigin);
575 0 return 0;
576 }
577 5 ▶ if (colourmaplength > 256
Branch: 1 branch
BranchTrueFalseTotal
if (colourmaplength > 256 4 1 5
578 4 ▶ || colourmaporigin + colourmaplength > 256) {
Branch: 1 branch
BranchTrueFalseTotal
|| colourmaporigin + colourmaplength > 256) { 0 4 4
579 1 colourmapusable = 256U - colourmaporigin;
580 }
581  
582 5 palbsize = (size_t)colourmaplength * bytepp;
583 5 palbuf = mymalloc(palbsize);
584
585 5 ▶ if ((size_t)i_io_read(ig, palbuf, palbsize) != palbsize) {
Branch: 1 branch
BranchTrueFalseTotal
if ((size_t)i_io_read(ig, palbuf, palbsize) != palbsize) { 2 3 5
586 2 myfree(palbuf);
587 2 i_push_error(errno, "could not read targa colormap");
588 2 return 0;
589 }
590
591 /* populate the palette of the new image */
592 233 ▶ for(i=0; i<colourmapusable; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for(i=0; i<colourmapusable; i++) { 230 3 233
593 230 color_unpack(palbuf+i*bytepp, bytepp, &val);
594 230 ▶ i_addcolors(img, &val, 1);
Branch: 1 branch
BranchTrueFalseTotal
i_addcolors(img, &val, 1); 230 0 230
595 }
596 /* discard anything from 256 to colourmaplength.
597 previously that would happen from i_addcolors() failing
598 */
599 3 myfree(palbuf);
600 3 return 1;
601 }
602  
603  
604 /*
605 =item tga_palette_write(ig, img, bitspp, colourmaplength)
606  
607 Stores the colormap of an image in the destination ig.
608  
609 ig - iolayer data source
610 img - image structure
611 bitspp - bits per pixel in colourmap
612 colourmaplength - number of colours in colourmap
613  
614 =cut
615 */
616  
617 static
618 int
619 7 tga_palette_write(io_glue *ig, i_img *img, int bitspp, int colourmaplength) {
620 int i;
621 7 size_t bytepp = bpp_to_bytes(bitspp);
622 7 ▶ size_t palbsize = i_colorcount(img)*bytepp;
Branch: 1 branch
BranchTrueFalseTotal
size_t palbsize = i_colorcount(img)*bytepp; 7 0 7
623 7 unsigned char *palbuf = mymalloc(palbsize);
624
625 1101 ▶ for(i=0; i<colourmaplength; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for(i=0; i<colourmaplength; i++) { 1094 7 1101
626 i_color val;
627 1094 ▶ i_getcolors(img, i, &val, 1);
Branch: 1 branch
BranchTrueFalseTotal
i_getcolors(img, i, &val, 1); 1094 0 1094
628 1094 color_pack(palbuf+i*bytepp, bitspp, &val);
629 }
630
631 7 ▶ if ((size_t)i_io_write(ig, palbuf, palbsize) != palbsize) {
Branch: 1 branch
BranchTrueFalseTotal
if ((size_t)i_io_write(ig, palbuf, palbsize) != palbsize) { 0 7 7
632 0 i_push_error(errno, "could not write targa colormap");
633 0 return 0;
634 }
635 7 myfree(palbuf);
636 7 return 1;
637 }
638  
639  
640  
641 /*
642 =item i_readtga_wiol(ig, length)
643  
644 Read in an image from the iolayer data source and return the image structure to it.
645 Returns NULL on error.
646  
647 ig - io_glue object
648 length - maximum length to read from data source, before closing it -1
649 signifies no limit.
650  
651 =cut
652 */
653  
654 i_img *
655 27 i_readtga_wiol(io_glue *ig, int length) {
656 27 i_img* img = NULL;
657 int x, y;
658 int width, height, channels;
659 int mapped;
660 27 char *idstring = NULL;
661  
662 tga_source src;
663 tga_header header;
664 unsigned char headbuf[18];
665 unsigned char *databuf;
666  
667 27 i_color *linebuf = NULL;
668 27 i_clear_error();
669  
670 27 mm_log((1,"i_readtga(ig %p, length %d)\n", ig, length));
671
672 27 ▶ if (i_io_read(ig, &headbuf, 18) != 18) {
Branch: 1 branch
BranchTrueFalseTotal
if (i_io_read(ig, &headbuf, 18) != 18) { 0 27 27
673 0 i_push_error(errno, "could not read targa header");
674 0 return NULL;
675 }
676  
677 27 tga_header_unpack(&header, headbuf);
678  
679 27 mm_log((1,"Id length: %d\n",header.idlength));
680 27 mm_log((1,"Colour map type: %d\n",header.colourmaptype));
681 27 mm_log((1,"Image type: %d\n",header.datatypecode));
682 27 mm_log((1,"Colour map offset: %d\n",header.colourmaporigin));
683 27 mm_log((1,"Colour map length: %d\n",header.colourmaplength));
684 27 mm_log((1,"Colour map depth: %d\n",header.colourmapdepth));
685 27 mm_log((1,"X origin: %d\n",header.x_origin));
686 27 mm_log((1,"Y origin: %d\n",header.y_origin));
687 27 mm_log((1,"Width: %d\n",header.width));
688 27 mm_log((1,"Height: %d\n",header.height));
689 27 mm_log((1,"Bits per pixel: %d\n",header.bitsperpixel));
690 27 mm_log((1,"Descriptor: %d\n",header.imagedescriptor));
691  
692 27 ▶ if (header.idlength) {
Branch: 1 branch
BranchTrueFalseTotal
if (header.idlength) { 3 24 27
693 /* max of 256, so this is safe */
694 3 idstring = mymalloc(header.idlength+1);
695 3 ▶ if (i_io_read(ig, idstring, header.idlength) != header.idlength) {
Branch: 1 branch
BranchTrueFalseTotal
if (i_io_read(ig, idstring, header.idlength) != header.idlength) { 0 3 3
696 0 i_push_error(errno, "short read on targa idstring");
697 0 return NULL;
698 }
699 }
700  
701 27 width = header.width;
702 27 height = header.height;
703  
704
705 /* Set tags here */
706
707 27 switch (header.datatypecode) {
708 0 case 0: /* No data in image */
709 0 i_push_error(0, "Targa image contains no image data");
710 0 ▶ if (idstring) myfree(idstring);
Branch: 1 branch
BranchTrueFalseTotal
if (idstring) myfree(idstring); 0 0 0
711 0 return NULL;
712 break;
713 5 case 1: /* Uncompressed, color-mapped images */
714 case 9: /* Compressed, color-mapped images */
715 case 3: /* Uncompressed, grayscale images */
716 case 11: /* Compressed, grayscale images */
717 5 ▶ if (header.bitsperpixel != 8) {
Branch: 1 branch
BranchTrueFalseTotal
if (header.bitsperpixel != 8) { 0 5 5
718 0 i_push_error(0, "Targa: mapped/grayscale image's bpp is not 8, unsupported.");
719 0 ▶ if (idstring) myfree(idstring);
Branch: 1 branch
BranchTrueFalseTotal
if (idstring) myfree(idstring); 0 0 0
720 0 return NULL;
721 }
722 5 src.bytepp = 1;
723 5 break;
724 22 case 2: /* Uncompressed, rgb images */
725 case 10: /* Compressed, rgb images */
726 22 ▶ if ((src.bytepp = bpp_to_bytes(header.bitsperpixel)))
Branch: 1 branch
BranchTrueFalseTotal
if ((src.bytepp = bpp_to_bytes(header.bitsperpixel))) 22 0 22
727 22 break;
728 0 i_push_error(0, "Targa: direct color image's bpp is not 15/16/24/32 - unsupported.");
729 0 ▶ if (idstring) myfree(idstring);
Branch: 1 branch
BranchTrueFalseTotal
if (idstring) myfree(idstring); 0 0 0
730 0 return NULL;
731 break;
732 0 case 32: /* Compressed color-mapped, Huffman, Delta and runlength */
733 case 33: /* Compressed color-mapped, Huffman, Delta and runlength */
734 0 i_push_error(0, "Unsupported Targa (Huffman/delta/rle/quadtree) subformat is not supported");
735 0 ▶ if (idstring) myfree(idstring);
Branch: 1 branch
BranchTrueFalseTotal
if (idstring) myfree(idstring); 0 0 0
736 0 return NULL;
737 break;
738 0 default: /* All others which we don't know which might be */
739 0 i_push_error(0, "Unknown targa format");
740 0 ▶ if (idstring) myfree(idstring);
Branch: 1 branch
BranchTrueFalseTotal
if (idstring) myfree(idstring); 0 0 0
741 0 return NULL;
742 break;
743 }
744
745 27 src.state = NoInit;
746 27 src.len = 0;
747 27 src.ig = ig;
748 27 src.compressed = !!(header.datatypecode & (1<<3));
749  
750 /* Determine number of channels */
751
752 27 mapped = 1;
753 27 switch (header.datatypecode) {
754 22 case 2: /* Uncompressed, rgb images */ /* FALLTHROUGH */
755 case 10: /* Compressed, rgb images */ /* FALLTHROUGH */
756 22 mapped = 0;
757 /* FALLTHROUGH */
758 27 case 1: /* Uncompressed, color-mapped images */
759 case 9: /* Compressed, color-mapped images */
760 27 ▶ if ((channels = bpp_to_channels(mapped ?
Branch: 1 branch
BranchTrueFalseTotal
if ((channels = bpp_to_channels(mapped ? 27 0 27
761 5 header.colourmapdepth :
762 22 header.bitsperpixel,
763 54 ▶ header.imagedescriptor & 0xF))) break;
Branch: 1 branch
BranchTrueFalseTotal
header.imagedescriptor & 0xF))) break; 5 22 27
764 0 i_push_error(0, "Targa Image has none of 15/16/24/32 pixel layout");
765 0 ▶ if (idstring) myfree(idstring);
Branch: 1 branch
BranchTrueFalseTotal
if (idstring) myfree(idstring); 0 0 0
766 0 return NULL;
767 break;
768 0 case 3: /* Uncompressed, grayscale images */ /* FALLTHROUGH */
769 case 11: /* Compressed, grayscale images */
770 0 mapped = 0;
771 0 channels = 1;
772 0 break;
773 0 default:
774 0 i_push_error(0, "invalid or unsupported datatype code");
775 0 return NULL;
776 }
777  
778 27 ▶ if (!i_int_check_image_file_limits(width, height, channels,
Branch: 1 branch
BranchTrueFalseTotal
if (!i_int_check_image_file_limits(width, height, channels, 3 24 27
779 sizeof(i_sample_t))) {
780 3 mm_log((1, "i_readtga_wiol: image size exceeds limits\n"));
781 3 return NULL;
782 }
783
784 24 img = mapped ?
785 24 ▶ i_img_pal_new(width, height, channels, 256) :
Branch: 1 branch
BranchTrueFalseTotal
i_img_pal_new(width, height, channels, 256) : 5 19 24
786 19 i_img_empty_ch(NULL, width, height, channels);
787  
788 24 ▶ if (!img) {
Branch: 1 branch
BranchTrueFalseTotal
if (!img) { 0 24 24
789 0 ▶ if (idstring)
Branch: 1 branch
BranchTrueFalseTotal
if (idstring) 0 0 0
790 0 myfree(idstring);
791 0 return NULL;
792 }
793
794 24 ▶ if (idstring) {
Branch: 1 branch
BranchTrueFalseTotal
if (idstring) { 3 21 24
795 3 i_tags_add(&img->tags, "tga_idstring", 0, idstring, header.idlength, 0);
796 3 myfree(idstring);
797 }
798  
799 29 if (mapped &&
800 5 !tga_palette_read(ig,
801 img,
802 5 bpp_to_bytes(header.colourmapdepth),
803 header.colourmaporigin,
804 header.colourmaplength)
805 ) {
806 /* tga_palette_read() sets a message */
807 2 ▶ if (img) i_img_destroy(img);
Branch: 1 branch
BranchTrueFalseTotal
if (img) i_img_destroy(img); 2 0 2
808 2 return NULL;
809 }
810
811 /* Allocate buffers */
812 /* width is max 0xffff, src.bytepp is max 4, so this is safe */
813 22 databuf = mymalloc(width*src.bytepp);
814 /* similarly here */
815 22 ▶ if (!mapped) linebuf = mymalloc(width*sizeof(i_color));
Branch: 1 branch
BranchTrueFalseTotal
if (!mapped) linebuf = mymalloc(width*sizeof(i_color)); 19 3 22
816
817 108811 ▶ for(y=0; y<height; y++) {
Branch: 1 branch
BranchTrueFalseTotal
for(y=0; y<height; y++) { 108789 22 108811
818 108789 ▶ if (!tga_source_read(&src, databuf, width)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!tga_source_read(&src, databuf, width)) { 0 108789 108789
819 0 i_push_error(errno, "read for targa data failed");
820 0 ▶ if (linebuf) myfree(linebuf);
Branch: 1 branch
BranchTrueFalseTotal
if (linebuf) myfree(linebuf); 0 0 0
821 0 myfree(databuf);
822 0 ▶ if (img) i_img_destroy(img);
Branch: 1 branch
BranchTrueFalseTotal
if (img) i_img_destroy(img); 0 0 0
823 0 return NULL;
824 }
825 108789 ▶ if (mapped && header.colourmaporigin) for(x=0; x<width; x++) databuf[x] -= header.colourmaporigin;
Branch: 3 branches
BranchTrueFalseTotal
if (mapped && header.colourmaporigin) for(x=0; x<width; x++) databuf[x] -= header.colourmaporigin; 450 108339 108789
if (mapped && header.colourmaporigin) for(x=0; x<width; x++) databuf[x] -= header.colourmaporigin; 0 450 450
if (mapped && header.colourmaporigin) for(x=0; x<width; x++) databuf[x] -= header.colourmaporigin; 0 0 0
826 108789 ▶ if (mapped) i_ppal(img, 0, width, header.imagedescriptor & (1<<5) ? y : height-1-y, databuf);
Branch: 3 branches
BranchTrueFalseTotal
if (mapped) i_ppal(img, 0, width, header.imagedescriptor & (1<<5) ? y : height-1-y, databuf); 450 108339 108789
if (mapped) i_ppal(img, 0, width, header.imagedescriptor & (1<<5) ? y : height-1-y, databuf); 450 0 450
if (mapped) i_ppal(img, 0, width, header.imagedescriptor & (1<<5) ? y : height-1-y, databuf); 0 450 450
827 else {
828 592133 ▶ for(x=0; x<width; x++) color_unpack(databuf+x*src.bytepp, src.bytepp, linebuf+x);
Branch: 1 branch
BranchTrueFalseTotal
for(x=0; x<width; x++) color_unpack(databuf+x*src.bytepp, src.bytepp, linebuf+x); 483794 108339 592133
829 108339 ▶ i_plin(img, 0, width, header.imagedescriptor & (1<<5) ? y : height-1-y, linebuf);
Branch: 1 branch
BranchTrueFalseTotal
i_plin(img, 0, width, header.imagedescriptor & (1<<5) ? y : height-1-y, linebuf); 0 108339 108339
830 }
831 }
832 22 myfree(databuf);
833 22 ▶ if (linebuf) myfree(linebuf);
Branch: 1 branch
BranchTrueFalseTotal
if (linebuf) myfree(linebuf); 19 3 22
834
835 22 i_tags_add(&img->tags, "i_format", 0, "tga", -1, 0);
836 22 ▶ i_tags_addn(&img->tags, "tga_bitspp", 0, mapped?header.colourmapdepth:header.bitsperpixel);
Branch: 1 branch
BranchTrueFalseTotal
i_tags_addn(&img->tags, "tga_bitspp", 0, mapped?header.colourmapdepth:header.bitsperpixel); 3 19 22
837 22 ▶ if (src.compressed) i_tags_addn(&img->tags, "compressed", 0, 1);
Branch: 1 branch
BranchTrueFalseTotal
if (src.compressed) i_tags_addn(&img->tags, "compressed", 0, 1); 16 6 22
838 22 return img;
839 }
840  
841  
842  
843 /*
844 =item i_writetga_wiol(img, ig)
845  
846 Writes an image in targa format. Returns 0 on error.
847  
848 img - image to store
849 ig - io_glue object
850  
851 =cut
852 */
853  
854 undef_int
855 26 i_writetga_wiol(i_img *img, io_glue *ig, int wierdpack, int compress, char *idstring, size_t idlen) {
856 tga_header header;
857 tga_dest dest;
858 unsigned char headbuf[18];
859 unsigned int bitspp;
860 26 unsigned int attr_bits = 0;
861
862 int mapped;
863  
864 /* parameters */
865  
866 /*
867 int compress = 1;
868 char *idstring = "testing";
869 int wierdpack = 0;
870 */
871  
872 26 idlen = strlen(idstring);
873 26 mapped = img->type == i_palette_type;
874  
875 26 mm_log((1,"i_writetga_wiol(img %p, ig %p, idstring %p, idlen %ld, wierdpack %d, compress %d)\n",
876 img, ig, idstring, (long)idlen, wierdpack, compress));
877 26 mm_log((1, "virtual %d, paletted %d\n", i_img_virtual(img), mapped));
878 26 mm_log((1, "channels %d\n", img->channels));
879
880 26 i_clear_error();
881  
882 26 ▶ if (img->xsize > TGA_MAX_DIM || img->ysize > TGA_MAX_DIM) {
Branch: 2 branches
BranchTrueFalseTotal
if (img->xsize > TGA_MAX_DIM || img->ysize > TGA_MAX_DIM) { 25 1 26
if (img->xsize > TGA_MAX_DIM || img->ysize > TGA_MAX_DIM) { 1 24 25
883 2 i_push_error(0, "image too large for TGA");
884 2 return 0;
885 }
886  
887 24 switch (img->channels) {
888 0 case 1:
889 0 bitspp = 8;
890 0 ▶ if (wierdpack) {
Branch: 1 branch
BranchTrueFalseTotal
if (wierdpack) { 0 0 0
891 0 mm_log((1,"wierdpack option ignored for 1 channel images\n"));
892 0 wierdpack=0;
893 }
894 0 break;
895 1 case 2:
896 1 i_push_error(0, "Cannot store 2 channel image in targa format");
897 1 return 0;
898 break;
899 22 case 3:
900 22 ▶ bitspp = wierdpack ? 15 : 24;
Branch: 1 branch
BranchTrueFalseTotal
bitspp = wierdpack ? 15 : 24; 4 18 22
901 22 break;
902 1 case 4:
903 1 ▶ bitspp = wierdpack ? 16 : 32;
Branch: 1 branch
BranchTrueFalseTotal
bitspp = wierdpack ? 16 : 32; 1 0 1
904 1 ▶ attr_bits = wierdpack ? 1 : 8;
Branch: 1 branch
BranchTrueFalseTotal
attr_bits = wierdpack ? 1 : 8; 1 0 1
905 1 break;
906 0 default:
907 0 i_push_error(0, "Targa only handles 1,3 and 4 channel images.");
908 0 return 0;
909 }
910  
911 23 header.idlength = idlen;
912 23 header.colourmaptype = mapped ? 1 : 0;
913 23 ▶ header.datatypecode = mapped ? 1 : img->channels == 1 ? 3 : 2;
Branch: 2 branches
BranchTrueFalseTotal
header.datatypecode = mapped ? 1 : img->channels == 1 ? 3 : 2; 16 7 23
header.datatypecode = mapped ? 1 : img->channels == 1 ? 3 : 2; 0 16 16
914 23 ▶ header.datatypecode += compress ? 8 : 0;
Branch: 1 branch
BranchTrueFalseTotal
header.datatypecode += compress ? 8 : 0; 20 3 23
915 23 mm_log((1, "datatypecode %d\n", header.datatypecode));
916 23 header.colourmaporigin = 0;
917 23 ▶ header.colourmaplength = mapped ? i_colorcount(img) : 0;
Branch: 2 branches
BranchTrueFalseTotal
header.colourmaplength = mapped ? i_colorcount(img) : 0; 7 16 23
header.colourmaplength = mapped ? i_colorcount(img) : 0; 7 0 7
918 23 ▶ header.colourmapdepth = mapped ? bitspp : 0;
Branch: 1 branch
BranchTrueFalseTotal
header.colourmapdepth = mapped ? bitspp : 0; 7 16 23
919 23 header.x_origin = 0;
920 23 header.y_origin = 0;
921 23 header.width = img->xsize;
922 23 header.height = img->ysize;
923 23 ▶ header.bitsperpixel = mapped ? 8 : bitspp;
Branch: 1 branch
BranchTrueFalseTotal
header.bitsperpixel = mapped ? 8 : bitspp; 16 7 23
924 23 header.imagedescriptor = (1<<5) | attr_bits; /* normal order instead of upside down */
925  
926 23 tga_header_pack(&header, headbuf);
927  
928 23 ▶ if (i_io_write(ig, &headbuf, sizeof(headbuf)) != sizeof(headbuf)) {
Branch: 1 branch
BranchTrueFalseTotal
if (i_io_write(ig, &headbuf, sizeof(headbuf)) != sizeof(headbuf)) { 0 23 23
929 0 i_push_error(errno, "could not write targa header");
930 0 return 0;
931 }
932  
933 23 ▶ if (idlen) {
Branch: 1 branch
BranchTrueFalseTotal
if (idlen) { 2 21 23
934 2 ▶ if ((size_t)i_io_write(ig, idstring, idlen) != idlen) {
Branch: 1 branch
BranchTrueFalseTotal
if ((size_t)i_io_write(ig, idstring, idlen) != idlen) { 0 2 2
935 0 i_push_error(errno, "could not write targa idstring");
936 0 return 0;
937 }
938 }
939
940 /* Make this into a constructor? */
941 23 dest.compressed = compress;
942 23 ▶ dest.bytepp = mapped ? 1 : bpp_to_bytes(bitspp);
Branch: 1 branch
BranchTrueFalseTotal
dest.bytepp = mapped ? 1 : bpp_to_bytes(bitspp); 16 7 23
943 23 dest.ig = ig;
944  
945 23 mm_log((1, "dest.compressed = %d\n", dest.compressed));
946 23 mm_log((1, "dest.bytepp = %d\n", dest.bytepp));
947  
948 23 ▶ if (img->type == i_palette_type) {
Branch: 1 branch
BranchTrueFalseTotal
if (img->type == i_palette_type) { 7 16 23
949 7 ▶ if (!tga_palette_write(ig, img, bitspp, i_colorcount(img))) return 0;
Branch: 2 branches
BranchTrueFalseTotal
if (!tga_palette_write(ig, img, bitspp, i_colorcount(img))) return 0; 7 0 7
if (!tga_palette_write(ig, img, bitspp, i_colorcount(img))) return 0; 0 7 7
950
951 7 ▶ if (!i_img_virtual(img) && !dest.compressed) {
Branch: 2 branches
BranchTrueFalseTotal
if (!i_img_virtual(img) && !dest.compressed) { 7 0 7
if (!i_img_virtual(img) && !dest.compressed) { 2 5 7
952 /* FIXME: assumes image layout */
953 2 ▶ if ((size_t)i_io_write(ig, img->idata, img->bytes) != img->bytes) {
Branch: 1 branch
BranchTrueFalseTotal
if ((size_t)i_io_write(ig, img->idata, img->bytes) != img->bytes) { 0 2 2
954 0 i_push_error(errno, "could not write targa image data");
955 0 return 0;
956 }
957 } else {
958 int y;
959 5 i_palidx *vals = mymalloc(sizeof(i_palidx)*img->xsize);
960 755 ▶ for(y=0; y<img->ysize; y++) {
Branch: 1 branch
BranchTrueFalseTotal
for(y=0; y<img->ysize; y++) { 750 5 755
961 750 ▶ i_gpal(img, 0, img->xsize, y, vals);
Branch: 1 branch
BranchTrueFalseTotal
i_gpal(img, 0, img->xsize, y, vals); 750 0 750
962 750 tga_dest_write(&dest, vals, img->xsize);
963 }
964 5 myfree(vals);
965 }
966 } else { /* direct type */
967 int x, y;
968 16 ▶ size_t bytepp = wierdpack ? 2 : bpp_to_bytes(bitspp);
Branch: 1 branch
BranchTrueFalseTotal
size_t bytepp = wierdpack ? 2 : bpp_to_bytes(bitspp); 13 3 16
969 16 size_t lsize = bytepp * img->xsize;
970 16 i_color *vals = mymalloc(img->xsize*sizeof(i_color));
971 16 unsigned char *buf = mymalloc(lsize);
972
973 108333 ▶ for(y=0; y<img->ysize; y++) {
Branch: 1 branch
BranchTrueFalseTotal
for(y=0; y<img->ysize; y++) { 108317 16 108333
974 108317 i_glin(img, 0, img->xsize, y, vals);
975 604307 ▶ for(x=0; x<img->xsize; x++) color_pack(buf+x*bytepp, bitspp, vals+x);
Branch: 1 branch
BranchTrueFalseTotal
for(x=0; x<img->xsize; x++) color_pack(buf+x*bytepp, bitspp, vals+x); 495990 108317 604307
976 108317 tga_dest_write(&dest, buf, img->xsize);
977 }
978 16 myfree(buf);
979 16 myfree(vals);
980 }
981  
982 23 ▶ if (i_io_close(ig))
Branch: 1 branch
BranchTrueFalseTotal
if (i_io_close(ig)) 1 22 23
983 1 return 0;
984  
985 22 return 1;
986 }
987  
988 /*
989 =back
990  
991 =head1 AUTHOR
992  
993 Arnar M. Hrafnkelsson <addi@umich.edu>
994  
995 =head1 SEE ALSO
996  
997 Imager(3)
998  
999 =cut
1000 */
« scale.im ↑ Summary rubthru.im »