Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. unsafe
  2. {
  3. byte* ptr = (byte*)data.Scan0;
  4. short colorValue = 0;
  5. bool isLastDigit = false;
  6. for (int length = file.ReadBlock(buffer, 0, buffer.Length); length != 0; length = file.ReadBlock(buffer, 0, buffer.Length))
  7. {
  8. for (int i = 0; i < length; i++)
  9. {
  10. if (Char.IsDigit(buffer[i]) && !isComment)
  11. {
  12. colorValue = (short)(colorValue * 10 + buffer[i] - '0');
  13. isLastDigit = true;
  14. }
  15. else if (isComment && (buffer[i] == '\n'))
  16. {
  17. isComment = false;
  18. }
  19. else
  20. {
  21. if (isLastDigit)
  22. {
  23. *(ptr++) = (byte)((colorValue * 255) / dimension.ColourRange.Value);
  24. isLastDigit = false;
  25. colorValue = 0;
  26. }
  27. if (buffer[i] == '#')
  28. isComment = true;
  29. }
  30. };
  31. }
  32. bmp.UnlockBits(data);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement