コード例 #1
0
ファイル: BaseManager.cpp プロジェクト: DotWolff/mygui
	void* BaseManager::loadImage(int& _width, int& _height, MyGUI::PixelFormat& _format, const std::string& _filename)
	{
		std::string fullname = MyGUI::OpenGL3DataManager::getInstance().getDataPath(_filename);

		void* result = 0;

		Gdiplus::Bitmap* image = Gdiplus::Bitmap::FromFile(MyGUI::UString(fullname).asWStr_c_str());
		if (image)
		{
			_width = image->GetWidth();
			_height = image->GetHeight();
			Gdiplus::PixelFormat format = image->GetPixelFormat();

			if (format == PixelFormat24bppRGB)
				_format = MyGUI::PixelFormat::R8G8B8;
			else if (format == PixelFormat32bppARGB)
				_format = MyGUI::PixelFormat::R8G8B8A8;
			else
				_format = MyGUI::PixelFormat::Unknow;

			if (_format != MyGUI::PixelFormat::Unknow)
			{
				Gdiplus::Rect rect(0, 0, _width, _height);
				Gdiplus::BitmapData out_data;
				image->LockBits(&rect, Gdiplus::ImageLockModeRead, format, &out_data);

				size_t size = out_data.Height * out_data.Stride;
				result = new unsigned char[size];

				convertRawData(&out_data, result, size, _format);

				image->UnlockBits(&out_data);
			}

			delete image;
		}

		return result;
	}
コード例 #2
0
ファイル: urg_ctrl.c プロジェクト: MuiLe/copter
static int internal_receiveData(urg_t *urg, long data[], int data_max,
                                int store_first, int store_last,
                                int skip_lines)
{
  enum {
    EchoBack = 0,
    ReplyCode,
    Timestamp,

    False = 0,
    True = 1,

    MD_MS_Length = 15,          /* Length of MD, MS */
    GD_GS_Length = 12,          /* Length of GD, GS */
  };

  int lines = 0;
  char buffer[UrgLineWidth];
  int filled = 0;
  int is_echoback = False;
  int n;

  char current_type[] = "xx";
  int current_first = -1;
  //int current_last = -1;
  //int current_skip_lines = -1;
  //int current_skip_frames = -1;
  //int current_capture_times = -1;
  int current_data_bytes = 3;
  int dummy_last;
  int timeout = ScipTimeout;

  /* Initialization of time stamp */
  urg->last_timestamp_ = UrgInvalidTimestamp;

  urg->errno_ = UrgNoResponse;

  while (1) {
    n = serial_getLine(&urg->serial_, buffer, ScipLineWidth, timeout);
    //fprintf(stderr, "%d: %s\n", urg_ticks(), buffer);
    if (n <= 0) {
      if (is_echoback) {
        is_echoback = False;
        lines = 0;
        continue;
      }
      break;
    }

    if (lines > 0) {
      /* ignore echoback */
      if (checkSum(buffer, n - 1, buffer[n - 1]) < 0) {
        urg->errno_ = UrgInvalidResponse;
        lines = 0;
        filled = 0;
        is_echoback = False;
        continue;
      }
    }

    if (lines > Timestamp) {
      /* convert data */
      filled = convertRawData(data, data_max, buffer, n - 1, filled,
                              current_data_bytes, skip_lines,
                              store_last, urg);

    } else if (lines == EchoBack) {

      if ((n != GD_GS_Length) && (n != MD_MS_Length)) {
        /* Return if response is not GD/GS, MD/MS */
        urg->errno_ = UrgInvalidResponse;
        lines = 0;
        filled = 0;
        is_echoback = False;
        continue;
      }
      /* Response command */
      current_type[0] = buffer[0];
      current_type[1] = buffer[1];

      /* Initialisation of receiving settings */
      current_first = atoi_substr(&buffer[2], 4);
      //current_last = atoi_substr(&buffer[6], 4);
      //current_skip_lines = atoi_substr(&buffer[10], 2);

      if ((current_first - store_first) >= data_max) {
        /* no data */
        return 0;
      }

      /* Arrangement of dummy data */
      dummy_last = current_first - store_first;
      for (filled = 0; filled < dummy_last; ++filled) {
        data[filled] = InvalidRange;
      }

      if (n == GD_GS_Length) {
        /* Ignore receive frame settings and number of frames settings for
           GD/GS command */
        urg->remain_times_ = 0;

      } else {
        //current_skip_frames = atoi_substr(&buffer[12], 1);
        //current_capture_times = atoi_substr(&buffer[13], 2);

        /* In case of MD/MS, store the remaining number of scans. */
        urg->remain_times_ = atoi(&buffer[13]);
      }
      current_data_bytes = (current_type[1] == 'S') ? 2 : 3;

    } else if (lines == ReplyCode) {
      if (! strncmp(buffer, "10", 2)) {
        urg->is_laser_on_ = UrgLaserOff;
      }

      /* If response is "0B", ignore all response. Because there is a
         possibility that the correspondence of the response shifts. */
      if (! strncmp(buffer, "0B", 2)) {
        serial_skip(&urg->serial_, ScipTimeout, timeout);
      }

      /* In case of MD/MS, response = "00" means transition request and hence
         readout one more line, and then reset the process */
      if (current_type[0] == 'M' && (! strncmp(buffer, "00", 2))) {
        is_echoback = True;
      }

    } else if (lines == Timestamp) {
      urg->last_timestamp_ = decode(buffer, 4);
    }

    ++lines;
    timeout = EachTimeout;
  }

  if (filled <= 0) {
    return urg->errno_;
  } else {
#if 0
    // fill to urg->parameters_.area_max_ or data_max
    int last_index = data_max;
    if (urg->parameters_.area_max_ < last_index) {
      last_index = urg->parameters_.area_max_;
    }
    for (; filled <= last_index; ++filled) {
      data[filled] = InvalidRagne;
    }
#endif

    return filled;
  }
}