//つぶやくボタン void TweetDialog::on_tweetButton_clicked() { //認証済みか確認 if(user_id().length() == 0) return; //画像が指定されてるか if(!QFile::exists(imagePath())) return; //画像のバイナリデータを読み込む QFile file(imagePath()); if(!file.open(QIODevice::ReadOnly)) return; QDataStream in(&file); QByteArray imagedata(in.device()->readAll()); file.close(); // qDebug() << "image:" << imagedata.length() << "," << imagePath(); //つぶやく QVariantMap map; QVariantList list; list.append(imagedata); QStringList slist; slist.append(imagePath()); map.insert("status", ui->tweetTextEdit->document()->toPlainText()); map.insert("media", slist); m_status.updateStatuses(map); //消す ui->tweetTextEdit->clear(); setImagePath(""); close(); }
///< The function evaluates SH functions and dumps values to latitude-longitude map void ShEvaluateAndDump(ImageIo& io, std::string const& filename, int width, int height, int lmax, float3 const* coeffs) { // Prepare image memory std::vector<float> imagedata(width * height * 3); // Allocate space for SH functions std::vector<float> ylm(NumShTerms(lmax)); // Precalculate sin and cos terms std::vector<float> sintheta(height); std::vector<float> costheta(height); std::vector<float> sinphi(width); std::vector<float> cosphi(width); float thetastep = PI / height; float phistep = 2.f*PI / width; float theta0 = PI / height / 2; float phi0= 2.f*PI / width / 2; for (int i = 0; i < width; ++i) { sinphi[i] = std::sin(phi0 + i * phistep); cosphi[i] = std::cos(phi0 + i * phistep); } for (int i = 0; i < height; ++i) { sintheta[i] = std::sin(theta0 + i * thetastep); costheta[i] = std::cos(theta0 + i * thetastep); } // Iterate thru image pixels for (int phi = 0; phi < width; ++phi) { for (int theta = 0; theta < height; ++theta) { // Calculate direction float3 w = normalize(float3(sintheta[theta] * cosphi[phi], costheta[theta], sintheta[theta] * sinphi[phi])); // Evaluate SH functions at w up to lmax band ShEvaluate(w, lmax, &ylm[0]); // Evaluate function injecting SH coeffs for (int i = 0; i < NumShTerms(lmax); ++i) { imagedata[theta * width * 3 + phi * 3] += ylm[i] * coeffs[i].x; imagedata[theta * width * 3 + phi * 3 + 1] += ylm[i] * coeffs[i].y; imagedata[theta * width * 3 + phi * 3 + 2] += ylm[i] * coeffs[i].z; } } } // Write image to file ImageIo::ImageDesc imgdesc(width, height, 3); io.Write(filename, imagedata, imgdesc); }
KisImageBuilder_Result PSDSaver::buildFile(QIODevice *io) { if (!m_image) return KisImageBuilder_RESULT_EMPTY; const bool haveLayers = m_image->rootLayer()->childCount() > 1 || checkIfHasTransparency(m_image->rootLayer()->firstChild()->projection()); // HEADER PSDHeader header; header.signature = "8BPS"; header.version = 1; header.nChannels = haveLayers ? m_image->colorSpace()->channelCount() : m_image->colorSpace()->colorChannelCount(); header.width = m_image->width(); header.height = m_image->height(); QPair<psd_color_mode, quint16> colordef = colormodelid_to_psd_colormode(m_image->colorSpace()->colorModelId().id(), m_image->colorSpace()->colorDepthId().id()); if (colordef.first == COLORMODE_UNKNOWN || colordef.second == 0 || colordef.second == 32) { return KisImageBuilder_RESULT_UNSUPPORTED_COLORSPACE; } header.colormode = colordef.first; header.channelDepth = colordef.second; dbgFile << "header" << header << io->pos(); if (!header.write(io)) { dbgFile << "Failed to write header. Error:" << header.error << io->pos(); return KisImageBuilder_RESULT_FAILURE; } // COLORMODE BlOCK PSDColorModeBlock colorModeBlock(header.colormode); // XXX: check for annotations that contain the duotone spec KisAnnotationSP annotation = m_image->annotation("DuotoneColormodeBlock"); if (annotation) { colorModeBlock.duotoneSpecification = annotation->annotation(); } dbgFile << "colormode block" << io->pos(); if (!colorModeBlock.write(io)) { dbgFile << "Failed to write colormode block. Error:" << colorModeBlock.error << io->pos(); return KisImageBuilder_RESULT_FAILURE; } // IMAGE RESOURCES SECTION PSDImageResourceSection resourceSection; vKisAnnotationSP_it it = m_image->beginAnnotations(); vKisAnnotationSP_it endIt = m_image->endAnnotations(); while (it != endIt) { KisAnnotationSP annotation = (*it); if (!annotation || annotation->type().isEmpty()) { dbgFile << "Warning: empty annotation"; it++; continue; } dbgFile << "Annotation:" << annotation->type() << annotation->description(); if (annotation->type().startsWith(QString("PSD Resource Block:"))) { // PSDResourceBlock *resourceBlock = dynamic_cast<PSDResourceBlock*>(annotation.data()); if (resourceBlock) { dbgFile << "Adding PSD Resource Block" << resourceBlock->identifier; resourceSection.resources[(PSDImageResourceSection::PSDResourceID)resourceBlock->identifier] = resourceBlock; } } it++; } // Add resolution block { RESN_INFO_1005 *resInfo = new RESN_INFO_1005; resInfo->hRes = INCH_TO_POINT(m_image->xRes()); resInfo->vRes = INCH_TO_POINT(m_image->yRes()); PSDResourceBlock *block = new PSDResourceBlock; block->identifier = PSDImageResourceSection::RESN_INFO; block->resource = resInfo; resourceSection.resources[PSDImageResourceSection::RESN_INFO] = block; } // Add icc block { ICC_PROFILE_1039 *profileInfo = new ICC_PROFILE_1039; profileInfo->icc = m_image->profile()->rawData(); PSDResourceBlock *block = new PSDResourceBlock; block->identifier = PSDImageResourceSection::ICC_PROFILE; block->resource = profileInfo; resourceSection.resources[PSDImageResourceSection::ICC_PROFILE] = block; } dbgFile << "resource section" << io->pos(); if (!resourceSection.write(io)) { dbgFile << "Failed to write resource section. Error:" << resourceSection.error << io->pos(); return KisImageBuilder_RESULT_FAILURE; } // LAYER AND MASK DATA // Only save layers and masks if there is more than one layer dbgFile << "m_image->rootLayer->childCount" << m_image->rootLayer()->childCount() << io->pos(); if (haveLayers) { PSDLayerMaskSection layerSection(header); layerSection.hasTransparency = true; if (!layerSection.write(io, m_image->rootLayer())) { dbgFile << "failed to write layer section. Error:" << layerSection.error << io->pos(); return KisImageBuilder_RESULT_FAILURE; } } else { // else write a zero length block dbgFile << "No layers, saving empty layers/mask block" << io->pos(); psdwrite(io, (quint32)0); } // IMAGE DATA dbgFile << "Saving composited image" << io->pos(); PSDImageData imagedata(&header); if (!imagedata.write(io, m_image->projection(), haveLayers)) { dbgFile << "Failed to write image data. Error:" << imagedata.error; return KisImageBuilder_RESULT_FAILURE; } return KisImageBuilder_RESULT_OK; }
KisImageBuilder_Result PSDSaver::buildFile(const KUrl& uri) { if (!m_image) return KisImageBuilder_RESULT_EMPTY; if (uri.isEmpty()) return KisImageBuilder_RESULT_NO_URI; if (!uri.isLocalFile()) return KisImageBuilder_RESULT_NOT_LOCAL; // Open file for writing QFile f(uri.toLocalFile()); if (!f.open(QIODevice::WriteOnly)) { return KisImageBuilder_RESULT_NOT_LOCAL; } // HEADER PSDHeader header; header.signature = "8BPS"; header.version = 1; header.nChannels = m_image->colorSpace()->channelCount(); header.width = m_image->width(); header.height = m_image->height(); QPair<PSDColorMode, quint16> colordef = colormodelid_to_psd_colormode(m_image->colorSpace()->colorModelId().id(), m_image->colorSpace()->colorDepthId().id()); if (colordef.first == UNKNOWN || colordef.second == 0 || colordef.second == 32) { return KisImageBuilder_RESULT_UNSUPPORTED_COLORSPACE; } header.colormode = colordef.first; header.channelDepth = colordef.second; dbgFile << "header" << header << f.pos(); if (!header.write(&f)) { dbgFile << "Failed to write header. Error:" << header.error << f.pos(); return KisImageBuilder_RESULT_FAILURE; } // COLORMODE BlOCK PSDColorModeBlock colorModeBlock(header.colormode); // XXX: check for annotations that contain the duotone spec dbgFile << "colormode block" << f.pos(); if (!colorModeBlock.write(&f)) { dbgFile << "Failed to write colormode block. Error:" << colorModeBlock.error << f.pos(); return KisImageBuilder_RESULT_FAILURE; } // IMAGE RESOURCES SECTION PSDResourceSection resourceSection; // Add resolution block { RESN_INFO_1005 *resInfo = new RESN_INFO_1005; resInfo->hRes = INCH_TO_POINT(m_image->xRes()); resInfo->vRes = INCH_TO_POINT(m_image->yRes()); PSDResourceBlock *block = new PSDResourceBlock; block->resource = resInfo; resourceSection.resources[PSDResourceSection::RESN_INFO] = block; } // Add icc block { ICC_PROFILE_1039 *profileInfo = new ICC_PROFILE_1039; profileInfo->icc = m_image->profile()->rawData(); PSDResourceBlock *block = new PSDResourceBlock; block->resource = profileInfo; resourceSection.resources[PSDResourceSection::ICC_PROFILE] = block; } // XXX: Add other blocks... dbgFile << "resource section" << f.pos(); if (!resourceSection.write(&f)) { dbgFile << "Failed to write resource section. Error:" << resourceSection.error << f.pos(); return KisImageBuilder_RESULT_FAILURE; } // LAYER AND MASK DATA // Only save layers and masks if there is more than one layer dbgFile << "m_image->rootLayer->childCount" << m_image->rootLayer()->childCount() << f.pos(); if (m_image->rootLayer()->childCount() > 1) { PSDLayerSection layerSection(header); layerSection.hasTransparency = true; if (!layerSection.write(&f, m_image->rootLayer())) { dbgFile << "failed to write layer section. Error:" << layerSection.error << f.pos(); return KisImageBuilder_RESULT_FAILURE; } } else { // else write a zero length block dbgFile << "No layers, saving empty layers/mask block" << f.pos(); psdwrite(&f, (quint32)0); } // IMAGE DATA dbgFile << "Saving composited image" << f.pos(); PSDImageData imagedata(&header); if (!imagedata.write(&f, m_image->projection())) { dbgFile << "Failed to write image data. Error:" << imagedata.error; return KisImageBuilder_RESULT_FAILURE; } f.close(); return KisImageBuilder_RESULT_OK; }
int main(int argc, char *argv[]) { int j, seg=0, done=0, ch, frames, i, startframe = 1, endframe = 0; uint32 temp,len; char *filename, *prefilename; if(argc < 5) { printf("vidconvert USAGE %s [-g gamma][-b brightness][-c contrast] -f frames -n prefilename [-s startframe][-e endframe]\n",argv[0]); exit(1); } while ((ch = getopt(argc, argv, "g:b:c:f:n:s:e:")) != EOF) { switch(ch) { case 'g': gamma = atoi(optarg); break; case 'b': bright = atoi(optarg); break; case 'c': contrast = atoi(optarg); break; case 's': startframe = atoi(optarg); break; case 'e': endframe = atoi(optarg); break; case 'f': frames = atoi(optarg); break; case 'n': prefilename = strdup(optarg); break; default: printf("vidconvert USAGE %s [-g gamma][-b brightness][-c contrast] -f frames -n prefilename [-s startframe][-e endframe]\n",argv[0]); } } if(!endframe) endframe = frames; if(strlen(prefilename)>11) { printf("invalid prefilename length.\n"); exit(1); } filename = malloc(17); sprintf(filename, "%s.rvd", prefilename); outfp = fopen(filename,"a"); if(!outfp) { printf("couldn't open output stream.\n"); exit(1); } maketab(); //generated from gamma contrast and brightness for(i = startframe; i<=frames; i++) { printf("Opening Frame %d\n", i); if(!endframe) break; endframe--; //Reset All variables... segbuf = NULL; seg = segsize = seglen = segin = yup = xup = ncomp = 0; heightDU = widthDU = colsDU = cols8 = maxy = linesize = restinv = ducount = 0; buff[0] = buff[1] = buff[2] = NULL; coltab = colloc = bmploc = bmpup = NULL; dc[0] = dc[1] = dc[2] = 0; reset(); //take into account for the zeros with greater frame totals if(frames < 100) { if(i<10) sprintf(filename, "%s 0%d.jpg", prefilename, i); else sprintf(filename, "%s %d.jpg", prefilename,i); } else { if(i<10) sprintf(filename, "%s 00%d.jpg", prefilename, i); else if(i<100) sprintf(filename, "%s 0%d.jpg", prefilename, i); else sprintf(filename, "%s %d.jpg", prefilename,i); } filefd = open(filename, O_READ); if (filefd == -1) { printf("Unable to open file %s... re-using previous frame.\n", filename); j=1; while(i-j > 0) { if(frames < 500) { if(i<10) sprintf(filename, "%s 0%d.jpg", prefilename, i-j); else sprintf(filename, "%s %d.jpg", prefilename,i-j); } else { if(i<10) sprintf(filename, "%s 00%d.jpg", prefilename, i-j); else if(i<100) sprintf(filename, "%s 0%d.jpg", prefilename, i-j); else sprintf(filename, "%s %d.jpg", prefilename,i-j); } filefd = open(filename, O_READ); if(filefd == -1) j++; else break; } if(i-j < 1) continue; } seg = loadseg(); if (seg == 0xd8) printf("It's a jpeg!\n"); else { printf("Image file %s, is not a JPEG '%d'... skipping it.\n", filename, seg); exit(1); } while(seg != 0xda) { seg = loadseg(); if(!seg) goto skiptonext; switch(seg) { case 0xdb: if(!segDQT()) goto skiptonext; break; case 0xc4: if(!segDHT()) goto skiptonext; break; case 0xda: segSOS(); break; case 0xc0: segSOF(); break; case 0xdd: segDRI(); break; } } bmpwidth = round8(width); bmpheight = round8(height); imgsize = ((bmpheight*bmpwidth)/8) + ((bmpwidth*bmpheight)/64); width8 = bmpwidth/8; temp = (uint32) width8 * bmpheight; len = temp/8+temp; bmpup = bmploc = calloc(len, 1); colloc = bmploc+temp; while (!done) { imagedata(); render(); yup += heightDU; if (yup >= height) { done=1; printf("Finished rendering frame %d\n", i); rle(); printf("Finished RLE encoding frame %d\n", i); } } done = 0; skiptonext: close(filefd); } fclose(outfp); return(1); }
int main(int argc, char *argv[]) { int RcvId, xsize,ysize,minxsize,minysize; void *msg; void *App, *window, *bmp, *scr, *view; int seg=0,done=0,ch; uint32 temp,len; JMeta * metadata = malloc(sizeof(JMeta)); while ((ch = getopt(argc, argv, "g:b:c:")) != EOF) { switch(ch) { case 'g': gamma = atoi(optarg); break; case 'b': bright = atoi(optarg); break; case 'c': contrast = atoi(optarg); break; } } if (argc-optind < 1) exit(1); filefd = open(argv[optind], O_READ); if (filefd == -1) { perror(argv[optind]); exit(1); } maketab(); chan = makeChan(); seg = loadseg(); if (seg == 0xd8) { printf("It's a jpeg!\n"); } else abort("Not a jpeg!\n"); while(seg != 0xda) { seg = loadseg(); /* printf("It's %2x, size %4x\n", seg, seglen); */ switch(seg) { case 0xdb: segDQT(); break; case 0xc4: segDHT(); break; case 0xda: segSOS(); break; case 0xc0: segSOF(); break; case 0xdd: segDRI(); break; default: printf("Unknown segment %d\n", seg); break; } } bmpwidth = round8(width); bmpheight = round8(height); metadata->launchpath = strdup(fpathname(argv[0],getappdir(),1)); metadata->title = "Jpeg viewer"; metadata->icon = app_icon; metadata->showicon = 1; metadata->parentreg = -1; App = JAppInit(NULL, chan); window = JWndInit(NULL, "Jpeg viewer by J. Maginnis and S. Judd", JWndF_Resizable,metadata); ((JCnt *)window)->Orient = JCntF_TopBottom; xsize = bmpwidth; ysize = bmpheight; if(xsize > 296) xsize = 296; else if(xsize < 64) xsize = 64; if(ysize > 160) ysize = 160; else if(ysize < 24) ysize = 24; if(xsize > 64) minxsize = 64; else minxsize = xsize; minysize = 24; JWSetBounds(window,0,0,xsize,ysize+16); JWSetMin(window,minxsize,minysize); JWSetMax(window,xsize+8,ysize+24); JAppSetMain(App,window); width8 = bmpwidth/8; temp = (uint32) width8 * bmpheight; len = temp/8+temp; bmpup = bmploc = calloc(len, 1); colloc = bmploc+temp; //printf("%dx%d, %lx bytes, %lx,%lx,%lx\n", bmpwidth, bmpheight, len, bmpup, colloc, bmpup+len); bmp = JBmpInit(NULL, bmpwidth, bmpheight, bmploc); view = JViewWinInit(NULL, bmp); scr = JScrInit(NULL, view, JScrF_VNotEnd|JScrF_HNotEnd); JWSetMin(scr,8,8); JCntAdd(window, scr); JWndSetProp(window); JWinShow(window); retexit(1); while(1) { while (!done && !chkRecv(chan)) { imagedata(); render(); JWReDraw(bmp); yup += heightDU; if (yup >= height) { FILE *fp; done=1; printf("Finished render\n"); /* fp = fopen("bmpout","wb"); if (fp) { fwrite(bmploc, 320*25+1000, 1, fp); fclose(fp); } */ } } RcvId = recvMsg(chan, &msg); switch (* (int *)msg) { case WIN_EventRecv: JAppDrain(App); break; } replyMsg(RcvId,0); } return 1; }