16
16
* 2002/01/25 - Use pbm instead of ppm for alpha maps and fix alpha
17
* sense. (black = transparent, white = opaque).
18
* Option renamed to -andpbms; -andppms retained
20
* ppmtowinicon should now be the true reverse of winicontoppm.
21
* Filled some "ignored" fields in ICO output for maximum
17
* sense. (black = transparent, white = opaque).
18
* Option renamed to -andpbms; -andppms retained
20
* ppmtowinicon should now be the true reverse of winicontoppm.
21
* Filled some "ignored" fields in ICO output for maximum
24
24
* 2000/05/24 - using colorhash_table instead of a straight array search
25
25
* Though it's a little slower for files due to the low # of
201
if (icBitmap == NULL)
202
pm_error("out of memory");
197
205
wt = (wt & ~3) + 4;
200
208
rowData = malloc2 ( rows, sizeof (char *));
210
pm_error("out of memory");
201
211
icBitmap->xBytes = xBytes;
202
212
icBitmap->data = rowData;
213
overflow2(xBytes, rows);
203
214
icBitmap->size = xBytes * rows;
204
215
for (y=0;y<rows;y++) {
205
216
u1 * row = malloc2 ( xBytes , sizeof (u1));
221
pm_error("out of memory");
209
222
memset (row, 0, xBytes);
210
223
rowData[rows-y-1] = row;
212
225
* Check there's a pixel array, otherwise we're just faking this...
215
for (x=0;x<cols;x++) {
217
* So we've got a colorhash_table with two colors in it.
220
* Unless the hashing function changes, 0's black.
222
value = ppm_lookupcolor(cht, &pa[y][x]);
226
row[byteOn] |= bitOn;
228
for (x=0;x<cols;x++) {
230
* So we've got a colorhash_table with two colors in it.
233
* Unless the hashing function changes, 0's black.
235
value = ppm_lookupcolor(cht, &pa[y][x]);
239
row[byteOn] |= bitOn;
265
if (icBitmap == NULL)
266
pm_error("out of memory");
254
269
wt = (wt & ~3) + 4;
257
272
rowData = malloc2 ( rows , sizeof (char *));
274
pm_error("out of memory");
258
275
icBitmap->xBytes = xBytes;
259
276
icBitmap->data = rowData;
260
277
overflow2(xBytes, rows);
261
278
icBitmap->size = xBytes * rows;
262
overflow2(xBytes, rows);
264
280
for (y=0;y<rows;y++) {
265
281
u1 * row = malloc2 ( xBytes, sizeof (u1));
267
283
int nibble = 1; /* high nibble = 1, low nibble = 0; */
286
pm_error("out of memory");
269
287
memset (row, 0, xBytes);
270
288
rowData[rows-y-1] = row;
272
290
* Check there's a pixel array, otherwise we're just faking this...
275
for (x=0;x<cols;x++) {
276
value = ppm_lookupcolor(cht, &pa[y][x]);
278
* Shift it, if we're putting it in the high nibble.
283
row[byteOn] |= value;
293
for (x=0;x<cols;x++) {
294
value = ppm_lookupcolor(cht, &pa[y][x]);
296
* Shift it, if we're putting it in the high nibble.
301
row[byteOn] |= value;
327
if (icBitmap == NULL)
328
pm_error("out of memory");
310
330
wt = (wt & ~3) + 4;
313
333
rowData = malloc2 ( rows, sizeof (char *));
335
pm_error("out of memory");
314
336
icBitmap->xBytes = xBytes;
315
337
icBitmap->data = rowData;
338
overflow2(xBytes, rows);
316
339
icBitmap->size = xBytes * rows;
317
overflow2(xBytes, rows);
319
341
for (y=0;y<rows;y++) {
320
342
u1 * row = malloc2 ( xBytes, sizeof (u1));
344
pm_error("out of memory");
321
345
memset (row, 0, xBytes);
322
346
rowData[rows-y-1] = row;
324
348
* Check there's a pixel array, otherwise we're just faking this...
327
for (x=0;x<cols;x++) {
328
row[x] = ppm_lookupcolor(cht, &pa[y][x]);
351
for (x=0;x<cols;x++) {
352
row[x] = ppm_lookupcolor(cht, &pa[y][x]);
371
403
addColorToPalette(IC_Palette const palette, int const i,
372
404
int const r, int const g, int const b) {
373
405
palette->colors[i] = malloc ( sizeof (* palette->colors[i]) );
374
palette->colors[i]->red = r;
375
palette->colors[i]->green = g;
376
palette->colors[i]->blue = b;
377
palette->colors[i]->reserved = 0;
406
if (palette->colors[i] == NULL)
407
pm_error("out of memory");
409
palette->colors[i]->red = r;
410
palette->colors[i]->green = g;
411
palette->colors[i]->blue = b;
412
palette->colors[i]->reserved = 0;
450
488
xorChv = ppm_computecolorhist(xorPPMarray, xorCols, xorRows, MAXCOLORS,
452
490
if (xorChv == (colorhist_vector) 0)
453
pm_error("%s has too many colors - try doing a 'ppmquant %d'"
454
, xorPPM, MAXCOLORS);
491
pm_error("%s has too many colors - try doing a 'pnmquant %d'"
492
, xorPPM, MAXCOLORS);
455
493
if (verbose) pm_message("%d colors found", colors);
457
495
if (verbose && (xorMaxval > 255))
458
496
pm_message("maxval is not 255 - automatically rescaling colors");
459
497
for (i = 0; i < colors; ++i)
461
if (xorMaxval == 255)
463
addColorToPalette(palette,i,
464
PPM_GETR(xorChv[i].color),
465
PPM_GETG(xorChv[i].color),
466
PPM_GETB(xorChv[i].color));
470
addColorToPalette(palette,i,
471
PPM_GETR(xorChv[i].color) * 255 / xorMaxval,
472
PPM_GETG(xorChv[i].color) * 255 / xorMaxval,
473
PPM_GETB(xorChv[i].color) * 255 / xorMaxval);
499
if (xorMaxval == 255)
501
addColorToPalette(palette,i,
502
PPM_GETR(xorChv[i].color),
503
PPM_GETG(xorChv[i].color),
504
PPM_GETB(xorChv[i].color));
508
addColorToPalette(palette,i,
509
PPM_GETR(xorChv[i].color) * 255 / xorMaxval,
510
PPM_GETG(xorChv[i].color) * 255 / xorMaxval,
511
PPM_GETB(xorChv[i].color) * 255 / xorMaxval);
477
515
/* And make a hash table for fast lookup. */
663
main (int argc, char ** argv) {
664
MS_Ico MSIconData = createIconFile();
668
char * usage = "[-andppms] [-output output.ico] [icon1.ppm icon2.ppm ... ]";
673
* ppmtowinicon [-andppms] icon1.ppm [icon2.ppm icon3.ppm ... ] output.ico
675
* Use -a flag if you supply your own and bitmaps.
677
ppm_init ( &argc, argv);
679
* Parse command line arguments.
682
while (argn < argc && argv[argn][0] == '-' && argv[argn][1] != '\0') {
683
if (pm_keymatch(argv[argn], "-verbose", 2))
685
else if (pm_keymatch(argv[argn], "-andpgms", 2)
686
|| pm_keymatch(argv[argn], "-andppms", 2)) {
689
else if (pm_keymatch(argv[argn], "-output", 2)) {
690
if (argc - argn > 1) {
691
outfname = argv[argn+1];
694
pm_error ("-output must be supplied a filename");
697
else pm_usage(usage);
703
* If there's cmd line args left over, fine.
701
main(int argc, char ** argv) {
702
MS_Ico MSIconData = createIconFile();
707
ppm_init ( &argc, argv);
709
* Parse command line arguments.
712
while (argn < argc && argv[argn][0] == '-' && argv[argn][1] != '\0') {
713
if (pm_keymatch(argv[argn], "-verbose", 2))
715
else if (pm_keymatch(argv[argn], "-andpgms", 2)
716
|| pm_keymatch(argv[argn], "-andppms", 2)) {
719
else if (pm_keymatch(argv[argn], "-output", 2)) {
720
if (argc - argn > 1) {
721
outfname = argv[argn+1];
724
pm_error ("-output must be supplied a filename");
727
else pm_error("Invalid option '%s'", argv[argn]);
733
* If there's cmd line args left over, fine.
714
addEntryToIcon(MSIconData, "-", "");
715
if (verbose) pm_message ("Added entry from stdin.\n");
718
* If we're not using fake and maps, then we skip 1 each time.
720
for ( iconOn = argn; iconOn < argc ; iconOn += (readAndMaps ? 2 : 1) ) {
723
xorPPM = argv[iconOn];
724
andPPM = (readAndMaps ? argv[iconOn+1] : "");
725
addEntryToIcon(MSIconData, xorPPM, andPPM);
729
* Now we have to go through and calculate the offsets.
730
* The first infoheader starts at 6 + count*16 bytes.
732
offset = (MSIconData->count * 16) + 6;
733
for ( iconOn = 0; iconOn < MSIconData->count; iconOn++ ) {
734
IC_Entry entry = MSIconData->entries[iconOn];
735
entry->file_offset = offset;
737
* Increase the offset by the size of this offset & data.
738
* this includes the size of the color data.
740
offset += entry->size_in_bytes;
743
* And now, we have to actually SAVE the .ico!
745
writeMS_Ico(MSIconData,argv[argc-1]);
744
addEntryToIcon(MSIconData, "-", "");
745
if (verbose) pm_message ("Added entry from stdin.\n");
748
* If we're not using fake and maps, then we skip 1 each time.
752
iconOn += (readAndMaps ? 2 : 1) ) {
755
xorPPM = argv[iconOn];
756
andPPM = (readAndMaps ? argv[iconOn+1] : "");
757
addEntryToIcon(MSIconData, xorPPM, andPPM);
761
* Now we have to go through and calculate the offsets.
762
* The first infoheader starts at 6 + count*16 bytes.
764
offset = (MSIconData->count * 16) + 6;
765
for ( iconOn = 0; iconOn < MSIconData->count; iconOn++ ) {
766
IC_Entry entry = MSIconData->entries[iconOn];
767
entry->file_offset = offset;
769
* Increase the offset by the size of this offset & data.
770
* this includes the size of the color data.
772
offset += entry->size_in_bytes;
775
* And now, we have to actually SAVE the .ico!
777
writeMS_Ico(MSIconData,argv[argc-1]);