X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?a=blobdiff_plain;f=pctb%2Frgbimage.c;fp=pctb%2Frgbimage.c;h=e49044f419f0f7ef06c530a74f8d46c10a8f0dd0;hb=74e4e249f2c3e848592984cb193aded6a77a341d;hp=0000000000000000000000000000000000000000;hpb=2aaae8ee04d0a6a8ab85751ceb67f222d259eba8;p=ypp-sc-tools.db-test.git diff --git a/pctb/rgbimage.c b/pctb/rgbimage.c new file mode 100644 index 0000000..e49044f --- /dev/null +++ b/pctb/rgbimage.c @@ -0,0 +1,132 @@ +/* + * Handling of colour (RGB) images + */ +/* + * This is part of ypp-sc-tools, a set of third-party tools for assisting + * players of Yohoho Puzzle Pirates. + * + * Copyright (C) 2009 Ian Jackson + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Yohoho and Puzzle Pirates are probably trademarks of Three Rings and + * are used without permission. This program is not endorsed or + * sponsored by Three Rings. + */ + +#include "convert.h" + +/* + * + * + * widgets.txt + * format + * + * + * + * + * + * ppmnoraw depth 8 + * + * + * + * ppmnoraw depth 8 + * . + * + */ + +#include "convert.h" + +#define dbassert(x) \ + ((x) ? (void)0 : \ + fatal("Error in pixmap database.\n" \ + " Requirement not met: %s:%d: %s", __FILE__,__LINE__, #x)) + +static int identify(const RgbImage *base, Rect portion, + char result[MAXIMGIDENT]) { + FILE *f; + sysassert( f= fopen("pixmaps.txt","r") ); + struct pam inpam; + +#define FGETSLINE (fgetsline(f,result,MAXIMGIDENT)) + + FGETSLINE; +fprintf(stderr,">%s<\n",result); + dbassert(!strcmp(result,"# ypp-sc-tools pctb pixmaps v1")); + + void *row= 0; + size_t rowa= 0; + + for (;;) { + FGETSLINE; + if (!result || result[0]=='#') continue; + if (!strcmp(result,".")) break; + + pnm_readpaminit(f, &inpam, sizeof(inpam)); + dbassert(inpam.maxval == 255); + dbassert(inpam.bytes_per_sample == 1); + dbassert(inpam.format == PPM_FORMAT); + + if (rowa < inpam.width) { + rowa= inpam.width; + row= mrealloc(row, rowa*3); + } + int diff= + inpam.width != RECT_W(portion) || + inpam.height != RECT_H(portion); + + int y; + for (y=0; yw= w; + ri->h= h; + return ri; +}