bool WeatherLoader::load(const std::string& filename, Weather& outWeather) { std::ifstream fstream(filename.c_str()); if (!fstream.is_open()) return false; std::string line; while (std::getline(fstream, line)) { if (line[0] == '/') // Comment line continue; Weather::Entry weather; std::stringstream ss(line); weather.ambientColor = readRGB(ss); weather.directLightColor = readRGB(ss); weather.skyTopColor = readRGB(ss); weather.skyBottomColor = readRGB(ss); weather.sunCoreColor = readRGB(ss); weather.sunCoronaColor = readRGB(ss); ss >> weather.sunCoreSize; ss >> weather.sunCoronaSize; ss >> weather.sunBrightness; ss >> weather.shadowIntensity; ss >> weather.lightShading; ss >> weather.poleShading; ss >> weather.farClipping; ss >> weather.fogStart; ss >> weather.amountGroundLight; weather.lowCloudColor = readRGB(ss); weather.topCloudColor = readRGB(ss); weather.bottomCloudColor = readRGB(ss); int d; for (auto &i : weather.unknown) { ss >> d; i = d; } outWeather.entries.push_back(weather); } return true; }
void readGradient(FILE *f, struct Gradient *s, Blocktype shapeType) { int i; int numGrads = readUInt8(f); s->nGradients = numGrads; s->colors = malloc(sizeof(struct RGBA)*numGrads); s->ratio = malloc(sizeof(int)*numGrads); for(i=0; i<numGrads; ++i) { s->ratio[i] = readUInt8(f); if(shapeType==DEFINESHAPE3) readRGBA(f, &(s->colors[i])); else readRGB(f, &(s->colors[i])); } }
void readFillStyle(FILE *f, struct FillStyle *s, Blocktype shapeType, int isMorph) { int type; type = readUInt8(f); s->type = type; if(type==0) /* solid fill */ { if(shapeType==DEFINESHAPE3) readRGBA(f, &(s->fill.color)); else readRGB(f, &(s->fill.color)); if(isMorph) readRGBA(f, &(s->fill2.color)); } else if(type==0x10 || type==0x12) { /* linear (0x10) or radial (0x10) gradient */ readMatrix(f, &(s->matrix)); if(isMorph) readMatrix(f, &(s->matrix2)); readGradient(f, &(s->fill.gradient), shapeType); } else if(type==0x40 || type==0x41) { /* tiled bitmap (0x40) or clipped bitmap (0x41) fill */ s->fill.bitmap = readUInt16(f); readMatrix(f, &(s->matrix)); if(isMorph) readMatrix(f, &(s->matrix2)); } else error("Unknown fill type: %i\n", type); }
void readLineStyleArray(FILE *f, struct Shape *shape, int isMorph) { struct LineStyles *s; struct LineStyle *l; int count, i; int start = shape->lines.nLines; shape->lineOffset = start; count = readUInt8(f); if(count==255) count = readUInt16(f); s = &(shape->lines); s->nLines += count; s->line = realloc(s->line, s->nLines * sizeof(struct LineStyle)); for(i=0; i<count; ++i) { l = &(s->line[start+i]); l->width = readUInt16(f); if(isMorph) l->width2 = readUInt16(f); if(shape->shapeType == DEFINESHAPE3) readRGBA(f, &(l->color)); else readRGB(f, &(l->color)); if(isMorph) readRGBA(f, &(l->color2)); } }
COLOR GroveColorSensor::getColor() { double X; double Y; double Z; double x; double y; COLOR color = UNKNOW_COLOR; readRGB(); /* X = (-0.14282) * red_ + (1.54924) * green_ + (-0.95641) * blue_; Y = (-0.32466) * red_ + (1.57837) * green_ + (-0.73191) * blue_; Z = (-0.68202) * red_ + (0.77073) * green_ + (0.563320) * blue_; */ X = 41.24f * red_ + 35.76f * green_ + 18.05f * blue_; Y = 21.26f * red_ + 71.52f * green_ + 7.2f * blue_; Z = 1.93f * red_ + 11.92f * green_ + 95.05f * blue_; x = X / (X + Y + Z); y = Y / (X + Y + Z); // if( (X > 0) && ( Y > 0) && ( Z > 0) ) // { // Serial.println("The x,y values are("); // Serial.print(x, 2); // Serial.print(" , "); // Serial.print(y, 2); // Serial.println(")"); // } // else // Serial.println("Error: overflow!"); if(0.52< x && x< 0.7 && 0.25 < y && y < 0.45){ //红色 color = RED; } else if(0.09 < x && x < 0.22 && 0.09 < y && y < 0.25){ //蓝色 color = BLUE; } else if(0.235 < x && x < 0.302 && 0.349 < y && y < 0.8){ //绿色 color = GREEN; } else if(0.29 < x && x < 0.34 && 0.44 < y && y< 0.8){ //绿色 color = GREEN; }else if(0.29< x && x < 0.328 && 0.30 < y && y < 0.345){ if(green_ < 100){ color = BLACK; //黑色 }else{ color = WHITE; //白色 } } // Serial.print("The color sensor param:( R0_ " ); // Serial.print(R0_,DEC); // Serial.print(", G0_ "); // Serial.print(G0_,DEC); // Serial.print(", B0 "); // Serial.print(B0_,DEC); // Serial.print(", kr_ "); // Serial.println(kr_,4); // Serial.print(", kb_ "); // Serial.println(kb_,4); // Serial.println(" )"); return color; }
int readMaterial() { printInt(8); printInt(2); //Placeholder for length printBytes("\xFF\xFF\xFF\xFF", 4); int beginningOffset = ftell(output); readNothing("*MATERIAL"); openBracket(); int matRefNo = readInt("*MATERIAL_REF_NO"); char* matName = readString("*MATERIAL_NAME"); char* matClass = readString("*MATERIAL_CLASS"); char* matAmbient = readRGB("*MATERIAL_AMBIENT"); char* matDiffuse = readRGB("*MATERIAL_DIFFUSE"); char* matSpecular = readRGB("*MATERIAL_SPECULAR"); float matShine = readFloat("*MATERIAL_SHINE"); float matShineStrength = readFloat("*MATERIAL_SHINESTRENGTH"); float matTransparency = readFloat("*MATERIAL_TRANSPARENCY"); /*float matTransparency; bracketize(); char* buffer = (char*) malloc(sizeof(char)* 24); int offset = ftell(input);*/ float matWireSize = readFloat("*MATERIAL_WIRESIZE"); char* matShading = readString("*MATERIAL_SHADING"); float matXPFallof = readFloat("*MATERIAL_XP_FALLOF"); float matSelfIllum = readFloat("*MATERIAL_SELFILLUM"); char* matFallof = readString("*MATERIAL_FALLOF"); char* matXPType = readString("*MATERIAL_XP_TYPE"); printInt(matRefNo); printString(matName); printString(matClass); printBytes(matAmbient, 4); printBytes(matDiffuse, 4); printBytes(matSpecular, 4); printFloat(matShine); printFloat(matShineStrength); printFloat(matTransparency); printFloat(matWireSize); if(!strncmp(matShading, "Blinn", 5)) printInt(12); else printInt(0); printFloat(matXPFallof); printFloat(matSelfIllum); if(!strncmp(matFallof, "In", 2)) printInt(1); else printInt(0); if(!strncmp(matXPType, "Filter", 6)) printInt(1); else printInt(0); char* nextType = (char*)malloc(sizeof(char)*32); int numMaterials = 0; int numTextures = 0; int tParsed = 0; int mParsed = 0; while(1) { int currentOffset = ftell(input); fscanf(input, "%s\n", nextType); if(!strncmp(nextType, "*TEXTURE_LIST", 14) && tParsed == 0) { //Placeholder for number of textures int numTexturesOffset = ftell(output); printBytes("\xDE\xAD\xBE\xEF", 4); numTextures += readTextureList(); int afterTextureList = ftell(output); fseek(output, numTexturesOffset, 0); printInt(numTextures); fseek(output, afterTextureList, 0); mParsed = 1; } else if(tParsed == 0) { tParsed = 1; printInt(0); } if(!strncmp(nextType, "*MATERIAL_LIST", 14) && mParsed == 0) { //Placeholder for number of textures int numMaterialsOffset = ftell(output); printBytes("\xDE\xAD\xBE\xEF", 4); numMaterials += readMaterialList(); int afterMaterialList = ftell(output); fseek(output, numMaterialsOffset, 0); printInt(numMaterials); fseek(output, afterMaterialList, 0); mParsed = 1; } else if (mParsed == 0) { mParsed = 1; printInt(0); } if(!strncmp(nextType, "}", 1)) { fseek(input, currentOffset, 0); break; } } closeBracket(); int endOffset = ftell(output); int size = endOffset - beginningOffset; fseek(output, beginningOffset - 4, 0); printInt(size); fseek(output, endOffset, 0); return 0; }
bool PSDImageData::read(QIODevice *io, KisPaintDeviceSP dev ) { psdread(io, &m_compression); quint64 start = io->pos(); m_channelSize = m_header->channelDepth/8; m_channelDataLength = m_header->height * m_header->width * m_channelSize; switch (m_compression) { case 0: // Uncompressed for (int channel = 0; channel < m_header->nChannels; channel++) { m_channelOffsets << 0; ChannelInfo channelInfo; channelInfo.channelId = channel; channelInfo.compressionType = Compression::Uncompressed; channelInfo.channelDataStart = start; channelInfo.channelDataLength = m_header->width * m_header->height * m_channelSize; start += channelInfo.channelDataLength; m_channelInfoRecords.append(channelInfo); } switch (m_header->colormode) { case Bitmap: break; case Grayscale: readGrayscale(io,dev); break; case Indexed: break; case RGB: readRGB(io, dev); break; case CMYK: readCMYK(io, dev); break; case MultiChannel: break; case DuoTone: break; case Lab: readLAB(io, dev); break; case UNKNOWN: break; default: break; } break; case 1: // RLE { quint32 rlelength = 0; // The start of the actual channel data is _after_ the RLE rowlengths block if (m_header->version == 1) { start += m_header->nChannels * m_header->height * 2; } else if (m_header->version == 2) { start += m_header->nChannels * m_header->height * 4; } for (int channel = 0; channel < m_header->nChannels; channel++) { m_channelOffsets << 0; quint32 sumrlelength = 0; ChannelInfo channelInfo; channelInfo.channelId = channel; channelInfo.channelDataStart = start; channelInfo.compressionType = Compression::RLE; for (quint32 row = 0; row < m_header->height; row++ ) { if (m_header->version == 1) { psdread(io,(quint16*)&rlelength); } else if (m_header->version == 2) { psdread(io,&rlelength); } channelInfo.rleRowLengths.append(rlelength); sumrlelength += rlelength; } channelInfo.channelDataLength = sumrlelength; start += channelInfo.channelDataLength; m_channelInfoRecords.append(channelInfo); } switch (m_header->colormode) { case Bitmap: break; case Grayscale: readGrayscale(io,dev); break; case Indexed: break; case RGB: readRGB(io, dev); break; case CMYK: readCMYK(io, dev); break; case MultiChannel: break; case DuoTone: break; case Lab: readLAB(io, dev); break; case UNKNOWN: break; default: break; } break; } case 2: // ZIP without prediction switch (m_header->colormode) { case Bitmap: break; case Grayscale: break; case Indexed: break; case RGB: break; case CMYK: break; case MultiChannel: break; case DuoTone: break; case Lab: break; case UNKNOWN: break; default: break; } break; case 3: // ZIP with prediction switch (m_header->colormode) { case Bitmap: break; case Grayscale: break; case Indexed: break; case RGB: break; case CMYK: break; case MultiChannel: break; case DuoTone: break; case Lab: break; case UNKNOWN: break; default: break; } break; default: break; } return true; }
bool ScImgDataLoader_GMagick::loadPicture(const QString& fn, int /*page*/, int res, bool thumbnail) { if (!QFile::exists(fn)) return false; bool valid = m_imageInfoRecord.isRequest; QMap<int, ImageLoadRequest> req = m_imageInfoRecord.RequestProps; initialize(); m_imageInfoRecord.RequestProps = req; m_imageInfoRecord.isRequest = valid; m_imageInfoRecord.type = ImageTypeOther; m_imageInfoRecord.exifDataValid = false; m_imageInfoRecord.layerInfo.clear(); m_imageInfoRecord.PDSpathData.clear(); initGraphicsMagick(); ExceptionInfo exception; GetExceptionInfo(&exception); ImageInfo *image_info = CloneImageInfo(0); strcpy(image_info->filename, fn.toUtf8().data()); image_info->units = PixelsPerInchResolution; Image *image = ReadImage(image_info, &exception); if (exception.severity != UndefinedException) CatchException(&exception); if (!image) { qCritical() << "Failed to read image" << fn; return false; } int width = image->columns; int height = image->rows; double xres = image->x_resolution; double yres = image->y_resolution; if (thumbnail) image = FlattenImages(image, &exception); else { struct PSDLayer layer; layerCount = 0; Image *flatten_image = CloneImage(image, 0, 0, true, &exception); Image *next; if ((flatten_image != (Image *) NULL) && (image->next != (Image *) NULL)) { bool visible = true; double opacity = 1.0; QString compositeOp = blendModeToString(flatten_image->compose); QString layerName = QString("layer%1").arg(layerCount+1); if ((m_imageInfoRecord.isRequest) && (m_imageInfoRecord.RequestProps.contains(layerCount))) opacity = m_imageInfoRecord.RequestProps[layerCount].opacity / 255.0; if ((m_imageInfoRecord.isRequest) && (m_imageInfoRecord.RequestProps.contains(layerCount))) visible = m_imageInfoRecord.RequestProps[layerCount].visible; if ((m_imageInfoRecord.isRequest) && (m_imageInfoRecord.RequestProps.contains(layerCount))) compositeOp = m_imageInfoRecord.RequestProps[layerCount].blend; layer.layerName = layerName; layer.channelType.clear(); layer.channelLen.clear(); layer.opacity = qRound(opacity * 255); layer.blend = compositeOp; layer.maskYpos = 0; layer.maskXpos = 0; layer.maskHeight = 0; layer.maskWidth = 0; layer.flags = visible ? 0 : 2; QImage imt; if (image->colorspace == CMYKColorspace) { RawImage r2_image; readCMYK(flatten_image, &r2_image, width, height); imt = r2_image.convertToQImage(true); } else { m_useRawImage = false; imt = QImage(width, height, QImage::Format_ARGB32); readRGB(flatten_image, &imt, width, height); } double sx = imt.width() / 40.0; double sy = imt.height() / 40.0; layer.thumb = sy < sx ? imt.scaled(qRound(imt.width() / sx), qRound(imt.height() / sx), Qt::IgnoreAspectRatio, Qt::SmoothTransformation) : imt.scaled(qRound(imt.width() / sy), qRound(imt.height() / sy), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); m_imageInfoRecord.layerInfo.append(layer); layerCount++; if (!visible) { (void)CompositeImage(flatten_image, ClearCompositeOp, flatten_image, flatten_image->page.x, flatten_image->page.y); } for (next = image->next; next != (Image*)NULL; next = next->next) { visible = true; opacity = 1.0; compositeOp = blendModeToString(next->compose); layerName = QString("layer%1").arg(layerCount+1); if ((m_imageInfoRecord.isRequest) && (m_imageInfoRecord.RequestProps.contains(layerCount))) opacity = m_imageInfoRecord.RequestProps[layerCount].opacity / 255.0; if ((m_imageInfoRecord.isRequest) && (m_imageInfoRecord.RequestProps.contains(layerCount))) visible = m_imageInfoRecord.RequestProps[layerCount].visible; if ((m_imageInfoRecord.isRequest) && (m_imageInfoRecord.RequestProps.contains(layerCount))) compositeOp = m_imageInfoRecord.RequestProps[layerCount].blend; layer.layerName = layerName; layer.channelType.clear(); layer.channelLen.clear(); layer.opacity = qRound(opacity * 255); layer.blend = compositeOp; layer.maskYpos = 0; layer.maskXpos = 0; layer.maskHeight = 0; layer.maskWidth = 0; layer.flags = visible ? 0 : 2; if (image->colorspace == CMYKColorspace) { RawImage r2_image; readCMYK(next, &r2_image, width, height); imt = r2_image.convertToQImage(true); } else { m_useRawImage = false; imt = QImage(width, height, QImage::Format_ARGB32); readRGB(next, &imt, width, height); } double sx = imt.width() / 40.0; double sy = imt.height() / 40.0; layer.thumb = sy < sx ? imt.scaled(qRound(imt.width() / sx), qRound(imt.height() / sx), Qt::IgnoreAspectRatio, Qt::SmoothTransformation) : imt.scaled(qRound(imt.width() / sy), qRound(imt.height() / sy), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); m_imageInfoRecord.layerInfo.append(layer); layerCount++; if (visible) (void)CompositeImage(flatten_image, (CompositeOperator)blendModeToInt(compositeOp), next, next->page.x, next->page.y); } image = CloneImage(flatten_image, 0, 0, true, &exception); } } if (image->colorspace == CMYKColorspace) { m_useRawImage = true; if (!readCMYK(image, &r_image, width, height)) return false; m_imageInfoRecord.colorspace = ColorSpaceCMYK; m_pixelFormat = (r_image.channels() == 5) ? Format_CMYKA_8 : Format_CMYK_8; } else { m_useRawImage = false; m_image = QImage(width, height, QImage::Format_ARGB32); if (!readRGB(image, &m_image, width, height)) return false; m_imageInfoRecord.colorspace = ColorSpaceRGB; m_pixelFormat = Format_BGRA_8; } m_imageInfoRecord.exifDataValid = false; if (thumbnail) { m_imageInfoRecord.exifDataValid = true; m_imageInfoRecord.exifInfo.thumbnail = m_image; m_imageInfoRecord.exifInfo.height = height; m_imageInfoRecord.exifInfo.width = width; } m_imageInfoRecord.type = ImageTypeOther; m_imageInfoRecord.xres = qMax(72, qRound(xres)); m_imageInfoRecord.yres = qMax(72, qRound(yres)); m_imageInfoRecord.BBoxX = 0; m_imageInfoRecord.BBoxH = m_image.height(); m_imageInfoRecord.valid = true; return true; }
void readBackgroundColor(ddMovieClip* p, ddReader* r, int length) { r->background = readRGB(r); }