static void I_UploadNewPalette(int pal) { // This is used to replace the current 256 colour cmap with a new one // Used by 256 colour PseudoColor modes // Array of SDL_Color structs used for setting the 256-colour palette static SDL_Color* colours; static int cachedgamma; static size_t num_pals; if ((colours == NULL) || (cachedgamma != usegamma)) { int pplump = W_GetNumForName("PLAYPAL"); int gtlump = (W_CheckNumForName)("GAMMATBL",ns_prboom); register const byte * palette = W_CacheLumpNum(pplump); register const byte * const gtable = (const byte *)W_CacheLumpNum(gtlump) + 256*(cachedgamma = usegamma); register int i; num_pals = W_LumpLength(pplump) / (3*256); num_pals *= 256; if (!colours) { // First call - allocate and prepare colour array colours = malloc(sizeof(SDL_Color)*num_pals); } // set the colormap entries for (i=0 ; (size_t)i<num_pals ; i++) { colours[i].r = gtable[palette[0]]; colours[i].g = gtable[palette[1]]; colours[i].b = gtable[palette[2]]; palette += 3; } W_UnlockLumpNum(pplump); W_UnlockLumpNum(gtlump); num_pals/=256; } #ifdef RANGECHECK if ((size_t)pal >= num_pals) I_Error("I_UploadNewPalette: Palette number out of range (%d>=%d)", pal, num_pals); #endif // store the colors to the current display //SDL_SetColors(SDL_GetVideoSurface(), colours+256*pal, 0, 256); u32 i; for(i = 0; i < 256; i++) { u8 r, g, b; r = (u8)colours[i+256*pal].r; g = (u8)colours[i+256*pal].g; b = (u8)colours[i+256*pal].b; // Jefklak 20/11/06 - also update lower screen palette BG_PALETTE[i]=RGB8(r,g,b); if(!gen_console_enable) BG_PALETTE_SUB[i]=RGB8(r,g,b); } }
void hblankHandler() { int currentLine = REG_VCOUNT; REG_BG2HOFS = -currentLine; REG_BG2VOFS = -currentLine; if((currentLine & 1) != 0) { BG_COLORS[4] = RGB8(0x00, 0x00, 0xFF); } else { BG_COLORS[4] = RGB8(0x00, 0xff, 0x00); } }
static inline u32 xGetPixel(int x,int y,int screen) { int idx = ((x)*240) + (239-(y)); if (screen == 0) { return RGB8(TopFB[idx*3+2], TopFB[idx*3+1], TopFB[idx*3+0]); } else if (screen == 1) { return RGB8(TopRFB[idx*3+2], TopRFB[idx*3+1], TopRFB[idx*3+0]); } else { return RGB8(BottomFB[idx*3+2], BottomFB[idx*3+1], BottomFB[idx*3+0]); } }
int main() { irqInit(); irqEnable(IRQ_VBLANK); consoleInit(0, 4, 0, NULL, 0, 15); BG_COLORS[0]=RGB8(58,110,165); BG_COLORS[241]=RGB5(31,31,31); SetMode(MODE_0 | BG0_ON); /* verify that the overlays are indeed overlapping */ printf("overlay1_test: %p\noverlay2_test: %p\n", overlay1_test, overlay2_test); /* set overlay 1 and run code from it */ memcpy(__iwram_overlay_start, __load_start_iwram1, (int)__load_stop_iwram1 - (int)__load_start_iwram1); overlay1_test(); /* set overlay 2 and run code from it */ memcpy(__iwram_overlay_start, __load_start_iwram2, (int)__load_stop_iwram2 - (int)__load_start_iwram2); overlay2_test(); /* back to normal */ memcpy(__iwram_overlay_start, __load_start_iwram0, (int)__load_stop_iwram0 - (int)__load_start_iwram0); while(1); }
static void vblank() { flash-=2; if (flash<0) flash=0; u16 farg = RGB8(flash, flash, flash); palette::add(BG_COLORS, poelse_pal, 256, farg); noise::update(); blanks++; }
static void vblank() { flash-=4; if (flash<0) flash=0; u16 farg = RGB8(flash, flash, flash); palette::add(BG_COLORS, lattice_pal, 256, farg); fixed16 fader = (endBeat - timer::getBeat())*(1.0/4); if (fader<fixed16(1.0)) { int amt = fader.get_val()>>8; palette::boost(BG_COLORS, BG_COLORS, 256, amt-256); }
void videoInitMode0() { VBlankIntrWait(); // Create palette BG_COLORS[0] = RGB8(0xFF, 0xFF, 0xFF); BG_COLORS[1] = RGB8(0x00, 0x00, 0x00); BG_COLORS[2] = RGB8(0xFF, 0x00, 0x00); BG_COLORS[3] = RGB8(0x00, 0xFF, 0x00); BG_COLORS[4] = RGB8(0x00, 0x00, 0xFF); BG_COLORS[5] = RGB8(0xFF, 0x00, 0xFF); BG_COLORS[6] = RGB8(0xFF, 0xFF, 0x00); // Create tiles for(int i = 0; i< 64; i+=4) { *((s32 *)(TILE_BASE_ADR(0)+64*0+i)) = 0x00000000; *((s32 *)(TILE_BASE_ADR(0)+64*1+i)) = 0x01010101; *((s32 *)(TILE_BASE_ADR(0)+64*2+i)) = 0x02020202; *((s32 *)(TILE_BASE_ADR(0)+64*3+i)) = 0x03030303; *((s32 *)(TILE_BASE_ADR(0)+64*4+i)) = 0x04040404; *((s32 *)(TILE_BASE_ADR(0)+64*5+i)) = 0x05050505; *((s32 *)(TILE_BASE_ADR(0)+64*6+i)) = 0x06060606; } // create maps for(int y = 0; y < 32; y++) { for(int x = 0; x < 32; x++) { // Checkerboard if(((x ^ y) & 1) != 0) { MAP[8][y][x] = 0x0002; } else { MAP[8][y][x] = 0x0001; } // 32x32 block if(x < 4 && y < 4) { MAP[12][y][x] = 0x0004; } else { MAP[12][y][x] = 0x0000; } } } REG_BG3CNT = BG_256_COLOR | BG_SIZE_0 | BG_TILE_BASE(0) | BG_MAP_BASE(8) | BG_PRIORITY(2); REG_BG2CNT = BG_256_COLOR | BG_SIZE_0 | BG_TILE_BASE(0) | BG_MAP_BASE(12) | BG_PRIORITY(1); REG_BG3HOFS = 0; REG_BG3VOFS = 0; REG_BG2HOFS = 0; REG_BG2VOFS = 0; REG_DISPCNT = MODE_0 | BG2_ON | BG3_ON; }
void image_load_pcx(Image* image, const u8* pcx) { pcx_rgb24* pal; pcx_header* hdr = (pcx_header*)pcx; pcx += sizeof(pcx_header); //move past the header if (hdr->bpp != 8) return; if (hdr->version != 5) return; image->width = hdr->x2 - hdr->x1 + 1; image->height = hdr->y2 - hdr->y1 + 1; int size = image->width * image->height; int count = 0; image->data = (u8*)malloc(size); image->palette = (u16*)malloc(256 * 2); while (count < size) { u8 c = *pcx++; if (c < 192) { image->data[count++] = c; } else { int run = c - 192; c = *pcx++; for (int i = 0; i < run; i++) { image->data[count++] = c; } } } if (*pcx != 0x0C) return; pal = (pcx_rgb24*)(pcx + 1); for (int i = 0; i < 256; i++) { image->palette[i] = RGB8(pal[i].r, pal[i].g, pal[i].b); } }
void SIO_TurnColor(int n) { if (n == BG) TextColor(RGB8(0, 0, 0, 0)); // WHITE else if (n == NEUTRAL) TextColor(RGB8(0, 1, 0, 0)); // GREEN else if (n == P1) TextColor(RGB8(1, 0, 0, 1)); // RED else if (n == P2) TextColor(RGB8(0, 0, 1, 1)); // BLUE else if (n == P1_SEMI) TextColor(RGB8(1, 0, 0, 0)); // DARK RED else if (n == P2_SEMI) TextColor(RGB8(0, 0, 1, 0)); // DARK BLUE else if (n == CL_BT) TextColor(RGB8(0, 1, 0, 0)); // GREEN }
//--------------------------------------------------------------------------------- void consoleDemoInit() { //--------------------------------------------------------------------------------- // initialise the console // setting NULL & 0 for the font address & size uses the default font // The font should be a complete 1bit 8x8 ASCII font consoleInit( 0, // charbase 4, // mapbase 0, // background number NULL, // font 0, // font size 15 // 16 color palette ); // set the screen colors, color 0 is the background color // the foreground color is index 1 of the selected 16 color palette BG_COLORS[0]=RGB8(58,110,165); BG_COLORS[241]=RGB5(31,31,31); SetMode(MODE_0 | BG0_ON); }
static int NDS_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b, Uint8 a, const SDL_Rect * rect) { NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; SDL_Rect real_rect = *rect; u16 color; int i, j; printf("NDS_RenderFill: stub\n"); color = RGB8(r, g, b); /* macro in libnds that makes an ARGB1555 pixel */ /* TODO: make a single-color sprite and stretch it. calculate the "HDX" width modifier of the sprite by: let S be the actual sprite's width (like, 32 pixels for example) let R be the rectangle's width (maybe 50 pixels) HDX = (R<<8) / S; (it's fixed point, hence the bit shift. same goes for vertical. be sure to use 32-bit int's for the bit shift before the division!) */ return 0; }
//------------------------------------------------------------------------------ // Graphic Functions MODE_0 //------------------------------------------------------------------------------ void InitJAM () { irqInit(); irqEnable(IRQ_VBLANK); // setting NULL & 0 for the font address & size uses the default font consoleInit( 0, // charbase 4, // mapbase 0, // background number NULL, // font (should be a complete 1bit 8x8 ASCII font) 0, // font size 15 // 16 color palette ); //consoleDemoInit(); // set the screen colors, color 0 is the background color // the foreground color is index 1 of the selected 16 color palette BG_COLORS[0] = RGB8(58,110,165); BG_COLORS[241] = RGB5(31,31,31); SetMode(MODE_0 | BG0_ON); return; }
int main() { ProfTimer mProfTimer; unsigned char *sTextData = TextData(); float mArrVecParser_CSV[nWidthParser]; float mArrVecParserCopy[nWidthParser]; float mArrVecParserCopy2[nWidthParser]; DataOpen("1909175498_image_profile.csv", mArrVecParser_CSV); //DataOpen("-1916029922_image_profile.csv", mArrVecParser_CSV); while (1) { memcpy(mArrVecParserCopy, mArrVecParser_CSV, sizeof(float)* nWidthParser); Global::Image mImageParser(nWidthParser, nheightParser, Global::TYPE::BYTE, 3); Global::Image mImageParser2(nWidthParser, nheightParser, Global::TYPE::BYTE, 3); Global::Image mImageParserReSize(img_wid, img_hig, Global::TYPE::BYTE, 3); for (int i = 0; i < nWidthParser; i++) { Global::Circle(&mImageParser, i, mArrVecParserCopy[i], 1, RGB8(0, 0, 255)); } #if 0 int nXTest0 = 800; int nXTest1 = 900; int nTest; Sample sSample; sSample.nX0 = nXTest0; sSample.nX1 = nXTest1; Line(&mImageParser, mArrVecParserCopy, sSample,true); nXTest0 = 400; nXTest1 = 810; //Line(&mImageParser, nXTest0, nXTest1, mArrVecParserCopy, nTest, true); //DeletePoint(nWidthParser, nheightParser, 400, 700, mArrVecParserCopy); #endif #if 1 int nLineCount(1); const int nSample = 1000; Sample sSample[nSample]; while (nLineCount) { mProfTimer.Start(); nLineCount--; int nArrNumderSize(0); int nSampleCount(0); memset(sSample, 0, sizeof(Sample)* nSample); int nMaxSample = 0; int nMaxSampleArrNum = 0; while (nSample - nArrNumderSize) { float fCutLine = nheightParser / 1.2; int nRandX0 = (std::rand() % nWidthParser);//중복은 나중에 고려 int nRandX1 = (std::rand() % nWidthParser);//중복은 나중에 고려 if (nRandX0 == nRandX1 || mArrVecParserCopy[nRandX0] < fCutLine || mArrVecParserCopy[nRandX1] < fCutLine) { continue; } sSample[nSampleCount].nX0 = nRandX0; sSample[nSampleCount].nX1 = nRandX1; if (Line(&mImageParser, mArrVecParserCopy, sSample[nSampleCount])) { if (sSample[nSampleCount].nSn > nMaxSample && sSample[nSampleCount].nSn > 10) { nMaxSample = sSample[nSampleCount].nSn; nMaxSampleArrNum = nSampleCount; nSampleCount++; //printf(" nMaxSampleArrNum : %d \n", nMaxSampleArrNum); } nArrNumderSize++; } } //mVecParserCopy if (nSampleCount > 0) { Line(0, mArrVecParserCopy, sSample[nMaxSampleArrNum], true); memcpy(mArrVecParserCopy2, mArrVecParser_CSV, sizeof(float)* nWidthParser); ReAgainst(nWidthParser, nheightParser, sSample[nMaxSampleArrNum], mArrVecParserCopy2); } mProfTimer.Stop(); printf("mProfTimer : %f \n", mProfTimer.GetDurationInSecs()); if (nSampleCount > 0) { Line(&mImageParser, mArrVecParserCopy, sSample[nMaxSampleArrNum], true); DeletePoint(nWidthParser, nheightParser, sSample[nMaxSampleArrNum], mArrVecParserCopy); for (int i = 0; i < nWidthParser; i++) { Global::Circle(&mImageParser2, i, mArrVecParserCopy2[i], 2, RGB8(0, 0, 255)); } } //break; } #endif #if 0 Global::Show("Parser ", &mImageParser); Global::Show("Test ", &mImageParser2); #else Global::Filter2D(&mImageParser2, &mImageParser2, Global::FILTER::GAUSSIAN, 1); Global::ReSize(&mImageParser2, &mImageParserReSize); Global::Show("Test ", &mImageParserReSize); Global::Filter2D(&mImageParser, &mImageParser, Global::FILTER::GAUSSIAN, 1); Global::ReSize(&mImageParser, &mImageParserReSize); Global::Show("Parser ", &mImageParserReSize); #endif //Sleep(1); } delete sTextData; return 0; }
int Line(Global::Image *mImageParser, float* pParser_CSV, Sample &mSample, const bool bSw = false) { //float fRandY0 = GlobalTool::Max(pParser_CSV[nRandX0], pParser_CSV[nRandX1]); //float fRandY1 = GlobalTool::Min(pParser_CSV[nRandX0], pParser_CSV[nRandX1]); float fLSX[2000] = { 0, }; float fLSY[2000] = { 0, }; int nCount = 0; mSample.nSn = 0; float fRandY0 = pParser_CSV[mSample.nX0]; float fRandY1 = pParser_CSV[mSample.nX1]; //int nMaxArray = GlobalTool::Max(mSample.nX0, mSample.nX1); //int nMinArray = GlobalTool::Min(mSample.nX0, mSample.nX1); float fU = mSample.nX1 - mSample.nX0; float fV = fRandY1 - fRandY0; float fM = (fV / fU); float nSurchDiff0; if (fM < 0) { nSurchDiff0 = fSurchDiff; //printf("slope : %f %f \n",90 + degree, (atan(fM) * 180) / M_PI); } else { nSurchDiff0 = -fSurchDiff; //printf("slope : %f %f \n", 90 - degree, (atan(fM) * 180) / M_PI); } float fDegree = (atan(fM) * 180) / M_PI; //double rad = atan2(fU, fV); //double degree = ((rad * 180) / M_PI); if (abs(fDegree) >= 30) { //printf("height : %f %f \n", fRandY0, fRandY1); //printf("slope : %f \n", (atan(fM) * 180) / M_PI); return 0; } if (mImageParser && bSw) { Global::Circle(mImageParser, mSample.nX0, fRandY0, 15, RGB8(0, 255, 255)); Global::Circle(mImageParser, mSample.nX1, fRandY1, 15, RGB8(0, 255, 255)); //printf("slope : %f \n", atan(fM)); } for (int i = 1; i < nWidthParser - 1; i++) { float nY0 = fM * ((i - 1) - mSample.nX0) + fRandY0; float nY1 = fM * ((i + 1) - mSample.nX0) + fRandY0; //printf("x: %d y : %d y : %d \n", i, nY0, nY1); if (nY0 < nheightParser || nY0 > 0) { if (mImageParser) { //Global::Line(mImageParser, (i - 1), nY0, (i + 1), nY1, RGB8(0, 255, 0)); //Global::Line(mImageParser, (i - 1) - nSurchDiff0, nY0 - fSurchDiff, (i + 1) - nSurchDiff0, nY1 - fSurchDiff, RGB8(0, 255, 0)); //Global::Line(mImageParser, (i - 1) + nSurchDiff0, nY0 + fSurchDiff, (i + 1) + nSurchDiff0, nY1 + fSurchDiff, RGB8(0, 255, 0)); } if (pParser_CSV[i] != 0) { float fSurchPointMin = fM * ((i + 1) - mSample.nX0 + nSurchDiff0) + fRandY0; float fSurchPointMax = fM * ((i + 1) - mSample.nX0 - nSurchDiff0) + fRandY0; if (pParser_CSV[i + 1] > fSurchPointMin - nSurchDiff0 && pParser_CSV[i + 1] < fSurchPointMax + nSurchDiff0) { fLSX[nCount] = i + 1; fLSY[nCount++] = pParser_CSV[i + 1]; mSample.nSn++; if (mImageParser && bSw) { Global::Circle(mImageParser, i + 1, pParser_CSV[i + 1], 2, RGB8(255, 0, 0)); } } //Sleep(10); //Global::Show("Parser ", mImageParser); } } } if (bSw) { linreg(nCount, fLSX, fLSY, &mSample.m, &mSample.b, &mSample.r); //Global::Line(mImageParser, 1, m + b, (mImageParser->width - nSurchDiff0), m*(mImageParser->width - nSurchDiff0) + b, RGB8(255, 0, 0)); printf("m=%g b=%g r=%g Ag=%f MeanAg=%f \n", mSample.m, mSample.b, mSample.r, fDegree, (atan(mSample.m) * 180) / M_PI); } if (mImageParser && bSw) { for (int i = 1; i < nWidthParser - 1; i++) { float nY0 = mSample.m * (i - 1) + mSample.b; float nY1 = mSample.m * (i + 1) + mSample.b; if (nY0 < mImageParser->height || nY0 > 0) { Global::Line(mImageParser, (i - 1), nY0, (i + 1), nY1, RGB8(0, 255, 0)); } } } return 1; }
void blockDraw(World* world, Vec4i loc, VertexBuffer* buffer) { Block block=worldGet(world,loc); Vec4f baseColor; #define RGB8(r,g,b) (Vec4f){r/255.0,g/255.0,b/255.0,1.0} Vec4f woolColors[16]={ RGB8(222, 223, 222), RGB8(234, 127, 57), RGB8(192, 77, 200), RGB8(105, 140, 211), RGB8(194, 182, 36), RGB8( 56, 189, 52), RGB8(217, 132, 155), RGB8( 66, 66, 66), RGB8(158, 166, 166), RGB8( 39, 117, 149), RGB8(130, 55, 195), RGB8( 40, 52, 153), RGB8( 85, 50, 28), RGB8( 55, 76, 25), RGB8(164, 45, 40), RGB8( 26, 22, 22), }; switch(block_definition[block.id].color_mode) { case COLOR_NONE: baseColor=(Vec4f){1.0,1.0,1.0,1.0}; break; case COLOR_GRASS: baseColor=(Vec4f){0.2,0.9,0.1,1.0}; break; case COLOR_WOOL: baseColor=woolColors[block.metadata&0xf]; break; default: panic("unknown color mode"); } switch(block_definition[block.id].draw_mode) { case DRAW_TREE: blockDrawTree(world,loc,buffer,baseColor,block_definition[block.id].textures); break; case DRAW_BLOCK: blockDrawCube(world,loc,buffer,baseColor,block_definition[block.id].textures); break; case DRAW_GRASS: blockDrawCube(world,loc,buffer,baseColor,block_definition[block.id].textures); blockDrawCube(world,loc,buffer,(Vec4f){1.0,1.0,1.0,1.0},block_definition[3].textures); break; default: break; } }
TextureFormat const * TextureFormat::fromImageType(AbstractImage::Type type, bool is_depth) { if (is_depth) { switch (type) { case AbstractImage::Type::LUMINANCE_16U : return DEPTH16(); case AbstractImage::Type::LUMINANCE_32U : return DEPTH32(); case AbstractImage::Type::LUMINANCE_32F : return DEPTH32F(); default: throw Error("TextureFormat: No supported depth texture format corresponds to the specified image format"); } } enum { COLOR_ORDER_RGB, COLOR_ORDER_BGR } color_order; color_order = (AbstractImage::Channel::RED < AbstractImage::Channel::BLUE ? COLOR_ORDER_RGB : COLOR_ORDER_BGR); switch (type) { case AbstractImage::Type::LUMINANCE_8U : return L8(); case AbstractImage::Type::LUMINANCE_16U : return L16(); case AbstractImage::Type::LUMINANCE_32F : return L32F(); case AbstractImage::Type::RGB_8U : return color_order == COLOR_ORDER_RGB ? RGB8() : BGR8(); case AbstractImage::Type::RGBA_8U : return color_order == COLOR_ORDER_RGB ? RGBA8() : BGRA8(); case AbstractImage::Type::RGB_16U : return color_order == COLOR_ORDER_RGB ? RGB16() : BGR16(); case AbstractImage::Type::RGBA_16U : return color_order == COLOR_ORDER_RGB ? RGBA16() : BGRA16(); case AbstractImage::Type::RGB_32F : return color_order == COLOR_ORDER_RGB ? RGB32F() : BGR32F(); case AbstractImage::Type::RGBA_32F : return color_order == COLOR_ORDER_RGB ? RGBA32F() : BGRA32F(); default: throw Error("TextureFormat: No supported texture format corresponds to the specified image format"); } }
TextureFormat const * TextureFormat::fromCode(Code code) { switch (code) { case Code::L8: return L8(); case Code::L16: return L16(); case Code::L16F: return L16F(); case Code::L32F: return L32F(); case Code::A8: return A8(); case Code::A16: return A16(); case Code::A16F: return A16F(); case Code::A32F: return A32F(); case Code::LA4: return LA4(); case Code::LA8: return LA8(); case Code::LA16: return LA16(); case Code::LA16F: return LA16F(); break; case Code::LA32F: return LA32F(); case Code::RGB5: return RGB5(); case Code::RGB5A1: return RGB5A1(); case Code::RGB8: return RGB8(); case Code::RGB10: return RGB10(); case Code::RGB10A2: return RGB10A2(); case Code::RGB16: return RGB16(); case Code::RGB32F: return RGB32F(); case Code::R11G11B10F: return R11G11B10F(); case Code::RGB9E5F: return RGB9E5F(); case Code::RGB8I: return RGB8I(); case Code::RGB8UI: return RGB8UI(); case Code::ARGB8: return NULL; case Code::BGR8: return BGR8(); case Code::BGRA8: return BGRA8(); case Code::BGR16: return BGR16(); case Code::BGRA16: return BGRA16(); case Code::BGR32F: return BGR32F(); case Code::BGRA32F: return BGRA32F(); case Code::R8: return R8(); case Code::RG8: return RG8(); case Code::RG8I: return RG8I(); case Code::RG8UI: return RG8UI(); case Code::RG16F: return RG16F(); case Code::RGBA8: return RGBA8(); case Code::RGBA16: return RGBA16(); case Code::RGBA16F: return RGBA16F(); case Code::RGBA32F: return RGBA32F(); case Code::RGBA32UI: return RGBA32UI(); case Code::BAYER_RGGB8: // TODO case Code::BAYER_GRBG8: // TODO case Code::BAYER_GBRG8: // TODO case Code::BAYER_BGGR8: // TODO case Code::BAYER_RGGB32F: // TODO case Code::BAYER_GRBG32F: // TODO case Code::BAYER_GBRG32F: // TODO case Code::BAYER_BGGR32F: // TODO case Code::HSV8: // TODO case Code::HSV32F: // TODO return NULL; break; case Code::RGB_DXT1: return RGB_DXT1(); break; case Code::RGBA_DXT1: return RGBA_DXT1(); break; case Code::RGBA_DXT3: return RGBA_DXT3(); break; case Code::RGBA_DXT5: return RGBA_DXT5(); break; case Code::SRGB8: return SRGB8(); break; case Code::SRGBA8: return SRGBA8(); break; case Code::SL8: return SL8(); break; case Code::SLA8: return SLA8(); break; case Code::SRGB_DXT1: return SRGB_DXT1(); break; case Code::SRGBA_DXT1: return SRGBA_DXT1(); break; case Code::SRGBA_DXT3: return SRGBA_DXT3(); break; case Code::SRGBA_DXT5: return SRGBA_DXT5(); break; case Code::DEPTH16: return DEPTH16(); break; case Code::DEPTH24: return DEPTH24(); break; case Code::DEPTH32: return DEPTH32(); break; case Code::DEPTH32F: return DEPTH32F(); break; case Code::STENCIL1: return STENCIL1(); break; case Code::STENCIL4: return STENCIL4(); break; case Code::STENCIL8: return STENCIL8(); break; case Code::STENCIL16: return STENCIL16(); break; case Code::DEPTH24_STENCIL8: return DEPTH24_STENCIL8(); break; case Code::YUV420_PLANAR: return YUV420_PLANAR(); break; case Code::YUV422: return YUV422(); break; case Code::YUV444: return YUV444(); break; default: return NULL; } }
int DecodeGif(const u8 *userData, u8 ScreenBuff[160][240], u16* Palette) #endif { int i, j, Row, Col, Width, Height, ExtCode, Count; GifRecordType RecordType; GifByteType *Extension; GifFileType *GifFile; ColorMapObject *ColorMap; if ((GifFile = DGifOpen(userData, readFunc)) == NULL) { PrintGifError(); return EXIT_FAILURE; } for (i = 0; i < GifFile->SWidth; i++) /* Set its color to BackGround. */ ScreenBuff[0][i] = GifFile->SBackGroundColor; for (i = 1; i < GifFile->SHeight; i++) { memcpy(ScreenBuff[i], ScreenBuff[0], GifFile->SWidth); } /* Scan the content of the GIF file and load the image(s) in: */ do { if (DGifGetRecordType(GifFile, &RecordType) == GIF_ERROR) { PrintGifError(); return EXIT_FAILURE; } switch (RecordType) { case IMAGE_DESC_RECORD_TYPE: if (DGifGetImageDesc(GifFile) == GIF_ERROR) { PrintGifError(); return EXIT_FAILURE; } Row = GifFile->Image.Top; /* Image Position relative to Screen. */ Col = GifFile->Image.Left; Width = GifFile->Image.Width; Height = GifFile->Image.Height; // Update Color map ColorMap = (GifFile->Image.ColorMap ? GifFile->Image.ColorMap : GifFile->SColorMap); #ifdef _WIN32 ZeroMemory(pBMI, sizeof(BITMAPINFOHEADER) + 256*sizeof(RGBQUAD)); pBMI->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); pBMI->bmiHeader.biWidth = Width; pBMI->bmiHeader.biHeight = -Height; // negative for top-down bitmap pBMI->bmiHeader.biPlanes = 1; pBMI->bmiHeader.biBitCount = 8; pBMI->bmiHeader.biClrUsed = 256; pBMI->bmiHeader.biClrImportant = 256; i = ColorMap->ColorCount; while (--i >= 0) { RGBQUAD rgb; GifColorType* color = &ColorMap->Colors[i]; rgb.rgbRed = color->Red; rgb.rgbGreen = color->Green; rgb.rgbBlue = color->Blue; rgb.rgbReserved = 0; pBMI->bmiColors[i] = rgb; } #else i = ColorMap->ColorCount; while (--i >= 0) { GifColorType* pColor = &ColorMap->Colors[i]; Palette[i] = RGB8(GAMMA(pColor->Red), GAMMA(pColor->Green), GAMMA(pColor->Blue)); } #endif if (GifFile->Image.Left + GifFile->Image.Width > GifFile->SWidth || GifFile->Image.Top + GifFile->Image.Height > GifFile->SHeight) { return EXIT_FAILURE; } if (GifFile->Image.Interlace) { /* Need to perform 4 passes on the images: */ for (Count = i = 0; i < 4; i++) for (j = Row + InterlacedOffset[i]; j < Row + Height; j += InterlacedJumps[i]) { if (DGifGetLineByte(GifFile, &ScreenBuff[j][Col], Width) == GIF_ERROR) { PrintGifError(); return EXIT_FAILURE; } } } else { for (i = 0; i < Height; i++) { if (DGifGetLineByte(GifFile, &ScreenBuff[Row++][Col], Width) == GIF_ERROR) { PrintGifError(); return EXIT_FAILURE; } } } break; case EXTENSION_RECORD_TYPE: /* Skip any extension blocks in file: */ if (DGifGetExtension(GifFile, &ExtCode, &Extension) == GIF_ERROR) { PrintGifError(); return EXIT_FAILURE; } while (Extension != NULL) { if (DGifGetExtensionNext(GifFile, &Extension) == GIF_ERROR) { PrintGifError(); return EXIT_FAILURE; } } break; case TERMINATE_RECORD_TYPE: break; default: /* Should be traps by DGifGetRecordType. */ break; } } while (RecordType != TERMINATE_RECORD_TYPE); /* Close file when done */ if (DGifCloseFile(GifFile) == GIF_ERROR) { PrintGifError(); return EXIT_FAILURE; } return 0; }
//--------------------------------------------------------------------------------- // Program entry point //--------------------------------------------------------------------------------- int main(void) { //--------------------------------------------------------------------------------- // the vblank interrupt must be enabled for VBlankIntrWait() to work // since the default dispatcher handles the bios flags no vblank handler // is required int gamecount = 1; irqInit(); irqEnable(IRQ_VBLANK); //consoleDemoInit(); consoleInit( 0, /* charbase */ 4, /* mapbase */ 0, /* background number */ NULL, /* font */ 0, /* font size */ 15 /* 16 color palette */); BG_COLORS[0]=RGB8(0,0,0); BG_COLORS[241]=RGB5(31,31,31); SetMode(MODE_0 | BG0_ON); // ansi escape sequence to clear screen and home cursor // /x1b[line;columnH iprintf("\x1b[2J"); // ansi escape sequence to set print co-ordinates // /x1b[line;columnH // ansi escape sequence to move cursor up // /x1b[linesA // ansi escape sequence to move cursor left // /x1b[columnsD // ansi escape sequence to move cursor down // /x1b[linesB // ansi escape sequence to move cursor right // /x1b[columnsC iprintf("\x1b[0;0HGames: %d",gamecount); while (1) { VBlankIntrWait(); scanKeys(); int keys_pressed = keysDown(); int keys_released = keysUp(); if (keys_pressed & KEY_UP) { gamecount = gamecount + 1; iprintf("\x1b[0;0H "); iprintf("\x1b[0;0HGames: %d",gamecount); } if (keys_pressed & KEY_DOWN) { if (gamecount > 1) { gamecount = gamecount - 1; iprintf("\x1b[0;0H "); iprintf("\x1b[0;0HGames: %d",gamecount); } } if (keys_pressed & KEY_A) { wincount = 0; rollstats[0] = 0; rollstats[1] = 0; rollstats[2] = 0; rollstats[3] = 0; rollstats[4] = 0; rollstats[5] = 0; simulateCraps(gamecount); iprintf("\x1b[1;0HWe simulated %d games",gamecount); iprintf("\x1b[2;0HYou won %d games",wincount); printStats(); } } }
#include <gba_systemcalls.h> #include <gba_interrupt.h> #include "C:\Users\Chris\Desktop\Uni\Trimester 5 2015\GBA DEV\devkitPro\examples\gba\graphics\SimpleBGScroll\font/r6502_portfont.bin" // -------------------------------------------------------------------- #define MAPADDRESS MAP_BASE_ADR(31) // our base map address #define DELAY 2 // slow things down #define TILEWIDTH 8 // how much to scroll #define ROW 10 // what row to place text at // -------------------------------------------------------------------- const u16 palette[] = { RGB8(0x40,0x80,0xc0), RGB8(0xFF,0xFF,0xFF), RGB8(0xF5,0xFF,0xFF), RGB8(0xDF,0xFF,0xF2), RGB8(0xCA,0xFF,0xE2), RGB8(0xB7,0xFD,0xD8), RGB8(0x2C,0x4F,0x8B) }; // -------------------------------------------------------------------- const u8 message[] = { " " \ "Hello, this is an example of an oldschool simple tile scroller " \ "not unlike how it was done in days of yore. The '@' symbol " \ "at the top of your screen is intentional, to dispel the illusion " \