static __regargs PaletteT *ReadColorMap(TgaHeaderT *hdr, FileT *tga) { LONG size = hdr->cmapLength * 3; UBYTE *data = MemAlloc(size, MEMF_PUBLIC); PaletteT *palette = NULL; if (FileRead(tga, data, size)) { palette = NewPalette(hdr->cmapLength); /* TGA palette is defined as BGR value. */ { ColorT *dst = palette->colors; UBYTE *src = data; WORD n = hdr->cmapLength; while (--n >= 0) { dst->b = *src++; dst->g = *src++; dst->r = *src++; dst++; } } } MemFree(data); return palette; }
__regargs PaletteT *LoadPalette(const char *filename) { PaletteT *palette = NULL; IffFileT iff; if (OpenIff(&iff, filename)) { if (iff.header.type == ID_ILBM) { while (ParseChunk(&iff)) { switch (iff.chunk.type) { case ID_CMAP: palette = NewPalette(iff.chunk.length / sizeof(ColorT)); ReadChunk(&iff, palette->colors); break; default: SkipChunk(&iff); break; } } } CloseIff(&iff); } return palette; }
/* * Set up resources. */ void SetupResources() { ResAdd("EffectPal", NewPalette(256)); #ifdef GENERATEMAPS ResAdd("Map0", NewUVMap(WIDTH, HEIGHT, UV_OPTIMIZED, 256, 256)); ResAdd("Map1", NewUVMap(WIDTH, HEIGHT, UV_OPTIMIZED, 256, 256)); ResAdd("Map2", NewUVMap(WIDTH, HEIGHT, UV_OPTIMIZED, 256, 256)); ResAdd("Map3", NewUVMap(WIDTH, HEIGHT, UV_OPTIMIZED, 256, 256)); ResAdd("Map4", NewUVMap(WIDTH, HEIGHT, UV_OPTIMIZED, 256, 256)); ResAdd("Map5", NewUVMap(WIDTH, HEIGHT, UV_OPTIMIZED, 256, 256)); ResAdd("Map6", NewUVMap(WIDTH, HEIGHT, UV_OPTIMIZED, 256, 256)); ResAdd("Map7", NewUVMap(WIDTH, HEIGHT, UV_OPTIMIZED, 256, 256)); ResAdd("Map8", NewUVMap(WIDTH, HEIGHT, UV_OPTIMIZED, 256, 256)); LOG("Generating map 0."); UVMapGenerate0(R_("Map0")); UVMapWriteToFile(R_("Map0"), "map0.bin"); LOG("Generating map 1."); UVMapGenerate1(R_("Map1")); UVMapWriteToFile(R_("Map1"), "map1.bin"); LOG("Generating map 2."); UVMapGenerate2(R_("Map2")); UVMapWriteToFile(R_("Map2"), "map2.bin"); LOG("Generating map 3."); UVMapGenerate3(R_("Map3")); UVMapWriteToFile(R_("Map3"), "map3.bin"); LOG("Generating map 4."); UVMapGenerate4(R_("Map4")); UVMapWriteToFile(R_("Map4"), "map4.bin"); LOG("Generating map 5."); UVMapGenerate5(R_("Map5")); UVMapWriteToFile(R_("Map5"), "map5.bin"); LOG("Generating map 6."); UVMapGenerate6(R_("Map6")); UVMapWriteToFile(R_("Map6"), "map6.bin"); LOG("Generating map 7."); UVMapGenerate7(R_("Map7")); UVMapWriteToFile(R_("Map7"), "map7.bin"); LOG("Generating map 8."); UVMapGenerate8(R_("Map8")); UVMapWriteToFile(R_("Map8"), "map8.bin"); #else ResAdd("Map0", NewUVMapFromFile("data/map0.bin")); ResAdd("Map1", NewUVMapFromFile("data/map1.bin")); ResAdd("Map2", NewUVMapFromFile("data/map2.bin")); ResAdd("Map3", NewUVMapFromFile("data/map3.bin")); ResAdd("Map4", NewUVMapFromFile("data/map4.bin")); ResAdd("Map5", NewUVMapFromFile("data/map5.bin")); ResAdd("Map6", NewUVMapFromFile("data/map6.bin")); ResAdd("Map7", NewUVMapFromFile("data/map7.bin")); ResAdd("Map8", NewUVMapFromFile("data/map8.bin")); #endif }
static PaletteT *PngToPalette(PngT *png) { if ((png->ihdr.bit_depth == 8) && (png->ihdr.colour_type == PNG_INDEXED)) { PaletteT *palette = NewPalette(png->plte.no_colors); LOG("The palette has %d colors.", png->plte.no_colors); MemCopy(palette->colors, png->plte.colors, sizeof(RGB) * palette->count); return palette; } return NULL; }
void LCD_makepalette(void) { Handle myClut; if (hasColorQD) { myClut = Get1Resource('clut', myRes); if (!myClut) { post("Color Problem"); myPalette = GetNewPalette(0); } /* DDZ changed palette from "courteous" to "tolerant" 12/14/92 */ else myPalette = NewPalette(numPaletteColors,(CTabHandle)myClut,pmTolerant,0x5000); } else myPalette = 0; }
PaletteT *NewPaletteFromFile(const StrT fileName) { DiskPaletteT *file = ReadFileSimple(fileName); if (file) { PaletteT *palette = NewPalette(file->count); palette->start = file->start; LOG("Palette '%s' has %d colors.", fileName, file->count); MemCopy(palette->colors, file->colors, sizeof(RGB) * file->count); MemUnref(file); return palette; } return NULL; }
__regargs BitmapT *LoadILBM(const char *filename, BOOL interleaved) { BitmapT *bitmap = NULL; PaletteT *palette = NULL; IffFileT iff; if (OpenIff(&iff, filename)) { if (iff.header.type == ID_ILBM) { BOOL compression = FALSE; while (ParseChunk(&iff)) { BitmapHeaderT bmhd; switch (iff.chunk.type) { case ID_BMHD: ReadChunk(&iff, &bmhd); bitmap = NewBitmap(bmhd.w, bmhd.h, bmhd.nPlanes, interleaved); compression = bmhd.compression; break; case ID_CMAP: palette = NewPalette(iff.chunk.length / sizeof(ColorT)); ReadChunk(&iff, palette->colors); break; case ID_BODY: { BYTE *data = MemAlloc(iff.chunk.length, MEMF_PUBLIC); LONG size = iff.chunk.length; ReadChunk(&iff, data); if (compression) { LONG newSize = bitmap->bplSize * bitmap->depth; BYTE *uncompressed = MemAlloc(newSize, MEMF_PUBLIC); UnRLE(data, size, uncompressed); MemFree(data, size); data = uncompressed; size = newSize; } if (!interleaved) Deinterleave(data, bitmap); else memcpy(bitmap->planes[0], data, bitmap->bplSize * bitmap->depth); MemFree(data, size); } break; default: SkipChunk(&iff); break; } } if (bitmap) bitmap->palette = palette; } CloseIff(&iff); } else { Log("File '%s' missing.\n", filename); } return bitmap; }
static int ROM_VideoInit(_THIS, SDL_PixelFormat *vformat) { long info; /* Check out some things about the system */ Gestalt(gestaltQuickdrawVersion, &info); if ( info == gestaltOriginalQD ) { SDL_SetError("Color Quickdraw not available"); return(-1); } /* Start ROMintosh events */ Mac_InitEvents(this); /* Get a handle to the main monitor */ SDL_Display = GetMainDevice(); /* Determine the current screen size */ this->info.current_w = (**SDL_Display).gdRect.right; this->info.current_h = (**SDL_Display).gdRect.bottom; /* Determine pixel format */ vformat->BitsPerPixel = (**(**SDL_Display).gdPMap).pixelSize; switch (vformat->BitsPerPixel) { case 16: /* 5-5-5 RGB */ vformat->Rmask = 0x00007c00; vformat->Gmask = 0x000003e0; vformat->Bmask = 0x0000001f; break; default: break; } /* Create our palette */ SDL_CTab = (CTabHandle)NewHandle(sizeof(ColorSpec)*256 + 8); if ( SDL_CTab == nil ) { SDL_OutOfMemory(); return(-1); } (**SDL_CTab).ctSeed = GetCTSeed(); (**SDL_CTab).ctFlags = 0; (**SDL_CTab).ctSize = 255; CTabChanged(SDL_CTab); SDL_CPal = NewPalette(256, SDL_CTab, pmExplicit+pmTolerant, 0); /* Get a list of available fullscreen modes */ SDL_modelist = (SDL_Rect **)SDL_malloc((1+1)*sizeof(SDL_Rect *)); if ( SDL_modelist ) { SDL_modelist[0] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect)); if ( SDL_modelist[0] ) { SDL_modelist[0]->x = 0; SDL_modelist[0]->y = 0; SDL_modelist[0]->w = (**SDL_Display).gdRect.right; SDL_modelist[0]->h = (**SDL_Display).gdRect.bottom; } SDL_modelist[1] = NULL; } /* Fill in some window manager capabilities */ this->info.wm_available = 1; /* We're done! */ return(0); }
LPPALETTE ReadPalette( LPSTR lpFileName, BOOL bCombine ) /************************************************************************/ { int ifh; /* file handle( unbuffered) */ FILEBUF ifd; /* file descriptor( buffered) */ short i, iColors; VERSIONINFO version; RECINFO rec; LPTR lpByte; LPWORD lpWord; LPLONG lpLong; BYTE Previous; BOOL bError; FNAME szName; LPPALETTE lpHeadPalette, lpPalette, lpBigPalette; /* open the palette file */ if ( ( ifh = _lopen( lpFileName, OF_READ)) < 0 ) { Message( IDS_EOPEN, lpFileName); return( NULL ); } /* create a buffered stream to speed access */ FileFDOpenRdr( &ifd, ifh, (LPTR)LineBuffer[0], 16*1024); // read palette version version.Length = sizeof(version.Number); version.Type = PALFILE_VERSION; FileRead(&ifd, (LPTR)&version, sizeof(version)); #ifdef _MAC swapw(&version.Length); swapw(&version.Number); #endif if (ifd.err || version.Type != PALFILE_VERSION || version.Length != sizeof(version.Number) || version.Number > CURRENT_VERSION) { Message(IDS_INVALIDPALETTE, lpFileName); _lclose(ifh); return(NULL); } rec.Type = 0; lpHeadPalette = NULL; lpPalette = NULL; bError = NO; while (!bError && !ifd.err && rec.Type != PALFILE_END) { Previous = rec.Type; FileRead(&ifd, (LPTR)&rec, sizeof(RECINFO)); #ifdef _MAC swapw(&rec.Length); #endif if (ifd.err) break; switch (rec.Type) { case PALFILE_VERSION: bError = YES; break; case PALFILE_COUNT: lpByte = Alloc((long)rec.Length); FileRead(&ifd, lpByte, rec.Length); FreeUp(lpByte); break; case PALFILE_COLORS: if (!lpPalette) { bError = YES; break; } lpWord = (LPWORD)Alloc((long)rec.Length); if (!lpWord) { Message (IDS_EMEMALLOC); bError = YES; break; } FileRead(&ifd, (LPTR)lpWord, rec.Length); if (ifd.err) { FreeUp((LPTR)lpWord); break; } #ifdef _MAC swapw(lpWord); #endif iColors = *lpWord; if ((iColors * sizeof(COLOR) + sizeof(WORD)) != rec.Length) { FreeUp((LPTR)lpWord); bError = YES; break; } lpPalette->iColors = iColors; if (!iColors) { FreeUp((LPTR)lpWord); break; } lpLong = (LPLONG)(lpWord+1); lpPalette->lpColorInfo = (LPCOLORINFO)Alloc((long)(sizeof(COLORINFO)*iColors)); if (!lpPalette->lpColorInfo) { Message(IDS_EMEMALLOC); FreeUp((LPTR)lpWord); bError = YES; break; } for (i = 0; i < iColors; ++i) { LPVOID lp = &lpPalette->lpColorInfo[i].rgb; #ifdef _MAC swapl((LPDWORD)lp); #endif CopyRGB(lpLong+i, lp); SetColorInfo( &lpPalette->lpColorInfo[i], &lpPalette->lpColorInfo[i], CS_RGB); } FreeUp((LPTR)lpWord); break; case PALFILE_NAME: if (Previous == PALFILE_NAME) { bError = YES; break; } if (lpPalette) { lpHeadPalette = LinkPalette(lpHeadPalette, lpPalette); lpPalette = NULL; } rec.Length = bound(rec.Length, 0, MAX_FNAME_LEN); FileRead(&ifd, (LPTR)szName, rec.Length); if (ifd.err) break; lpPalette = NewPalette(szName); if (!lpPalette) { Message (IDS_EMEMALLOC); bError = YES; break; } break; case PALFILE_GROUP: if (!lpPalette || (rec.Length != sizeof(lpPalette->dwGroup))) { bError = YES; break; } FileRead(&ifd, (LPTR)&lpPalette->dwGroup, rec.Length); #ifdef _MAC swapl((LPDWORD)(&lpPalette->dwGroup)); #endif break; case PALFILE_LABELS: if (!lpPalette) { bError = YES; break; } lpPalette->lpLabels = Alloc((long)rec.Length); if (!lpPalette->lpLabels) { Message (IDS_EMEMALLOC); bError = YES; break; } lpPalette->LabelsLength = rec.Length; FileRead(&ifd, lpPalette->lpLabels, rec.Length); break; case PALFILE_FORMAT: if (!lpPalette || (rec.Length > MAX_STR_LEN)) { bError = YES; break; } FileRead(&ifd, (LPTR)lpPalette->szFormat, rec.Length); break; case PALFILE_END: if (lpPalette) { lpHeadPalette = LinkPalette(lpHeadPalette, lpPalette); lpPalette = NULL; } break; default: bError = YES; break; } } _lclose(ifh); if (lpPalette) { if (lpPalette->lpColorInfo) FreeUp((LPTR)lpPalette->lpColorInfo); if (lpPalette->lpLabels) FreeUp((LPTR)lpPalette->lpLabels); FreeUp((LPTR)lpPalette); } if (ifd.err || bError || rec.Type != PALFILE_END || lpPalette) { Message(IDS_INVALIDPALETTE, lpFileName); FreeUpPalette(lpHeadPalette); return(NULL); } if ( !bCombine || !lpHeadPalette ) return( lpHeadPalette ); if ( !(lpBigPalette = CombinePalettes(lpHeadPalette)) ) Message (IDS_EMEMALLOC); FreeUpPalette(lpHeadPalette); return( lpBigPalette ); }
Bitmap* ReadPCXFile (const Collection* A) /* Read a bitmap from a PCX file */ { PCXHeader* P; Bitmap* B; unsigned char* L; Pixel* Px; unsigned MaxIdx = 0; unsigned X, Y; /* Get the file name */ const char* Name = NeedAttrVal (A, "name", "read pcx file"); /* Open the file */ FILE* F = fopen (Name, "rb"); if (F == 0) { Error ("Cannot open PCX file `%s': %s", Name, strerror (errno)); } /* Read the PCX header */ P = ReadPCXHeader (F, Name); /* Dump the header if requested */ if (Verbosity > 0) { DumpPCXHeader (P, Name); } /* Create the bitmap */ B = NewBitmap (P->Width, P->Height); /* Copy the name */ SB_CopyStr (&B->Name, Name); /* Allocate memory for the scan line */ L = xmalloc (P->Width); /* Read the pixel data */ Px = B->Data; if (P->Planes == 1) { /* This is either monochrome or indexed */ if (P->BPP == 1) { /* Monochrome */ for (Y = 0, Px = B->Data; Y < P->Height; ++Y) { unsigned I; unsigned char Mask; /* Read the plane */ ReadPlane (F, P, L); /* Create pixels */ for (X = 0, I = 0, Mask = 0x01; X < P->Width; ++Px) { Px->Index = (L[I] & Mask) != 0; if (Mask == 0x80) { Mask = 0x01; ++I; } else { Mask <<= 1; } } } } else { /* One plane with 8bpp is indexed */ for (Y = 0, Px = B->Data; Y < P->Height; ++Y) { /* Read the plane */ ReadPlane (F, P, L); /* Create pixels */ for (X = 0; X < P->Width; ++X, ++Px) { if (L[X] > MaxIdx) { MaxIdx = L[X]; } Px->Index = L[X]; } } } /* One plane means we have a palette which is either part of the header ** or follows. */ if (P->PalInfo == 0) { /* Create the monochrome palette */ B->Pal = NewMonochromePalette (); } else { unsigned Count; unsigned I; unsigned char Palette[256][3]; unsigned long EndPos; /* Determine the current file position */ unsigned long CurPos = FileGetPos (F); /* Seek to the end of the file */ (void) fseek (F, 0, SEEK_END); /* Get this position */ EndPos = FileGetPos (F); /* There's a palette if the old location is 769 bytes from the end */ if (EndPos - CurPos == sizeof (Palette) + 1) { /* Seek back */ FileSetPos (F, CurPos); /* Check for palette marker */ if (Read8 (F) != 0x0C) { Error ("Invalid palette marker in PCX file `%s'", Name); } } else if (EndPos == CurPos) { /* The palette is in the header */ FileSetPos (F, 16); /* Check the maximum index for safety */ if (MaxIdx > 15) { Error ("PCX file `%s' contains more than 16 indexed colors " "but no extra palette", Name); } } else { Error ("Error in PCX file `%s': %lu bytes at end of pixel data", Name, EndPos - CurPos); } /* Read the palette. We will just read what we need. */ Count = MaxIdx + 1; ReadData (F, Palette, Count * sizeof (Palette[0])); /* Create the palette from the data */ B->Pal = NewPalette (Count); for (I = 0; I < Count; ++I) { B->Pal->Entries[I].R = Palette[I][0]; B->Pal->Entries[I].G = Palette[I][1]; B->Pal->Entries[I].B = Palette[I][2]; B->Pal->Entries[I].A = 0; } } } else { /* 3 or 4 planes are RGB or RGBA (don't know if this exists) */ for (Y = 0, Px = B->Data; Y < P->Height; ++Y) { /* Read the R plane and move the data */ ReadPlane (F, P, L); for (X = 0; X < P->Width; ++X, ++Px) { Px->C.R = L[X]; } /* Read the G plane and move the data */ ReadPlane (F, P, L); for (X = 0; X < P->Width; ++X, ++Px) { Px->C.G = L[X]; } /* Read the B plane and move the data */ ReadPlane (F, P, L); for (X = 0; X < P->Width; ++X, ++Px) { Px->C.B = L[X]; } /* Either read the A plane or clear it */ if (P->Planes == 4) { ReadPlane (F, P, L); for (X = 0; X < P->Width; ++X, ++Px) { Px->C.A = L[X]; } } else { for (X = 0; X < P->Width; ++X, ++Px) { Px->C.A = 0; } } } } /* Close the file */ fclose (F); /* Free memory for the scan line */ xfree (L); /* Free the PCX header */ FreePCXHeader (P); /* Return the bitmap */ return B; }
void init() { RgnHandle tempRgn; Rect BaseRect; OSErr err; long QDfeature/*, OSfeature*/; GDHandle SaveGD; CGrafPtr SavePort; /* Initialize Managaer. */ //InitGraf(&qd.thePort); //InitWindows(); //InitDialogs(nil); InitCursor(); FlushEvents(everyEvent, 0); /* Set up menus. */ mymenu0 = GetMenu(appleID); //AppendResMenu(mymenu0, 'DRVR'); InsertMenu(mymenu0,0); mymenu1 = GetMenu(fileID); InsertMenu(mymenu1,0); DrawMenuBar(); DoneFlag = false; ThePict = GetPicture(PictID); if (ThePict == nil) DoneFlag = true; /* Use Gestalt to find is QuickDraw is avaiable. */ /*if ((GetOSTrapAddress(Gestalttest) != GetOSTrapAddress(NoTrap))) { err = Gestalt(gestaltQuickdrawVersion, &QDfeature); if (err) DoneFlag = true; err = Gestalt(gestaltSystemVersion, &OSfeature); if (err) DoneFlag = true; if (!DoneFlag && (QDfeature & 0x0f00) != 0x0200 && OSfeature < 0x0605) DoneFlag = true; } else DoneFlag = true;*/ err = Gestalt(gestaltQuickdrawVersion, &QDfeature); if (err != noErr || QDfeature < gestalt32BitQD) DoneFlag = true; /* Set Rects. */ SetRect(&BaseRect, 40, 60, 472, 282); SetRect(&WinMinusScroll, BaseRect.left-40, BaseRect.top-60, BaseRect.right-60, BaseRect.bottom - 80); SetRect(&InitWindowSize, WinMinusScroll.left, WinMinusScroll.top, WinMinusScroll.right, WinMinusScroll.bottom); tempRgn = GetGrayRgn(); HLock ((Handle) tempRgn); //TotalRect = (**tempRgn).rgnBBox; GetRegionBounds(tempRgn, &TotalRect); /*SetRect(&minRect, 80, 80, (**tempRgn).rgnBBox.right - 40, (**tempRgn).rgnBBox.bottom - 40);*/ SetRect(&minRect, 80, 80, TotalRect.right - 40, TotalRect.bottom - 40); HUnlock ((Handle) tempRgn); /* Open window and set up picture. */ GetGWorld (&SavePort, &SaveGD); mycolors = GetCTable (clutID); (*mycolors)->ctFlags |= 0x4000; myWindow = NewCWindow(nil, &BaseRect, (ConstStr255Param)"", true, zoomDocProc, (WindowPtr) -1, true, 150); SetGWorld(GetWindowPort(myWindow), SaveGD); DrawGrowIcon (myWindow); srcPalette = NewPalette (((**mycolors).ctSize)+1, mycolors, pmTolerant + pmExplicit + pmAnimated, 0); SetPalette ((WindowPtr) myWindow, srcPalette, true); GetGWorld (&SavePort, &SaveGD); err = NewGWorld (&offscreenGWorld, 8, &InitWindowSize, mycolors, nil, 0); if (err) Debugger(); SetGWorld (offscreenGWorld, nil); EraseRect (&InitWindowSize); DrawPicture (ThePict, &InitWindowSize); SetGWorld (SavePort, SaveGD); }
/* * Set up resources. */ void AddInitialResources() { ResAdd("Canvas", NewPixBuf(PIXBUF_CLUT, WIDTH, HEIGHT + 2)); ResAdd("Palette", NewPalette(256)); }