void LCD_Init() { rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPDEN); //MOSI gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO10); //CLK gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO11); //RST gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO12); //A0 gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO13); //CS gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO14); NCS_HI(); RST_HI(); lcd_delay(5); RST_LO(); lcd_delay(120); //11ms RST_HI(); lcd_delay(2500); AspiCmd(0xE2); lcd_delay(2500); lcd_screen_init(); lcd_delay(120); lcd_screen_init(); lcd_delay(120); AspiCmd(0xAF); //dc2=1, IC into exit SLEEP MODE, dc3=1 gray=ON, dc4=1 Green Enhanc mode disabled memset(img, 0, sizeof(img)); memset(dirty, 0, sizeof(dirty)); //Clear screen for (int y = 0; y < LCD_HEIGHT; y++) { lcd_set_row(y); AspiCmd(0xAF); CLK_HI(); A0_HI(); NCS_LO(); for (int x = 0; x < 212; x++) { //write_pixel(((x/53) % 2) ^ ((y / 16) %2)); write_pixel(0); } NCS_HI(); A0_HI(); AspiData(0); } }
void PrintBorder(){ int i, x1=5, y1=5, x2=315, y2=195, color1, color2; color1 = GREEN; color2 = RED; for(i=5;i<315;i++) write_pixel(i, y1, color1); //TOP for(i=5;i<315;i++) write_pixel(i, y1+2, color2); //TOP for(i=5;i<315;i++) write_pixel(i, y2, color1); //BOTTOM for(i=5;i<315;i++) write_pixel(i, y2+2, color2); //BOTTOM for(i=5;i<195;i++) write_pixel(x1, i, color2); //LEFT for(i=5;i<195;i++) write_pixel(x1+2, i, color1); //LEFT for(i=5;i<195;i++) write_pixel(x2, i, color2); //RIGHT for(i=5;i<195;i++) write_pixel(x2+2, i, color1); //RIGHT }
void PrintMenu(){ int i, y=55, color; color = RED; write_text("8-", 20, 20, GREEN, 1); write_text("Puzzle", 40, 20, RED, 1); write_text("A game by CMSC 125 Students", 55, 35, WHITE, 0); for(i=15;i<305;i++) write_pixel(i, y, color); write_text("Start Game", 100, 100, WHITE, 1); write_text("Quit", 100, 120, WHITE, 1); write_text("ICS-OS", 250, 160, WHITE, 1); }
/* paddle * Draw paddle at certain coordinate of specific colour * [x origin, y origin, colour] */ void paddle(int xc, int yc, short c) { int old_value = prev_p1_h; int x, y; if(xc == PADDLE_2_XOFF) { old_value = prev_p2_h; } if (yc < 26) { yc = 26; } if (yc > 150) { yc = 150; } for (y = old_value; y < (old_value+64); y++) { for (x = xc; x < (xc+8); x++) { write_pixel(x,y,C_GREEN); } } for (y = yc; y < (yc+64); y++) { for (x = xc; x < (xc+8); x++) { write_pixel(x,y,c); } } if(xc == PADDLE_2_XOFF) { prev_p2_h = yc; } else if (xc == PADDLE_1_XOFF) { prev_p1_h = yc; } }
/* palette * Print a colours like a swatch. Used for selecting colours/design elements * [row, colour] */ void palette(int r, short c) { int x, y; if(px == 320) { px = 0; } py = r*60; for (x = px; x < (x+8); x++) { for (y = py; y < (y+60); y++) { write_pixel(x,y,c); } } px += 8; py = r*60; }
/** * write_line: Draw a line of arbitrary angle. * * @param buff pointer to buffer to write in * @param x0 first x coordinate * @param y0 first y coordinate * @param x1 second x coordinate * @param y1 second y coordinate * @param mode 0 = clear, 1 = set, 2 = toggle */ void write_line(uint8_t *buff, int x0, int y0, int x1, int y1, int mode) { // Based on http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm int steep = abs(y1 - y0) > abs(x1 - x0); if (steep) { SWAP(x0, y0); SWAP(x1, y1); } if (x0 > x1) { SWAP(x0, x1); SWAP(y0, y1); } int deltax = x1 - x0; int deltay = abs(y1 - y0); int error = deltax / 2; int ystep; int y = y0; int x; // , lasty = y, stox = 0; if (y0 < y1) { ystep = 1; } else { ystep = -1; } for (x = x0; x < x1; x++) { if (steep) { write_pixel(buff, y, x, mode); } else { write_pixel(buff, x, y, mode); } error -= deltay; if (error < 0) { y += ystep; error += deltax; } } }
void render_image(char *fbp,int x,int y,char **image){ unsigned short int which_color = 0; unsigned long int imgdata_pos = 0; int r,g,b; int x_cur; int y_cur; x_cur = x; y_cur = y; printf("Image: %d x %d\n",atoi(image[0]),atoi(image[1])); if ( ( ( x + atoi(image[0]) ) > vinfo.xres ) || ( ( y + atoi(image[1]) ) > vinfo.yres ) ) { printf("Warning: Attempted to access beyond end of framebuffer device. Operation cancelled.\n"); } else { for ( imgdata_pos = 0; imgdata_pos < ( atoi(image[0]) * atoi(image[1]) * 3 ); imgdata_pos++) { switch ( which_color ) { case 0: r = image[2][imgdata_pos]; which_color++; break; case 1: g = image[2][imgdata_pos]; which_color++; break; case 2: b = image[2][imgdata_pos]; which_color = 0; write_pixel(fbp,x_cur,y_cur,r,g,b,0); if ( x_cur - x < ( atoi(image[0]) - 1 ) ){ x_cur++; } else { x_cur = x; y_cur++; } break; } } } }
int draw_square(char* buf, unsigned short x, unsigned short y, unsigned short size, unsigned long color) { coord_t pos; pos.x = x; pos.y = y; unsigned short i = 0; unsigned short j = 0; for(; i < size; i++) { for(; j < size; j++) { write_pixel(buf,pos,color); pos.x++; } j = 0; pos.y++; pos.x = x; } return 0; }
void SeqMeasureControl::ConstructRightBg(BRect bounds) { if ( !Window() ) return; BScreen screen( Window() ); mRightBg = new BBitmap(bounds, screen.ColorSpace() ); if (!mRightBg) return; pixel_access pa(mRightBg->ColorSpace() ); BRect b = mRightBg->Bounds(); rgb_color c = Prefs().Color( AM_MEASURE_TOP_BG_C ); float r_row_delta = 0, g_row_delta = 0, b_row_delta = 0; { rgb_color bc = Prefs().Color( AM_MEASURE_BOTTOM_BG_C ); float height = b.bottom; if (c.red != bc.red) r_row_delta = ((float)bc.red - (float)c.red) / height; if (c.green != bc.green) g_row_delta = ((float)bc.green - (float)c.green) / height; if (c.blue != bc.blue) b_row_delta = ((float)bc.blue - (float)c.blue) / height; } rgb_color rowC = c; rgb_color rightC = Prefs().Color( AM_MEASURE_RIGHT_BG_C ); float i = 1; for (float k=0; k<b.bottom; k++) { float r_col_delta = 0, g_col_delta = 0, b_col_delta = 0; float width = b.right; if (rowC.red != rightC.red) r_col_delta = ((float)rightC.red - (float)rowC.red) / width; if (rowC.green != rightC.green) g_col_delta = ((float)rightC.green - (float)rowC.green) / width; if (rowC.blue != rightC.blue) b_col_delta = ((float)rightC.blue - (float)rowC.blue) / width; for (float j=0; j<b.right; j++) { rgb_color c; c.red = (uint8)(rowC.red + (j * r_col_delta)); c.green = (uint8)(rowC.green + (j * g_col_delta)); c.blue = (uint8)(rowC.blue + (j * b_col_delta)); write_pixel(mRightBg, j, k, c, pa); } rowC.red = (uint8)(c.red + (i * r_row_delta)); rowC.green = (uint8)(c.green + (i * g_row_delta)); rowC.blue = (uint8)(c.blue + (i * b_row_delta)); i++; } }
/* Screen is 212 x 64 with 4bpp */ void LCD_DrawStop(void) { for (int y = 0; y < LCD_HEIGHT; y++) { if(! (dirty[y / 8] & (1 << (y % 8)))) continue; u8 *p = &img[(y / 8) * LCD_WIDTH]; u8 mask = 1 << (y % 8); lcd_set_row(y); AspiCmd(0xAF); CLK_HI(); A0_HI(); NCS_LO(); for (int x = 0; x < LCD_WIDTH; x++) { write_pixel(p[x] & mask); } NCS_HI(); A0_HI(); AspiData(0); } memset(dirty, 0, sizeof(dirty)); }
int draw_pixmap(char* buf, int xi, int yi, int height, int width, char* pix) { coord_t pos; pos.x = xi; pos.y = yi; unsigned short i = 0; unsigned short j = 0; for(; i < height; i++) { for(; j < width; j++) { if(*pix != 0) write_pixel(buf,pos,*pix); pix++; pos.x++; } j = 0; pos.y++; pos.x = xi; } return 0; }
void KGDAL2CV::write_ctable_pixel(const double& pixelValue, const GDALDataType& gdalType, GDALColorTable const* gdalColorTable, cv::Mat& image, const int& y, const int& x, const int& c){ if (gdalColorTable == NULL){ write_pixel(pixelValue, gdalType, 1, image, y, x, c); } // if we are Grayscale, then do a straight conversion if (gdalColorTable->GetPaletteInterpretation() == GPI_Gray){ write_pixel(pixelValue, gdalType, 1, image, y, x, c); } // if we are rgb, then convert here else if (gdalColorTable->GetPaletteInterpretation() == GPI_RGB){ // get the pixel short r = gdalColorTable->GetColorEntry((int)pixelValue)->c1; short g = gdalColorTable->GetColorEntry((int)pixelValue)->c2; short b = gdalColorTable->GetColorEntry((int)pixelValue)->c3; short a = gdalColorTable->GetColorEntry((int)pixelValue)->c4; write_pixel(r, gdalType, 4, image, y, x, 2); write_pixel(g, gdalType, 4, image, y, x, 1); write_pixel(b, gdalType, 4, image, y, x, 0); if (image.channels() > 3){ write_pixel(a, gdalType, 4, image, y, x, 1); } } // otherwise, set zeros else{ write_pixel(pixelValue, gdalType, 1, image, y, x, c); } }
void fill( int x, int y, int old_color, int new_color ) { /* Perform an interior-defined 4-connected fill. */ stack S ; if( init_stack( &S ) == ERROR ) { printf( INIT_ERR ) ; return ; } push_xy( &S, x, y ) ; while( !empty_stack( &S ) ) { pop_xy( &S, &x, &y ) ; if( read_pixel( x, y ) == old_color ) { write_pixel( x, y, new_color ) ; PUSH_XY( &S, x, ( y - 1 ) ) ; PUSH_XY( &S, x, ( y + 1 ) ) ; PUSH_XY( &S, ( x - 1 ), y ) ; PUSH_XY( &S, ( x + 1 ), y ) ; } } }
void light(int r, int c, int x, int y){ //prints a bulb light int i, color; switch(board[r][c]){ //sets the bulb's color case on: color = YELLOW; break; case son: color = WHITE; break; case off: color = DARK_BLUE; break; case soff: color = BLUE; break; } for (i=9;i<17;i++)write_pixel(i+x,2+y,color); for (i=7;i<19;i++)write_pixel(i+x,3+y,color); for (i=5;i<20;i++)write_pixel(i+x,4+y,color); for (i=4;i<21;i++)write_pixel(i+x,5+y,color); for (i=4;i<21;i++)write_pixel(i+x,6+y,color); for (i=3;i<22;i++)write_pixel(i+x,7+y,color); for (i=3;i<22;i++)write_pixel(i+x,8+y,color); for (i=4;i<21;i++)write_pixel(i+x,9+y,color); for (i=4;i<21;i++)write_pixel(i+x,10+y,color); for (i=5;i<20;i++)write_pixel(i+x,11+y,color); for (i=7;i<18;i++)write_pixel(i+x,12+y,color); for (i=9;i<17;i++)write_pixel(i+x,13+y,color); }
void light2(int x, int y, int color){ //prints bulb light without checking, int i; //explicit color defining for (i=9;i<17;i++)write_pixel(i+x,2+y,color); for (i=7;i<19;i++)write_pixel(i+x,3+y,color); for (i=5;i<20;i++)write_pixel(i+x,4+y,color); for (i=4;i<21;i++)write_pixel(i+x,5+y,color); for (i=4;i<21;i++)write_pixel(i+x,6+y,color); for (i=3;i<22;i++)write_pixel(i+x,7+y,color); for (i=3;i<22;i++)write_pixel(i+x,8+y,color); for (i=4;i<21;i++)write_pixel(i+x,9+y,color); for (i=4;i<21;i++)write_pixel(i+x,10+y,color); for (i=5;i<20;i++)write_pixel(i+x,11+y,color); for (i=7;i<18;i++)write_pixel(i+x,12+y,color); for (i=9;i<17;i++)write_pixel(i+x,13+y,color); }
cv::Mat KGDAL2CV::ImgReadByGDAL(GDALRasterBand* pBand, int xStart, int yStart, int xWidth, int yWidth) { m_width = pBand->GetXSize(); m_height = pBand->GetYSize(); m_nBand = 1; // check if we have a color palette int tempType; if (pBand->GetColorInterpretation() == GCI_PaletteIndex){ // remember that we have a color palette hasColorTable = true; // if the color tables does not exist, then we failed if (pBand->GetColorTable() == NULL){ return cv::Mat(); } // otherwise, get the pixeltype // convert the palette interpretation to opencv type tempType = gdalPaletteInterpretation2OpenCV(pBand->GetColorTable()->GetPaletteInterpretation(), pBand->GetRasterDataType()); if (tempType == -1){ return cv::Mat(); } m_type = tempType; } // otherwise, we have standard channels else{ // remember that we don't have a color table hasColorTable = false; // convert the datatype to opencv tempType = gdal2opencv(pBand->GetRasterDataType(), m_nBand); if (tempType == -1){ return cv::Mat(); } m_type = tempType; } if (xStart < 0 || yStart < 0 || xWidth < 1 || yWidth < 1 || xStart > m_width - 1 || yStart > m_height - 1) return cv::Mat(); if (xStart + xWidth > m_width) { std::cout << "The specified width is invalid, Automatic optimization is executed!" << std::endl; xWidth = m_width - xStart; } if (yStart + yWidth > m_height) { std::cout << "The specified height is invalid, Automatic optimization is executed!" << std::endl; yWidth = m_height - yStart; } cv::Mat img(yWidth, xWidth, m_type, cv::Scalar::all(0.f)); // iterate over each raster band // note that OpenCV does bgr rather than rgb GDALColorTable* gdalColorTable = NULL; if (pBand->GetColorTable() != NULL){ gdalColorTable = pBand->GetColorTable(); } const GDALDataType gdalType = pBand->GetRasterDataType(); //if (m_nBand > img.channels()){ // m_nBand = img.channels(); //} for (int c = 0; c < img.channels(); c++){ // grab the raster size if (hasColorTable && gdalColorTable->GetPaletteInterpretation() == GPI_RGB) c = img.channels() - 1; // create a temporary scanline pointer to store data double* scanline = new double[xWidth]; // iterate over each row and column for (int y = 0; y<yWidth; y++){ // get the entire row pBand->RasterIO(GF_Read, xStart, y + yStart, xWidth, 1, scanline, xWidth, 1, GDT_Float64, 0, 0); // set inside the image for (int x = 0; x<xWidth; x++){ // set depending on image types // given boost, I would use enable_if to speed up. Avoid for now. if (hasColorTable == false){ write_pixel(scanline[x], gdalType, m_nBand, img, y, x, c); } else{ write_ctable_pixel(scanline[x], gdalType, gdalColorTable, img, y, x, c); } } } // delete our temp pointer delete[] scanline; } return img; }
cv::Mat KGDAL2CV::ImgReadByGDAL(cv::String filename, int xStart, int yStart, int xWidth, int yWidth, bool beReadFourth) { m_filename = filename; if (!readHeader()) return cv::Mat(); int tempType = m_type; if (xStart < 0 || yStart < 0 || xWidth < 1 || yWidth < 1 || xStart > m_width - 1 || yStart > m_height - 1) return cv::Mat(); if (xStart + xWidth > m_width) { std::cout << "The specified width is invalid, Automatic optimization is executed!" << std::endl; xWidth = m_width - xStart; } if (yStart + yWidth > m_height) { std::cout << "The specified height is invalid, Automatic optimization is executed!" << std::endl; yWidth = m_height - yStart; } if (!beReadFourth && 4 == m_nBand) { for (unsigned int index = CV_8S; index < CV_USRTYPE1; ++index) { if (CV_MAKETYPE(index, m_nBand) == m_type) { std::cout << "We won't read the fourth band unless it's datatype is GDT_Byte!" << std::endl; //tempType = -1; tempType = tempType - ((3 << CV_CN_SHIFT) - (2 << CV_CN_SHIFT)); break; //tempType = CV_MAKETYPE(index, m_nBand); } } } cv::Mat img(yWidth, xWidth, tempType, cv::Scalar::all(0.f)); // iterate over each raster band // note that OpenCV does bgr rather than rgb int nChannels = m_dataset->GetRasterCount(); GDALColorTable* gdalColorTable = NULL; if (m_dataset->GetRasterBand(1)->GetColorTable() != NULL){ gdalColorTable = m_dataset->GetRasterBand(1)->GetColorTable(); } const GDALDataType gdalType = m_dataset->GetRasterBand(1)->GetRasterDataType(); //if (nChannels > img.channels()){ // nChannels = img.channels(); //} for (int c = 0; c < img.channels(); c++){ int realBandIndex = c; // get the GDAL Band GDALRasterBand* band = m_dataset->GetRasterBand(c + 1); //if (hasColorTable == false){ if (GCI_RedBand == band->GetColorInterpretation()) realBandIndex = 2; if (GCI_GreenBand == band->GetColorInterpretation()) realBandIndex = 1; if (GCI_BlueBand == band->GetColorInterpretation()) realBandIndex = 0; //} if (hasColorTable && gdalColorTable->GetPaletteInterpretation() == GPI_RGB) c = img.channels() - 1; // make sure the image band has the same dimensions as the image if (band->GetXSize() != m_width || band->GetYSize() != m_height){ return cv::Mat(); } // create a temporary scanline pointer to store data double* scanline = new double[xWidth]; // iterate over each row and column for (int y = 0; y<yWidth; y++){ // get the entire row band->RasterIO(GF_Read, xStart, y + yStart, xWidth, 1, scanline, xWidth, 1, GDT_Float64, 0, 0); // set inside the image for (int x = 0; x<xWidth; x++){ // set depending on image types // given boost, I would use enable_if to speed up. Avoid for now. if (hasColorTable == false){ write_pixel(scanline[x], gdalType, nChannels, img, y, x, realBandIndex); } else{ write_ctable_pixel(scanline[x], gdalType, gdalColorTable, img, y, x, c); } } } // delete our temp pointer delete[] scanline; } return img; }
cv::Mat KGDAL2CV::ImgReadByGDAL(GDALRasterBand* pBand) { m_width = pBand->GetXSize(); m_height = pBand->GetYSize(); m_nBand = 1; // check if we have a color palette int tempType; if (pBand->GetColorInterpretation() == GCI_PaletteIndex){ // remember that we have a color palette hasColorTable = true; // if the color tables does not exist, then we failed if (pBand->GetColorTable() == NULL){ return cv::Mat(); } // otherwise, get the pixeltype // convert the palette interpretation to opencv type tempType = gdalPaletteInterpretation2OpenCV(pBand->GetColorTable()->GetPaletteInterpretation(), pBand->GetRasterDataType()); if (tempType == -1){ return cv::Mat(); } m_type = tempType; } // otherwise, we have standard channels else{ // remember that we don't have a color table hasColorTable = false; // convert the datatype to opencv tempType = gdal2opencv(pBand->GetRasterDataType(), m_nBand); if (tempType == -1){ return cv::Mat(); } m_type = tempType; } cv::Mat img(m_height, m_width, m_type, cv::Scalar::all(0.f)); // iterate over each raster band // note that OpenCV does bgr rather than rgb GDALColorTable* gdalColorTable = NULL; if (pBand->GetColorTable() != NULL){ gdalColorTable = pBand->GetColorTable(); } const GDALDataType gdalType = pBand->GetRasterDataType(); int nRows, nCols; //if (m_nBand > img.channels()){ // m_nBand = img.channels(); //} for (int c = 0; c < img.channels(); c++){ // grab the raster size nRows = pBand->GetYSize(); nCols = pBand->GetXSize(); if (hasColorTable && gdalColorTable->GetPaletteInterpretation() == GPI_RGB) c = img.channels() - 1; // create a temporary scanline pointer to store data double* scanline = new double[nCols]; // iterate over each row and column for (int y = 0; y<nRows; y++){ // get the entire row pBand->RasterIO(GF_Read, 0, y, nCols, 1, scanline, nCols, 1, GDT_Float64, 0, 0); // set inside the image for (int x = 0; x<nCols; x++){ // set depending on image types // given boost, I would use enable_if to speed up. Avoid for now. if (hasColorTable == false){ write_pixel(scanline[x], gdalType, m_nBand, img, y, x, c); } else{ write_ctable_pixel(scanline[x], gdalType, gdalColorTable, img, y, x, c); } } } // delete our temp pointer delete[] scanline; } return img; }
/** * read data */ bool KGDAL2CV::readData(cv::Mat img){ // make sure the image is the proper size if (img.size().height != m_height){ return false; } if (img.size().width != m_width){ return false; } // make sure the raster is alive if (m_dataset == NULL || m_driver == NULL){ return false; } // set the image to zero img = 0; // iterate over each raster band // note that OpenCV does bgr rather than rgb int nChannels = m_dataset->GetRasterCount(); GDALColorTable* gdalColorTable = NULL; if (m_dataset->GetRasterBand(1)->GetColorTable() != NULL){ gdalColorTable = m_dataset->GetRasterBand(1)->GetColorTable(); } const GDALDataType gdalType = m_dataset->GetRasterBand(1)->GetRasterDataType(); int nRows, nCols; //if (nChannels > img.channels()){ // nChannels = img.channels(); //} for (int c = 0; c < img.channels(); c++){ int realBandIndex = c; // get the GDAL Band GDALRasterBand* band = m_dataset->GetRasterBand(c + 1); //if (hasColorTable == false){ if (GCI_RedBand == band->GetColorInterpretation()) realBandIndex = 2; if (GCI_GreenBand == band->GetColorInterpretation()) realBandIndex = 1; if (GCI_BlueBand == band->GetColorInterpretation()) realBandIndex = 0; //} if (hasColorTable && gdalColorTable->GetPaletteInterpretation() == GPI_RGB) c = img.channels() - 1; // make sure the image band has the same dimensions as the image if (band->GetXSize() != m_width || band->GetYSize() != m_height){ return false; } // grab the raster size nRows = band->GetYSize(); nCols = band->GetXSize(); // create a temporary scanline pointer to store data double* scanline = new double[nCols]; // iterate over each row and column for (int y = 0; y<nRows; y++){ // get the entire row band->RasterIO(GF_Read, 0, y, nCols, 1, scanline, nCols, 1, GDT_Float64, 0, 0); // set inside the image for (int x = 0; x<nCols; x++){ // set depending on image types // given boost, I would use enable_if to speed up. Avoid for now. if (hasColorTable == false){ write_pixel(scanline[x], gdalType, nChannels, img, y, x, realBandIndex); } else{ write_ctable_pixel(scanline[x], gdalType, gdalColorTable, img, y, x, c); } } } // delete our temp pointer delete[] scanline; } return true; }
void Erase(int x, int y, int w, int h){ //basically covers an area with a black rectangle int i,j; for (i=y;i<=(y+h);i++) for (j=x;j<=(x+w);j++) write_pixel(j,i,100); }
static void plot_minutiae(unsigned char *rgbdata, int width, int height, struct fp_minutia **minlist, int nr_minutiae) { int i; #define write_pixel(num) do { \ rgbdata[((num) * 3)] = 0xff; \ rgbdata[((num) * 3) + 1] = 0; \ rgbdata[((num) * 3) + 2] = 0; \ } while(0) for (i = 0; i < nr_minutiae; i++) { struct fp_minutia *min = minlist[i]; size_t pixel_offset = (min->y * width) + min->x; write_pixel(pixel_offset - 2); write_pixel(pixel_offset - 1); write_pixel(pixel_offset); write_pixel(pixel_offset + 1); write_pixel(pixel_offset + 2); write_pixel(pixel_offset - (width * 2)); write_pixel(pixel_offset - (width * 1) - 1); write_pixel(pixel_offset - (width * 1)); write_pixel(pixel_offset - (width * 1) + 1); write_pixel(pixel_offset + (width * 1) - 1); write_pixel(pixel_offset + (width * 1)); write_pixel(pixel_offset + (width * 1) + 1); write_pixel(pixel_offset + (width * 2)); } }
void gray(int x, int y){ //prints a gray bulb socket int i; for (i=8;i<18;i++)write_pixel(i+x,0+y,56); for (i=6;i<20;i++)write_pixel(i+x,1+y,56); for (i=4;i<21;i++)write_pixel(i+x,2+y,56); for (i=3;i<22;i++)write_pixel(i+x,3+y,56); for (i=2;i<23;i++)write_pixel(i+x,4+y,56); for (i=1;i<24;i++)write_pixel(i+x,5+y,56); for (i=1;i<25;i++)write_pixel(i+x,6+y,56); for (i=0;i<25;i++)write_pixel(i+x,7+y,56); for (i=0;i<25;i++)write_pixel(i+x,8+y,56); for (i=0;i<25;i++)write_pixel(i+x,9+y,56); for (i=0;i<25;i++)write_pixel(i+x,10+y,56); for (i=0;i<25;i++)write_pixel(i+x,11+y,56); for (i=1;i<24;i++)write_pixel(i+x,12+y,56); for (i=1;i<24;i++)write_pixel(i+x,13+y,56); for (i=2;i<23;i++)write_pixel(i+x,14+y,56); for (i=3;i<22;i++)write_pixel(i+x,15+y,56); for (i=5;i<20;i++)write_pixel(i+x,16+y,56); for (i=7;i<18;i++)write_pixel(i+x,17+y,56); for (i=9;i<15;i++)write_pixel(i+x,18+y,56); }
void mouseUp( int x, int y ) { write_pixel( x, y, 0xff, 0xff, 0x00 ); };
LLDSPEC void gdisp_lld_write_color(GDisplay *g) { write_pixel(g, gdispColor2Native(g->p.color)); }
RGBImage * image_gen_image_scale(RGBImage * data, int scale) { RGBImage *img; int x, y; int i, j; double cum_r, cum_g, cum_b; double avg_r, avg_g, avg_b; double min_color, max_color; int x_scale, y_scale; int columns, rows, nbytes; assert(data->rows); assert(data->columns); /* compute new real size */ columns = data->columns / scale; rows = data->rows / scale; nbytes = sizeof(RGBImage) + columns * rows * sizeof(RGBPixel); img = (RGBImage *) malloc(nbytes); if (img == NULL) { /* * XXX log */ printf("XXX failed to allocate image \n"); exit(1); } /* * First go through all the data to cmpute the number of rows, * max number of columns as well as the min and max values * for this image. */ img->columns = columns; img->rows = rows; img->nbytes = nbytes; img->type = data->type; min_color = 0; max_color = 255; #ifdef VERBOSE fprintf(stderr, "min color %f max %f diff %f \n", min_color, max_color, max_color - min_color); fprintf(stderr, "orig row %d col %d \n", data->columns, data->rows); fprintf(stderr, "scaled row %d col %d \n", img->columns, img->rows); #endif for (y = 0; y < img->rows; y++) { for (x = 0; x < img->columns; x++) { y_scale = y * scale; x_scale = x * scale; cum_r = cum_g = cum_b = 0; for (i = 0; i < scale; i++) { for (j = 0; j < scale; j++) { RGBPixel *pixel = &data->data[(y_scale + j) * data->columns + (x_scale + i)]; cum_r += pixel->r; cum_g += pixel->g; cum_b += pixel->b; } } avg_r = cum_r / ((double) (scale * scale)); avg_g = cum_g / ((double) (scale * scale)); avg_b = cum_b / ((double) (scale * scale)); if (avg_r < min_color) { avg_r = min_color; } if (avg_g < min_color) { avg_g = min_color; } if (avg_b < min_color) { avg_b = min_color; } if (avg_r > max_color) { avg_r = max_color; } if (avg_g > max_color) { avg_g = max_color; } if (avg_b > max_color) { avg_b = max_color; } write_pixel(img, x, y, (u_char) avg_r, (u_char) avg_g, (u_char) avg_b); } } #ifdef VERBOSE fprintf(stderr, "image_gen_image_scale\n"); #endif return (img); }
void mouseDown( int x, int y ) { write_pixel( x, y, 0xff, 0x00, 0x00 ); };
void MediaPluginExample::receiveMessage( const char* message_string ) { LLPluginMessage message_in; if ( message_in.parse( message_string ) >= 0 ) { std::string message_class = message_in.getClass(); std::string message_name = message_in.getName(); if ( message_class == LLPLUGIN_MESSAGE_CLASS_BASE ) { if ( message_name == "init" ) { LLPluginMessage message( "base", "init_response" ); LLSD versions = LLSD::emptyMap(); versions[ LLPLUGIN_MESSAGE_CLASS_BASE ] = LLPLUGIN_MESSAGE_CLASS_BASE_VERSION; versions[ LLPLUGIN_MESSAGE_CLASS_MEDIA ] = LLPLUGIN_MESSAGE_CLASS_MEDIA_VERSION; versions[ LLPLUGIN_MESSAGE_CLASS_MEDIA_BROWSER ] = LLPLUGIN_MESSAGE_CLASS_MEDIA_BROWSER_VERSION; message.setValueLLSD( "versions", versions ); std::string plugin_version = "Example media plugin, Example Version 1.0.0.0"; message.setValue( "plugin_version", plugin_version ); sendMessage( message ); } else if ( message_name == "idle" ) { // no response is necessary here. F64 time = message_in.getValueReal( "time" ); // Convert time to milliseconds for update() update( time ); } else if ( message_name == "cleanup" ) { // clean up here } else if ( message_name == "shm_added" ) { SharedSegmentInfo info; info.mAddress = message_in.getValuePointer( "address" ); info.mSize = ( size_t )message_in.getValueS32( "size" ); std::string name = message_in.getValue( "name" ); mSharedSegments.insert( SharedSegmentMap::value_type( name, info ) ); } else if ( message_name == "shm_remove" ) { std::string name = message_in.getValue( "name" ); SharedSegmentMap::iterator iter = mSharedSegments.find( name ); if( iter != mSharedSegments.end() ) { if ( mPixels == iter->second.mAddress ) { // This is the currently active pixel buffer. // Make sure we stop drawing to it. mPixels = NULL; mTextureSegmentName.clear(); }; mSharedSegments.erase( iter ); } else { //std::cerr << "MediaPluginExample::receiveMessage: unknown shared memory region!" << std::endl; }; // Send the response so it can be cleaned up. LLPluginMessage message( "base", "shm_remove_response" ); message.setValue( "name", name ); sendMessage( message ); } else { //std::cerr << "MediaPluginExample::receiveMessage: unknown base message: " << message_name << std::endl; }; } else if ( message_class == LLPLUGIN_MESSAGE_CLASS_MEDIA ) { if ( message_name == "init" ) { // Plugin gets to decide the texture parameters to use. LLPluginMessage message( LLPLUGIN_MESSAGE_CLASS_MEDIA, "texture_params" ); message.setValueS32( "default_width", mWidth ); message.setValueS32( "default_height", mHeight ); message.setValueS32( "depth", mDepth ); message.setValueU32( "internalformat", GL_RGBA ); message.setValueU32( "format", GL_RGBA ); message.setValueU32( "type", GL_UNSIGNED_BYTE ); message.setValueBoolean( "coords_opengl", false ); sendMessage( message ); } else if ( message_name == "size_change" ) { std::string name = message_in.getValue( "name" ); S32 width = message_in.getValueS32( "width" ); S32 height = message_in.getValueS32( "height" ); S32 texture_width = message_in.getValueS32( "texture_width" ); S32 texture_height = message_in.getValueS32( "texture_height" ); if ( ! name.empty() ) { // Find the shared memory region with this name SharedSegmentMap::iterator iter = mSharedSegments.find( name ); if ( iter != mSharedSegments.end() ) { mPixels = ( unsigned char* )iter->second.mAddress; mWidth = width; mHeight = height; mTextureWidth = texture_width; mTextureHeight = texture_height; init(); }; }; LLPluginMessage message( LLPLUGIN_MESSAGE_CLASS_MEDIA, "size_change_response" ); message.setValue( "name", name ); message.setValueS32( "width", width ); message.setValueS32( "height", height ); message.setValueS32( "texture_width", texture_width ); message.setValueS32( "texture_height", texture_height ); sendMessage( message ); } else if ( message_name == "load_uri" ) { std::string uri = message_in.getValue( "uri" ); if ( ! uri.empty() ) { }; } else if ( message_name == "mouse_event" ) { std::string event = message_in.getValue( "event" ); S32 button = message_in.getValueS32( "button" ); // left mouse button if ( button == 0 ) { int mouse_x = message_in.getValueS32( "x" ); int mouse_y = message_in.getValueS32( "y" ); std::string modifiers = message_in.getValue( "modifiers" ); if ( event == "move" ) { if ( mMouseButtonDown ) write_pixel( mouse_x, mouse_y, rand() % 0x80 + 0x80, rand() % 0x80 + 0x80, rand() % 0x80 + 0x80 ); } else if ( event == "down" ) { mMouseButtonDown = true; } else if ( event == "up" ) { mMouseButtonDown = false; } else if ( event == "double_click" ) { }; }; } else if ( message_name == "key_event" ) { std::string event = message_in.getValue( "event" ); S32 key = message_in.getValueS32( "key" ); std::string modifiers = message_in.getValue( "modifiers" ); if ( event == "down" ) { if ( key == ' ') { mLastUpdateTime = 0; update( 0.0f ); }; }; } else { //std::cerr << "MediaPluginExample::receiveMessage: unknown media message: " << message_string << std::endl; }; } else if ( message_class == LLPLUGIN_MESSAGE_CLASS_MEDIA_BROWSER ) { if ( message_name == "browse_reload" ) { mLastUpdateTime = 0; mFirstTime = true; mStopAction = false; update( 0.0f ); } else if ( message_name == "browse_stop" ) { for( int n = 0; n < ENumObjects; ++n ) mXInc[ n ] = mYInc[ n ] = 0; mStopAction = true; update( 0.0f ); } else { //std::cerr << "MediaPluginExample::receiveMessage: unknown media_browser message: " << message_string << std::endl; }; } else { //std::cerr << "MediaPluginExample::receiveMessage: unknown message class: " << message_class << std::endl; }; }; }
void mouseMove( int x, int y ) { write_pixel( x, y, 0xff, 0x00, 0xff ); };
void render_char(char *fbp,int x,int y,char **font,int charname,unsigned short int effects){ /* Effects: * 0 - None * 1 - Red * 2 - Green * 3 - Blue */ unsigned short int which_color = 0; unsigned long int fontdata_pos = 0; unsigned long int wanted_pos = 0; int r,g,b; int x_cur; int y_cur; x_cur = x; y_cur = y; if ( ( ( x + *font[0] ) > vinfo.xres ) || ( ( y + *font[1] ) > vinfo.yres ) ) { printf("Warning: Attempted to access beyond end of framebuffer device. Operation cancelled.\n"); } else { wanted_pos = (charname - 0x20) * *font[0] * *font[1] * 3; for ( fontdata_pos = wanted_pos; fontdata_pos < (wanted_pos+(*font[0] * *font[1] * 3)); fontdata_pos++) { switch ( which_color ) { case 0: r = font[2][fontdata_pos]; which_color++; break; case 1: g = font[2][fontdata_pos]; which_color++; break; case 2: b = font[2][fontdata_pos]; which_color = 0; if ( r == 0 && g == 0 && b == 0){ } else { switch ( effects ) { case 0: write_pixel(fbp,x_cur,y_cur,r,g,b,0); break; case 1: write_pixel(fbp,x_cur,y_cur,r,0,0,0); break; case 2: write_pixel(fbp,x_cur,y_cur,0,g,0,0); break; case 3: write_pixel(fbp,x_cur,y_cur,0,0,b,0); break; } } if ( x_cur - x < (*font[0] - 1) ){ x_cur++; } else { x_cur = x; y_cur++; } break; } } } }