Ejemplo n.º 1
0
Archivo: utils.cpp Proyecto: menpo/mesa
void OpenBitmapFromFile(
    const WCHAR *pFilename,
    void **pBuffer,
    uint32_t *width,
    uint32_t *height)
{
    GdiplusStartupInput gdiplusStartupInput;
    ULONG_PTR gdiplusToken;
    GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, nullptr);

    Bitmap *bitmap  = new Bitmap(pFilename);

    *width          = bitmap->GetWidth();
    *height         = bitmap->GetHeight();
    *pBuffer        = new BYTE[*width * *height * 4]; // width * height * |RGBA|

    // The folder 'stb_image' contains a PNG open/close module which
    // is far less painful than this is, yo.
    Gdiplus::Color clr;
    for (uint32_t y = 0, idx = 0; y < *height; ++y)
    {
        for (uint32_t x = 0; x < *width; ++x, idx += 4)
        {
            bitmap->GetPixel(x, *height - y - 1, &clr);
            ((BYTE*)*pBuffer)[idx + 0] = clr.GetBlue();
            ((BYTE*)*pBuffer)[idx + 1] = clr.GetGreen();
            ((BYTE*)*pBuffer)[idx + 2] = clr.GetRed();
            ((BYTE*)*pBuffer)[idx + 3] = clr.GetAlpha();
        }
    }

    delete bitmap;
    bitmap = 0;
}
DirectionalLight::DirectionalLight(Gdiplus::Color colour, Vector3D direction)
{
	_redIntensity = colour.GetRed();
	_greenIntensity = colour.GetGreen();
	_blueIntensity = colour.GetBlue();
	_lightDirection = direction;
}
Ejemplo n.º 3
0
// if an identical pen is set up already, find and use it
// if no such pen is set up, create one and save it for future use
std::shared_ptr<Gdiplus::Pen> PenWeight::GetPen(Gdiplus::Color color, float width) 
{
	std::stringstream newStream;
	newStream << "(" << color.GetRed() << ",";
	newStream << color.GetGreen() << ",";
	newStream << color.GetBlue() << ");";
	newStream << std::setprecision(2) << width;
	std::string newString = newStream.str();
	// when an identical pen is found
	if (this->pens.find(newString) != this->pens.end()) {
		return pens.at(newString);
	}
	// no identical pens are found
	else {
		std::shared_ptr<Gdiplus::Pen> newPen = std::make_shared<Gdiplus::Pen>(color, width);
		pens.insert(std::pair<std::string, std::shared_ptr<Gdiplus::Pen>>(newString, newPen));
		return newPen;
	}
}
Ejemplo n.º 4
0
void v(const wchar_t* f1, const char* f2) {
  Gdiplus::Bitmap bmp(f1);
  Gdiplus::Graphics g(bmp2);
  g.Clear(Gdiplus::Color(0,0,0));  
  std::vector<char> data, data2;
  for(int y=0; y<bmp.GetHeight(); y+=2) {
    int lc=0, lc2=0;
    for(int u=0; u<8; u++) {
      data.push_back(0);
      data2.push_back(0);
    }
    int v = data.size();
    int prevcl=-1, prevcl2=-1;
    for(int x=0; x<bmp.GetWidth(); x+=3) {
      int ca[3][2]; int cac=0;
      int cb[3][2]; int cbc=0;
      for(int xx=0; xx<3; xx++)
        for(int yy=0; yy<2; yy++)
          ca[xx][yy]=cb[xx][yy]=0;

      for(int sy=0; sy<2; sy++)
        for(int sx=0; sx<3; sx++) {
          Gdiplus::Color clr;
          bmp.GetPixel(x+sx, y+sy, &clr);
          int cc1 = int(clr.GetRed()<<16) | (int(clr.GetGreen()) << 8) | (int(clr.GetBlue()));
          int c1, c2;
          if(cc1==0x000000) continue; else
          if(cc1==0xFF0000) c1=0x8C, c2=c1;   else
          if(cc1==0xFF8000) c1=0x8C, c2=0x84; else
          if(cc1==0xFFFF00) c1=0x84, c2=c1;   else
          if(cc1==0x80FF00) c1=0x84, c2=0x85; else
          if(cc1==0x00FF00) c1=0x85, c2=c1;   else
          if(cc1==0x00FF80) c1=0x85, c2=0x81; else
          if(cc1==0x00FFFF) c1=0x81, c2=c1;   else
          if(cc1==0x0080FF) c1=0x81, c2=0x89; else
          if(cc1==0x0000FF) c1=0x89, c2=c1;   else
          if(cc1==0x8000FF) c1=0x89, c2=0x88; else
          if(cc1==0xFF00FF) c1=0x88, c2=c1;   else
          if(cc1==0xFF0080) c1=0x88, c2=0x8C; else
          if(cc1==0x800000) c1=0x8C, c2=0;    else
          if(cc1==0x808000) c1=0x84, c2=0;    else
          if(cc1==0x008000) c1=0x85, c2=0;    else
          if(cc1==0x008080) c1=0x81, c2=0;    else
          if(cc1==0x000080) c1=0x89, c2=0;    else
          if(cc1==0x800080) c1=0x88, c2=0;    else
          if(cc1==0x808080) c1=0x80, c2=0;    else
          if(cc1==0xFF8080) c1=0x8C, c2=0x80; else
          if(cc1==0xFFFF80) c1=0x84, c2=0x80; else
          if(cc1==0x80FF80) c1=0x85, c2=0x80; else
          if(cc1==0x80FFFF) c1=0x81, c2=0x80; else
          if(cc1==0x8080FF) c1=0x89, c2=0x80; else
          if(cc1==0xFF80FF) c1=0x88, c2=0x80; else
          if(cc1==0xFFFFFF) c1=0x80, c2=c1;   else continue;

          int used;
          if(cac==0 || cac==c1) {
            cac = c1;
            ca[sx][sy] = 1;
            used=1;
          } else 
          if(cbc==0 || cbc==c1) {
            cbc = c1;
            cb[sx][sy] = 1;
            used=2;
          } else {
            int x=1;
          }

          if(c2!=0) {
            if(used!=1 && (cac==0 || cac==c2)) {
              cac = c2;
              ca[sx][sy] = 1;
            } else 
            if(used!=2 && (cbc==0 || cbc==c2)) {
              cbc = c2;
              cb[sx][sy] = 1;
            } else {
              int x=1;
            }
          }
          /* 
          if(c1!=0) {
            int j;
            for(j=0; j<cln; j++) {
              if(clv[j]==c1) {
                clc[j]++;
                break;
              }
            }
            if(j==cln) {
              clv[cln] = c1;
              clvr[cln] = c1r;
              clc[cln] = 1;
              cln++;
            }
          }*/
          //raise("Color limit. "+i2s(x)+":"+i2s(y)+"-"+i2s(x+2)+":"+i2s(y+1));
        }
          
        /*
      int fc=0, fcr=0;
      if(cln>=1) {
        int m=0;
        for(int i=0; i<cln; i++)
          if(clc[i]>m) { 
            m=clc[i];
            fc=clv[i]; 
            fcr=clvr[i]; 
          }
        for(int sy=0; sy<2; sy++)
          for(int sx=0; sx<3; sx++) 
            if(c[sx][sy]!=0) {
              c[sx][sy]=fc;
              //dc.setPixel(x+sx,y+sy,fcr);
            }
      }
      */

      putByte(data, ca, cac, prevcl, lc);
      putByte(data2, cb, cbc, prevcl2, lc2);

      if(cac!=0) {
        int ar, ag, ab;
        switch(cac) {
          case 0x80: ar=0x80; ag=0x80; ab=0x80; break;
          case 0x8C: ar=0x80; ag=0x00; ab=0x00; break;
          case 0x84: ar=0x80; ag=0x80; ab=0x00; break;
          case 0x85: ar=0x00; ag=0x80; ab=0x00; break;
          case 0x81: ar=0x00; ag=0x80; ab=0x80; break;
          case 0x89: ar=0x00; ag=0x00; ab=0x80; break;
          case 0x88: ar=0x80; ag=0x00; ab=0x80; break;
          default: raise("x");
        }
        int br, bg, bb;
        switch(cbc) {
          case 0:
          case 0x80: br=0x80; bg=0x80; bb=0x80; break;
          case 0x8C: br=0x80; bg=0x00; bb=0x00; break;
          case 0x84: br=0x80; bg=0x80; bb=0x00; break;
          case 0x85: br=0x00; bg=0x80; bb=0x00; break;
          case 0x81: br=0x00; bg=0x80; bb=0x80; break;
          case 0x89: br=0x00; bg=0x00; bb=0x80; break;
          case 0x88: br=0x80; bg=0x00; bb=0x80; break;
          default: raise("x");
        }

        for(int sy=0; sy<2; sy++)
          for(int sx=0; sx<3; sx++) {
            int r=0, g=0, b=0;
            if(ca[sx][sy]) r += ar, g += ag, b += ab;
            if(cb[sx][sy]) r += br, g += bg, b += bb;
            if(r>255) r=255;
            if(g>255) g=255;
            if(b>255) b=255;
            bmp2->SetPixel(x+sx, y+sy, Gdiplus::Color(r, g, b));
          }
      }

    }
    colors(data, v, 0, 16, 0x80);
    colors(data2, v, 0, 16, 0x80);
    for(int u=0; u<6; u++) {
      data.push_back(0);
      data2.push_back(0);
    }
  }  

  string s;
  for(int i=0; i<data.size(); i++) {
    if(i%16==15) s += "\r\n";
    s += "0x"+hex(data[i] & 0xFF)+",";
  }
  saveFile(f2, fcmCreateAlways, s); 

  s = "0,0xF1,0,0xF1,0,0xF1,0,0xF1,0,0xF1,0,0xF1,0,0xF1,\r\n";
  int j=0;
  for(int i=0; i<data.size(); i++) {
    s += "0x";
    if((unsigned char)data[i] < 16) s += "0";
    s += hex(data[i] & 0xFF)+",";
    j++;
    if(j==94) j=0, s += "\r\n";
  }
  s += "0xFF,\r\n";
  s += "0,0xF1,0,0xF1,0,0xF1,0,0xF1,0,0xF1,0,0xF1,0,0xF1,\r\n";
  for(int i=0; i<data2.size(); i++) {
    s += "0x";
    if((unsigned char)data2[i] < 16) s += "0";
    s += hex(data2[i] & 0xFF)+",";
    j++;
    if(j==94) j=0, s += "\r\n";
  }
  s += "0xFF,\r\n";
  saveFile("Screen.txt", fcmCreateAlways, s); 
}