//センサで取得した値から何色かを識別する関数 int what_color(){ get_color_value(); if(IR > 40){ //ボールを持っているかの確認 return NO_BALL; } else{ if(R > 50 && G > 30 && B < 50){ //赤色だよー // printf("\tred\n"); return RED; } //ここの閾値がなんかなー else if(R > 90 && G > 100 && B > 40){ // if(R > 90 && G > 100 && B > 40) //それ以外は黄色じゃね? //printf("\tyello\n"); return YELLO; } else { //if( R < 50 && G > 30 && B > 50) //青色だよー //printf("\tblue\n"); return BLUE; } } }
void findMarks(jbyte* data, Count width,Count height) { int fillColor= 254; for ( Count y= height/8; y < 7*height/8; y++) { for ( Count x= width/8; x < 7*width/8; x++) { if ( get_color_value(data, x,y,width)== 255 ) { colorMark(data, width, height, x, y, fillColor); } } } }
void colorMark(jbyte* data, Count width, Count height, Count x, Count y, int fillColor) { set_color_value(data,x,y,width,fillColor); fillColor= 80; for (int delta_x= -1; delta_x <= 1; delta_x++) { for (int delta_y= -1; delta_y <= 1; delta_y++) { if ((delta_x != 0 || delta_y != 0)) { if (get_color_value(data,x+delta_x,y+delta_y,width) == 255) { colorMark(data,width,height,x+delta_x,y+delta_y,fillColor); } } } } }
/** * \brief Clears a rectangle of this surface. * * This is only supported for software surfaces. * The rectangle cleared becomes fully transparent. * * \param where The rectangle to clear. */ void Surface::clear(const Rectangle& where) { Debug::check_assertion(software_destination, "Partial surface clear is only supported with software surfaces"); if (internal_surface == nullptr) { // Nothing to do. return; } SDL_FillRect( internal_surface.get(), where.get_internal_rect(), get_color_value(Color::transparent) ); is_rendered = false; // The surface has changed. }
/** * \brief Clears this surface. * * The surface becomes fully transparent and its size remains unchanged. * The opacity property of the surface is preserved. */ void Surface::clear() { clear_subsurfaces(); internal_color = nullptr; if (internal_texture != nullptr) { internal_texture = nullptr; } if (internal_surface != nullptr) { if (software_destination) { SDL_FillRect( internal_surface.get(), nullptr, get_color_value(Color::transparent) ); } else { internal_surface = nullptr; } } }
/** * \brief Draws a subrectangle of this surface on another surface. * \param region The subrectangle to draw in this object. * \param dst_surface The destination surface. * \param dst_position Coordinates on the destination surface. */ void Surface::raw_draw_region( const Rectangle& region, Surface& dst_surface, const Point& dst_position) { if (dst_surface.software_destination // The destination surface is in RAM. || !Video::is_acceleration_enabled() // The rendering is in RAM. ) { if (dst_surface.internal_surface == nullptr) { dst_surface.create_software_surface(); } // First, draw subsurfaces if any. // They can exist if the video mode recently switched from an accelerated // one to a software one. if (!subsurfaces.empty()) { if (this->internal_surface == nullptr) { create_software_surface(); } std::vector<SubSurfaceNodePtr> subsurfaces = this->subsurfaces; this->subsurfaces.clear(); // Avoid infinite recursive calls if there are cycles. for (SubSurfaceNodePtr& subsurface: subsurfaces) { // TODO draw the subsurfaces of the whole tree recursively instead. // The current version is not correct because it handles only one level // (it ignores subsurface->subsurfaces). // Plus it needs the workaround above to avoid a stack overflow. subsurface->src_surface->raw_draw_region( subsurface->src_rect, *this, subsurface->dst_rect.get_xy() ); subsurface = nullptr; } clear_subsurfaces(); } if (this->internal_surface != nullptr) { // The source surface is not empty: draw it onto the destination. SDL_SetSurfaceBlendMode( this->internal_surface.get(), get_sdl_blend_mode() ); SDL_BlitSurface( this->internal_surface.get(), region.get_internal_rect(), dst_surface.internal_surface.get(), Rectangle(dst_position).get_internal_rect() ); } else if (internal_color != nullptr) { // No internal surface to draw: this may be a color. if (get_blend_mode() == BlendMode::BLEND && internal_color->get_alpha() == 255) { // Fill with opaque color: we can directly modify the destination pixels. Rectangle dst_rect( dst_position, region.get_size() ); SDL_FillRect( dst_surface.internal_surface.get(), dst_rect.get_internal_rect(), get_color_value(*internal_color) ); } else { // Fill with semi-transparent pixels: perform alpha-blending. create_software_surface(); SDL_FillRect( this->internal_surface.get(), nullptr, get_color_value(*internal_color) ); SDL_BlitSurface( this->internal_surface.get(), region.get_internal_rect(), dst_surface.internal_surface.get(), Rectangle(dst_position).get_internal_rect() ); } } } else { // The destination is a GPU surface (a texture). // Do not draw anything, just store the operation in the tree instead. // The actual drawing will be done at rendering time in GPU. SurfacePtr src_surface = std::static_pointer_cast<Surface>(shared_from_this()); dst_surface.add_subsurface(src_surface, region, dst_position); } dst_surface.is_rendered = false; }
int nv_write_config_file(const char *filename, CtrlHandles *h, ParsedAttribute *p, ConfigProperties *conf) { int screen, ret, entry, bit, val; FILE *stream; time_t now; AttributeTableEntry *a; ReturnStatus status; NVCTRLAttributeValidValuesRec valid; uint32 mask; CtrlHandleTarget *t; char *tmp_d_str, *prefix, scratch[4]; const char *tmp; char *locale = "C"; if (!filename) { nv_error_msg("Unable to open configuration file for writing."); return NV_FALSE; } stream = fopen(filename, "w"); if (!stream) { nv_error_msg("Unable to open file '%s' for writing.", filename); return NV_FALSE; } /* write header */ now = time(NULL); fprintf(stream, "#\n"); fprintf(stream, "# %s\n", filename); fprintf(stream, "#\n"); fprintf(stream, "# Configuration file for nvidia-settings - the NVIDIA " "X Server Settings utility\n"); /* NOTE: ctime(3) generates a new line */ fprintf(stream, "# Generated on %s", ctime(&now)); fprintf(stream, "#\n"); /* * set the locale to "C" before writing the configuration file to * reduce the risk of locale related parsing problems. Restore * the original locale before exiting this function. */ if (setlocale(LC_NUMERIC, "C") == NULL) { nv_warning_msg("Error writing configuration file '%s': could " "not set the locale 'C'.", filename); locale = conf->locale; } /* write the values in ConfigProperties */ write_config_properties(stream, conf, locale); /* for each screen, query each attribute in the table */ fprintf(stream, "\n"); fprintf(stream, "# Attributes:\n"); fprintf(stream, "\n"); /* * Note: we only save writable attributes addressable by X screen * (i.e., we don't look at other target types, yet). */ for (screen = 0; screen < h->targets[X_SCREEN_TARGET].n; screen++) { t = &h->targets[X_SCREEN_TARGET].t[screen]; /* skip it if we don't have a handle for this screen */ if (!t->h) continue; /* * construct the prefix that will be printed in the config * file infront of each attribute on this screen; this will * either be "[screen]" or "[displayname]". */ if (conf->booleans & CONFIG_PROPERTIES_INCLUDE_DISPLAY_NAME_IN_CONFIG_FILE) { prefix = t->name; } else { snprintf(scratch, 4, "%d", screen); prefix = scratch; } /* loop over all the entries in the table */ for (entry = 0; attributeTable[entry].name; entry++) { a = &attributeTable[entry]; /* * skip all attributes that are not supposed to be written * to the config file */ if (a->flags & NV_PARSER_TYPE_NO_CONFIG_WRITE) continue; /* * special case the color attributes because we want to * print floats */ if (a->flags & NV_PARSER_TYPE_COLOR_ATTRIBUTE) { float c[3], b[3], g[3]; status = NvCtrlGetColorAttributes(t->h, c, b, g); if (status != NvCtrlSuccess) continue; fprintf(stream, "%s%c%s=%f\n", prefix, DISPLAY_NAME_SEPARATOR, a->name, get_color_value(a->attr, c, b, g)); continue; } for (bit = 0; bit < 24; bit++) { mask = 1 << bit; /* * if this bit is not present in the screens's enabled * display device mask (and the X screen has enabled * display devices), skip to the next bit */ if (((t->d & mask) == 0x0) && (t->d)) continue; status = NvCtrlGetValidDisplayAttributeValues (t->h, mask, a->attr, &valid); if (status != NvCtrlSuccess) goto exit_bit_loop; if ((valid.permissions & ATTRIBUTE_TYPE_WRITE) == 0x0) goto exit_bit_loop; status = NvCtrlGetDisplayAttribute(t->h, mask, a->attr, &val); if (status != NvCtrlSuccess) goto exit_bit_loop; if (valid.permissions & ATTRIBUTE_TYPE_DISPLAY) { tmp_d_str = display_device_mask_to_display_device_name(mask); fprintf(stream, "%s%c%s[%s]=%d\n", prefix, DISPLAY_NAME_SEPARATOR, a->name, tmp_d_str, val); free(tmp_d_str); continue; } else { fprintf(stream, "%s%c%s=%d\n", prefix, DISPLAY_NAME_SEPARATOR, a->name, val); /* fall through to exit_bit_loop */ } exit_bit_loop: bit = 25; /* XXX force us out of the display device loop */ } /* bit */ } /* entry */ } /* screen */ /* * loop the ParsedAttribute list, writing the attributes to file. * note that we ignore conf->include_display_name_in_config_file * when writing these parsed attributes; this is because parsed * attributes (like the framelock properties) require a display * name be specified (since there are multiple X servers * involved). */ while (p) { char target_str[64]; if (!p->next) { p = p->next; continue; } tmp = nv_get_attribute_name(p->attr, NV_PARSER_TYPE_STRING_ATTRIBUTE, p->flags); if (!tmp) { nv_error_msg("Failure to save unknown attribute %d.", p->attr); p = p->next; continue; } /* * if the parsed attribute has a target specification, and a * target type other than an X screen, include a target * specification in what we write to the .rc file. */ target_str[0] = '\0'; if ((p->flags & NV_PARSER_HAS_TARGET) && (p->target_type != NV_CTRL_TARGET_TYPE_X_SCREEN)) { int j; /* Find the target name of the target type */ for (j = 0; targetTypeTable[j].name; j++) { if (targetTypeTable[j].nvctrl == p->target_type) { snprintf(target_str, 64, "[%s:%d]", targetTypeTable[j].parsed_name, p->target_id); break; } } } if (p->display_device_mask) { tmp_d_str = display_device_mask_to_display_device_name (p->display_device_mask); fprintf(stream, "%s%s%c%s[%s]=%d\n", p->display, target_str, DISPLAY_NAME_SEPARATOR, tmp, tmp_d_str, p->val); free(tmp_d_str); } else { fprintf(stream, "%s%s%c%s=%d\n", p->display, target_str, DISPLAY_NAME_SEPARATOR, tmp, p->val); } p = p->next; } setlocale(LC_NUMERIC, conf->locale); /* close the configuration file */ ret = fclose(stream); if (ret != 0) { nv_error_msg("Failure while closing file '%s'.", filename); return NV_FALSE; } return NV_TRUE; } /* nv_write_config_file() */
int nv_write_config_file(const char *filename, const CtrlSystem *system, const ParsedAttribute *p, const ConfigProperties *conf) { int ret, entry, val, randr_gamma_available; FILE *stream; time_t now; ReturnStatus status; CtrlAttributePerms perms; CtrlTargetNode *node; CtrlTarget *t; char *prefix, scratch[4]; char *locale = "C"; if (!filename) { nv_error_msg("Unable to open configuration file for writing."); return NV_FALSE; } stream = fopen(filename, "w"); if (!stream) { nv_error_msg("Unable to open file '%s' for writing.", filename); return NV_FALSE; } /* write header */ now = time(NULL); fprintf(stream, "#\n"); fprintf(stream, "# %s\n", filename); fprintf(stream, "#\n"); fprintf(stream, "# Configuration file for nvidia-settings - the NVIDIA " "X Server Settings utility\n"); /* NOTE: ctime(3) generates a new line */ fprintf(stream, "# Generated on %s", ctime(&now)); fprintf(stream, "#\n"); /* * set the locale to "C" before writing the configuration file to * reduce the risk of locale related parsing problems. Restore * the original locale before exiting this function. */ if (setlocale(LC_NUMERIC, "C") == NULL) { nv_warning_msg("Error writing configuration file '%s': could " "not set the locale 'C'.", filename); locale = conf->locale; } /* write the values in ConfigProperties */ write_config_properties(stream, conf, locale); /* for each screen, query each attribute in the table */ fprintf(stream, "\n"); fprintf(stream, "# Attributes:\n"); fprintf(stream, "\n"); /* * Note: we only save writable attributes addressable by X screen here * followed by attributes for display target types. */ for (node = system->targets[X_SCREEN_TARGET]; node; node = node->next) { t = node->t; /* skip it if we don't have a handle for this screen */ if (!t->h) continue; /* * construct the prefix that will be printed in the config * file in front of each attribute on this screen; this will * either be "[screen]" or "[displayname]". */ if (conf->booleans & CONFIG_PROPERTIES_INCLUDE_DISPLAY_NAME_IN_CONFIG_FILE) { prefix = t->name; } else { snprintf(scratch, 4, "%d", NvCtrlGetTargetId(t)); prefix = scratch; } /* loop over all the entries in the table */ for (entry = 0; entry < attributeTableLen; entry++) { const AttributeTableEntry *a = &attributeTable[entry]; /* * skip all attributes that are not supposed to be written * to the config file */ if (a->flags.no_config_write) { continue; } /* * special case the color attributes because we want to * print floats */ if (a->type == CTRL_ATTRIBUTE_TYPE_COLOR) { float c[3], b[3], g[3]; /* * if we are using RandR gamma, skip saving the color info */ status = NvCtrlGetAttribute(t, NV_CTRL_ATTR_RANDR_GAMMA_AVAILABLE, &val); if (status == NvCtrlSuccess && val) continue; status = NvCtrlGetColorAttributes(t, c, b, g); if (status != NvCtrlSuccess) continue; fprintf(stream, "%s%c%s=%f\n", prefix, DISPLAY_NAME_SEPARATOR, a->name, get_color_value(a->attr, c, b, g)); continue; } /* Only write out integer attributes, string and SDI CSC attributes * aren't written here. */ if (a->type != CTRL_ATTRIBUTE_TYPE_INTEGER) { continue; } /* * Ignore display attributes (they are written later on) and only * write attributes that can be written for an X screen target */ status = NvCtrlGetAttributePerms(t, a->type, a->attr, &perms); if (status != NvCtrlSuccess || !(perms.write) || !(perms.valid_targets & CTRL_TARGET_PERM_BIT(X_SCREEN_TARGET)) || (perms.valid_targets & CTRL_TARGET_PERM_BIT(DISPLAY_TARGET))) { continue; } status = NvCtrlGetAttribute(t, a->attr, &val); if (status != NvCtrlSuccess) { continue; } if (a->f.int_flags.is_display_id) { const char *name = NvCtrlGetDisplayConfigName(system, val); if (name) { fprintf(stream, "%s%c%s=%s\n", prefix, DISPLAY_NAME_SEPARATOR, a->name, name); } continue; } fprintf(stream, "%s%c%s=%d\n", prefix, DISPLAY_NAME_SEPARATOR, a->name, val); } /* entry */ } /* screen */ /* * Write attributes addressable to display targets */ for (node = system->targets[DISPLAY_TARGET]; node; node = node->next) { t = node->t; /* skip it if we don't have a handle for this display */ if (!t->h) continue; /* * check to see if we have RANDR gamma available. We may * skip writing attributes if it is missing. */ status = NvCtrlGetAttribute(t, NV_CTRL_ATTR_RANDR_GAMMA_AVAILABLE, &randr_gamma_available); if (status != NvCtrlSuccess) { randr_gamma_available = 0; } /* Get the prefix we want to use for the display device target */ prefix = create_display_device_target_string(t, conf); /* loop over all the entries in the table */ for (entry = 0; entry < attributeTableLen; entry++) { const AttributeTableEntry *a = &attributeTable[entry]; /* * skip all attributes that are not supposed to be written * to the config file */ if (a->flags.no_config_write) { continue; } /* * for the display target we only write color attributes for now */ if (a->type == CTRL_ATTRIBUTE_TYPE_COLOR) { float c[3], b[3], g[3]; if (!randr_gamma_available) continue; status = NvCtrlGetColorAttributes(t, c, b, g); if (status != NvCtrlSuccess) continue; fprintf(stream, "%s%c%s=%f\n", prefix, DISPLAY_NAME_SEPARATOR, a->name, get_color_value(a->attr, c, b, g)); continue; } /* Only write out integer attributes, string and SDI CSC attributes * aren't written here. */ if (a->type != CTRL_ATTRIBUTE_TYPE_INTEGER) { continue; } /* Make sure this is a display and writable attribute */ status = NvCtrlGetAttributePerms(t, a->type, a->attr, &perms); if (status != NvCtrlSuccess || !(perms.write) || !(perms.valid_targets & CTRL_TARGET_PERM_BIT(DISPLAY_TARGET))) { continue; } status = NvCtrlGetAttribute(t, a->attr, &val); if (status == NvCtrlSuccess) { fprintf(stream, "%s%c%s=%d\n", prefix, DISPLAY_NAME_SEPARATOR, a->name, val); } } free(prefix); } /* * loop the ParsedAttribute list, writing the attributes to file. * note that we ignore conf->include_display_name_in_config_file * when writing these parsed attributes; this is because parsed * attributes (like the framelock properties) require a display * name be specified (since there are multiple X servers * involved). */ while (p) { char target_str[64]; const AttributeTableEntry *a = p->attr_entry; if (!p->next) { p = p->next; continue; } /* * if the parsed attribute has a target specification, and a * target type other than an X screen, include a target * specification in what we write to the .rc file. */ target_str[0] = '\0'; if (p->parser_flags.has_target && (p->target_type != X_SCREEN_TARGET)) { const CtrlTargetTypeInfo *targetTypeInfo; /* Find the target name of the target type */ targetTypeInfo = NvCtrlGetTargetTypeInfo(p->target_type); if (targetTypeInfo) { snprintf(target_str, 64, "[%s:%d]", targetTypeInfo->parsed_name, p->target_id); } } if (a->flags.hijack_display_device) { fprintf(stream, "%s%s%c%s[0x%08x]=%d\n", p->display, target_str, DISPLAY_NAME_SEPARATOR, a->name, p->display_device_mask, p->val.i); } else { fprintf(stream, "%s%s%c%s=%d\n", p->display, target_str, DISPLAY_NAME_SEPARATOR, a->name, p->val.i); } p = p->next; } setlocale(LC_NUMERIC, conf->locale); /* close the configuration file */ ret = fclose(stream); if (ret != 0) { nv_error_msg("Failure while closing file '%s'.", filename); return NV_FALSE; } return NV_TRUE; } /* nv_write_config_file() */