| 1 |
/* ---------------------------------------------------------------------- |
| 2 |
* |
| 3 |
* Convert an AVS X image to a PAM image |
| 4 |
* |
| 5 |
* By Scott Pakin <[email protected]> |
| 6 |
* |
| 7 |
* ---------------------------------------------------------------------- |
| 8 |
* |
| 9 |
* Copyright (C) 2010 Scott Pakin <[email protected]> |
| 10 |
* |
| 11 |
* This program is free software: you can redistribute it and/or modify |
| 12 |
* it under the terms of the GNU General Public License as published by |
| 13 |
* the Free Software Foundation, either version 3 of the License, or (at |
| 14 |
* your option) any later version. |
| 15 |
* |
| 16 |
* This program is distributed in the hope that it will be useful, but |
| 17 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 19 |
* General Public License for more details. |
| 20 |
* |
| 21 |
* You should have received a copy of the GNU General Public License |
| 22 |
* along with this program. If not, see http://www.gnu.org/licenses/. |
| 23 |
* |
| 24 |
* ---------------------------------------------------------------------- |
| 25 |
*/ |
| 26 |
|
| 27 |
#include <stdio.h> |
| 28 |
|
| 29 |
#include "pm.h" |
| 30 |
#include "pam.h" |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
static void |
| 35 |
producePam(FILE * const avsFileP, |
| 36 |
struct pam * const pamP) { |
| 37 |
|
| 38 |
tuple * tuplerow; |
| 39 |
unsigned int row; |
| 40 |
|
| 41 |
tuplerow = pnm_allocpamrow(pamP); |
| 42 |
for (row = 0; row < pamP->height; ++row) { |
| 43 |
unsigned int col; |
| 44 |
for (col = 0; col < pamP->width; ++col) { |
| 45 |
tuple const thisTuple = tuplerow[col]; |
| 46 |
unsigned char c; |
| 47 |
pm_readcharu(avsFileP, &c); thisTuple[3] = c; |
| 48 |
pm_readcharu(avsFileP, &c); thisTuple[0] = c; |
| 49 |
pm_readcharu(avsFileP, &c); thisTuple[1] = c; |
| 50 |
pm_readcharu(avsFileP, &c); thisTuple[2] = c; |
| 51 |
} |
| 52 |
pnm_writepamrow(pamP, tuplerow); |
| 53 |
} |
| 54 |
pnm_freepamrow(tuplerow); |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
int |
| 60 |
main(int argc, const char *argv[]) { |
| 61 |
|
| 62 |
const char * comment = "Produced by avstopam"; /* constant */ |
| 63 |
|
| 64 |
struct pam outPam; |
| 65 |
const char * inputFilename; |
| 66 |
FILE * inFileP; |
| 67 |
long width; |
| 68 |
long height; |
| 69 |
|
| 70 |
pm_proginit(&argc, argv); |
| 71 |
|
| 72 |
inputFilename = (argc > 1) ? argv[1] : "-"; |
| 73 |
|
| 74 |
inFileP = pm_openr(inputFilename); |
| 75 |
|
| 76 |
pm_readbiglong(inFileP, &width); |
| 77 |
pm_readbiglong(inFileP, &height); |
| 78 |
|
| 79 |
outPam.size = sizeof(struct pam); |
| 80 |
outPam.len = PAM_STRUCT_SIZE(comment_p); |
| 81 |
outPam.file = stdout; |
| 82 |
outPam.format = PAM_FORMAT; |
| 83 |
outPam.plainformat = 0; |
| 84 |
outPam.width = width; |
| 85 |
outPam.height = height; |
| 86 |
outPam.depth = 4; |
| 87 |
outPam.maxval = 255; |
| 88 |
outPam.bytes_per_sample = 1; |
| 89 |
sprintf(outPam.tuple_type, "RGB_ALPHA"); |
| 90 |
outPam.allocation_depth = 4; |
| 91 |
outPam.comment_p = &comment; |
| 92 |
|
| 93 |
/* Produce a PAM output header. Note that AVS files *always* |
| 94 |
contain four channels with one byte per channel. |
| 95 |
*/ |
| 96 |
pnm_writepaminit(&outPam); |
| 97 |
|
| 98 |
producePam(inFileP, &outPam); |
| 99 |
|
| 100 |
pm_closer(inFileP); |
| 101 |
|
| 102 |
return 0; |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
|