byte parseCommandSphere( char *message, byte length, byte *position, command_t *command, bytecode_t *bytecode) { byte positionX1; byte positionY1; byte positionZ1; byte size; byte errorCode = 0; bytecode->executer = command->executer; skipWhitespace(message, length, position); errorCode = parsePosition(message, length, position, & positionX1, & positionY1, & positionZ1); skipWhitespace(message, length, position); errorCode = parseOffset(message, length, position, & size); skipWhitespace(message, length, position); errorCode = parseRGB(message, length, position, & bytecode->u.lit.colorFrom); skipWhitespace(message, length, position); errorCode = parseRGB(message, length, position, & bytecode->u.lit.colorTo); if (errorCode) { errorCode = 0; bytecode->u.lit.colorTo = BLACK; } if (errorCode == 0) cubeSphere( positionX1, positionY1, positionZ1, size, bytecode->u.lit.colorFrom, bytecode->u.lit.colorTo); return(errorCode); };
byte parseCommandMoveplane( char *message, byte length, byte *position, command_t *command, bytecode_t *bytecode) { byte axis; byte offset; byte destination; rgb_t rgb; byte errorCode = 0; bytecode->executer = command->executer; skipWhitespace(message, length, position); errorCode = parseAxis(message, length, position, & axis); skipWhitespace(message, length, position); errorCode = parseOffset(message, length, position, & offset); skipWhitespace(message, length, position); errorCode = parseOffset(message, length, position, & destination); skipWhitespace(message, length, position); errorCode = parseRGB(message, length, position, & rgb); if (errorCode == 0) cubeMoveplane(axis, offset, destination, rgb); return(errorCode); };
byte parseCommandLine( char *message, byte length, byte *position, command_t *command, bytecode_t *bytecode) { byte positionX1; byte positionY1; byte positionZ1; byte positionX2; byte positionY2; byte positionZ2; byte errorCode = 0; bytecode->executer = command->executer; skipWhitespace(message, length, position); errorCode = parsePosition(message, length, position, & positionX1, & positionY1, & positionZ1); skipWhitespace(message, length, position); errorCode = parsePosition(message, length, position, & positionX2, & positionY2, & positionZ2); skipWhitespace(message, length, position); errorCode = parseRGB(message, length, position, & bytecode->u.lit.colorFrom); if (errorCode == 0) cubeLine( positionX1, positionY1, positionZ1, positionX2, positionY2, positionZ2, bytecode->u.lit.colorFrom); return(errorCode); };
web_color web_color::from_string(const wchar_t* str) { web_color result; if (str) { if (canParse(str)) { result = parseRGB(str); } else { if (colorMap.empty()) { load_names(); } auto found = colorMap.find(str); if (found != colorMap.end()) { result = found->second; } } } return result; }
static void load_names() { for (int i = 0; g_def_colors[i].name; i++) { colorMap[g_def_colors[i].name] = parseRGB(g_def_colors[i].rgb); } }
// ###################################################################### GenericFrame PngParser::getFrame() { if (rep->isGray()) return GenericFrame(parseGray()); else if (rep->isColor()) return GenericFrame(parseRGB()); // else... rep->onError("unsupported image type (neither grayscale nor RGB)"); /* can't happen */ return GenericFrame(); }
// Load a png from ram // I can't be bothered handling errors correctly, lets just abort Image loadPng(const uint8_t *png) { // Make sure we have a valid png here. assert(png_sig_cmp((png_bytep) png, 0, 8) == 0); // get PNG file info struct png_structp png_ptr = NULL; png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); assert(png_ptr != NULL); // get PNG image data info struct png_infop info_ptr = NULL; info_ptr = png_create_info_struct(png_ptr); assert(info_ptr != NULL); png_set_read_fn(png_ptr, (png_bytep) png, ReadDataFromMemory); // seek to start of png. seek = NULL; png_read_info(png_ptr, info_ptr); png_uint_32 width = 0; png_uint_32 height = 0; int bitDepth = 0; int colorType = -1; assert(png_get_IHDR(png_ptr, info_ptr, &width, &height, &bitDepth, &colorType, NULL, NULL, NULL) == 1); Image image; image.data = rsxMemAlign(16, 2*1024*1024); image.width = width; image.height = height; switch(colorType) { case PNG_COLOR_TYPE_RGB: parseRGB(image.data, width, height, png_ptr, info_ptr); break; case PNG_COLOR_TYPE_RGBA: parseRGBA(image.data, width, height, png_ptr, info_ptr); break; default: printf("Unsupported png type\n"); abort(); } png_destroy_read_struct(&png_ptr, &info_ptr, NULL); return image; }
byte parseCommandBox( char *message, byte length, byte *position, command_t *command, bytecode_t *bytecode) { byte positionX1; byte positionY1; byte positionZ1; byte positionX2; byte positionY2; byte positionZ2; byte style = 0; byte errorCode = 0; bytecode->executer = command->executer; skipWhitespace(message, length, position); errorCode = parsePosition(message, length, position, & positionX1, & positionY1, & positionZ1); skipWhitespace(message, length, position); errorCode = parsePosition(message, length, position, & positionX2, & positionY2, & positionZ2); skipWhitespace(message, length, position); errorCode = parseRGB(message, length, position, & bytecode->u.lit.colorFrom); skipWhitespace(message, length, position); errorCode = parseOffset(message, length, position, & style); if (errorCode) { errorCode = 0; style = 0; } skipWhitespace(message, length, position); errorCode = parseRGB(message, length, position, & bytecode->u.lit.colorTo); if (errorCode) { errorCode = 0; bytecode->u.lit.colorTo = BLACK; } if (errorCode == 0) cubeBox( positionX1, positionY1, positionZ1, positionX2, positionY2, positionZ2, bytecode->u.lit.colorFrom, style, bytecode->u.lit.colorTo); return(errorCode); };
byte parseCommandNext( char *message, byte length, byte *position, command_t *command, bytecode_t *bytecode) { byte errorCode = 0; bytecode->executer = command->executer; skipWhitespace(message, length, position); errorCode = parseRGB(message, length, position, & bytecode->u.lit.colorFrom); if (errorCode == 0) cubeNext(bytecode->u.lit.colorFrom); return(errorCode); };
byte parseCommandSet( char *message, byte length, byte *position, command_t *command, bytecode_t *bytecode) { byte positionX; byte positionY; byte positionZ; byte errorCode = 0; bytecode->executer = command->executer; skipWhitespace(message, length, position); errorCode = parsePosition(message, length, position, & positionX, & positionY, & positionZ); skipWhitespace(message, length, position); errorCode = parseRGB(message, length, position, & bytecode->u.lit.colorFrom); if (errorCode == 0) cubeSet( positionX, positionY, positionZ, bytecode->u.lit.colorFrom); return(errorCode); };
byte parseCommandSetplane( char *message, byte length, byte *position, command_t *command, bytecode_t *bytecode) { byte axis; byte offset; byte errorCode = 0; bytecode->executer = command->executer; skipWhitespace(message, length, position); errorCode = parseAxis(message, length, position, & axis); skipWhitespace(message, length, position); errorCode = parseOffset(message, length, position, & offset); skipWhitespace(message, length, position); errorCode = parseRGB(message, length, position, & bytecode->u.lit.colorFrom); if (errorCode == 0) cubeSetplane(axis, offset, bytecode->u.lit.colorFrom); return(errorCode); };