コード例 #1
0
ファイル: ColorRGBA.cpp プロジェクト: EternalWind/MyRenderer
ColorRGBA::ColorRGBA(float red, float green, float blue, float alpha)
{
	SetRed(red);
	SetGreen(green);
	SetBlue(blue);
	SetAlpha(alpha);
}
コード例 #2
0
void Led::SetColor(
  const unsigned char red,
  const unsigned char green,
  const unsigned char blue)
{
  SetRed(red);
  SetGreen(green);
  SetBlue(blue);
}
コード例 #3
0
Colour::Colour(u8 red, u8 green, u8 blue)
{
	SetRed(red);
	SetGreen(green);
	SetBlue(blue);
}
コード例 #4
0
int R2Image::
ReadBMP(const char *filename)
{
  // Open file
  FILE *fp = fopen(filename, "rb");
  if (!fp) {
    fprintf(stderr, "Unable to open image file: %s\n", filename);
    return 0;
  }

  /* Read file header */
  BITMAPFILEHEADER bmfh;
  bmfh.bfType = WordReadLE(fp);
  bmfh.bfSize = DWordReadLE(fp);
  bmfh.bfReserved1 = WordReadLE(fp);
  bmfh.bfReserved2 = WordReadLE(fp);
  bmfh.bfOffBits = DWordReadLE(fp);
  
  /* Check file header */
  assert(bmfh.bfType == BMP_BF_TYPE);
  /* ignore bmfh.bfSize */
  /* ignore bmfh.bfReserved1 */
  /* ignore bmfh.bfReserved2 */
  assert(bmfh.bfOffBits == BMP_BF_OFF_BITS);
  
  /* Read info header */
  BITMAPINFOHEADER bmih;
  bmih.biSize = DWordReadLE(fp);
  bmih.biWidth = LongReadLE(fp);
  bmih.biHeight = LongReadLE(fp);
  bmih.biPlanes = WordReadLE(fp);
  bmih.biBitCount = WordReadLE(fp);
  bmih.biCompression = DWordReadLE(fp);
  bmih.biSizeImage = DWordReadLE(fp);
  bmih.biXPelsPerMeter = LongReadLE(fp);
  bmih.biYPelsPerMeter = LongReadLE(fp);
  bmih.biClrUsed = DWordReadLE(fp);
  bmih.biClrImportant = DWordReadLE(fp);
  
  // Check info header 
  assert(bmih.biSize == BMP_BI_SIZE);
  assert(bmih.biWidth > 0);
  assert(bmih.biHeight > 0);
  assert(bmih.biPlanes == 1);
  assert(bmih.biBitCount == 24);  /* RGB */
  assert(bmih.biCompression == BI_RGB);   /* RGB */
  int lineLength = bmih.biWidth * 3;  /* RGB */
  if ((lineLength % 4) != 0) lineLength = (lineLength / 4 + 1) * 4;
  assert(bmih.biSizeImage == (unsigned int) lineLength * (unsigned int) bmih.biHeight);

  // Assign width, height, and number of pixels
  width = bmih.biWidth;
  height = bmih.biHeight;
  nchannels = 3;

  // Allocate unsigned char buffer for reading pixels
  int rowsize = nchannels * width;
  if ((rowsize % 4) != 0) rowsize = (rowsize / 4 + 1) * 4;
  int nbytes = bmih.biSizeImage;
  unsigned char *buffer = new unsigned char [nbytes];
  if (!buffer) {
    fprintf(stderr, "Unable to allocate temporary memory for BMP file");
    fclose(fp);
    return 0;
  }

  // Read buffer 
  fseek(fp, (long) bmfh.bfOffBits, SEEK_SET);
  if (fread(buffer, 1, bmih.biSizeImage, fp) != bmih.biSizeImage) {
    fprintf(stderr, "Error while reading BMP file %s", filename);
    return 0;
  }

  // Close file
  fclose(fp);

  // Allocate pixels for image
  pixels = new double [ width * height * nchannels ];
  if (!pixels) {
    fprintf(stderr, "Unable to allocate memory for BMP file");
    fclose(fp);
    return 0;
  }

  // Assign pixels
  for (int j = 0; j < height; j++) {
    unsigned char *p = &buffer[j * rowsize];
    for (int i = 0; i < width; i++) {
      SetBlue(i, j, (double) *(p++) / 255.0);
      SetGreen(i, j, (double) *(p++) / 255.0);
      SetRed(i, j, (double) *(p++) / 255.0);
    }
  }

  // Free unsigned char buffer for reading pixels
  delete [] buffer;

  // Return success
  return 1;
}
コード例 #5
0
void ExpandedLEDSerialControllerMega::SetMode (Mode mode) {
  switch (mode) {
    case kRed:
      SetRed (255);
      SetGreen ();
      SetBlue ();
      SetWhite ();
      break;
    case kBlue:
      SetRed ();
      SetGreen ();
      SetBlue (255);
      SetWhite ();
      break;
    case kGreen:
      SetRed ();
      SetGreen (255);
      SetBlue ();
      SetWhite ();
      break;
    case kYellow:
      SetRed (255);
      SetGreen (255);
      SetBlue ();
      SetWhite ();
      break;
    case kMagenta:
      SetRed (255);
      SetGreen ();
      SetBlue (255);
      SetWhite ();
      break;
    case kCyan:
      SetRed ();
      SetGreen (255);
      SetBlue (255);
      SetWhite ();
      break;
    case kOrange:
      SetRed (255);
      SetGreen (63);
      SetBlue ();
      SetWhite ();
      break;
    case kPurple:
      SetRed (127);
      SetGreen ();
      SetBlue (255);
      SetWhite ();
      break;
    case kWhite:
      SetRed ();
      SetGreen ();
      SetBlue ();
      SetWhite (255);
      break;
    case kCycle:
      SetWhite();
      SetHSV ((double(millis() % (loopSeconds * 1000)) / double(loopSeconds * 1000)), 1, 1);
      break;
    case kRainbow: {
        unsigned long timeStamp = (millis() % 8000);
        if (timeStamp < 1000) {
          SetRed (255);
          SetGreen (0);
          SetBlue (0);
          SetWhite();

        }
        else if (timeStamp < 2000) {
          SetRed (255);
          SetGreen (31);
          SetBlue (0);
          SetWhite();

        }
        else if (timeStamp < 3000) {
          SetRed (255);
          SetGreen (150);
          SetBlue (0);
          SetWhite();

        }
        else if (timeStamp < 4000) {
          SetRed (0);
          SetGreen (255);
          SetBlue (0);
          SetWhite();

        }
        else if (timeStamp < 5000) {
          SetRed (0);
          SetGreen (255);
          SetBlue (255);
          SetWhite();

        }
        else if (timeStamp < 6000) {
          SetRed (0);
          SetGreen (0);
          SetBlue (255);
          SetWhite();

        }
        else if (timeStamp < 7000) {
          SetRed (127);
          SetGreen (0);
          SetBlue (255);
          SetWhite();

        }
        else {
          SetRed (255);
          SetGreen (0);
          SetBlue (255);
          SetWhite();
        }
      }
      break;
    default:
      SetRed (0);
      SetGreen (0);
      SetBlue (0);
      SetWhite();
      break;
  }
}