예제 #1
0
static int32 framebuffer_ppmout24( framebuffer_t *image, framebuffer_file_t file )
{
    int32   x;
    int32   y;
    int8    d[3];
    color_t c;

    // Output the file type
    framebuffer_fprintf( file, "P6 " );

    // Output the image dimensions
    framebuffer_fprintf( file, "%d ", image->width );
    framebuffer_fprintf( file, "%d ", image->height );
    framebuffer_fprintf( file, "255\n" );

    // Output the image data
    for( y = 0; y < image->height; y++ )
    {
        for( x = 0; x < image->width; x++ )
        {
            c = framebuffer_get( image, x, y );
            d[0] = color_red( c );
            d[1] = color_green( c );
            d[2] = color_blue( c );

            framebuffer_fwrite( d, sizeof(uint8), 3, file );
        }
    }

    // Return successfully
    return 0;
}
예제 #2
0
int32 framebuffer_invert( framebuffer_t *dst, framebuffer_t *src )
{
    int32   x;
    int32   y;
    int32   r_inv;
    int32   g_inv;
    int32   b_inv;
    color_t t;

    if( dst->width != src->width )      return EINVAL;
    if( dst->height != src->height )    return EINVAL;

    // Invert image pixel by pixel
    for( y = 0; y < src->height; y++ )
    {
        for( x = 0; x < src->width; x++ )
        {            
            // Grab a pixel and invert it
            t = framebuffer_get( src, x, y);
            r_inv = MAX_VALUE - color_red(t);
            g_inv = MAX_VALUE - color_green(t);
            b_inv = MAX_VALUE - color_blue(t);

            // Write out inverted pixel
            framebuffer_set (dst, x, y, color_make(r_inv,g_inv,b_inv,255));
        }
    }

    return 0;
}
예제 #3
0
파일: TDB2.cpp 프로젝트: austinwagner/task
void TDB2::show_diff (
  const std::string& current,
  const std::string& prior,
  const std::string& when)
{
  ISO8601d lastChange (strtol (when.c_str (), NULL, 10));

  // Set the colors.
  Color color_red   (context.color () ? context.config.get ("color.undo.before") : "");
  Color color_green (context.color () ? context.config.get ("color.undo.after") : "");

  if (context.config.get ("undo.style") == "side")
  {
    std::cout << "\n"
              << format (STRING_TDB2_LAST_MOD, lastChange.toString ())
              << "\n";

    // Attributes are all there is, so figure the different attribute names
    // between before and after.
    ViewText view;
    view.width (context.getWidth ());
    view.intraPadding (2);
    view.add (Column::factory ("string", ""));
    view.add (Column::factory ("string", STRING_TDB2_UNDO_PRIOR));
    view.add (Column::factory ("string", STRING_TDB2_UNDO_CURRENT));

    Color label (context.config.get ("color.label"));
    view.colorHeader (label);

    Task after (current);

    if (prior != "")
    {
      Task before (prior);

      std::vector <std::string> beforeAtts;
      for (auto& att : before)
        beforeAtts.push_back (att.first);

      std::vector <std::string> afterAtts;
      for (auto& att : after)
        afterAtts.push_back (att.first);

      std::vector <std::string> beforeOnly;
      std::vector <std::string> afterOnly;
      listDiff (beforeAtts, afterAtts, beforeOnly, afterOnly);

      int row;
      for (auto& name : beforeOnly)
      {
        row = view.addRow ();
        view.set (row, 0, name);
        view.set (row, 1, renderAttribute (name, before.get (name)), color_red);
      }

      for (auto& att : before)
      {
        std::string priorValue   = before.get (att.first);
        std::string currentValue = after.get  (att.first);

        if (currentValue != "")
        {
          row = view.addRow ();
          view.set (row, 0, att.first);
          view.set (row, 1, renderAttribute (att.first, priorValue),
                    (priorValue != currentValue ? color_red : Color ()));
          view.set (row, 2, renderAttribute (att.first, currentValue),
                    (priorValue != currentValue ? color_green : Color ()));
        }
      }

      for (auto& name : afterOnly)
      {
        row = view.addRow ();
        view.set (row, 0, name);
        view.set (row, 2, renderAttribute (name, after.get (name)), color_green);
      }
    }
    else
    {
      int row;
      for (auto& att : after)
      {
        row = view.addRow ();
        view.set (row, 0, att.first);
        view.set (row, 2, renderAttribute (att.first, after.get (att.first)), color_green);
      }
    }

    std::cout << "\n"
              << view.render ()
              << "\n";
  }

  // This style looks like this:
  //  --- before    2009-07-04 00:00:25.000000000 +0200
  //  +++ after    2009-07-04 00:00:45.000000000 +0200
  //
  // - name: old           // att deleted
  // + name:
  //
  // - name: old           // att changed
  // + name: new
  //
  // - name:
  // + name: new           // att added
  //
  else if (context.config.get ("undo.style") == "diff")
  {
    // Create reference tasks.
    Task before;
    if (prior != "")
      before.parse (prior);

    Task after (current);

    // Generate table header.
    ViewText view;
    view.width (context.getWidth ());
    view.intraPadding (2);
    view.add (Column::factory ("string", ""));
    view.add (Column::factory ("string", ""));

    int row = view.addRow ();
    view.set (row, 0, STRING_TDB2_DIFF_PREV, color_red);
    view.set (row, 1, STRING_TDB2_DIFF_PREV_DESC, color_red);

    row = view.addRow ();
    view.set (row, 0, STRING_TDB2_DIFF_CURR, color_green);  // Note trailing space.
    view.set (row, 1, format (STRING_TDB2_DIFF_CURR_DESC,
                              lastChange.toString (context.config.get ("dateformat"))),
                      color_green);

    view.addRow ();

    // Add rows to table showing diffs.
    std::vector <std::string> all = context.getColumns ();

    // Now factor in the annotation attributes.
    for (auto& it : before)
      if (it.first.substr (0, 11) == "annotation_")
        all.push_back (it.first);

    for (auto& it : after)
      if (it.first.substr (0, 11) == "annotation_")
        all.push_back (it.first);

    // Now render all the attributes.
    std::sort (all.begin (), all.end ());

    std::string before_att;
    std::string after_att;
    std::string last_att;
    for (auto& a : all)
    {
      if (a != last_att)  // Skip duplicates.
      {
        last_att = a;

        before_att = before.get (a);
        after_att  = after.get (a);

        // Don't report different uuid.
        // Show nothing if values are the unchanged.
        if (a == "uuid" ||
            before_att == after_att)
        {
          // Show nothing - no point displaying that which did not change.

          // row = view.addRow ();
          // view.set (row, 0, *a + ":");
          // view.set (row, 1, before_att);
        }

        // Attribute deleted.
        else if (before_att != "" && after_att == "")
        {
          row = view.addRow ();
          view.set (row, 0, "-" + a + ":", color_red);
          view.set (row, 1, before_att, color_red);

          row = view.addRow ();
          view.set (row, 0, "+" + a + ":", color_green);
        }

        // Attribute added.
        else if (before_att == "" && after_att != "")
        {
          row = view.addRow ();
          view.set (row, 0, "-" + a + ":", color_red);

          row = view.addRow ();
          view.set (row, 0, "+" + a + ":", color_green);
          view.set (row, 1, after_att, color_green);
        }

        // Attribute changed.
        else
        {
          row = view.addRow ();
          view.set (row, 0, "-" + a + ":", color_red);
          view.set (row, 1, before_att, color_red);

          row = view.addRow ();
          view.set (row, 0, "+" + a + ":", color_green);
          view.set (row, 1, after_att, color_green);
        }
      }
    }

    std::cout << "\n"
              << view.render ()
              << "\n";
  }
}
예제 #4
0
int32 framebuffer_dct( framebuffer_t *dst, framebuffer_t *src )
{
    int32   x;
    int32   y;
    int32   r;
    int32   c;
    int32   pixelValue;
    int32   input_block[BLOCK_SIZE][BLOCK_SIZE];
    int32   intermediate_block[BLOCK_SIZE][BLOCK_SIZE]; 
    int32   temp_block[BLOCK_SIZE][BLOCK_SIZE]; 
    int32   output_block[BLOCK_SIZE][BLOCK_SIZE];
    color_t t;
    int32 scale_factor = 16;

    if( dst->width != src->width )      return EINVAL;
    if( dst->height != src->height )    return EINVAL;

    // Make sure that the cosine matrices are initialized
    if (!dct_initialized)
       initialize_dct_matrix();
    if (!idct_initialized)
       initialize_idct_matrix();

    // Calculate the DCT of the image in blocks
    for( y = 0; y < src->height; y = y + BLOCK_SIZE )
    {
        for( x = 0; x < src->width; x = x + BLOCK_SIZE )
        {            


            // Form a  block of pixels
            for (r = 0; r < BLOCK_SIZE; r++)
            {
               for (c = 0; c < BLOCK_SIZE; c++)
               {
                    t = framebuffer_get( src, x+c, y+r );
                    pixelValue = color_green(t);
                    input_block[r][c] = pixelValue;
               }
            } 

            // Perform DCT on the block
            // Calculate:
            //  intermediate   = input_block * dct_matrix_trans
            //  ouptut         = dct_matrix * intermediate
            dct_matrix_mult( input_block, dct_matrix_trans, intermediate_block );
            dct_matrix_scale(intermediate_block, scale_factor, input_block);
            dct_matrix_mult( dct_matrix, input_block, output_block );
            dct_matrix_scale(output_block, scale_factor, temp_block);
/*
            // Perform IDCT on the block
            // Calculate:
            //  intermediate   = input_block * idct_matrix
            //  ouptut         = idct_matrix_trans * intermediate
            idct_matrix_mult( temp_block, idct_matrix, intermediate_block );
            idct_matrix_scale( intermediate_block, scale_factor, input_block);
            idct_matrix_mult( idct_matrix_trans, input_block, output_block );
            idct_matrix_scale( output_block, scale_factor, intermediate_block);
*/

            // Write the transformed block to the destination image
            for (r = 0; r < BLOCK_SIZE; r++)
            {
               for (c = 0; c < BLOCK_SIZE; c++)
               {
                    
                    pixelValue = intermediate_block[r][c];
                    framebuffer_set (dst, x+c, y+r, color_make(pixelValue,pixelValue,pixelValue,255));
               }
            } 


        }
    }

    return 0;
}