예제 #1
0
static SkString make_png_name(const char* filename) {
    SkString pngName = SkString(filename);
    pngName.remove(pngName.size() - 3, 3);
    pngName.append("png");
    return pngName;
}
예제 #2
0
bool CopyTilesRenderer::render(SkBitmap** out) {
    int i = 0;
    bool success = true;
    SkBitmap dst;
    for (int x = 0; x < this->getViewWidth(); x += fLargeTileWidth) {
        for (int y = 0; y < this->getViewHeight(); y += fLargeTileHeight) {
            SkAutoCanvasRestore autoRestore(fCanvas, true);
            // Translate so that we draw the correct portion of the picture.
            // Perform a postTranslate so that the scaleFactor does not interfere with the
            // positioning.
            SkMatrix mat(fCanvas->getTotalMatrix());
            mat.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y));
            fCanvas->setMatrix(mat);
            // Draw the picture
            if (fUseMultiPictureDraw) {
                SkMultiPictureDraw mpd;

                mpd.add(fCanvas, fPicture);

                mpd.draw();
            } else {
                fCanvas->drawPicture(fPicture);
            }
            // Now extract the picture into tiles
            SkBitmap baseBitmap;
            fCanvas->readPixels(SkIRect::MakeSize(fCanvas->getBaseLayerSize()), &baseBitmap);
            SkIRect subset;
            for (int tileY = 0; tileY < fLargeTileHeight; tileY += this->getTileHeight()) {
                for (int tileX = 0; tileX < fLargeTileWidth; tileX += this->getTileWidth()) {
                    subset.set(tileX, tileY, tileX + this->getTileWidth(),
                               tileY + this->getTileHeight());
                    SkDEBUGCODE(bool extracted =)
                    baseBitmap.extractSubset(&dst, subset);
                    SkASSERT(extracted);
                    if (!fWritePath.isEmpty()) {
                        // Similar to write() in PictureRenderer.cpp, but just encodes
                        // a bitmap directly.
                        // TODO: Share more common code with write() to do this, to properly
                        // write out the JSON summary, etc.
                        SkString pathWithNumber = SkOSPath::Join(fWritePath.c_str(),
                                                  fInputFilename.c_str());
                        pathWithNumber.remove(pathWithNumber.size() - 4, 4);
                        pathWithNumber.appendf("%i.png", i++);
                        SkBitmap copy;
#if SK_SUPPORT_GPU
                        if (isUsingGpuDevice()) {
                            dst.pixelRef()->readPixels(&copy, &subset);
                        } else {
#endif
                            dst.copyTo(&copy);
#if SK_SUPPORT_GPU
                        }
#endif
                        success &= SkImageEncoder::EncodeFile(pathWithNumber.c_str(), copy,
                                                              SkImageEncoder::kPNG_Type, 100);
                    }
                }
            }
        }
    }
    return success;
}