void AMI_ILBM_setScreenPalette(const amiVideo_Palette *palette, struct Screen *screen)
{
    if(AMI_ILBM_agaIsSupported())
    {
        amiVideo_ULong *colorSpecs = amiVideo_generateRGB32ColorSpecs(palette);
        LoadRGB32(&screen->ViewPort, (ULONG*)colorSpecs);
        free(colorSpecs);
    }
    else
    {
        amiVideo_UWord *colorSpecs = amiVideo_generateRGB4ColorSpecs(palette);
        LoadRGB4(&screen->ViewPort, (UWORD*)colorSpecs, palette->bitplaneFormat.numOfColors);
        free(colorSpecs);
    }
}
// Load a 32 bit palette, even under <39
void LIBFUNC L_LoadPalette32(
	REG(a0, struct ViewPort *vp),
	REG(a1, unsigned long *palette))
{
	// Under 39 pass to Gfx library
	if( ((struct Library *)GfxBase)->lib_Version>=39) 
	{
		LoadRGB32(vp,palette);
	}

	// Otherwise, convert to 4 bit
	else
	{
		unsigned short *backup_palette;
		short pen,numcols;

		// Get count
		numcols=*(unsigned short *)palette;
		++palette;

		// Allocate backup palette
		if ((backup_palette=AllocVec(numcols*sizeof(unsigned short),0)))
		{
			// Convert to 4 bit colour
			for (pen=0;pen<numcols;pen++)
			{
				backup_palette[pen]=((*palette++)&0xf0000000)>>20;
				backup_palette[pen]|=((*palette++)&0xf0000000)>>24;
				backup_palette[pen]|=((*palette++)&0xf0000000)>>28;
			}

			// Load palette
			LoadRGB4(vp,backup_palette,numcols);

			// Free backup
			FreeVec(backup_palette);
		}
	}
}
Exemple #3
0
void
EditColor()
{
    extern const char *configfile;
    int i, done = 0, okay = 0;
    long code, qual, class;
    register struct Gadget *gd, *dgad;
    register struct Window *nw;
    register struct IntuiMessage *imsg;
    register struct PropInfo *pip;
    register struct Screen *scrn;
    long aidx;
    int msx, msy;
    int curcol = 0, drag = 0;
    int bxorx, bxory, bxxlen, bxylen;
    static UWORD colors[AMII_MAXCOLORS];
    static UWORD svcolors[AMII_MAXCOLORS];
    static int once = 0;
    scrn = HackScreen;

    if (!once) {
        if (WINVERS_AMIV) {
            Col_NewWindowStructure1.Width += 300;
            Col_NewWindowStructure1.Height += 20;
            Col_NewWindowStructure1.LeftEdge -= 150;
            Col_BluePen.Width += 300;
            Col_RedPen.Width += 300;
            Col_GreenPen.Width += 300;
            Col_Cancel.LeftEdge += 300;
            Col_Okay.LeftEdge += 150;
            Col_Cancel.TopEdge += 20;
            Col_Save.TopEdge += 20;
            Col_Okay.TopEdge += 20;
        }
        SetBorder(&Col_Okay);
        SetBorder(&Col_Cancel);
        SetBorder(&Col_Save);
        once = 1;
    }

    bxylen = Col_NewWindowStructure1.Height
             - (Col_BluePen.TopEdge + Col_BluePen.Height + 6);
    bxxlen = Col_BluePen.Width;
    bxorx = Col_BluePen.LeftEdge;
    bxory = Col_BluePen.TopEdge + Col_BluePen.Height + 2;

    /* Save the current colors */
    for (i = 0; i < amii_numcolors; ++i)
        svcolors[i] = colors[i] = GetRGB4(scrn->ViewPort.ColorMap, i);

    Col_NewWindowStructure1.Screen = scrn;
#ifdef INTUI_NEW_LOOK
    if (IntuitionBase->LibNode.lib_Version >= 37) {
        ((struct PropInfo *) Col_BluePen.SpecialInfo)->Flags |= PROPNEWLOOK;
        ((struct PropInfo *) Col_RedPen.SpecialInfo)->Flags |= PROPNEWLOOK;
        ((struct PropInfo *) Col_GreenPen.SpecialInfo)->Flags |= PROPNEWLOOK;
    }
#endif
    if (WINVERS_AMIV || WINVERS_AMII) {
#ifdef INTUI_NEW_LOOK
        Col_NewWindowStructure1.Extension = wintags;
        Col_NewWindowStructure1.Flags |= WFLG_NW_EXTENDED;
#ifdef __GNUC__
        fillhook.h_Entry = (void *) &LayerFillHook;
#else
        fillhook.h_Entry = (ULONG (*) ()) LayerFillHook;
#endif
        fillhook.h_Data = (void *) -2;
        fillhook.h_SubEntry = 0;
#endif
    }

    nw = OpenWindow((void *) &Col_NewWindowStructure1);

    if (nw == NULL) {
        DisplayBeep(NULL);
        return;
    }

    PrintIText(nw->RPort, &Col_IntuiTextList1, 0, 0);

    ClearCol(nw);
    DrawCol(nw, curcol, colors);
    while (!done) {
        WaitPort(nw->UserPort);

        while (imsg = (struct IntuiMessage *) GetMsg(nw->UserPort)) {
            gd = (struct Gadget *) imsg->IAddress;
            code = imsg->Code;
            class = imsg->Class;
            qual = imsg->Qualifier;
            msx = imsg->MouseX;
            msy = imsg->MouseY;

            ReplyMsg((struct Message *) imsg);

            switch (class) {
            case VANILLAKEY:
                if (code == 'v' && qual == AMIGALEFT)
                    okay = done = 1;
                else if (code == 'b' && qual == AMIGALEFT)
                    okay = 0, done = 1;
                else if (code == 'o' || code == 'O')
                    okay = done = 1;
                else if (code == 'c' || code == 'C')
                    okay = 0, done = 1;
                break;

            case CLOSEWINDOW:
                done = 1;
                break;

            case GADGETUP:
                drag = 0;
                if (gd->GadgetID == GADREDPEN || gd->GadgetID == GADBLUEPEN
                    || gd->GadgetID == GADGREENPEN) {
                    pip = (struct PropInfo *) gd->SpecialInfo;
                    aidx = pip->HorizPot / (MAXPOT / 15);
                    if (gd->GadgetID == GADREDPEN) {
                        colors[curcol] =
                            (colors[curcol] & ~0xf00) | (aidx << 8);
                        LoadRGB4(&scrn->ViewPort, colors, amii_numcolors);
                    } else if (gd->GadgetID == GADBLUEPEN) {
                        colors[curcol] = (colors[curcol] & ~0xf) | aidx;
                        LoadRGB4(&scrn->ViewPort, colors, amii_numcolors);
                    } else if (gd->GadgetID == GADGREENPEN) {
                        colors[curcol] =
                            (colors[curcol] & ~0x0f0) | (aidx << 4);
                        LoadRGB4(&scrn->ViewPort, colors, amii_numcolors);
                    }
                    DispCol(nw, curcol, colors);
                } else if (gd->GadgetID == GADCOLOKAY) {
                    done = 1;
                    okay = 1;
                } else if (gd->GadgetID == GADCOLSAVE) {
                    FILE *fp, *nfp;
                    char buf[300], nname[300], oname[300];
                    int once = 0;

                    fp = fopen(configfile, "r");
                    if (!fp) {
                        pline("can't find NetHack.cnf");
                        break;
                    }

                    strcpy(oname, dirname((char *) configfile));
                    if (oname[strlen(oname) - 1] != ':') {
                        sprintf(nname, "%s/New_NetHack.cnf", oname);
                        strcat(oname, "/");
                        strcat(oname, "Old_NetHack.cnf");
                    } else {
                        sprintf(nname, "%sNew_NetHack.cnf", oname);
                        strcat(oname, "Old_NetHack.cnf");
                    }

                    nfp = fopen(nname, "w");
                    if (!nfp) {
                        pline("can't write to New_NetHack.cnf");
                        fclose(fp);
                        break;
                    }
                    while (fgets(buf, sizeof(buf), fp)) {
                        if (strncmp(buf, "PENS=", 5) == 0) {
                            once = 1;
                            fputs("PENS=", nfp);
                            for (i = 0; i < amii_numcolors; ++i) {
                                fprintf(nfp, "%03x", colors[i]);
                                if ((i + 1) < amii_numcolors)
                                    putc('/', nfp);
                            }
                            putc('\n', nfp);
                        } else {
                            fputs(buf, nfp);
                        }
                    }

                    /* If none in the file yet, now write it */
                    if (!once) {
                        fputs("PENS=", nfp);
                        for (i = 0; i < amii_numcolors; ++i) {
                            fprintf(nfp, "%03x", colors[i]);
                            if ((i + 1) < amii_numcolors)
                                putc(',', nfp);
                        }
                        putc('\n', nfp);
                    }
                    fclose(fp);
                    fclose(nfp);
                    unlink(oname);
                    if (filecopy((char *) configfile, oname) == 0)
                        if (filecopy(nname, (char *) configfile) == 0)
                            unlink(nname);
                    done = 1;
                    okay = 1;
                } else if (gd->GadgetID == GADCOLCANCEL) {
                    done = 1;
                    okay = 0;
                }
                break;

            case GADGETDOWN:
                drag = 1;
                dgad = gd;
                break;

            case MOUSEMOVE:
                if (!drag)
                    break;
                pip = (struct PropInfo *) dgad->SpecialInfo;
                aidx = pip->HorizPot / (MAXPOT / 15);
                if (dgad->GadgetID == GADREDPEN) {
                    colors[curcol] = (colors[curcol] & ~0xf00) | (aidx << 8);
                    LoadRGB4(&scrn->ViewPort, colors, amii_numcolors);
                } else if (dgad->GadgetID == GADBLUEPEN) {
                    colors[curcol] = (colors[curcol] & ~0xf) | aidx;
                    LoadRGB4(&scrn->ViewPort, colors, amii_numcolors);
                } else if (dgad->GadgetID == GADGREENPEN) {
                    colors[curcol] = (colors[curcol] & ~0x0f0) | (aidx << 4);
                    LoadRGB4(&scrn->ViewPort, colors, amii_numcolors);
                }
                DispCol(nw, curcol, colors);
                break;

            case MOUSEBUTTONS:
                if (code == SELECTDOWN) {
                    if (msy > bxory && msy < bxory + bxylen - 1 && msx > bxorx
                        && msx < bxorx + bxxlen - 1) {
                        curcol = (msx - bxorx) / (bxxlen / amii_numcolors);
                        if (curcol >= 0 && curcol < amii_numcolors)
                            DrawCol(nw, curcol, colors);
                    }
                }
                break;
            }
        }
    }

    if (okay) {
        for (i = 0; i < (amii_numcolors); ++i)
            sysflags.amii_curmap[i] = colors[i];
        LoadRGB4(&scrn->ViewPort, sysflags.amii_curmap, amii_numcolors);
    } else
        LoadRGB4(&scrn->ViewPort, svcolors, amii_numcolors);
    CloseWindow(nw);
}