Beispiel #1
0
    void Clipboard::_SetData(const ValueList& args, KValueRef result)
    {
        args.VerifyException("setData", "s s|o|l|0");

        std::string mimeType(args.GetString(0));
        DataType type = MimeTypeToDataType(mimeType);

        if (args.at(1)->IsNull() ||
            (args.at(1)->IsString() && !strcmp(args.at(1)->ToString(), "")))
        {
            this->ClearData(type);
        }
        else if (type == URI_LIST)
        {
            std::vector<std::string> uriList(ValueToURIList(args.at(1)));
            this->SetURIList(uriList);
        }
        else if (type == IMAGE)
        {
            BytesRef imageBytes(ValueToBytes(args.at(1)));
            this->SetImage(mimeType, imageBytes);
        }
        else
        {
            std::string newText(args.GetString(1, ""));
            this->SetText(newText);
        }
    }
Beispiel #2
0
static std::vector<unsigned char> ImageByteSwapped(int width, int height, const unsigned char *pixelsImage)
{
	// Input is RGBA, but Format_ARGB32 is BGRA, so swap the red bytes and blue bytes
	size_t bytes = width * height * 4;
	std::vector<unsigned char> imageBytes(pixelsImage, pixelsImage+bytes);
	for (size_t i=0; i<bytes; i+=4)
		std::swap(imageBytes[i], imageBytes[i+2]);
	return imageBytes;
}
Beispiel #3
0
Texture2d* Texture2d::load(std::string path)
{
  arc<internal::PngData> image = internal::PngData::create();
  path = path + ".png";

  if(lodepng_decode32_file(&image->image, &image->width, &image->height, path.c_str()) != 0)
  {
    throw std::exception();
  }

  Texture2d* texture = new Texture2d(image->width, image->height);

  if(texture->nativeTexture.get() == NULL)
  {
    texture->nativeTexture = gl::Uint::genTexture();
  }

  int sampleWidth = image->width;
  int sampleHeight = image->height;

  sampleWidth = poweroftwo(image->width);
  sampleHeight = poweroftwo(image->height);

  std::cout << sampleWidth << " " << sampleHeight << std::endl;

  std::vector<GLbyte> imageBytes(sampleHeight * sampleWidth * 4);

  double scaleWidth =  (double)sampleWidth / (double)image->width;
  double scaleHeight = (double)sampleHeight / (double)image->height;

  for(int cy = 0; cy < sampleHeight; cy++)
  {
    for(int cx = 0; cx < sampleWidth; cx++)
    {
      int pixel = (cy * (sampleWidth * 4)) + (cx * 4);
      int nearestMatch =  (((int)(cy / scaleHeight) * (image->width * 4)) + ((int)(cx / scaleWidth) * 4) );
      imageBytes[pixel    ] =  image->image[nearestMatch    ];
      imageBytes[pixel + 1] =  image->image[nearestMatch + 1];
      imageBytes[pixel + 2] =  image->image[nearestMatch + 2];
      imageBytes[pixel + 3] =  image->image[nearestMatch + 3];
    }
  }

  glBindTexture(GL_TEXTURE_2D, texture->nativeTexture->getGLuint());
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, sampleWidth, sampleHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, &imageBytes[0]);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
  //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  //glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
  //glGenerateMipmap(GL_TEXTURE_2D);
  glBindTexture(GL_TEXTURE_2D, 0);

  return texture;
}
Beispiel #4
0
 //% help=basic/plot-leds weight=80
 void plotLeds(ImageLiteral leds) {
   MicroBitImage i(imageBytes(leds));
   uBit.display.print(i, 0, 0, 0, 0);
 }
Beispiel #5
0
 //% help=basic/show-animation imageLiteral=1 async
 void showAnimation(ImageLiteral leds, int interval = 400) {
   uBit.display.animate(MicroBitImage(imageBytes(leds)), interval, 5, 0);
 }
Beispiel #6
0
 //% help=basic/show-leds 
 //% weight=95 blockGap=8
 //% imageLiteral=1 async
 //% blockId=device_show_leds
 //% block="show leds" icon="\uf00a"
 void showLeds(ImageLiteral leds, int interval = 400) {
   uBit.display.print(MicroBitImage(imageBytes(leds)), 0, 0, 0, interval);
 }
Beispiel #7
0
 //% weight=75 help=images/create-image
 //% blockId=device_build_image block="create image"
 //% parts="ledmatrix"
 Image createImage(ImageLiteral leds) {
     return MicroBitImage(imageBytes(leds)).clone().leakData();
 }