コード例 #1
0
ファイル: life.c プロジェクト: konkers/lk-firmware
void life_frame(void) {
    int x, y;
    uint8_t sub_frame = life_frame_num++ & 0x1f;
    static bool reset_next = false;

    if (sub_frame == 0) {
        if (reset_next) {
            life_init();
            reset_next = false;
        }
        for (y = 0; y < HEIGHT; y++) {
            for (x = 0; x < WIDTH; x++) {
                bool alive = life_is_alive(x, y);
                uint8_t age = life_get_age(x, y);
                int neighbors = life_calc_neighbors(x, y);

                // Life rules from:
                //     https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life
                // 1. Any live cell with fewer than two live neighbours dies, as if
                //    caused by under-population.
                // 2. Any live cell with two or three live neighbours lives on to
                //    the next generation.
                // 3. Any live cell with more than three live neighbours dies, as
                //    if by over-population.
                // 4. Any dead cell with exactly three live neighbours becomes a
                //    live cell, as if by reproduction.
                if (alive) {
                    if (neighbors == 2 || neighbors == 3) {
                        life_set(x, y, true, age < 0xff ? age + 1 : age);
                    } else {
                        life_set(x, y, false, 0);
                    }
                } else {
                    if (neighbors == 3) {
                        life_set(x, y, true, 0);
                    } else {
                        life_set(x, y, false, 0);
                    }
                }
            }
        }
        if (!memcmp(life_alive, life_new_alive, sizeof(life_alive))
            || !memcmp(life_last_alive, life_new_alive, sizeof(life_alive))) {
            reset_next = true;
        }
        memcpy(life_last_alive, life_alive, sizeof(life_alive));
        memcpy(life_alive, life_new_alive, sizeof(life_alive));
    }

    for (y = 0; y < HEIGHT; y++) {
        for (x = 0; x < WIDTH; x++) {
            uint32_t color;
            if (life_is_alive(x, y)) {
                int age = life_get_age(x, y);
                uint32_t index = hsv_inc(life_color_index, age * 0x20 * 4);
                color = hsv_pixel(index);
            } else {
                color = matrix_color(0, 0x00, 0x00);
            }
            matrix_set_pixel(x, y, color);
        }
    }
    life_color_index = hsv_inc(life_color_index, 4);
}
コード例 #2
0
//*****************************************************************************
//  METHOD: ossimHsvGridRemapEngine::remapTile
//  
//*****************************************************************************
void ossimHsvGridRemapEngine::remapTile(const ossimDpt&       origin,
                                        ossimGridRemapSource* remapper,
                                        ossimRefPtr<ossimImageData>& tile)
{
   static const char MODULE[] = "ossimHsvGridRemapEngine::remapTile";
   if (traceExec())  CLOG << "entering..." << endl;

   //***
   // Fetch tile size and NULL pixel value:
   //***
   int    width         = tile->getWidth();
   int    height        = tile->getHeight();
   int    offset        = 0;
   
   void* red_buf = tile->getBuf(0);
   void* grn_buf = tile->getBuf(1);
   void* blu_buf = tile->getBuf(2);

   ossimDblGrid& gridH = *(remapper->getGrid(0));
   ossimDblGrid& gridS = *(remapper->getGrid(1));
   ossimDblGrid& gridV = *(remapper->getGrid(2));
      
   //---
   // Remap according to pixel type:
   //---
   switch(tile->getScalarType())
   {
      case OSSIM_UINT8:
      {
         for (double line=origin.line; line<origin.line+height; line+=1.0)
         {
            for (double samp=origin.samp; samp<origin.samp+width; samp+=1.0)
            {
               //---
               // Fetch pixel from the input tile band buffers and convert
               // to HSV:
               //---
               ossimRgbVector rgb_pixel (((ossim_uint8*)red_buf)[offset],
                                         ((ossim_uint8*)grn_buf)[offset],
                                         ((ossim_uint8*)blu_buf)[offset]);
               ossimHsvVector hsv_pixel (rgb_pixel);
               
               //---
               // Remap pixel HSV  with spatially variant bias value:
               //---
               hsv_pixel.setH(hsv_pixel.getH() + gridH(samp,line));
               hsv_pixel.setS(hsv_pixel.getS() + gridS(samp,line));
               hsv_pixel.setV(hsv_pixel.getV() + gridV(samp,line));
               
               //---
               // Convert back to RGB and write to the tile:
               //---
               rgb_pixel = hsv_pixel;  // auto-clamped
               ((ossim_uint8*)red_buf)[offset] = rgb_pixel.getR();
               ((ossim_uint8*)grn_buf)[offset] = rgb_pixel.getG();
               ((ossim_uint8*)blu_buf)[offset] = rgb_pixel.getB();
               
               offset++;
            }
         }
         break;
      }
      
      case OSSIM_USHORT11:
         break;
         
      case OSSIM_UINT16:
         break;
         
      case OSSIM_SINT16:
         break;	

      case OSSIM_FLOAT64:
         break;	

      case OSSIM_NORMALIZED_DOUBLE:
         break;	

      case OSSIM_FLOAT32:
         break;	

      case OSSIM_NORMALIZED_FLOAT:
         break;	

      case OSSIM_SCALAR_UNKNOWN:
      default:
         break;

   }   // end switch statement

   if (traceExec())  CLOG << "returning..." << endl;
   return;
};