void DspLine::processDspWithIndex(int fromIndex, int toIndex) { if (numSamplesToTarget <= 0.0f) { // if we have already reached the target if (ArrayArithmetic::hasAccelerate) { #if __APPLE__ vDSP_vfill(&target, dspBufferAtOutlet0+fromIndex, 1, toIndex-fromIndex); #endif } else { memset_pattern4(dspBufferAtOutlet0+fromIndex, &target, (toIndex-fromIndex)*sizeof(float)); } lastOutputSample = target; } else { // the number of samples to be processed this iteration float processLength = toIndex - fromIndex; if (processLength > 0.0f) { // if there is anything to process at all (several messages may be received at once) if (numSamplesToTarget < processLength) { int targetIndexInt = fromIndex + numSamplesToTarget; if (ArrayArithmetic::hasAccelerate) { #if __APPLE__ vDSP_vramp(&lastOutputSample, &slope, dspBufferAtOutlet0+fromIndex, 1, targetIndexInt-fromIndex); vDSP_vfill(&target, dspBufferAtOutlet0+targetIndexInt, 1, toIndex-targetIndexInt); #endif } else { // if we will process more samples than we have remaining to the target // i.e., if we will arrive at the target while processing dspBufferAtOutlet0[fromIndex] = lastOutputSample + slope; for (int i = fromIndex+1; i < targetIndexInt; i++) { dspBufferAtOutlet0[i] = dspBufferAtOutlet0[i-1] + slope; } for (int i = targetIndexInt; i < toIndex; i++) { dspBufferAtOutlet0[i] = target; } } lastOutputSample = target; numSamplesToTarget = 0; } else { // if the target is far off if (ArrayArithmetic::hasAccelerate) { #if __APPLE__ vDSP_vramp(&lastOutputSample, &slope, dspBufferAtOutlet0+fromIndex, 1, toIndex-fromIndex); #endif } else { dspBufferAtOutlet0[fromIndex] = lastOutputSample + slope; for (int i = fromIndex+1; i < toIndex; i++) { dspBufferAtOutlet0[i] = dspBufferAtOutlet0[i-1] + slope; } } lastOutputSample = dspBufferAtOutlet0[toIndex-1]; numSamplesToTarget -= processLength; } } } }
int main(void) { // R G B A uint32_t pattern = 0xFFFF00FF; #ifdef __APPLE__ memset_pattern4(gfx, &pattern, sizeof(gfx)); #else wmemset(gfx, pattern, (64*32) * sizeof(char)); #endif gfx[0] = 0xFF0000FF; // R gfx[1] = 0x00FF00FF; // G gfx[2] = 0x0000FFFF; // B gfx[63] = 0xFF0000FF; // R gfx[64*31] =0x00FF00FF; // G int x = 64, y = 32; gfx[(y-1)*64+(x-1)] = 0x0000FFFF; // B caca_canvas_t *cv; caca_display_t *dp; caca_event_t ev; dp = caca_create_display(NULL); if(!dp) return 1; /* printf("Current driver: %s\n", caca_get_display_driver(dp)); char **drivers = caca_get_display_driver_list(); caca_free_display(dp); while(*drivers != NULL) { printf("%s\n", *drivers); drivers++; } exit(0);*/ cv = caca_get_canvas(dp); caca_dither_t *dither = caca_create_dither(32, 64, 32, 4*64, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF); int cw = caca_get_canvas_width(cv); int ch = caca_get_canvas_height(cv); caca_set_display_title(dp, "Hello!"); //caca_set_color_ansi(cv, CACA_BLUE, CACA_WHITE); //caca_put_str(cv, 0, 0, "This is a message"); caca_dither_bitmap(cv, 0,0,cw,ch, dither, gfx); caca_refresh_display(dp); caca_free_dither(dither); //caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1); caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1); caca_free_display(dp); return 0; }
int* rtrans_build(int n, int n_targets, trans_tbl_t* translation_tbl) { // Create reverse translation table for tids int* rtrans = (int*)malloc(sizeof(int32_t)*n*n_targets); const int32_t NOTID = INT32_MIN; memset_pattern4((void*)rtrans, &NOTID, sizeof(int32_t)*n*n_targets); int i; for (i = 0; i < n; ++i) { int j; for (j = 0; j < (translation_tbl+i)->n_targets; ++j) { if ((translation_tbl+i)->tid_trans[j] != -1) { rtrans[i*n_targets + (translation_tbl+i)->tid_trans[j]] = j; } } } return rtrans; }
inline static void memset_cell(void *dst, cell pattern, size_t size) { #ifdef __APPLE__ #ifdef FACTOR_64 memset_pattern8(dst,&pattern,size); #else memset_pattern4(dst,&pattern,size); #endif #else if(pattern == 0) memset(dst,0,size); else { cell *start = (cell *)dst; cell *end = (cell *)((cell)dst + size); while(start < end) { *start = pattern; start++; } } #endif }
void *csAllocatingArray_newObject(void *opaqueArray) { CSAllocatingArray *array = (CSAllocatingArray *)opaqueArray; if(array->numberOfObjects == array->numberOfAllocatedObjects) { uint8_t *newBuffer; unsigned int newNumberOfAllocatedObjects = (array->numberOfAllocatedObjects << 1) + 1; newBuffer = (uint8_t *)realloc(array->objects, array->objectSize*newNumberOfAllocatedObjects); if(!newBuffer) return NULL; uint32_t zero = 0; memset_pattern4(&newBuffer[array->numberOfAllocatedObjects * array->objectSize], &zero, (newNumberOfAllocatedObjects - array->numberOfAllocatedObjects) * array->objectSize); array->objects = newBuffer; array->numberOfAllocatedObjects = newNumberOfAllocatedObjects; } void *newMemory = &array->objects[array->numberOfObjects * array->objectSize]; array->numberOfObjects++; return newMemory; }
/*********************************************************************** * create_surface */ struct window_surface *create_surface(macdrv_window window, const RECT *rect, struct window_surface *old_surface, BOOL use_alpha) { struct macdrv_window_surface *surface; struct macdrv_window_surface *old_mac_surface = get_mac_surface(old_surface); int width = rect->right - rect->left, height = rect->bottom - rect->top; DWORD *colors; pthread_mutexattr_t attr; int err; DWORD window_background; surface = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, FIELD_OFFSET(struct macdrv_window_surface, info.bmiColors[3])); if (!surface) return NULL; err = pthread_mutexattr_init(&attr); if (!err) { err = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); if (!err) err = pthread_mutex_init(&surface->mutex, &attr); pthread_mutexattr_destroy(&attr); } if (err) { HeapFree(GetProcessHeap(), 0, surface); return NULL; } surface->info.bmiHeader.biSize = sizeof(surface->info.bmiHeader); surface->info.bmiHeader.biWidth = width; surface->info.bmiHeader.biHeight = height; /* bottom-up */ surface->info.bmiHeader.biPlanes = 1; surface->info.bmiHeader.biBitCount = 32; surface->info.bmiHeader.biSizeImage = get_dib_image_size(&surface->info); surface->info.bmiHeader.biCompression = BI_RGB; surface->info.bmiHeader.biClrUsed = 0; colors = (DWORD *)((char *)&surface->info + surface->info.bmiHeader.biSize); colors[0] = 0x00ff0000; colors[1] = 0x0000ff00; colors[2] = 0x000000ff; surface->header.funcs = &macdrv_surface_funcs; surface->header.rect = *rect; surface->header.ref = 1; surface->window = window; reset_bounds(&surface->bounds); if (old_mac_surface && old_mac_surface->drawn) { surface->drawn = CreateRectRgnIndirect(rect); OffsetRgn(surface->drawn, -rect->left, -rect->top); if (CombineRgn(surface->drawn, surface->drawn, old_mac_surface->drawn, RGN_AND) <= NULLREGION) { DeleteObject(surface->drawn); surface->drawn = 0; } } update_blit_data(surface); surface->use_alpha = use_alpha; surface->bits = HeapAlloc(GetProcessHeap(), 0, surface->info.bmiHeader.biSizeImage); if (!surface->bits) goto failed; window_background = macdrv_window_background_color(); memset_pattern4(surface->bits, &window_background, surface->info.bmiHeader.biSizeImage); TRACE("created %p for %p %s bits %p-%p\n", surface, window, wine_dbgstr_rect(rect), surface->bits, surface->bits + surface->info.bmiHeader.biSizeImage); return &surface->header; failed: macdrv_surface_destroy(&surface->header); return NULL; }
void bordered_texture_atlas::createTextures(GLuint *textureNames) { GLubyte *data = (GLubyte *) malloc(4 * result_page_width * result_page_width); qglGenTextures((GLsizei) number_result_pages, textureNames); textures_indexes = textureNames; for (unsigned long page = 0; page < number_result_pages; page++) { for (unsigned long texture = 0; texture < number_canonical_object_textures; texture++) { const canonical_object_texture &canonical = canonical_object_textures[texture]; if (canonical.new_page != page) continue; if(canonical.original_page == WHITE_TEXTURE_INDEX) { uint32_t white_pixels[1] = {0xFFFFFFFFU}; // Add top border for (int border = 0; border < border_width; border++) { unsigned x = canonical.new_x_with_border; unsigned y = canonical.new_y_with_border + border; // expand top-left pixel memset_pattern4(&data[(y*result_page_width + x) * 4], white_pixels, 4 * border_width); // copy top line memset_pattern4(&data[(y*result_page_width + x + border_width) * 4], white_pixels, canonical.width * 4); // expand top-right pixel memset_pattern4(&data[(y*result_page_width + x + border_width + canonical.width) * 4], white_pixels, 4 * border_width); } // Copy main content for (int line = 0; line < canonical.height; line++) { unsigned x = canonical.new_x_with_border; unsigned y = canonical.new_y_with_border + border_width + line; // expand left pixel memset_pattern4(&data[(y*result_page_width + x) * 4], white_pixels, 4 * border_width); // copy line memset_pattern4(&data[(y*result_page_width + x + border_width) * 4], white_pixels, canonical.width * 4); // expand right pixel memset_pattern4(&data[(y*result_page_width + x + border_width + canonical.width) * 4], white_pixels, 4 * border_width); } // Add bottom border for (int border = 0; border < border_width; border++) { unsigned x = canonical.new_x_with_border; unsigned y = canonical.new_y_with_border + canonical.height + border_width + border; // expand bottom-left pixel memset_pattern4(&data[(y*result_page_width + x) * 4], white_pixels, 4 * border_width); // copy bottom line memset_pattern4(&data[(y*result_page_width + x + border_width) * 4], white_pixels, canonical.width * 4); // expand bottom-right pixel memset_pattern4(&data[(y*result_page_width + x + border_width + canonical.width) * 4], white_pixels, 4 * border_width); } } else { const char *original = (char *) original_pages[canonical.original_page].pixels; // Add top border for (int border = 0; border < border_width; border++) { unsigned x = canonical.new_x_with_border; unsigned y = canonical.new_y_with_border + border; unsigned old_x = canonical.original_x; unsigned old_y = canonical.original_y; // expand top-left pixel memset_pattern4(&data[(y*result_page_width + x) * 4], &(original[(old_y * 256 + old_x) * 4]), 4 * border_width); // copy top line memcpy(&data[(y*result_page_width + x + border_width) * 4], &original[(old_y * 256 + old_x) * 4], canonical.width * 4); // expand top-right pixel memset_pattern4(&data[(y*result_page_width + x + border_width + canonical.width) * 4], &(original[(old_y * 256 + old_x + canonical.width) * 4]), 4 * border_width); } // Copy main content for (int line = 0; line < canonical.height; line++) { unsigned x = canonical.new_x_with_border; unsigned y = canonical.new_y_with_border + border_width + line; unsigned old_x = canonical.original_x; unsigned old_y = canonical.original_y + line; // expand left pixel memset_pattern4(&data[(y*result_page_width + x) * 4], &(original[(old_y * 256 + old_x) * 4]), 4 * border_width); // copy line memcpy(&data[(y*result_page_width + x + border_width) * 4], &original[(old_y * 256 + old_x) * 4], canonical.width * 4); // expand right pixel memset_pattern4(&data[(y*result_page_width + x + border_width + canonical.width) * 4], &(original[(old_y * 256 + old_x + canonical.width) * 4]), 4 * border_width); } // Add bottom border for (int border = 0; border < border_width; border++) { unsigned x = canonical.new_x_with_border; unsigned y = canonical.new_y_with_border + canonical.height + border_width + border; unsigned old_x = canonical.original_x; unsigned old_y = canonical.original_y + canonical.height; // expand bottom-left pixel memset_pattern4(&data[(y*result_page_width + x) * 4], &(original[(old_y * 256 + old_x) * 4]), 4 * border_width); // copy bottom line memcpy(&data[(y*result_page_width + x + border_width) * 4], &original[(old_y * 256 + old_x) * 4], canonical.width * 4); // expand bottom-right pixel memset_pattern4(&data[(y*result_page_width + x + border_width + canonical.width) * 4], &(original[(old_y * 256 + old_x + canonical.width) * 4]), 4 * border_width); } } } qglBindTexture(GL_TEXTURE_2D, textureNames[page]); qglTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)result_page_width, (GLsizei) result_page_height[page], 0, GL_RGBA, GL_UNSIGNED_BYTE, data); if(qglGenerateMipmap != NULL) { qglGenerateMipmap(GL_TEXTURE_2D); } else { int mip_level = 1; int w = result_page_width / 2; int h = result_page_height[page] / 2; GLubyte *mip_data = (GLubyte *) malloc(4 * w * h); assert(w > 0 && h > 0); for(int i = 0; i < h; i++) { for(int j = 0; j < w; j++) { mip_data[i * w * 4 + j * 4 + 0] = 0.25 * ((int)data[i * w * 16 + j * 8 + 0] + (int)data[i * w * 16 + j * 8 + 4 + 0] + (int)data[i * w * 16 + w * 8 + j * 8 + 0] + (int)data[i * w * 16 + w * 8 + j * 8 + 4 + 0]); mip_data[i * w * 4 + j * 4 + 1] = 0.25 * ((int)data[i * w * 16 + j * 8 + 1] + (int)data[i * w * 16 + j * 8 + 4 + 1] + (int)data[i * w * 16 + w * 8 + j * 8 + 1] + (int)data[i * w * 16 + w * 8 + j * 8 + 4 + 1]); mip_data[i * w * 4 + j * 4 + 2] = 0.25 * ((int)data[i * w * 16 + j * 8 + 2] + (int)data[i * w * 16 + j * 8 + 4 + 2] + (int)data[i * w * 16 + w * 8 + j * 8 + 2] + (int)data[i * w * 16 + w * 8 + j * 8 + 4 + 2]); mip_data[i * w * 4 + j * 4 + 3] = 0.25 * ((int)data[i * w * 16 + j * 8 + 3] + (int)data[i * w * 16 + j * 8 + 4 + 3] + (int)data[i * w * 16 + w * 8 + j * 8 + 3] + (int)data[i * w * 16 + w * 8 + j * 8 + 4 + 3]); } } //char tgan[128]; //WriteTGAfile("mip_00.tga", data, result_page_width, result_page_height[page], 0); //sprintf(tgan, "mip_%0.2d.tga", mip_level); //WriteTGAfile(tgan, mip_data, w, h, 0); qglTexImage2D(GL_TEXTURE_2D, mip_level, GL_RGBA, (GLsizei)w, (GLsizei)h, 0, GL_RGBA, GL_UNSIGNED_BYTE, mip_data); while((w > 1) && (h > 1) /*&& (mip_level < 4)*/) { mip_level++; w /= 2; w = (w==0)?1:w; h /= 2; h = (h==0)?1:h; for(int i = 0; i < h; i++) { for(int j = 0; j < w; j++) { mip_data[i * w * 4 + j * 4 + 0] = 0.25 * ((int)mip_data[i * w * 16 + j * 8 + 0] + (int)mip_data[i * w * 16 + j * 8 + 4 + 0] + (int)mip_data[i * w * 16 + w * 8 + j * 8 + 0] + (int)mip_data[i * w * 16 + w * 8 + j * 8 + 4 + 0]); mip_data[i * w * 4 + j * 4 + 1] = 0.25 * ((int)mip_data[i * w * 16 + j * 8 + 1] + (int)mip_data[i * w * 16 + j * 8 + 4 + 1] + (int)mip_data[i * w * 16 + w * 8 + j * 8 + 1] + (int)mip_data[i * w * 16 + w * 8 + j * 8 + 4 + 1]); mip_data[i * w * 4 + j * 4 + 2] = 0.25 * ((int)mip_data[i * w * 16 + j * 8 + 2] + (int)mip_data[i * w * 16 + j * 8 + 4 + 2] + (int)mip_data[i * w * 16 + w * 8 + j * 8 + 2] + (int)mip_data[i * w * 16 + w * 8 + j * 8 + 4 + 2]); mip_data[i * w * 4 + j * 4 + 3] = 0.25 * ((int)mip_data[i * w * 16 + j * 8 + 3] + (int)mip_data[i * w * 16 + j * 8 + 4 + 3] + (int)mip_data[i * w * 16 + w * 8 + j * 8 + 3] + (int)mip_data[i * w * 16 + w * 8 + j * 8 + 4 + 3]); } } //sprintf(tgan, "mip_%0.2d.tga", mip_level); //WriteTGAfile(tgan, mip_data, w, h, 0); qglTexImage2D(GL_TEXTURE_2D, mip_level, GL_RGBA, (GLsizei)w, (GLsizei)h, 0, GL_RGBA, GL_UNSIGNED_BYTE, mip_data); } free(mip_data); } qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); } free(data); }