static int magick_fill_region( VipsRegion *out, void *seq, void *a, void *b, gboolean *stop ) { Read *read = (Read *) a; VipsRect *r = &out->valid; int y; for( y = 0; y < r->height; y++ ) { int top = r->top + y; int frame = top / read->frame_height; int line = top % read->frame_height; PixelPacket *pixels; g_mutex_lock( read->lock ); pixels = get_pixels( read->frames[frame], r->left, line, r->width, 1 ); g_mutex_unlock( read->lock ); if( !pixels ) { vips_error( "magick2vips", "%s", _( "unable to read pixels" ) ); return( -1 ); } unpack_pixels( read->im, VIPS_REGION_ADDR( out, r->left, top ), pixels, r->width ); } return( 0 ); }
void ShootMovement::update(float dt) { double add_x, add_y; get_dir(instance->direction, add_x, add_y); double m = get_pixels(speed) * instance->frame->timer_mul; move(add_x * m, add_y * m); }
void EightDirections::update(float dt) { if (max_speed == 0) return; bool on = false; int dir = get_joystick_direction(1); if (dir == 8) dir = instance->direction; else { on = true; dir *= 4; instance->set_direction(dir, false); } double mul = instance->frame->timer_mul; double change; if (on) change = get_accelerator(acceleration); else change = -get_accelerator(deceleration); set_speed(int_max(0, int_min(speed + change * mul, max_speed))); if (speed == 0) return; double add_x, add_y; get_dir(instance->direction, add_x, add_y); double m = get_pixels(speed) * mul; move(add_x * m, add_y * m); last_move = m; }
void ProxySurface::apply_xform() { if(!_patch) return; // apply the transform to the vertices of the proxy mesh assert(_proxy_mesh); PIXEL o = _patch->get_old_sample_center(); PIXEL n = _patch->get_sample_center(); VEXEL z = _patch->get_z(); CBvert_list& verts = _proxy_mesh->verts(); // vertices of the proxy mesh PIXEL_list pixels = get_pixels(verts, this); // their old pixel locations // compute and apply the transform to each vertex: for (int i=0; i<verts.num(); i++) { set_pix(verts[i], this, n + cmult(pixels[i] - o, z)); } //cache _uv_orig, _uv_u_pt, _uv_v_pt so that we can grow new quads _o = n + cmult(_o - o, z); _u_o = n + cmult(_u_o - o, z); _v_o = n + cmult(_v_o - o, z); // take care of bizness: _proxy_mesh->changed(); //BMESH::VERT_POSITIONS_CHANGED }
bool ImageBuf::write (ImageOutput *out, ProgressCallback progress_callback, void *progress_callback_data) const { stride_t as = AutoStride; bool ok = true; if (m_localpixels) { // In-core pixel buffer for the whole image ok = out->write_image (m_spec.format, m_localpixels, as, as, as, progress_callback, progress_callback_data); } else if (deep()) { // Deep image record ok = out->write_deep_image (m_deepdata); } else { // Backed by ImageCache std::vector<char> tmp (m_spec.image_bytes()); get_pixels (xbegin(), xend(), ybegin(), yend(), zbegin(), zend(), m_spec.format, &tmp[0]); ok = out->write_image (m_spec.format, &tmp[0], as, as, as, progress_callback, progress_callback_data); // FIXME -- not good for huge images. Instead, we should read // little bits at a time (scanline or tile blocks). } if (! ok) error ("%s", out->geterror ()); return ok; }
/** * This routine will convert one MCU from YUYV planar storage into 4 * DCT macro blocks, converting from 8-bit format in the planar * storage to 16-bit format used in the DCT. * * \param j pointer to jpeg_enc structure, and also storage for DCT macro blocks * \param x pixel x-coordinate for the first pixel * \param y pixel y-coordinate for the first pixel * \param y_data pointer to the Y plane * \param u_data pointer to the U plane * \param v_data pointer to the V plane */ static av_always_inline void fill_block(jpeg_enc_t *j, int x, int y, unsigned char *y_data, unsigned char *u_data, unsigned char *v_data) { int i, k; short int *dest; unsigned char *source; // The first Y, Y0 get_pixels(j->s->block[0], y*8*j->y_rs + 16*x + y_data, j->y_rs); // The second Y, Y1 get_pixels(j->s->block[1], y*8*j->y_rs + 16*x + 8 + y_data, j->y_rs); if (!j->bw && j->cheap_upsample) { source = y * 4 * j->u_rs + 8*x + u_data; dest = j->s->block[2]; for (i = 0; i < 4; i++) { for (k = 0; k < 8; k++) { dest[k] = source[k]; // First row dest[k+8] = source[k]; // Duplicate to next row } dest += 16; source += j->u_rs; } source = y * 4 * j->v_rs + 8*x + v_data; dest = j->s->block[3]; for (i = 0; i < 4; i++) { for (k = 0; k < 8; k++) { dest[k] = source[k]; dest[k+8] = source[k]; } dest += 16; source += j->u_rs; } } else if (!j->bw && !j->cheap_upsample) { // U get_pixels(j->s->block[2], y*8*j->u_rs + 8*x + u_data, j->u_rs); // V get_pixels(j->s->block[3], y*8*j->v_rs + 8*x + v_data, j->v_rs); } }
image_frame_rgbx& image_frame_rgbx::resize(uint32_t nwidth, uint32_t nheight, rescaler_group& rescalers) { if(width == nwidth && height == nheight) return *this; image_frame_rgbx* newf = new image_frame_rgbx(nwidth, nheight); if(width == 0 && height == 0) { //Fill with black. memset(newf->get_pixels(), 0, newf->get_data_size()); return *newf; } rescalers(newf->get_pixels(), nwidth, nheight, get_pixels(), width, height); return *newf; }
void PathMovement::update(float dt) { node_changed = false; if (current_node < 0) { instance->set_animation(STOPPED); return; } instance->set_animation(WALKING); PathNode & node = nodes[current_node]; float m = get_pixels(speed) * instance->frame->timer_mul; float move_dist = std::min<float>(m, distance_left); float move_val = move_dist * dir; int old_x = instance->x; int old_y = instance->y; move(node.dir_x * move_val, node.dir_y * move_val); start_x -= instance->x - old_x; start_y -= instance->y - old_y; distance_left -= move_dist; if (distance_left <= 0.0f) { int final_x = instance->x + start_x + node.x * dir; int final_y = instance->y + start_y + node.y * dir; instance->set_position(final_x, final_y); add_x = add_y = 0; start_x = start_y = 0; node_changed = true; int next_node = current_node+dir; bool is_last = next_node == nodes.size() || next_node == -1; if (!is_last) { set_current_node(next_node); return; } if (has_reverse && dir == 1) { dir = -1; set_current_node(current_node); return; } if (!has_reverse && dir == 1) move(-end_x, -end_y); if (!loop) { current_node = -2; return; } if (has_reverse || dir == -1) dir = -dir; next_node = (current_node+dir) % nodes.size(); set_current_node(next_node); } }
void BallMovement::update() { if (stop_speed != 0 || speed == 0) { instance->set_animation(STOPPED); return; } else instance->set_animation(WALKING); double add_x, add_y; get_dir(instance->direction, add_x, add_y); double m = get_pixels(speed) * instance->frame->timer_mul; if (speed > 100 && has_back_col) { double move_x = add_x * m; double move_y = add_y * m; int steps = 4; move_x /= steps; move_y /= steps; old_x = instance->x; old_y = instance->y; clear_collisions(); for (int i = 0; i < steps; ++i) { this->add_x += move_x; this->add_y += move_y; double xx = floor(this->add_x); double yy = floor(this->add_y); this->add_x -= xx; this->add_y -= yy; instance->set_position(instance->x + xx, instance->y + yy); if (instance->overlaps_background()) break; } } else { move(add_x * m, add_y * m); } if (deceleration != 0) speed_change -= get_accelerator(deceleration) * instance->frame->timer_mul; int change = (int)speed_change; speed_change -= change; speed = int_max(0, speed + change); }
void detect_ellipses(unsigned char** sobel_output, int w, int h, double threshold, int min_dist, EllipseList* ellipses_result_list) { List* pixels = get_pixels(sobel_output, w, h); if(pixels->size < 3) { printf("To few pixels\n"); return; } //minor axis double acc[BSIZE]; int i; for(i=0; i<BSIZE; i++) { acc[i] = 0.; } Node *i_node, *j_node, *k_node; double center_x, center_y, a, b, d, f, alpha, cosine, cosine_sq, sin_sq, max_acc; // printf("przed przetw %d\n", pixels->size); // // print_list(pixels); for(i_node = pixels->head; i_node->next; i_node = i_node->next) { for(j_node = i_node->next; j_node; j_node = j_node->next) { if(INODEX == JNODEX) { if(get_dist(INODEX, INODEY, JNODEX, JNODEY) > min_dist) { // printf("Rozwazane punkty: (%d, %d), (%d, %d)\n", // INODEX, INODEY, JNODEX, JNODEY); center_x = (INODEX + JNODEX)/2; center_y = (INODEY + JNODEY)/2; a = get_dist(INODEX, INODEY, JNODEX, JNODEY)/2; if(JNODEX != INODEX) alpha = atan((JNODEY - INODEY)/(JNODEX - INODEX)); // printf("a = %lf\n", a); for(k_node = i_node->next; k_node != j_node; k_node = k_node->next) { if((KNODEY != INODEY) && (KNODEY != JNODEY)) { if((d = get_dist(KNODEX, KNODEY, center_x, center_y)) > min_dist) { // printf("Rozwazane punkty: (%d, %d), (%d, %d), (%d, %d)\n", // INODEX, INODEY, JNODEX, JNODEY, KNODEX, KNODEY); f = get_dist(KNODEX, KNODEY, JNODEX, JNODEY); cosine = (a*a + d*d - f*f)/(2*a*d); cosine_sq = cosine*cosine; sin_sq = 1 - cosine_sq; double tmp2 = (a*a - d*d *cosine_sq); double tmp1 = (a*a * d*d * sin_sq); // printf("tmp1 = %lf, tmp2=%lf\t", tmp1, tmp2); if(tmp1 < 0) tmp1 = -tmp1; if(tmp2 < 0) tmp2 = -tmp2; b = sqrt(tmp1/tmp2); int round_b = round(b); if(round_b < BSIZE && round_b > 0) { k_node->b_ellipse = round_b; acc[round_b]++; } else { // printf("BLAD!!\n"); // printf("Rozwazane punkty: (%d, %d), (%d, %d), (%d, %d)\n", // INODEX, INODEY, JNODEX, JNODEY, KNODEX, KNODEY); // printf("tmp1 = %lf, tmp2=%lf\n", tmp1, tmp2); // printf("a = %lf\n", a); // printf("b = %lf\n\n", b); } } } } max_acc = 0.; double max_wart = 0.; for(i=0; i<BSIZE; i++) { if(acc[i] > max_wart) { // printf("%d ", (int)acc[i]); max_wart = acc[i]; max_acc = i; } } double obwod; if(abs(a-max_acc) < 4) obwod = M_PI*a*2/3; else obwod = M_PI*(3/2 * (a+max_acc) - sqrt(a*max_acc))*1/2; if(max_wart >= obwod*4/5 && max_wart >= threshold && max_wart>0 && (int)max_acc>10) { // printf("ELLIPSE FOUND!! %d %d %d %d\n", 512-(int)center_x, (int)center_y, (int)a, (int)max_acc); // printf("(%d, %d), (%d, %d)\n\n", 512-INODEX, INODEY, 512-JNODEX, JNODEY); add_first_ellipse(ellipses_result_list, (int)center_y, (int)center_x, (int)max_acc, (int)a); drawEllipse("output_ellipse.bmp", (int)center_y, (int)center_x, (int)max_acc, (int)a, 512, 512); removeEllipseFromImage(i_node, j_node, max_acc); i_node->b_ellipse = 0.; j_node->b_ellipse = 0.; } for(i=0; i<BSIZE; i++) { acc[i] = 0.; } } } } } }
ITunesPixelFormat ivis_render( ITunesVis* plugin, short audio_data[][512], float freq_data[][512], void* buffer, long buffer_size, bool idle ) { ITunesPixelFormat format = ITunesPixelFormatUnknown; /* make sure we have a plugin and a visual handler */ if ( !plugin || !plugin->imports.visual_handler ) return format; int i=0, w=0; RenderVisualData visual_data; DSPSplitComplex splitComplex[2]; float *data[2]; /* perform FFT if we're not idling */ if ( ! idle ) { /* allocate some complex vars */ for ( i = 0 ; i < 2 ; i++ ) { splitComplex[i].realp = calloc( 512, sizeof(float) ); splitComplex[i].imagp = calloc( 512, sizeof(float) ); data[i] = calloc( 512, sizeof(float) ); } /* 2 channels for spectrum and waveform data */ visual_data.numWaveformChannels = 2; visual_data.numSpectrumChannels = 2; /* copy spectrum audio data to visual data strucure */ for ( w = 0 ; w < 512 ; w++ ) { /* iTunes visualizers expect waveform data from 0 - 255, with level 0 at 128 */ visual_data.waveformData[0][w] = (UInt8)( (long)(audio_data[0][w]) / 128 + 128 ); visual_data.waveformData[1][w] = (UInt8)( (long)(audio_data[1][w]) / 128 + 128 ); /* scale to -1, +1 */ *( data[0] + w ) = (float)(( audio_data[0][w]) / (2.0 * 8192.0) ); *( data[1] + w ) = (float)(( audio_data[1][w]) / (2.0 * 8192.0) ); } /* FFT scaler */ float scale = ( 1.0 / 1024.0 ) ; /* scale by length of input * 2 (due to how vDSP does FFTs) */ float nyq=0, dc=0, freq=0; for ( i = 0 ; i < 2 ; i++ ) { /* pack data into format fft_zrip expects it */ vDSP_ctoz( (COMPLEX*)( data[i] ), 2, &( splitComplex[i] ), 1, 256 ); /* perform FFT on normalized audio data */ fft_zrip( plugin->fft_setup, &( splitComplex[i] ), 1, 9, FFT_FORWARD ); /* scale the values */ vDSP_vsmul( splitComplex[i].realp, 1, &scale, splitComplex[i].realp, 1, 256 ); vDSP_vsmul( splitComplex[i].imagp, 1, &scale, splitComplex[i].imagp, 1, 256 ); /* unpack data */ vDSP_ztoc( &splitComplex[i], 1, (COMPLEX*)( data[i] ), 2, 256 ); /* ignore phase */ dc = *(data[i]) = fabs( *(data[i]) ); nyq = fabs( *(data[i] + 1) ); for ( w = 1 ; w < 256 ; w++ ) { /* don't use vDSP for this since there's some overflow */ freq = hypot( *(data[i] + w * 2), *(data[i] + w * 2 + 1) ) * 256 * 16; freq = MAX( 0, freq ); freq = MIN( 255, freq ); visual_data.spectrumData[i][ w - 1 ] = (UInt8)( freq ); } visual_data.spectrumData[i][256] = nyq; } /* deallocate complex vars */ for ( i = 0 ; i < 2 ; i++ ) { free( splitComplex[i].realp ); free( splitComplex[i].imagp ); free( data[i] ); } /* update the render message with the new visual data and timestamp */ plugin->visual_message.u.renderMessage.renderData = &visual_data; plugin->visual_message.u.renderMessage.timeStampID++; } /* update time */ plugin->visual_message.u.renderMessage.currentPositionInMS = ivis_current_time() - plugin->start_time; // FIXME: real time /* save our GL context and send the vis a render message */ CGLContextObj currentContext = CGLGetCurrentContext(); if ( plugin->gl_context ) aglSetCurrentContext( (AGLContext)(plugin->gl_context ) ); /* call the plugin's render method */ if ( idle ) { /* idle message */ if ( plugin->wants_idle ) plugin->imports.visual_handler( kVisualPluginIdleMessage, &( plugin->visual_message ), plugin->vis_ref ); } else { /* render message */ plugin->imports.visual_handler( kVisualPluginRenderMessage, &( plugin->visual_message ), plugin->vis_ref ); /* set position message */ plugin->visual_message.u.setPositionMessage.positionTimeInMS = plugin->visual_message.u.renderMessage.currentPositionInMS; plugin->imports.visual_handler( kVisualPluginSetPositionMessage, &( plugin->visual_message ), plugin->vis_ref ); } /* update message */ plugin->imports.visual_handler( kVisualPluginUpdateMessage, NULL, plugin->vis_ref ); /* read pixels and restore our GL context */ CGLLockContext( CGLGetCurrentContext() ); switch ( get_pixels( buffer, buffer_size, CGLGetCurrentContext() != currentContext ) ) { case 3: format = ITunesPixelFormatRGB24; break; case 4: format = ITunesPixelFormatRGBA32; break; default: break; } CGLUnlockContext ( CGLGetCurrentContext() ); /* restore our GL context */ CGLSetCurrentContext( currentContext ); return format; }
std::shared_ptr<Image_8> Bitmap_Handler::get_Image(const char * file_name) { auto input = std::ifstream{ file_name, std::ios::binary }; if (input.is_open()) { // get length of file: input.seekg(0, input.end); unsigned long length = input.tellg(); input.seekg(0, input.beg); if (length > 50) { //Should be replaced by an import into a vector char *buffer = new char[length]; input.read(buffer, length); auto data_offset = merge_bytes_unsigned(buffer, 10, 4); auto size_x = merge_bytes_unsigned(buffer, 18, 4); auto size_y = merge_bytes_unsigned(buffer, 22, 4); auto biBitCount = merge_bytes_unsigned(buffer, 28, 2); auto bCompression = merge_bytes_unsigned(buffer, 30, 24); auto output = std::make_shared<Image_8>(size_x, size_y); unsigned long index = data_offset; unsigned int row_ind = 0; auto pixels = output->get_pixels(); unsigned int z = 0; for (auto it = pixels->begin(); it != pixels->end(); it++) { (*it).set_RGB((unsigned char)(buffer[index]),(unsigned char)(buffer[index + 1]),(unsigned char)(buffer[index + 2])); index += 3; row_ind += 3; z++; //Catch last Bytes in Row if (z == (size_x)) { while (row_ind % 4 != 0) { index++; row_ind++; } row_ind = 0; z = 0; } } input.close(); delete[] buffer; return output; } } else { return std::make_shared<Image_8>(0, 0); std::cout << "Image not found" << std::endl; } }