int main(void){ ctr = 0; int i = 0; spi_init(); char *text; printf("Welcome to Nyancat, pls launch the music\n"); readBMP("nyan/nyblack2.bmp", buffer1); readBMP("nyan/nyblack.bmp", buffer2); while(42) { if((i%2)==0) { blit(buffer1,i); } else { blit(buffer2,i); } update(); usleep(100000); i++; } }
Examples() { Geometry3d::Vector zero(0, 0, 0); Geometry3d::Parallelogram screen(Geometry3d::Vector(1, 0, 0), Geometry3d::Vector(0, 1, 0), Geometry3d::Vector(0, 1, 1)); MyGL::Color red(200, 0, 0); redTriangle = MyGL::Scene(zero, screen, std::make_pair(700, 700)); Geometry3d::Shape *fig = (Geometry3d::Shape *)new Geometry3d::Triangle( Geometry3d::Vector(10, 0, 1), Geometry3d::Vector(0, 10, 0.3), Geometry3d::Vector(5, 5, 5)); redTriangle.addUnit(fig, red); redTriangle.addLight(Geometry3d::Vector(2, 0, 8), 100.); screen = Geometry3d::Parallelogram(Geometry3d::Vector(80, -5, -5), Geometry3d::Vector(80, 5, -5), Geometry3d::Vector(80, 5, 5)); greenSphere = MyGL::Scene(Geometry3d::Vector(100, 0, 0), screen, std::make_pair(700, 700), 1); fig = (Geometry3d::Shape *)new Geometry3d::Sphere( Geometry3d::Vector(-5, -10, -10), 7.5, Geometry3d::Sphere::MERCATOR); auto pic = readBMP("MyGL/Examples/earth.bmp"); greenSphere.addUnit(fig, pic); pic = readBMP("MyGL/Examples/earth2.bmp"); fig = (Geometry3d::Shape *)new Geometry3d::Sphere( Geometry3d::Vector(5, 10, 10), 7.5); greenSphere.addUnit(fig, pic); greenSphere.addLight(Geometry3d::Vector(100, 50, 50), 10000.); }
GLImageStructure readImage(const std::string& FileName, ImageType type_hint) { if (type_hint==itUnknown) { type_hint = getImageType(FileName); } switch (type_hint) { case itJPEG: return readJPEG(FileName); case itPNG: return readPNG(FileName); case itGIF: return readGIF(FileName); case itBitmap: return readBMP(FileName); case itPPM: return readPPM(FileName); } //no supported image here GLImageStructure temp_glis; temp_glis.setWidth(0); temp_glis.setHeight(0); temp_glis.setFormat(0); temp_glis.setBuffer(NULL); return temp_glis; }
int main() { FILE *input, *output; BMP bmp; int error; Color blue = {255, 0, 0}; char nombre[50]; scanf("%s",nombre); strcat(nombre,".bmp"); printf("%s",nombre); input = fopen(nombre, "rb"); error = 0; bmp = readBMP(input, &error); if (!error) { output = fopen("salida.bmp", "wb"); flipBMP(&bmp); //greyscaleBMP(&bmp); tintBMP(&bmp, blue); writeBMP(bmp, output); freeBMP(&bmp); fclose(output); } else { puts("error al leer archivo"); } fclose(input); }
void RayTracer::loadBGImage( char* fn ) { unsigned char *data; if( (data = readBMP(fn, bg_width, bg_height)) == NULL) { fl_alert( "Can't load bitmap file " ); } if(bg) { delete [] bg; } bg = data; }
void RayTracer::loadBackground(char* fn) { unsigned char* data = NULL; data = readBMP(fn, m_bWidth, m_bHeight); if (data){ if (backgroundImage)delete[] backgroundImage; useBackground = true; backgroundImage = data; } }
Scene *readHeights(char* fn) { int width, height; unsigned char *height_map; height_map = readBMP(fn, width, height); if (!height_map) { fl_alert("Error loading height map\n"); return false; } Scene * ret = new Scene(); //TODO: customize mat Material * mat = new Material(); mat->kd = vec3f(1.0, 1.0, 1.0); //extract the points Trimesh * trimesh = new Trimesh(ret, mat, &ret->transformRoot); for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x) { int pos = y * width + x; unsigned char pixel[3]; memcpy(pixel, height_map + pos * 3, 3); double height = double(pixel[0] + pixel[1] + pixel[2]) / 3 / 128; vec3f point(x, y, height); trimesh->addVertex(point); if (x > 0 && y > 0) { //link the points trimesh->addFace(pos, pos - 1, pos - 1 - width); trimesh->addFace(pos, pos - 1 - width, pos - width); } } } char *error; if (error = trimesh->doubleCheck()) throw ParseError(error); //add a trimesh ret->add(trimesh); //add a pointlight PointLight* point_light = new PointLight(ret, vec3f(width, height, 10), vec3f(1.0, 1.0, 1.0)); ret->add(point_light); //set the camerea //TODO: calculate the correct viewing distance; vec3f map_center((double)width / 2 - 0.5, (double)height / 2 - 0.5, 0.5); double camera_distance = (double)width + 3.0; vec3f camera_pos(0, -camera_distance, 2 * camera_distance); camera_pos += map_center; ret->getCamera()->setEye(camera_pos); ret->getCamera()->setLook((map_center - camera_pos).normalize(), vec3f(0, 0, 1).normalize()); return ret; }
// @override bool MaskBrush::init(void) { char* newfile = fl_file_chooser("Load mask image?", "*.bmp", fileName); if (newfile == NULL) { return false; } if ((data = readBMP(newfile, width, height)) == NULL) { fl_alert("Can't load bitmap file"); return false; } return true; }
TextureMap::TextureMap( string filename ) { data = readBMP( filename.c_str(), width, height ); if( 0 == data ) { width = 0; height = 0; string error( "Unable to load texture map '" ); error.append( filename ); error.append( "'." ); throw TextureMapException( error ); } }
void fileDLLToNet(char* filename) { char* header = NULL; int headerLen = 0; char* data = NULL; int dataLen = readBMP(filename,&header,&headerLen,&data); if (dataLen >0) { message headerMessage; headerMessage.code = END_HEADER; headerMessage.data = (char*)malloc(headerLen*sizeof(char)); memcpy(headerMessage.data,header,headerLen); headerMessage.dataLen = headerLen; packet* headerPackets = NULL; int headerPacketsLen = splitHeader(headerMessage,&headerPackets); int k; for (k = 0; k<headerPacketsLen; k++) { fromDLL(headerPackets[k]); free(headerPackets[k].mess.data); } free(headerPackets); free(headerMessage.data); message dataMessage; dataMessage.code = END_FILE; dataMessage.data = (char*)malloc(dataLen*sizeof(char)); memcpy(dataMessage.data,data,dataLen); dataMessage.dataLen = dataLen; packet* dataPackets = NULL; int dataPacketsLen = splitFile(dataMessage,&dataPackets); for (k = 0; k<dataPacketsLen; k++) { fromDLL(dataPackets[k]); free(dataPackets[k].mess.data); } free(dataPackets); free(dataMessage.data); } else printf("ERROR: Test file doesn't exist.\n"); free(header); free(data); }
void textureInitialization() { int height; int width; unsigned char* data = readBMP("hehe.bmp", width, height); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data); glDisable(GL_TEXTURE_2D); delete[]data; }
void ImgBuffer::loadImage(const char * filename) { originalPixelArray = readBMP(filename, _imgWidth, _imgHeight); padWidth = _imgWidth * 3; // 3 bytes per pixel int pad = 0; if (padWidth % 4 != 0) { // width is require to be multiple of 4 pad = 4 - (padWidth % 4); padWidth += pad; } contourPixelArray = new unsigned char[_imgHeight * padWidth]; memcpy(contourPixelArray, originalPixelArray, _imgHeight * padWidth); nodeBuffer = new Node[_imgHeight * _imgWidth]; initNodeBuffer(nodeBuffer, this); }
ColorPixels* loadBitmap(const char* filename, int &width, int &height) { int raw_width, raw_height; const char* const data = readBMP(filename, raw_width, raw_height); width = raw_width/SCALE_FACTOR; height = raw_height/SCALE_FACTOR; ColorPixels *c = new ColorPixels(); // scan goes in bitmap order - bottom left to top right for (int y = 0 ; y < height ; ++y) { for (int x = 0 ; x < width ; ++x) { int offset = (x + y * raw_width) * SCALE_FACTOR; const char* cursor = data + 3*offset; const Rgb rgb = {*cursor, *(cursor+1), *(cursor+2)}; if (c->find(rgb) == c->end()) { //printf("NOT FOUND: %x%x%x", rgb[0], rgb[1], rgb[2]); (*c)[rgb] = new ImageArea(width, height); } (*c)[rgb]->left = std::min((*c)[rgb]->left, x); (*c)[rgb]->right = std::min((*c)[rgb]->right, width - x - 1); (*c)[rgb]->bottom = std::min((*c)[rgb]->bottom, y); (*c)[rgb]->top = std::min((*c)[rgb]->top, height - y - 1); } } for (auto it : *c) { auto area = *it.second; area.height = width - area.left - area.right; area.width = height - area.top - area.bottom; area.present.resize(area.height * area.width); auto rgb = it.first; // printf("for the area with rgb %s its %i %i", rgb.c_str(), area.height, area.width); for (int y = area.bottom + area.height; y > area.bottom ; y--) { for (int x = area.left ; x < area.left + area.width ; x++) { int offset = (x + y * raw_width) * SCALE_FACTOR; auto cursor = data + offset; const Rgb rgb = {*cursor, *(cursor+1), (*cursor+2)}; if (it.first != rgb) { printf("Doing things to %d out of %d. hmmm so y is %d and top is %d\n", x + (height-area.top-y)*area.height, area.height*area.width, y, area.top); printf("height is %d\n", height); printf("r %d g %d b %d\n", std::get<0>(rgb), std::get<1>(rgb), std::get<2>(rgb)); area.present[x + (height-area.top-y)*area.height] = true; } } } } // don't delete data as we have pointers into it. instead, leak it! WOO return c; }
unsigned char* imageIO::openImage(char* filename) { std::string strFilename = std::string(filename); printf("%s", "Opening File: "); printf("%s \n", filename); if (strFilename.substr(strFilename.length() - 4) == ".bmp") { unsigned char* readData = readBMP(filename); return readData; } else if (strFilename.substr(strFilename.length() - 4) == ".png") { std::vector <unsigned char> buffer; loadPNG(filename, buffer); unsigned char* readData = new unsigned char[buffer.size()]; memcpy(readData, buffer.data(), buffer.size()); return readData; } }
int main(int argc, char *argv[]) { unsigned char* image; unsigned char header[54]; unsigned char end[1024]; unsigned char* final_image; float DesE = 20.0; int size; int window = 30; int TX,TY,p=4; double startT,stopT; int nt=4; if(isdigit(argv[1])){ p = atoi(argv[1]); if(p<1 || p>20) printf("# of threads should be between 1 and 20 - it runs 4 threads -> default"); else nt = p; } omp_set_num_threads(nt); startT = clock(); double ss = omp_get_wtime(); image = readBMP("lady1000.bmp",header,end,&size); //applying filter //extracting size TX = *(int*)&header[18]; TY = *(int*)&header[22]; final_image = (unsigned char*) malloc(size*sizeof(unsigned char)); //copy image copy_image(image,final_image,size); //applying filter promediador(image,TX,TY,window,final_image,DesE); //write final result writeBMP("exit.bmp",final_image,header,end,size); stopT = clock(); double ee = omp_get_wtime(); printf("%d processors; %f secs\n",p,ee-ss); }
int main(int argc, char **argv) { tagBITMAPFILEHEADER BITMAPFILEHEADER; tagBITMAPINFOHEADER BITMAPINFOHEADER; matrix image; char source_file_name[100]; parameters inputParameters; bool dontStopMeNow = true;//flag for help calling or incorrect parameters initParameters(inputParameters); readParameters(argc, argv, inputParameters, source_file_name[0], dontStopMeNow); //function: sort parameters by queue --> user can combine it as he want if (dontStopMeNow) { readBMP(BITMAPFILEHEADER, BITMAPINFOHEADER, image, source_file_name[0]); runFilters(inputParameters, BITMAPFILEHEADER, BITMAPINFOHEADER, image); writeBMP(BITMAPFILEHEADER, BITMAPINFOHEADER, image); } }
int main (void) { clock_t begin, einde; byte in[1280][1280], out[1280][1280]; readBMP (in, "ct-scan.bmp"); in_counter = 0; gtemp_counter = 0; gauss_counter = 0; edge_counter = 0; out_counter = 0; accux_counter = 0; accuy_counter = 0; buffer_counter = 0; memory_counter = 0; printf ("Version: %s\n", VERSION); printf ("----------------------------------------------------\n"); #ifdef COUNT_MEMORY_ACCESSES cavityDetection (in, out); if (in_counter != 0) printf ("in: %7d accesses\n", in_counter); if (gtemp_counter != 0) printf ("gtemp: %7d accesses\n", gtemp_counter); if (gauss_counter != 0) printf ("gauss: %7d accesses\n", gauss_counter); if (edge_counter != 0) printf ("edge: %7d accesses\n", edge_counter); if (out_counter != 0) printf ("out: %7d accesses\n", out_counter); if (accux_counter != 0) printf ("accux: %7d accesses\n", accux_counter); if (accuy_counter != 0) printf ("accuy: %7d accesses\n", accuy_counter); if (memory_counter != 0) printf ("memory: %7d accesses\n", memory_counter); printf ("----------------------------------------------------\n"); printf ("Total: %7d accesses\n", in_counter + gtemp_counter + gauss_counter + edge_counter + out_counter + accux_counter + accuy_counter + memory_counter); if (buffer_counter != 0) printf ("buffer: %7d accesses\n", buffer_counter); #else begin = clock(); for (int i = 0; i < NUMBER_OF_TEST_RUNS; i++) cavityDetection (in, out); einde = clock(); printf ("Execution time: %.1f ms\n", 1000 * (double) (einde - begin) / (double) CLOCKS_PER_SEC / (double) NUMBER_OF_TEST_RUNS); #endif printf ("----------------------------------------------------\n"); writeBMP (out, "output.bmp"); diffBMP ("output.bmp", "output-correct.bmp", "output-diff.bmp"); printf ("\n"); return 0; }
Terrain* gen_Terrain(char* filename,float height){ Image* image = readBMP(filename); int w = image->width; int h = image->height; Terrain* terrain = new Terrain(w,h); /* * Actually tx of terrain will range from 0 to h-1 * and tz of terrain will range from 0 to w-1 */ for(int tx=0;tx<h;tx++){ for(int tz=0;tz<w;tz++){ unsigned char color = image->imagedata[3*(tz*w+tx)]; float y = height*((color/255.0f)-0.5f); terrain->setHeight(tx,y,tz); } } delete image; terrain->computenormals(); return terrain; }
long main(long argc, char * argv[]) { long n, m, i, j; if (readBMP("in.bmp") == 0) { printf("Error"); return 0; } double ang =(double)angle/180.0 * M_PI; //угол задается define'ом long top, bot, lft, rgt; double sinn=sin(ang); double coss=cos(ang); n=hat.height; m=hat.width; //Вычиление координат углов после поворота long d1=newY(0,0,sinn,coss); long d2=newY(0,n-1,sinn,coss); long d3=newY(m-1,0,sinn,coss); long d4=newY(m-1,n-1,sinn,coss); top=max(d1, max(d2, max(d3, d4))); bot=min(d1, min(d2, min(d3, d4))); d1=newX(0,0,sinn,coss); d2=newX(0,n-1,sinn,coss); d3=newX(m-1,0,sinn,coss); d4=newX(m-1,n-1,sinn,coss); rgt=max(d1, max(d2, max(d3, d4))); lft=min(d1, min(d2, min(d3, d4))); pxl pic[top-bot+1][rgt-lft+1]; //новая картинка for(i=0; i<=top-bot; i++) for(j=0; j<=rgt-lft; j++){ //вычисление старых координат по новым d1=(i+bot)*sinn+(j+lft)*coss; d2=-(j+lft)*sinn+(i+bot)*coss; if(d1>=0 && d1<m && d2<n && d2>=0){ pic[i][j].a=img[d2][d1].a; pic[i][j].b=img[d2][d1].b; pic[i][j].c=img[d2][d1].c; } else{ pic[i][j].a=255; pic[i][j].b=255; pic[i][j].c=255; } } //изменение hat hat.width=rgt-lft+1; hat.height=top-bot+1; hat.size=(3*hat.width+hat.width%4)*hat.height+sizeof(hat); FILE* file = fopen("out.bmp","wb"); if(file == NULL) return 0; fwrite(&hat, sizeof(hat), 1, file); char dump[3]={255}; for(i=0; i<hat.height; i++){ for(j=0; j<hat.width; j++) fwrite(&pic[i][j], sizeof(pxl), 1, file); fwrite(dump, sizeof(char), hat.width%4, file); } fclose(file); return 0; }
void Texture::TextureBMP( GLuint name, char* fileName, int width, int height) { unsigned char* dataRGB ; unsigned char* data ; _name = name ; printf("file_name %s\n", fileName ) ; // open texture data dataRGB = readBMP( fileName, width, height); if ( dataRGB == NULL ) { printf("bitmap not read\n"); assert(false) ; } // make the texture contain all the given texture information in the alpha // channel only. with this we will only map the alpha channel - and not // affect the rgb channels in the textured area. data = new unsigned char [ 4 * width * height ] ; assert( data ) ; // calculate the intensity for each pix in the rgb data and copy to the rgba data. for ( int row = 0 ; row < height ; row ++ ) { for ( int col = 0 ; col < width ; col ++ ) { unsigned char luminance = 0.299 *dataRGB[ 3*( row*width + col) + 0] + 0.587 *dataRGB[ 3*( row*width + col) + 1] + 0.114 *dataRGB[ 3*( row*width + col) + 2] ; if (luminance < 50 ) luminance = 0 ; if ( luminance > 205 ) luminance = 255 ; data [ 4*( row*width + col ) + 0 ] = 255; data [ 4*( row*width + col ) + 1 ] = 255 ; data [ 4*( row*width + col ) + 2 ] = 255; data [ 4*( row*width + col ) + 3 ] = 255-luminance; } } glBindTexture( GL_TEXTURE_2D, _name ) ; glPixelStorei( GL_UNPACK_ALIGNMENT , 1 ) ; /*** Have to make sure that blending with colors is happening ***/ glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE , GL_MODULATE ) ; //glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE , GL_DECAL ) ; glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // length of stroke glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); // cross section of stroke // when texture area is small, bilinear filter the closest mipmap glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); // when texture area is large, bilinear filter the first mipmap glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data ); assert(glGetError() == GL_NO_ERROR); delete [] dataRGB ; delete [] data ; }