void Pattern_spinner::activate(void *arg) { g_x0 = 0; g_y0 = 0; g_x1 = flip_x(0); g_y1 = flip_y(0); display_current(); m_last_move_ms = millis(); }
bool Pattern_spectrum_timeline::display() { int hue = g_hue.get(); // Copy previous rows. int start_row = TIMELINE_DIRECTION > 0 ? 0 : ROW_COUNT - 1; int end_row = flip_y(start_row); for (int y = end_row; y != start_row; y -= TIMELINE_DIRECTION) { for (int x = 0; x < COLUMN_COUNT; ++x) { draw_pixel(x, y, get_pixel(x, y - TIMELINE_DIRECTION)); } } for (int x = 0; x < COLUMN_COUNT; ++x) { int lightness = g_bins[x] * g_brightness.get() / MAX_BRIGHTNESS; draw_pixel(x, start_row, make_hsv(hue, MAX_SATURATION, lightness)); } return true; }
void resymmetrise(LifeList *cells) { if (!FLIP_X && !FLIP_Y) return; int i, n = cells->ncells; resizeIfNeeded(cells, 2 * n); for (i = 0; i < n; i++) { int pos = cells->cellList[i].position; if (FLIP_X) pos = flip_x(pos); if (FLIP_Y) pos = flip_y(pos); cells->cellList[i+n].position = pos; cells->cellList[i+n].value = cells->cellList[i].value; } cells->ncells = 2 * n; makeRowMajor(cells); }
virtual void on_draw() { struct font_type { const agg::int8u* font; const char* name; } fonts[] = { { agg::gse4x6, "gse4x6" }, { agg::gse4x8, "gse4x8" }, { agg::gse5x7, "gse5x7" }, { agg::gse5x9, "gse5x9" }, { agg::gse6x9, "gse6x9" }, { agg::gse6x12, "gse6x12" }, { agg::gse7x11, "gse7x11" }, { agg::gse7x11_bold, "gse7x11_bold" }, { agg::gse7x15, "gse7x15" }, { agg::gse7x15_bold, "gse7x15_bold" }, { agg::gse8x16, "gse8x16" }, { agg::gse8x16_bold, "gse8x16_bold" }, { agg::mcs11_prop, "mcs11_prop" }, { agg::mcs11_prop_condensed, "mcs11_prop_condensed" }, { agg::mcs12_prop, "mcs12_prop" }, { agg::mcs13_prop, "mcs13_prop" }, { agg::mcs5x10_mono, "mcs5x10_mono" }, { agg::mcs5x11_mono, "mcs5x11_mono" }, { agg::mcs6x10_mono, "mcs6x10_mono" }, { agg::mcs6x11_mono, "mcs6x11_mono" }, { agg::mcs7x12_mono_high, "mcs7x12_mono_high" }, { agg::mcs7x12_mono_low, "mcs7x12_mono_low" }, { agg::verdana12, "verdana12" }, { agg::verdana12_bold, "verdana12_bold" }, { agg::verdana13, "verdana13" }, { agg::verdana13_bold, "verdana13_bold" }, { agg::verdana14, "verdana14" }, { agg::verdana14_bold, "verdana14_bold" }, { agg::verdana16, "verdana16" }, { agg::verdana16_bold, "verdana16_bold" }, { agg::verdana17, "verdana17" }, { agg::verdana17_bold, "verdana17_bold" }, { agg::verdana18, "verdana18" }, { agg::verdana18_bold, "verdana18_bold" }, 0, 0 }; glyph_gen glyph(0); pixfmt pixf(rbuf_window()); ren_base rb(pixf); rb.clear(agg::rgba(1,1,1)); agg::renderer_raster_htext_solid<ren_base, glyph_gen> rt(rb, glyph); int i; double y = 5; rt.color(agg::rgba(0,0,0)); for(i = 0; fonts[i].font; i++) { char buf[100]; strcpy(buf, "A quick brown fox jumps over the lazy dog 0123456789: "); strcat(buf, fonts[i].name); // Testing "wide-char" unsigned wbuf[100]; unsigned* wp = wbuf; const char* p = buf; while(*p) *wp++ = *(unsigned char*)p++; *wp++ = 0; glyph.font(fonts[i].font); rt.render_text(5, y, wbuf, !flip_y()); y += glyph.height() + 1; } // Rendering raster text with a custom span generator, gradient typedef agg::span_interpolator_linear<> interpolator_type; typedef agg::span_allocator<agg::rgba8> span_alloc_type; typedef agg::span_gradient<agg::rgba8, interpolator_type, gradient_sine_repeat_adaptor<agg::gradient_circle>, agg::gradient_linear_color<agg::rgba8> > span_gen_type; typedef agg::renderer_scanline_aa<ren_base, span_alloc_type, span_gen_type> ren_type; agg::trans_affine mtx; gradient_sine_repeat_adaptor<agg::gradient_circle> grad_func; grad_func.periods(5); agg::gradient_linear_color<agg::rgba8> color_func; color_func.colors(agg::rgba(1.0,0,0), agg::rgba(0,0.5,0)); interpolator_type inter(mtx); span_alloc_type sa; span_gen_type sg(inter, grad_func, color_func, 0, 150.0); ren_type ren(rb, sa, sg); agg::renderer_raster_htext<ren_type, glyph_gen> rt2(ren, glyph); rt2.render_text(5, 465, (unsigned char*)"RADIAL REPEATING GRADIENT: A quick brown fox jumps over the lazy dog", !flip_y()); }
void APITests::testBasicOperations(int width, int height) { const PixelFormat format = PF_R8G8B8A8; const int bpp = 4; auto_ptr<Image> image(CreateImage(width, height, format)); CPPUNIT_ASSERT(image->getWidth() == width); CPPUNIT_ASSERT(image->getHeight() == height); CPPUNIT_ASSERT(image->getFormat() == format); // verify that the image is black byte* pixels = (byte*)image->getPixels(); for (int i = 0; i < width * height * bpp; ++i) { CPPUNIT_ASSERT(pixels[i] == 0); } // fill the image with random pixels for (int i = 0; i < width * height * bpp; ++i) { pixels[i] = rand() % 256; } auto_ptr<Image> create_clone( CreateImage(image->getWidth(), image->getHeight(), image->getFormat(), image->getPixels())); CPPUNIT_ASSERT(create_clone.get() != 0); CPPUNIT_ASSERT(image->getWidth() == create_clone->getWidth()); CPPUNIT_ASSERT(image->getHeight() == create_clone->getHeight()); CPPUNIT_ASSERT(image->getFormat() == create_clone->getFormat()); CPPUNIT_ASSERT(memcmp(image->getPixels(), create_clone->getPixels(), width * height * bpp) == 0); // clone the image (use same pixel format) auto_ptr<Image> identical_clone(CloneImage(image.get())); CPPUNIT_ASSERT(image->getWidth() == identical_clone->getWidth()); CPPUNIT_ASSERT(image->getHeight() == identical_clone->getHeight()); CPPUNIT_ASSERT(image->getFormat() == identical_clone->getFormat()); CPPUNIT_ASSERT(memcmp(image->getPixels(), identical_clone->getPixels(), width * height * bpp) == 0); // clone the image, removing the alpha channel auto_ptr<Image> other_clone(CloneImage(identical_clone.get(), PF_R8G8B8)); CPPUNIT_ASSERT(image->getWidth() == other_clone->getWidth()); CPPUNIT_ASSERT(image->getHeight() == other_clone->getHeight()); CPPUNIT_ASSERT(other_clone->getFormat() == PF_R8G8B8); byte* image_p = (byte*)image->getPixels(); byte* other_p = (byte*)other_clone->getPixels(); for (int i = 0; i < width * height; ++i) { CPPUNIT_ASSERT(*image_p++ == *other_p++); CPPUNIT_ASSERT(*image_p++ == *other_p++); CPPUNIT_ASSERT(*image_p++ == *other_p++); ++image_p; // skip alpha } // flip the image // clone source first, since flip frees the original auto_ptr<Image> flip_none(FlipImage(CloneImage(image.get()), 0)); auto_ptr<Image> flip_x (FlipImage(CloneImage(image.get()), CA_X)); auto_ptr<Image> flip_y (FlipImage(CloneImage(image.get()), CA_Y)); auto_ptr<Image> flip_xy (FlipImage(CloneImage(image.get()), CA_X | CA_Y)); AssertImagesEqual("No flipping", flip_none.get(), image.get()); CPPUNIT_ASSERT(flip_x.get() != 0); CPPUNIT_ASSERT(width == flip_x->getWidth()); CPPUNIT_ASSERT(height == flip_x->getHeight()); CPPUNIT_ASSERT(format == flip_x->getFormat()); CPPUNIT_ASSERT(flip_y.get() != 0); CPPUNIT_ASSERT(width == flip_y->getWidth()); CPPUNIT_ASSERT(height == flip_y->getHeight()); CPPUNIT_ASSERT(format == flip_y->getFormat()); CPPUNIT_ASSERT(flip_xy.get() != 0); CPPUNIT_ASSERT(width == flip_xy->getWidth()); CPPUNIT_ASSERT(height == flip_xy->getHeight()); CPPUNIT_ASSERT(format == flip_xy->getFormat()); const byte* flip_x_pixels = (const byte*)flip_x->getPixels(); const byte* flip_y_pixels = (const byte*)flip_y->getPixels(); const byte* flip_xy_pixels = (const byte*)flip_xy->getPixels(); for (int h = 0; h < height; h++) { for (int w = 0; w < width; w++) { const int image_index = (h * width + w) * bpp; const int opp_w = width - 1 - w; const int opp_h = height - 1 - h; const int flip_x_index = (opp_h * width + w) * bpp; const int flip_y_index = (h * width + opp_w) * bpp; const int flip_xy_index = (opp_h * width + opp_w) * bpp; for (int p = 0; p < bpp; p++) { CPPUNIT_ASSERT(pixels[image_index] == flip_x_pixels [flip_x_index]); CPPUNIT_ASSERT(pixels[image_index] == flip_y_pixels [flip_y_index]); CPPUNIT_ASSERT(pixels[image_index] == flip_xy_pixels[flip_xy_index]); } } } }