/* --------------------------------------------------------------------------- * 函数名称:void Application(void) * 函数功能:读取图像数据,进行图像处理根据处理结果控制舵机方向与车速 * 输入形参:无 * 返回值:无 --------------------------------------------------------------------------- */ void Application(void) { Change_Speed(540); while(1) { /*如果图像数据可读*/ if(OV_State==Read) { /*屏蔽中断*/ EXTI_Config(DIS); /*读取图像*/ Read_Pic(); /*图像处理*/ Image_Process(); /*舵机、电调控制*/ Steer_control(); SpeedContiol(2500); /*图像处理完毕状态转换*/ OV_State=Wait_Vsync1; /*打开中断*/ EXTI_Config(EN); } } }
/* ================= LoadEntityIndexMap based on LoadAlphaMap() from terrain.c, a little more generic ================= */ void LoadEntityIndexMap( entity_t *e ) { int i, size, numLayers; const char *value, *indexMapFilename, *shader; char offset[ 4096 ], *search, *space; rgbdata_t *image; byte *pixels; uint *pixels32; indexMap_t *im; brush_t *b; parseMesh_t *p; if( e->brushes == NULL && e->patches == NULL ) return; value = ValueForKey( e, "_indexmap" ); if( value[0] == '\0' ) value = ValueForKey( e, "alphamap" ); if( value[0] == '\0' ) return; indexMapFilename = value; // get number of layers (support legacy "layers" key as well) value = ValueForKey( e, "_layers" ); if( value[0] == '\0' ) value = ValueForKey( e, "layers" ); if( value[0] == '\0' ) { Msg( "Warning: Entity with index/alpha map \"%s\" has missing \"_layers\" or \"layers\" key\n", indexMapFilename ); Msg( "Entity will not be textured properly. Check your keys/values.\n" ); return; } numLayers = com.atoi( value ); if( numLayers < 1 ) { Msg( "Warning: Entity with index/alpha map \"%s\" has < 1 layer (%d)\n", indexMapFilename, numLayers ); Msg( "Entity will not be textured properly. Check your keys/values.\n" ); return; } // get base shader name (support legacy "shader" key as well) value = ValueForKey( mapEnt, "_shader" ); if( value[0] == '\0' ) value = ValueForKey( e, "shader" ); if( value[0] == '\0' ) { Msg( "Warning: Entity with index/alpha map \"%s\" has missing \"_shader\" or \"shader\" key\n", indexMapFilename ); Msg( "Entity will not be textured properly. Check your keys/values.\n" ); return; } shader = value; MsgDev( D_NOTE, "Entity %d (%s) has shader index map \"%s\"\n", mapEnt->mapEntityNum, ValueForKey( e, "classname" ), indexMapFilename ); image = FS_LoadImage( indexMapFilename, NULL, 0 ); if( !image ) return; Image_Process( &image, 0, 0, IMAGE_FORCE_RGBA ); size = image->width * image->height; pixels = Malloc( size ); pixels32 = (uint *)image->buffer; for( i = 0; i < size; i++ ) { pixels[i] = ((pixels32[i] & 0xFF) * numLayers) / 256; if( pixels[i] >= numLayers ) pixels[i] = numLayers - 1; } // the index map must be at least 2x2 pixels if( image->width < 2 || image->height < 2 ) { Msg( "Warning: Entity with index/alpha map \"%s\" is smaller than 2x2 pixels\n", indexMapFilename ); Msg( "Entity will not be textured properly. Check your keys/values.\n" ); FS_FreeImage( image ); return; } // create a new index map im = Malloc( sizeof( *im )); im->w = image->width; im->h = image->height; im->numLayers = numLayers; com.strncpy( im->name, indexMapFilename, sizeof( im->name )); com.strncpy( im->shader, shader, sizeof( im->shader )); im->pixels = pixels; value = ValueForKey( mapEnt, "_offsets" ); if( value[0] == '\0' ) value = ValueForKey( e, "offsets" ); if( value[0] != '\0' ) { // value is a space-seperated set of numbers com.strncpy( offset, value, sizeof( offset )); search = offset; for( i = 0; i < 256 && *search != '\0'; i++ ) { space = com.strstr( search, " " ); if( space != NULL ) *space = '\0'; im->offsets[i] = com.atof( search ); if( space == NULL ) break; search = space + 1; } } // store the index map in every brush/patch in the entity for( b = e->brushes; b != NULL; b = b->next ) b->im = im; for( p = e->patches; p != NULL; p = p->next ) p->im = im; FS_FreeImage( image ); }
/* ================= VID_CubemapShot ================= */ qboolean VID_CubemapShot( const char *base, uint size, const float *vieworg, qboolean skyshot ) { rgbdata_t *r_shot, *r_side; byte *temp = NULL; byte *buffer = NULL; string basename; int i = 1, flags, result; if( !RI.drawWorld || !cl.worldmodel ) return false; // make sure the specified size is valid while( i < size ) i<<=1; if( i != size ) return false; if( size > glState.width || size > glState.height ) return false; // setup refdef RI.params |= RP_ENVVIEW; // do not render non-bmodel entities // alloc space temp = Mem_Alloc( r_temppool, size * size * 3 ); buffer = Mem_Alloc( r_temppool, size * size * 3 * 6 ); r_shot = Mem_Alloc( r_temppool, sizeof( rgbdata_t )); r_side = Mem_Alloc( r_temppool, sizeof( rgbdata_t )); // use client vieworg if( !vieworg ) vieworg = cl.refdef.vieworg; for( i = 0; i < 6; i++ ) { // go into 3d mode R_Set2DMode( false ); if( skyshot ) { R_DrawCubemapView( vieworg, r_skyBoxInfo[i].angles, size ); flags = r_skyBoxInfo[i].flags; } else { R_DrawCubemapView( vieworg, r_envMapInfo[i].angles, size ); flags = r_envMapInfo[i].flags; } pglReadPixels( 0, 0, size, size, GL_RGB, GL_UNSIGNED_BYTE, temp ); r_side->flags = IMAGE_HAS_COLOR; r_side->width = r_side->height = size; r_side->type = PF_RGB_24; r_side->size = r_side->width * r_side->height * 3; r_side->buffer = temp; if( flags ) Image_Process( &r_side, 0, 0, 0.0f, flags, NULL ); Q_memcpy( buffer + (size * size * 3 * i), r_side->buffer, size * size * 3 ); } RI.params &= ~RP_ENVVIEW; r_shot->flags = IMAGE_HAS_COLOR; r_shot->flags |= (skyshot) ? IMAGE_SKYBOX : IMAGE_CUBEMAP; r_shot->width = size; r_shot->height = size; r_shot->type = PF_RGB_24; r_shot->size = r_shot->width * r_shot->height * 3 * 6; r_shot->palette = NULL; r_shot->buffer = buffer; // make sure what we have right extension Q_strncpy( basename, base, MAX_STRING ); FS_StripExtension( basename ); FS_DefaultExtension( basename, ".tga" ); // write image as 6 sides result = FS_SaveImage( basename, r_shot ); FS_FreeImage( r_shot ); FS_FreeImage( r_side ); return result; }
qboolean VID_ScreenShot( const char *filename, int shot_type ) { rgbdata_t *r_shot; uint flags = IMAGE_FLIP_Y; int width = 0, height = 0; qboolean result; r_shot = Mem_Alloc( r_temppool, sizeof( rgbdata_t )); r_shot->width = (glState.width + 3) & ~3; r_shot->height = (glState.height + 3) & ~3; r_shot->flags = IMAGE_HAS_COLOR | IMAGE_HAS_ALPHA; r_shot->type = PF_RGBA_32; r_shot->size = r_shot->width * r_shot->height * PFDesc[r_shot->type].bpp; r_shot->palette = NULL; r_shot->buffer = Mem_Alloc( r_temppool, r_shot->size ); // get screen frame pglPixelStorei(GL_PACK_ALIGNMENT, 1); // PANDORA, just in case pglReadPixels( 0, 0, r_shot->width, r_shot->height, GL_RGBA, GL_UNSIGNED_BYTE, r_shot->buffer ); switch( shot_type ) { case VID_SCREENSHOT: if( !gl_overview->integer ) VID_ImageAdjustGamma( r_shot->buffer, r_shot->width, r_shot->height ); // scrshot gamma break; case VID_SNAPSHOT: if( !gl_overview->integer ) VID_ImageAdjustGamma( r_shot->buffer, r_shot->width, r_shot->height ); // scrshot gamma FS_AllowDirectPaths( true ); break; case VID_LEVELSHOT: flags |= IMAGE_RESAMPLE; if( glState.wideScreen ) { height = 480; width = 800; } else { height = 480; width = 640; } break; case VID_MINISHOT: flags |= IMAGE_RESAMPLE; height = 200; width = 320; break; case VID_MAPSHOT: V_WriteOverviewScript(); // store overview script too flags |= IMAGE_RESAMPLE|IMAGE_QUANTIZE; // GoldSrc request overviews in 8-bit format height = 768; width = 1024; break; } Image_Process( &r_shot, width, height, 0.0f, flags, NULL ); // write image result = FS_SaveImage( filename, r_shot ); host.write_to_clipboard = false; // disable write to clipboard FS_AllowDirectPaths( false ); // always reset after store screenshot FS_FreeImage( r_shot ); return result; }