int image_hsi_of_block(void *image_, int x, int y, float *hue, float *saturation, float *intensity) { struct image *image = image_; int i, j, n, w, h; unsigned char *rgb; w = BLOCK_WIDTH; h = BLOCK_HEIGHT; if(x+w > image_width(image_)) w -= image_width(image_)-x; if(y+h > image_height(image_)) h -= image_height(image_)-y; rgb = image->rgb + x + (y * bytes_per_scanline(image)); for(i = 0, n = 0; i < h; i++, rgb += 3*(image_width(image_)-w)) { for(j = 0; j < w; j++, n++, rgb += 3, hue++, saturation++, intensity++) { float r, g, b, sum; sum = rgb[0] + rgb[1] + rgb[2] + EPSILON_F; r = (float)rgb[0] / sum; g = (float)rgb[1] / sum; b = (float)rgb[2] / sum; *hue = acosf((0.5 * ((r-g) + (r-b))) / (EPSILON_F + sqrtf(((r-g)*(r-g)) + ((r-b) * (g-b))))); if(b > g) *hue = (2.0*M_PI_F) - *hue; *saturation = 1.0 - 3.0 * minf(r, g, b); *intensity = (float)(rgb[0]+rgb[1]+rgb[2]) / 765.0; } } return n; }
int bilinear_intensity(Image* image, float x, float y, int padding) { int left_x = (int)x; int top_y = (int)y; int right_x = left_x + 1; int bottom_y = top_y + 1; float delta_y = y - top_y; float delta_x = x - left_x; if (right_x < image_width(image) && bottom_y < image_height(image)) { int top = (1 - delta_x)*image_get_pixel_intensity(image, left_x, top_y) + delta_x*image_get_pixel_intensity(image, right_x, top_y); int bottom = (1 - delta_x)*image_get_pixel_intensity(image, left_x, bottom_y) + delta_x*image_get_pixel_intensity(image, right_x, bottom_y); return (1 - delta_y)*top + delta_y*bottom; } else if (right_x < image_width(image)) { int top = (1 - delta_x)*image_get_pixel_intensity(image, left_x, top_y) + delta_x*image_get_pixel_intensity(image, right_x, top_y); int bottom = padding; return (1 - delta_y)*top + delta_y*bottom; } else if (bottom_y < image_height(image)) { int top = (1 - delta_x)*image_get_pixel_intensity(image, left_x, top_y) + delta_x*padding; int bottom = (1 - delta_x)*image_get_pixel_intensity(image, left_x, bottom_y) + delta_x*padding; return (1 - delta_y)*top + delta_y*bottom; } else { int top = (1 - delta_x)*image_get_pixel_intensity(image, left_x, top_y) + delta_x*padding; int bottom = padding; return (1 - delta_y)*top + delta_y*bottom; } }
Image* image_convolution(Image* image, Matrix* matrix) { int height = image_height(image); int width = image_width(image); int new_height = (height - matrix->row_count) + 1; int new_width = (width - matrix->column_count) + 1; Image* output = image_blank_copy(image, new_width, new_height); int top = (matrix->row_count / 2); int bottom = height - (matrix->row_count / 2 + matrix->row_count % 2) + 1; int left = (matrix->column_count / 2); int right = width - (matrix->column_count / 2 + matrix->column_count % 2) + 1; for (int y = top; y < bottom ; y++) { for (int x = left; x < right; x++) { assert(y < image_height(image)); assert(x < image_width(image)); assert(y - top < image_height(output)); assert(x - left < image_width(output)); assert(y - top >= 0); assert(x - left >= 0); int value = pixel_convolution(image, matrix, y, x); image_set_pixel_intensity(output, x - left, y - top, value); } } return output; }
float min_rotation_step(Image* image) { int width = image_width(image); int height = image_height(image); int mid_x = width / 2; int mid_y = height / 2; float degrees = 45; float radians = degrees_to_radians(45); float x = 0; float y = 0; float current_x = 0; float current_y = 0; float next_x = cos(radians)*(x - mid_x) + sin(radians)*(y - mid_y) + mid_x; float next_y = -sin(radians)*(x - mid_x) + cos(radians)*(y - mid_y) + mid_y; do { current_x = next_x; current_y = next_y; degrees /= 2.0; radians = degrees_to_radians(degrees); next_x = cos(radians)*(x - mid_x) + sin(radians)*(y - mid_y) + mid_x; next_y = -sin(radians)*(x - mid_x) + cos(radians)*(y - mid_y) + mid_y; } while (abs(next_x - current_x) > 1 || abs(next_y - current_y) > 1); return degrees; }
int pixel_convolution(Image* image, Matrix* matrix, int top, int left) { float value = 0; int top_offset = top - matrix->row_count / 2; int left_offset = left - matrix->column_count / 2; for (int y = 0; y < matrix->row_count; y++) { for (int x = 0; x < matrix->column_count; x++) { assert(y + top_offset < image_height(image)); assert(x + left_offset < image_width(image)); assert(y + top_offset >= 0); assert(x + left_offset >= 0); int matrix_value = matrix->data[y][x] / 255.0; int pixel_value = image_get_pixel_intensity(image, left_offset + x, top_offset + y) / 255.0; value += matrix_value * pixel_value; } } value /= (float)(matrix->row_count * matrix->column_count); assert(value >= 0); assert(value <= 1); return (int)(value * 255.0); }
Image* image_rotate(Image* image, float angle, int padding) { int width = image_width(image); int height = image_height(image); Image* output = image_blank_copy(image, width, height); float radians = degrees_to_radians(angle); int mid_x = width / 2; int mid_y = height / 2; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { float original_x = cos(radians)*(x - mid_x) + sin(radians)*(y - mid_y) + mid_x; float original_y = -sin(radians)*(x - mid_x) + cos(radians)*(y - mid_y) + mid_y; if (original_x >= width || original_y >= height || original_x < 0 || original_y < 0) { image_set_pixel_intensity(output, x, y, padding); } else { // int intensity = image_get_pixel_intensity(image, original_x, original_y); int intensity = bilinear_intensity(image, original_x, original_y, padding); image_set_pixel_intensity(output, x, y, intensity); } } } return output; }
/* returns true if the player has pressed the switch (item) */ int pressed_the_switch(item_t *item, player_t *player) { float a[4], b[4]; a[0] = item->actor->position.x - item->actor->hot_spot.x; a[1] = item->actor->position.y - item->actor->hot_spot.y; a[2] = a[0] + image_width(actor_image(item->actor)); a[3] = a[1] + image_height(actor_image(item->actor)); b[0] = player->actor->position.x - player->actor->hot_spot.x + image_width(actor_image(player->actor)) * 0.3; b[1] = player->actor->position.y - player->actor->hot_spot.y + image_height(actor_image(player->actor)) * 0.5; b[2] = b[0] + image_width(actor_image(player->actor)) * 0.4; b[3] = b[1] + image_height(actor_image(player->actor)) * 0.5; return (!player_is_dying(player) && bounding_box(a,b)); }
/* DDS3.2.12: Get Group Width */ static unsigned int get_group_width(const struct electorate *voter_electorate) { struct image *image; image = get_group_image(voter_electorate->code,1); return image_width(image); }
static int load_image(Image *p, Stream *st) { unsigned char *buf, *d; unsigned int size; int w, h; /* Read whole stream into buffer... */ size = 0; buf = NULL; { unsigned char *tmp; int len; int bufsize = 65536; for (;;) { if ((tmp = realloc(buf, bufsize)) == NULL) { free(buf); return LOAD_ERROR; } buf = tmp; len = stream_read(st, buf + size, bufsize - size); size += len; if (len < bufsize - size) break; bufsize += 65536; } } d = WebPDecodeRGB(buf, size, &w, &h); if (d == NULL) return 0; image_width(p) = w; image_height(p) = h; p->type = _RGB24; p->bits_per_pixel = 24; p->depth = 24; debug_message_fnc("WEBP (%d,%d) %d bytes\n", image_width(p), image_height(p), size); image_bpl(p) = (image_width(p) * p->bits_per_pixel) >> 3; memory_set(image_image(p), d, _NORMAL, image_bpl(p) * image_height(p), image_bpl(p) * image_height(p)); return 1; }
/* DDS3.2.12: Draw Group Entry */ void draw_group_entry(struct cursor cursor, enum HlFlag highlight, bool interrupt) { struct image_set set; struct image *image, *highlighted; struct coordinates coordinates; unsigned int pref_size; struct audio_set audio = { NULL, { NULL, NULL, NULL } }; /* We play audio only if highlighted */ if (highlight) audio = get_audio_at_cursor(&cursor); set = get_img_at_cursor(&cursor); coordinates = get_cursor_coordinates(cursor); /* set contains either a group heading image or a candidate and pref_box image */ if (set.group) { image = set.group; if (highlight) { highlighted = highlight_image(image); paste_image(coordinates.x, coordinates.y, highlighted); play_audio_loop(interrupt, audio.group_audio); } else { paste_image(coordinates.x, coordinates.y, image); } } else { /* set contains candidate and pref_box images */ image = set.candidate; pref_size = image_width(set.prefnumber); paste_image(coordinates.x, coordinates.y, set.prefnumber); if (highlight) { highlighted = highlight_image(image); paste_image(coordinates.x + pref_size, coordinates.y, highlighted); /* Audio for this candidate */ play_multiaudio_loop(interrupt, 3, audio.candidate_audio); } else { paste_image(coordinates.x + pref_size, coordinates.y, image); } } }
/* creates the background */ image_t* create_background() { image_t* img = image_create(VIDEO_SCREEN_W, VIDEO_SCREEN_H); font_t *fnt = font_create("disclaimer"); v2d_t camera = v2d_new(VIDEO_SCREEN_W/2, VIDEO_SCREEN_H/2); image_clear(video_get_backbuffer(), image_rgb(0,0,0)); font_set_width(fnt, VIDEO_SCREEN_W - 6); font_set_text(fnt, "%s", text); font_set_position(fnt, v2d_new(3,3)); font_render(fnt, camera); image_blit(video_get_backbuffer(), img, 0, 0, 0, 0, image_width(img), image_height(img)); font_destroy(fnt); return img; }
/* * player_hit() * player가 공격한다. collectibles가 없다면 죽는다. */ void player_hit(player_t *player, actor_t *hazard) { int w = image_width(actor_image(hazard))/2, h = image_height(actor_image(hazard))/2; v2d_t hazard_centre = v2d_add(v2d_subtract(hazard->position, hazard->hot_spot), v2d_new(w/2, h/2)); if(player->invincible || physicsactor_get_state(player->pa) == PAS_GETTINGHIT || player->blinking || player_is_dying(player)) return; if(player_get_collectibles() > 0 || player->shield_type != SH_NONE) { player->actor->speed.x = 120.0f * sign(player->actor->position.x - hazard_centre.x); player->actor->speed.y = -240.0f; player->actor->position.y -= 2; /* bugfix */ player->pa_old_state = physicsactor_get_state(player->pa); physicsactor_hit(player->pa); if(player->shield_type != SH_NONE) { player->shield_type = SH_NONE; sound_play( soundfactory_get("damaged") ); } else if(!player->disable_collectible_loss) { float a = 101.25f, spd = 240.0f*2; int i, r = min(32, player_get_collectibles()); item_t *b; player_set_collectibles(0); /* collectibles 생성 */ for(i=0; i<r; i++) { b = level_create_item(IT_BOUNCINGRING, player->actor->position); bouncingcollectible_set_speed(b, v2d_new(-sin(a*PI/180.0f)*spd*(1-2*(i%2)), cos(a*PI/180.0f)*spd)); a += 22.5f * (i%2); if(i%16 == 0) { spd /= 2.0f; a = 101.25f; } } sound_play( soundfactory_get("collectible loss") ); } else sound_play( soundfactory_get("damaged") ); } else player_kill(player); }
static int get_buffer(AVCodecContext *vcodec_ctx, AVFrame *vcodec_picture) { VideoDecoder *vdec = (VideoDecoder *)vcodec_ctx->opaque; struct videodecoder_avcodec *vdm = (struct videodecoder_avcodec *)vdec->opaque; int width, height; Picture_buffer *buf; /* alignment */ width = (vcodec_ctx->width + 15) & ~15; height = (vcodec_ctx->height + 15) & ~15; if (vcodec_ctx->pix_fmt != PIX_FMT_YUV420P || width != vcodec_ctx->width || height != vcodec_ctx->height) { debug_message_fnc("avcodec: unsupported frame format, DR1 disabled.\n"); vdm->vcodec_ctx->get_buffer = avcodec_default_get_buffer; vdm->vcodec_ctx->reget_buffer = avcodec_default_reget_buffer; vdm->vcodec_ctx->release_buffer = avcodec_default_release_buffer; return avcodec_default_get_buffer(vcodec_ctx, vcodec_picture); } buf = &vdm->picture_buffer[vdm->picture_buffer_count]; if (buf->base == NULL) { int datasize = image_bpl(vdm->p) * image_height(vdm->p); int size = sizeof(struct pic_buf) + datasize; struct pic_buf *pb; if ((buf->base = memory_create()) == NULL) { err_message_fnc("No enough memory for Memory object buf->base.\n"); return -1; } if ((pb = memory_alloc(buf->base, size)) == NULL) { err_message_fnc("Cannot allocate %d bytes. No enough memory for pic_buf.\n", size); return -1; } pb->idx = vdm->picture_buffer_count; pb->mem = buf->base; memset(pb->data, 128, datasize); buf->pb = pb; buf->linesize[0] = image_width(vdm->p); buf->linesize[1] = image_width(vdm->p) >> 1; buf->linesize[2] = image_width(vdm->p) >> 1; }
/* player의 애니메이션을 업데이트한다. */ void update_animation(player_t *p) { /* animations */ if(!p->disable_animation_control) { switch(physicsactor_get_state(p->pa)) { case PAS_STOPPED: CHANGE_ANIM(stopped); break; case PAS_WALKING: CHANGE_ANIM(walking); break; case PAS_RUNNING: CHANGE_ANIM(running); break; case PAS_JUMPING: CHANGE_ANIM(jumping); break; case PAS_SPRINGING: CHANGE_ANIM(springing); break; case PAS_ROLLING: CHANGE_ANIM(rolling); break; case PAS_PUSHING: CHANGE_ANIM(pushing); break; case PAS_GETTINGHIT: CHANGE_ANIM(gettinghit); break; case PAS_DEAD: CHANGE_ANIM(dead); break; case PAS_BRAKING: CHANGE_ANIM(braking); break; case PAS_LEDGE: CHANGE_ANIM(ledge); break; case PAS_DROWNED: CHANGE_ANIM(drowned); break; case PAS_BREATHING: CHANGE_ANIM(breathing); break; case PAS_WAITING: CHANGE_ANIM(waiting); break; case PAS_DUCKING: CHANGE_ANIM(ducking); break; case PAS_LOOKINGUP: CHANGE_ANIM(lookingup); break; case PAS_WINNING: CHANGE_ANIM(winning); break; } } else p->disable_animation_control = FALSE; /* for set_player_animation (scripting) */ /* sounds */ ON_STATE(PAS_JUMPING) { sound_play( charactersystem_get(p->name)->sample.jump ); } ON_STATE(PAS_ROLLING) { sound_play( charactersystem_get(p->name)->sample.roll ); } ON_STATE(PAS_BRAKING) { sound_play( charactersystem_get(p->name)->sample.brake ); } /* "gambiarra" */ p->actor->hot_spot = v2d_new(image_width(actor_image(p->actor))/2, image_height(actor_image(p->actor))-20); }
int image_max_convolution(Image* image, Matrix* template_matix, int padding) { Image* full = image_blank_copy(image); int width = image_width(image); int height = image_height(image); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { image_set_pixel_intensity(full, x, y, padding); } } Image* convolution = image_convolution(full, template_matix); int max_convolution = image_max_intensity(convolution); free_image(convolution); free_image(full); return max_convolution; }
/** Create image from LUT. * Create image from LUT, useful for debugging and analysing. * This method produces a representation of the given level * (Y range with 0 <= level < depth) for visual inspection of the colormap. * The dimensions of the resulting image are 512x512 pixels. It uses standard strong * colors for the different standard color classes. C_UNKNOWN is grey, C_BACKGROUND * is black (like C_BLACK). * If the standard method does not suit your needs you can override this method. * @param yuv422_planar_buffer contains the image upon return, must be initialized * with the appropriate memory size before calling, dimensions are 512x512 pixels. * @param level the level to draw, it's a range in the Y direction and is in the * range 0 <= level < depth. */ void Colormap::to_image(unsigned char *yuv422_planar_buffer, unsigned int level) { unsigned int iwidth = image_width() / 2; unsigned int iheight = image_height() / 2; unsigned int lwidth = width(); unsigned int lheight = height(); unsigned int pixel_per_step = iheight / lheight; unsigned int lines_per_step = iwidth / lwidth; unsigned char *yp = yuv422_planar_buffer; unsigned char *up = YUV422_PLANAR_U_PLANE(yuv422_planar_buffer, iwidth * 2, iheight * 2); unsigned char *vp = YUV422_PLANAR_V_PLANE(yuv422_planar_buffer, iwidth * 2, iheight * 2); unsigned int y = level * deepness() / depth(); YUV_t c; for (unsigned int v = lwidth; v > 0 ; --v) { unsigned int v_index = (v - 1) * deepness() / lwidth; for (unsigned int u = 0; u < lheight; ++u) { unsigned int u_index = u * deepness() / lheight; c = ColorObjectMap::get_color(determine(y, u_index, v_index)); for (unsigned int p = 0; p < pixel_per_step; ++p) { *yp++ = c.Y; *yp++ = c.Y; *up++ = c.U; *vp++ = c.V; } } // Double line unsigned int lines = (2 * (lines_per_step - 1)) + 1; memcpy(yp, (yp - iwidth * 2), (iwidth * 2) * lines); yp += (iwidth * 2) * lines; memcpy(up, (up - iwidth), iwidth * lines); memcpy(vp, (vp - iwidth), iwidth * lines); up += iwidth * lines; vp += iwidth * lines; } }
/* * player_bounce() * player의 반동을 제어하는 함수 */ void player_bounce(player_t *player, actor_t *hazard) { int w = image_width(actor_image(hazard))/2, h = image_height(actor_image(hazard))/2; v2d_t hazard_centre = v2d_add(v2d_subtract(hazard->position, hazard->hot_spot), v2d_new(w/2, h/2)); actor_t *act = player->actor; if(physicsactor_is_in_the_air(player->pa)) { if(act->position.y <= hazard_centre.y && act->speed.y > 0.0f) { if(input_button_down(act->input, IB_FIRE1) || physicsactor_get_state(player->pa) == PAS_ROLLING) act->speed.y *= -1.0f; else act->speed.y = 4 * max(-60.0f, -60.0f * act->speed.y); player->pa_old_state = physicsactor_get_state(player->pa); physicsactor_bounce(player->pa); } else act->speed.y -= 4 * 60.0f * sign(act->speed.y); } }
Image* image_scale(Image* image, int new_width, int new_height, int padding) { int width = image_width(image); int height = image_height(image); float x_ratio = (float)width / (float)new_width; float y_ratio = (float)height / (float)new_height; Image* output = image_blank_copy(image, new_width, new_height); for (int y = 0; y < new_height; y++) { for (int x = 0; x < new_width; x++) { float original_y = (int)y * y_ratio; float original_x = (int)x * x_ratio; int intensity = image_get_pixel_intensity(image, original_x, original_y); // int intensity = bilinear_intensity(image, original_x, original_y, padding); image_set_pixel_intensity(output, x, y, intensity); } } return output; }
static int operate_on_image(char *path) { void *image; unsigned char *luma; float *out, **emap, da_ratio, blur_extent; int n, w, h; image = image_open(path, LUMA_COLORSPACE); if(image == NULL) return 1; luma = image_luma(image); w = image_width(image); h = image_height(image); n = w*h; out = malloc(sizeof(float)*n); assert(out != NULL); for(int i = 0; i < n; i++) out[i] = luma[i]/255.0; haar_transform(out, w, h); emap = malloc(sizeof(float*)*(LEVELS+1)); memset(emap, 0, sizeof(float*)*(LEVELS+1)); for(int i = 1; i <= LEVELS; i++) emap[i] = malloc(sizeof(float)*((w>>i)*(h>>i))); construct_edge_map(out, emap, w, h); /* Note: we don't perform non-maxima suppression at this * point, because it seems to yield worse results compared to * simply adjusting the threshold. */ detect_blur(emap, w, h, threshold, &da_ratio, &blur_extent); printf("%s -- da_ratio: %f blur_extent: %f\n", (da_ratio > min_zero) ? "sharp":"blurred", da_ratio, blur_extent); for(int i = 1; i <= LEVELS; i++) free(emap[i]); free(emap); free(out); return 0; }
static int load_image(Image *p, Stream *st) { unsigned char buf[BUFSIZE], *pp, *d; unsigned int file_size, header_size, image_size, offset_to_image; unsigned short int biPlanes; unsigned int bytes_per_pal; int i, c, c2, y, compress_method; if (stream_read(st, buf, 12) != 12) return 0; file_size = utils_get_little_uint32(&buf[0]); offset_to_image = utils_get_little_uint32(&buf[8]); if (file_size < offset_to_image) return 0; if (!stream_read_little_uint32(st, &header_size)) return 0; if (header_size > 64) return 0; if (stream_read(st, buf, header_size - 4) != (int)(header_size - 4)) return 0; if (header_size >= WIN_BMP_HEADER_SIZE) { image_width(p) = utils_get_little_uint32(&buf[0]); image_height(p) = utils_get_little_uint32(&buf[4]); biPlanes = utils_get_little_uint16(&buf[8]); p->bits_per_pixel = utils_get_little_uint16(&buf[10]); } else { image_width(p) = utils_get_little_uint16(&buf[0]); image_height(p) = utils_get_little_uint16(&buf[2]); biPlanes = utils_get_little_uint16(&buf[4]); p->bits_per_pixel = utils_get_little_uint16(&buf[6]); } if (biPlanes != 1) return 0; if (image_width(p) > 10000 || image_height(p) > 10000) return 0; switch (p->bits_per_pixel) { case 1: p->type = _BITMAP_MSBFirst; /* XXX: check order */ p->depth = p->bits_per_pixel; break; case 4: p->type = _INDEX44; p->depth = 4; break; case 8: p->type = _INDEX; p->depth = 8; break; case 16: p->type = _RGB555; p->depth = 16; break; case 24: p->type = _BGR24; p->depth = 24; break; case 32: p->type = _BGRA32; p->depth = 24; break; default: show_message("bmp: read_header: unknown bpp %d detected.\n", p->bits_per_pixel); return 0; } compress_method = 0; if (header_size >= WIN_BMP_HEADER_SIZE) { compress_method = utils_get_little_uint16(&buf[12]); image_size = utils_get_little_uint32(&buf[16]); image_size = image_size; // dummy } /* other header informations are intentionally ignored */ if (p->depth <= 8) { p->ncolors = 1 << p->depth; bytes_per_pal = (header_size >= WIN_BMP_HEADER_SIZE) ? 4 : 3; if (p->ncolors * bytes_per_pal > BUFSIZE) { err_message_fnc("BUFSIZE is too small. It must be greater than %d.\n", p->ncolors * bytes_per_pal); return 0; } if (stream_read(st, buf, p->ncolors * bytes_per_pal) != (int)(p->ncolors * bytes_per_pal)) return 0; for (i = 0; i < (int)p->ncolors; i++) { p->colormap[i][0] = buf[bytes_per_pal * i + 2]; p->colormap[i][1] = buf[bytes_per_pal * i + 1]; p->colormap[i][2] = buf[bytes_per_pal * i + 0]; } } else if (p->depth == 16 && compress_method == 3) { /* Read bitmasks */ if (stream_read(st, buf, 3 * 4) != 3 * 4) return 0; unsigned int rm = utils_get_little_uint32(buf); unsigned int gm = utils_get_little_uint32(buf + 4); unsigned int bm = utils_get_little_uint32(buf + 8); if (rm == 0xf800) p->type = _RGB565; else if (rm == 0x7c00) p->type = _RGB555; else warning_fnc("Mask: R %X G %X B %X is not supported\n", rm, gm, bm); compress_method = 0; } image_bpl(p) = (image_width(p) * p->bits_per_pixel) >> 3; image_bpl(p) += (4 - (image_bpl(p) % 4)) % 4; debug_message_fnc("(%d, %d): bpp %d depth %d compress %d\n", image_width(p), image_height(p), p->bits_per_pixel, p->depth, compress_method); if ((d = memory_alloc(image_image(p), image_bpl(p) * image_height(p))) == NULL) return 0; stream_seek(st, offset_to_image, _SET); pp = d + image_bpl(p) * (image_height(p) - 1); switch (compress_method) { case BI_RGB: for (i = (int)(image_height(p) - 1); i >= 0; i--) { stream_read(st, pp, image_bpl(p)); pp -= image_bpl(p); } break; case BI_RLE4: if (p->depth != 4) show_message("Compressed RI_BLE4 bitmap with depth %d != 4.\n", p->depth); /* RLE compressed data */ /* Not complete. */ y = image_height(p); while ((c = stream_getc(st)) != -1 && y >= 0) { if (c != 0) { /* code mode */ c2 = stream_getc(st); show_message_fnc("len %d data %d\n", c, c2); for (i = 0; i < c; i += 2) { *pp++ = (unsigned char)c2; } } else { if ((c = stream_getc(st)) == 0) { /* line end */ show_message_fnc("line end %d\n", y); pp = d + image_bpl(p) * (y - 1); y--; } else if (c == 1) { /* image end */ break; } else if (c == 2) { /* offset */ c = stream_getc(st); c2 = stream_getc(st); show_message_fnc("offset %d, %d\n", c, c2); pp += (c - c2 * image_width(p)) / 2; } else { /* absolute mode */ show_message_fnc("abs len %d\n", c); for (i = 0; i < c; i += 2) *pp++ = (unsigned char)stream_getc(st); if (c % 2 != 0) /* read dummy */ c = stream_getc(st); } } } break; case BI_RLE8: if (p->depth != 8) show_message("Compressed RI_BLE8 bitmap with depth %d != 8.\n", p->depth); /* RLE compressed data */ y = image_height(p); while ((c = stream_getc(st)) != -1 && y >= 0) { if (c != 0) { /* code mode */ c2 = stream_getc(st); for (i = 0; i < c; i++) { *pp++ = (unsigned char)c2; } } else { if ((c = stream_getc(st)) == 0) { /* line end */ pp = d + image_bpl(p) * (y - 1); y--; } else if (c == 1) { /* image end */ break; } else if (c == 2) { /* offset */ c = stream_getc(st); c2 = stream_getc(st); pp += (c - c2 * image_width(p)); } else { /* absolute mode */ for (i = 0; i < c; i++) *pp++ = (unsigned char)stream_getc(st); if (c % 2 != 0) /* read dummy */ c = stream_getc(st); } } } break; default: show_message("Compressed bitmap (method = %d) not supported.\n", compress_method); return 0; } return 1; }
void Driver::setup() { double hz(DEFAULT_RATE); int32_t device_id(0); std::string frame_id("camera"); std::string file_path(""); private_node_.getParam("device_id", device_id); private_node_.getParam("frame_id", frame_id); private_node_.getParam("rate", hz); int32_t image_width(640); int32_t image_height(480); camera_.reset(new Capture(camera_node_, "image_raw", PUBLISHER_BUFFER_SIZE, frame_id)); if (private_node_.getParam("file", file_path) && file_path != "") { camera_->openFile(file_path); } else { camera_->open(device_id); } if (private_node_.getParam("image_width", image_width)) { if (!camera_->setWidth(image_width)) { ROS_WARN("fail to set image_width"); } } if (private_node_.getParam("image_height", image_height)) { if (!camera_->setHeight(image_height)) { ROS_WARN("fail to set image_height"); } } camera_->setPropertyFromParam(CV_CAP_PROP_POS_MSEC, "cv_cap_prop_pos_msec"); camera_->setPropertyFromParam(CV_CAP_PROP_POS_AVI_RATIO, "cv_cap_prop_pos_avi_ratio"); camera_->setPropertyFromParam(CV_CAP_PROP_FRAME_WIDTH, "cv_cap_prop_frame_width"); camera_->setPropertyFromParam(CV_CAP_PROP_FRAME_HEIGHT, "cv_cap_prop_frame_height"); camera_->setPropertyFromParam(CV_CAP_PROP_FPS, "cv_cap_prop_fps"); camera_->setPropertyFromParam(CV_CAP_PROP_FOURCC, "cv_cap_prop_fourcc"); camera_->setPropertyFromParam(CV_CAP_PROP_FRAME_COUNT, "cv_cap_prop_frame_count"); camera_->setPropertyFromParam(CV_CAP_PROP_FORMAT, "cv_cap_prop_format"); camera_->setPropertyFromParam(CV_CAP_PROP_MODE, "cv_cap_prop_mode"); camera_->setPropertyFromParam(CV_CAP_PROP_BRIGHTNESS, "cv_cap_prop_brightness"); camera_->setPropertyFromParam(CV_CAP_PROP_CONTRAST, "cv_cap_prop_contrast"); camera_->setPropertyFromParam(CV_CAP_PROP_SATURATION, "cv_cap_prop_saturation"); camera_->setPropertyFromParam(CV_CAP_PROP_HUE, "cv_cap_prop_hue"); camera_->setPropertyFromParam(CV_CAP_PROP_GAIN, "cv_cap_prop_gain"); camera_->setPropertyFromParam(CV_CAP_PROP_EXPOSURE, "cv_cap_prop_exposure"); camera_->setPropertyFromParam(CV_CAP_PROP_CONVERT_RGB, "cv_cap_prop_convert_rgb"); camera_->setPropertyFromParam(CV_CAP_PROP_RECTIFICATION, "cv_cap_prop_rectification"); camera_->setPropertyFromParam(CV_CAP_PROP_ISO_SPEED, "cv_cap_prop_iso_speed"); #ifdef CV_CAP_PROP_WHITE_BALANCE_U camera_->setPropertyFromParam(CV_CAP_PROP_WHITE_BALANCE_U, "cv_cap_prop_white_balance_u"); #endif // CV_CAP_PROP_WHITE_BALANCE_U #ifdef CV_CAP_PROP_WHITE_BALANCE_V camera_->setPropertyFromParam(CV_CAP_PROP_WHITE_BALANCE_V, "cv_cap_prop_white_balance_v"); #endif // CV_CAP_PROP_WHITE_BALANCE_V #ifdef CV_CAP_PROP_BUFFERSIZE camera_->setPropertyFromParam(CV_CAP_PROP_BUFFERSIZE, "cv_cap_prop_buffersize"); #endif // CV_CAP_PROP_BUFFERSIZE rate_.reset(new ros::Rate(hz)); }
#include "sawfish.h" DEFUN("draw-vertical-gradient", Fdraw_vertical_gradient, Sdraw_vertical_gradient, (repv img, repv from_, repv to_), rep_Subr3) { unsigned char from[3], to[3]; int width, height, stride, channels; int x, y; unsigned char *data; rep_DECLARE1(img, IMAGEP); rep_DECLARE2(from_, COLORP); rep_DECLARE3(to_, COLORP); data = image_pixels (VIMAGE(img)); width = image_width (VIMAGE(img)); height = image_height (VIMAGE(img)); stride = image_row_stride (VIMAGE(img)); channels = image_channels (VIMAGE(img)); from[0] = VCOLOR(from_)->red / 256; from[1] = VCOLOR(from_)->green / 256; from[2] = VCOLOR(from_)->blue / 256; to[0] = VCOLOR(to_)->red / 256; to[1] = VCOLOR(to_)->green / 256; to[2] = VCOLOR(to_)->blue / 256; for (y = 0; y < height; y++) { for (x = 0; x < width; x++) {
/* * player_update() * player를 업데이트하는 함수. */ void player_update(player_t *player, player_t **team, int team_size, brick_list_t *brick_list, item_list_t *item_list, enemy_list_t *enemy_list) { int i; actor_t *act = player->actor; float dt = timer_get_delta(); act->hot_spot = v2d_new(image_width(actor_image(act))/2, image_height(actor_image(act))-20); /* physics */ if(!player->disable_movement) { player->pa_old_state = physicsactor_get_state(player->pa); physics_adapter(player, team, team_size, brick_list, item_list, enemy_list); } /* player 깜빡거림 */ if(player->blinking) { player->blink_timer += timer_get_delta(); if(player->blink_timer - player->blink_visibility_timer >= 0.067f) { player->blink_visibility_timer = player->blink_timer; act->visible = !act->visible; } if(player->blink_timer >= PLAYER_MAX_BLINK) { player->blinking = FALSE; act->visible = TRUE; } } if(physicsactor_get_state(player->pa) != PAS_GETTINGHIT && player->pa_old_state == PAS_GETTINGHIT) { player->blinking = TRUE; player->blink_timer = 0.0f; player->blink_visibility_timer = 0.0f; } /* 방패 */ if(player->shield_type != SH_NONE) update_shield(player); /* 수중에서 */ if(!(player->underwater) && player->actor->position.y >= level_waterlevel()) player_enter_water(player); else if(player->underwater && player->actor->position.y < level_waterlevel()) player_leave_water(player); /* 수중인지 확인 */ if(player->underwater) { player->speedshoes_timer = max(player->speedshoes_timer, PLAYER_MAX_SPEEDSHOES); /* disable speed shoes */ if(player->shield_type != SH_WATERSHIELD) player->underwater_timer += dt; else player->underwater_timer = 0.0f; if(player_seconds_remaining_to_drown(player) <= 0.0f) player_drown(player); } /* 무적의 별 */ if(player->invincible) { int maxf = sprite_get_animation("SD_INVSTAR", 0)->frame_count; int invangle[PLAYER_MAX_INVSTAR]; v2d_t starpos; player->invtimer += dt; for(i=0; i<PLAYER_MAX_INVSTAR; i++) { invangle[i] = (180*4) * timer_get_ticks()*0.001 + (i+1)*(360/PLAYER_MAX_INVSTAR); starpos.x = 25*cos(invangle[i]*PI/180); starpos.y = ((timer_get_ticks()+i*400)%2000)/40; /*starpos = v2d_rotate(starpos, act->angle);*/ player->invstar[i]->position.x = act->position.x - act->hot_spot.x + image_width(actor_image(act))/2 + starpos.x; player->invstar[i]->position.y = act->position.y - act->hot_spot.y + image_height(actor_image(act)) - starpos.y + 5; actor_change_animation_frame(player->invstar[i], random(maxf)); } if(player->invtimer >= PLAYER_MAX_INVINCIBILITY) player->invincible = FALSE; } /* speed shoes */ if(player->got_speedshoes) { physicsactor_t *pa = player->pa; if(player->speedshoes_timer == 0) { physicsactor_set_acc(pa, physicsactor_get_acc(pa) * 2.0f); physicsactor_set_frc(pa, physicsactor_get_frc(pa) * 2.0f); physicsactor_set_topspeed(pa, physicsactor_get_topspeed(pa) * 2.0f); physicsactor_set_air(pa, physicsactor_get_air(pa) * 2.0f); physicsactor_set_rollfrc(pa, physicsactor_get_rollfrc(pa) * 2.0f); player->speedshoes_timer += dt; } else if(player->speedshoes_timer >= PLAYER_MAX_SPEEDSHOES) { physicsactor_set_acc(pa, physicsactor_get_acc(pa) / 2.0f); physicsactor_set_frc(pa, physicsactor_get_frc(pa) / 2.0f); physicsactor_set_topspeed(pa, physicsactor_get_topspeed(pa) / 2.0f); physicsactor_set_air(pa, physicsactor_get_air(pa) / 2.0f); physicsactor_set_rollfrc(pa, physicsactor_get_rollfrc(pa) / 2.0f); player->got_speedshoes = FALSE; } else player->speedshoes_timer += dt; } /* 애니메이션 */ update_animation(player); /* CPU가 제어하는 player인지 확인 */ if(player != level_player()) { for(i=0; i<IB_MAX; i++) input_simulate_button_up(act->input, (inputbutton_t)i); } /* 승리 포즈 */ if(level_has_been_cleared()) physicsactor_enable_winning_pose(player->pa); }
/* converts giflib format image into enfle format image */ static int gif_convert(Image *p, GIF_info *g_info, GIF_image *image) { GIF_ct *ct; int i, if_animated; //int transparent_disposal; #if 0 if (image->next != NULL) { if ((p->next = image_create()) == NULL) { image_destroy(p); return 0; } if (!gif_convert(p->next, g_info, image->next)) { image_destroy(p); return 0; } } else p->next = NULL; #endif //swidth = g_info->sd->width; //sheight = g_info->sd->height; image_left(p) = image->id->left; image_top(p) = image->id->top; image_width(p) = image->id->width; image_height(p) = image->id->height; #if 0 if (image_width(p) > swidth || image_height(p) > sheight) { show_message("screen (%dx%d) but image (%dx%d)\n", swidth, sheight, p->width, p->height); swidth = image_width(p); sheight = image_height(p); } #endif p->ncolors = image->id->lct_follows ? 1 << image->id->depth : 1 << g_info->sd->depth; p->type = _INDEX; //p->delay = image->gc->delay ? image->gc->delay : 1; if_animated = g_info->npics > 1 ? 1 : 0; debug_message("GIF: %d pics animation %d\n", g_info->npics, if_animated); #if 0 if (image->gc->transparent) { p->transparent_disposal = if_animated ? _TRANSPARENT : transparent_disposal; p->transparent.index = image->gc->transparent_index; } else p->transparent_disposal = _DONOTHING; p->image_disposal = image->gc->disposal; p->background.index = g_info->sd->back; #endif if (image->id->lct_follows) ct = image->id->lct; else if (g_info->sd->gct_follows) ct = g_info->sd->gct; else { fprintf(stderr, "Null color table..\n"); ct = NULL; } for (i = 0; i < (int)p->ncolors; i++) { p->colormap[i][0] = ct->cell[i]->value[0]; p->colormap[i][1] = ct->cell[i]->value[1]; p->colormap[i][2] = ct->cell[i]->value[2]; } image_bpl(p) = image_width(p); if (!image_image(p)) image_image(p) = memory_create(); if (memory_alloc(image_image(p), image_bpl(p) * image_height(p)) == NULL) return 0; memcpy(memory_ptr(image_image(p)), image->data, image_bpl(p) * image_height(p)); return 1; }
/* * intro_render() * Renders the introduction scene */ void intro_render() { image_blit(bg, video_get_backbuffer(), 0, 0, (VIDEO_SCREEN_W - image_width(bg))/2, (VIDEO_SCREEN_H - image_height(bg))/2, image_width(bg), image_height(bg)); }
DEFINE_SAVER_PLUGIN_SAVE(p, fp, c, params) { struct jpeg_compress_struct *cinfo = malloc(sizeof(struct jpeg_compress_struct)); struct my_error_mgr jerr; JSAMPROW buffer[1]; /* output row buffer */ int quality, result; debug_message("jpeg: save (%s) (%d, %d) called.\n", image_type_to_string(p->type), image_width(p), image_height(p)); if (cinfo == NULL) return 0; switch (p->type) { case _BITMAP_LSBFirst: case _BITMAP_MSBFirst: case _GRAY_ALPHA: case _INDEX: case _RGB565: case _BGR565: case _RGB555: case _BGR555: case _BGR24: case _RGBA32: case _ABGR32: case _ARGB32: case _BGRA32: show_message("Saving of %s type image is not yet implemented.\n", image_type_to_string(p->type)); return 0; case _GRAY: case _RGB24: break; default: fprintf(stderr, "Unknown image type: %d (maybe bug)\n", p->type); return 0; } cinfo->err = jpeg_std_error(&jerr.pub); jerr.pub.error_exit = my_error_exit; /* Establish the setjmp return context for my_error_exit to use. */ if (setjmp(jerr.setjmp_buffer)) { jpeg_destroy_compress(cinfo); free(cinfo); return 0; } quality = config_get_int(c, "/enfle/plugins/saver/jpeg/quality", &result); if (!result) quality = JPEG_SAVE_DEFAULT_QUALITY; else if (quality < 1 || quality > 100) { show_message("Invalid quality %d: defaults to %d.\n", quality, JPEG_SAVE_DEFAULT_QUALITY); quality = JPEG_SAVE_DEFAULT_QUALITY; } /* Now we can initialize the JPEG decompression object. */ jpeg_create_compress(cinfo); jpeg_stdio_dest(cinfo, fp); cinfo->image_width = image_width(p); cinfo->image_height = image_height(p); if (p->type == _GRAY) { cinfo->input_components = 1; cinfo->in_color_space = JCS_GRAYSCALE; } else { cinfo->input_components = 3; cinfo->in_color_space = JCS_RGB; } jpeg_set_defaults(cinfo); jpeg_set_quality(cinfo, quality, TRUE); jpeg_start_compress(cinfo, TRUE); while (cinfo->next_scanline < cinfo->image_height) { buffer[0] = (JSAMPROW)(memory_ptr(image_image(p)) + image_bpl(p) * cinfo->next_scanline); (void)jpeg_write_scanlines(cinfo, buffer, 1); } (void)jpeg_finish_compress(cinfo); jpeg_destroy_compress(cinfo); free(cinfo); debug_message("jpeg: saved.\n"); return 1; }
DEFINE_LOADER_PLUGIN_LOAD(p, st, vw #if !defined(IDENTIFY_BEFORE_LOAD) __attribute__((unused)) #endif , c #if !defined(IDENTIFY_BEFORE_LOAD) __attribute__((unused)) #endif , priv #if !defined(IDENTIFY_BEFORE_LOAD) __attribute__((unused)) #endif ) { jas_image_t *ji; jas_stream_t *js; unsigned char *d; char *buf = NULL; int k, cmp[3]; unsigned int i, j; int tlx, tly; int vs, hs; //debug_message("JasPer: load() called\n"); #ifdef IDENTIFY_BEFORE_LOAD { LoaderStatus status; if ((status = identify(p, st, vw, c, priv)) != LOAD_OK) return status; stream_rewind(st); } #endif /* Read whole stream into buffer... */ { char *tmp; int size = 0, len; int bufsize = 65536; for (;;) { if ((tmp = realloc(buf, bufsize)) == NULL) { free(buf); return LOAD_ERROR; } buf = tmp; len = stream_read(st, (unsigned char *)(buf + size), bufsize - size); size += len; if (len < bufsize - size) break; bufsize += 65536; } if ((js = jas_stream_memopen(buf, size)) == NULL) { free(buf); return LOAD_ERROR; } } /* loading... */ if ((ji = jas_image_decode(js, -1, 0)) == NULL) { err_message_fnc("jas_image_decode() failed.\n"); goto error_clear; } /* colorspace conversion */ { jas_cmprof_t *jc; jas_image_t *new_ji; if ((jc = jas_cmprof_createfromclrspc(JAS_CLRSPC_SRGB)) == NULL) goto error_destroy_free; if ((new_ji = jas_image_chclrspc(ji, jc, JAS_CMXFORM_INTENT_PER)) == NULL) goto error_destroy_free; jas_image_destroy(ji); ji = new_ji; } jas_stream_close(js); free(buf); debug_message("JasPer: jas_image_decode() OK: (%ld,%ld)\n", jas_image_cmptwidth(ji, 0), jas_image_cmptheight(ji, 0)); /* convert to enfle format */ p->bits_per_pixel = 24; p->type = _RGB24; p->depth = 24; cmp[0] = jas_image_getcmptbytype(ji, JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_RGB_R)); cmp[1] = jas_image_getcmptbytype(ji, JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_RGB_G)); cmp[2] = jas_image_getcmptbytype(ji, JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_RGB_B)); /* dimension */ image_width(p) = jas_image_cmptwidth(ji, cmp[0]); image_height(p) = jas_image_cmptheight(ji, cmp[0]); image_left(p) = 0; image_top(p) = 0; image_bpl(p) = image_width(p) * 3; tlx = jas_image_cmpttlx(ji, cmp[0]); tly = jas_image_cmpttly(ji, cmp[0]); vs = jas_image_cmptvstep(ji, cmp[0]); hs = jas_image_cmpthstep(ji, cmp[0]); debug_message("JasPer: tlx %d tly %d vs %d hs %d ncomponents %d\n", tlx, tly, vs, hs, jas_image_numcmpts(ji)); /* memory allocation */ if ((d = memory_alloc(image_image(p), image_bpl(p) * image_height(p))) == NULL) { err_message("No enough memory (%d bytes)\n", image_bpl(p) * image_height(p)); goto error_destroy_free; } for (i = 0; i < image_height(p); i++) { for (j = 0; j < image_width(p); j++) { for (k = 0; k < 3; k++) *d++ = jas_image_readcmptsample(ji, cmp[k], j, i); } } jas_image_destroy(ji); return LOAD_OK; error_destroy_free: jas_image_destroy(ji); error_clear: return LOAD_ERROR; }
return -1; } pb->idx = vdm->picture_buffer_count; pb->mem = buf->base; memset(pb->data, 128, datasize); buf->pb = pb; buf->linesize[0] = image_width(vdm->p); buf->linesize[1] = image_width(vdm->p) >> 1; buf->linesize[2] = image_width(vdm->p) >> 1; } vcodec_picture->base[0] = vcodec_picture->data[0] = buf->pb->data; vcodec_picture->base[1] = vcodec_picture->data[1] = vcodec_picture->data[0] + image_width(vdm->p) * image_height(vdm->p); vcodec_picture->base[2] = vcodec_picture->data[2] = vcodec_picture->data[1] + (image_width(vdm->p) >> 1) * (image_height(vdm->p) >> 1); vcodec_picture->linesize[0] = buf->linesize[0]; vcodec_picture->linesize[1] = buf->linesize[1]; vcodec_picture->linesize[2] = buf->linesize[2]; vcodec_picture->age = 256 * 256 * 256 * 64; vcodec_picture->type = FF_BUFFER_TYPE_USER; vdm->picture_buffer_count++; return 0; } static int reget_buffer(AVCodecContext *vcodec_ctx, AVFrame *vcodec_picture)