Beispiel #1
0
void DumpResourcesToDisk(const string& exe, const string& dump)
{
  DWORD wtf;
  DWORD size = GetFileVersionInfoSize(exe.c_str(), &wtf);
  LibCC::Blob<BYTE> bindata(size);
  GetFileVersionInfo(exe.c_str(), 0, size, bindata.GetBuffer());
  BinaryFile f(dump, true);
  f.Write(bindata.GetBuffer(), bindata.Size());
}
Beispiel #2
0
Result LoadVersionResource(const string& file, Version::VersionResource& resource)
{
  DWORD wtf;
  DWORD size = GetFileVersionInfoSize(file.c_str(), &wtf);
  LibCC::Blob<BYTE> bindata(size);
  GetFileVersionInfo(file.c_str(), 0, size, bindata.GetBuffer());
  BinaryMemory mem(bindata.GetBuffer(), size);
  return resource.Read(mem);
}
bool GSCreator::getEPSIPreview(const QString &path, long start, long
			       end, QImage &outimg, int imgwidth, int imgheight)
{
  FILE *fp;
  fp = fopen(QFile::encodeName(path), "r");
  if (fp == 0) return false;

  const long previewsize = end - start + 1;

  char *buf = (char *) malloc(previewsize);
  fseek(fp, start, SEEK_SET);
  int count = fread(buf, sizeof(char), previewsize - 1, fp);
  fclose(fp);
  buf[previewsize - 1] = 0;
  if (count != previewsize - 1)
  {
    free(buf);
    return false;
  }

  QString previewstr = QString::fromLatin1(buf);
  free(buf);

  int offset = 0;
  while ((offset < previewsize) && !(previewstr[offset].isDigit())) offset++;
  int digits = 0;
  while ((offset + digits < previewsize) && previewstr[offset + digits].isDigit()) digits++;
  int width = previewstr.mid(offset, digits).toInt();
  offset += digits + 1;
  while ((offset < previewsize) && !(previewstr[offset].isDigit())) offset++;
  digits = 0;
  while ((offset + digits < previewsize) && previewstr[offset + digits].isDigit()) digits++;
  int height = previewstr.mid(offset, digits).toInt();
  offset += digits + 1;
  while ((offset < previewsize) && !(previewstr[offset].isDigit())) offset++;
  digits = 0;
  while ((offset + digits < previewsize) && previewstr[offset + digits].isDigit()) digits++;
  int depth = previewstr.mid(offset, digits).toInt();

  // skip over the rest of the BeginPreview comment
  while ((offset < previewsize) &&
         previewstr[offset] != '\n' &&
	 previewstr[offset] != '\r') offset++;
  while ((offset < previewsize) && previewstr[offset] != '%') offset++;

  unsigned int imagedepth;
  switch (depth) {
  case 1:
  case 2:
  case 4:
  case 8:
    imagedepth = 8;
    break;
  case 12: // valid, but not (yet) supported
  default: // illegal value
    return false;
  }

  unsigned int colors = (1U << depth);
  QImage img(width, height, QImage::Format_Indexed8);
  img.setColorCount(colors);

  if (imagedepth <= 8) {
    for (unsigned int gray = 0; gray < colors; gray++) {
      unsigned int grayvalue = (255U * (colors - 1 - gray)) /
	(colors - 1);
      img.setColor(gray, qRgb(grayvalue, grayvalue, grayvalue));
    }
  }

  const unsigned int bits_per_scan_line = width * depth;
  unsigned int bytes_per_scan_line = bits_per_scan_line / 8;
  if (bits_per_scan_line % 8) bytes_per_scan_line++;
  const unsigned int bindatabytes = height * bytes_per_scan_line;
  QVector<unsigned char> bindata(bindatabytes);

  for (unsigned int i = 0; i < bindatabytes; i++) {
    if (offset >= previewsize)
      return false;

    while (!isxdigit(previewstr[offset].toLatin1()) &&
	   offset < previewsize)
      offset++;

    bool ok = false;
    bindata[i] = static_cast<unsigned char>(previewstr.mid(offset, 2).toUInt(&ok, 16));
    if (!ok)
      return false;

    offset += 2;
  }

  for (int scanline = 0; scanline < height; scanline++) {
    unsigned char *scanlineptr = img.scanLine(scanline);

    for (int pixelindex = 0; pixelindex < width; pixelindex++) {
      unsigned char pixelvalue = 0;
      const unsigned int bitoffset =
        scanline * bytes_per_scan_line * 8U + pixelindex * depth;
      for (int depthindex = 0; depthindex < depth;
           depthindex++) {
        const unsigned int byteindex = (bitoffset + depthindex) / 8U;
        const unsigned int bitindex =
          7 - ((bitoffset + depthindex) % 8U);
        const unsigned char bitvalue =
          (bindata[byteindex] & static_cast<unsigned char>(1U << bitindex)) >> bitindex;
        pixelvalue |= (bitvalue << depthindex);
      }
      scanlineptr[pixelindex] = pixelvalue;
    }
  }

  outimg = img.convertToFormat(QImage::Format_RGB32).scaled(imgwidth, imgheight, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);

  return true;
}