Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1f089004 authored by Colin Cross's avatar Colin Cross Committed by Android (Google) Code Review
Browse files

Merge changes Ib4d0e0c0,Iea8f4a23

* changes:
  libmedia: remove skia include
  stagefright: remove dependency on skia
parents cc1110dc 60d3a416
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -4,18 +4,18 @@ include $(CLEAR_VARS)

LOCAL_SRC_FILES:=       \
	stagefright.cpp \
	jpeg.cpp	\
	SineSource.cpp

LOCAL_SHARED_LIBRARIES := \
	libstagefright libmedia libmedia_native libutils libbinder libstagefright_foundation \
        libskia libgui
        libjpeg libgui

LOCAL_C_INCLUDES:= \
	frameworks/base/media/libstagefright \
	frameworks/base/media/libstagefright/include \
	$(TOP)/frameworks/native/include/media/openmax \
	external/skia/include/core \
	external/skia/include/images \
	external/jpeg \

LOCAL_CFLAGS += -Wno-multichar

+91 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2012 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <errno.h>
#include <setjmp.h>
#include <stdio.h>

extern "C" {
#include "jpeglib.h"
}

static inline uint8_t from565to8(uint16_t p, int start, int bits) {
    uint8_t c = (p >> start) & ((1 << bits) - 1);
    return (c << (8 - bits)) | (c >> (bits - (8 - bits)));
}

struct sf_jpeg_error_mgr {
    struct jpeg_error_mgr jerr;
    jmp_buf longjmp_buffer;
};

void sf_jpeg_error_exit(j_common_ptr cinfo) {
    struct sf_jpeg_error_mgr *sf_err = (struct sf_jpeg_error_mgr *)cinfo->err;
    longjmp(sf_err->longjmp_buffer, 0);
}

int writeJpegFile(const char *filename, uint8_t *frame, int width, int height) {
    struct sf_jpeg_error_mgr sf_err;
    struct jpeg_compress_struct cinfo;
    uint8_t row_data[width * 3];
    JSAMPROW row_pointer = row_data;
    FILE *f;

    f = fopen(filename, "w");
    if (!f) {
        return -errno;
    }

    cinfo.err = jpeg_std_error(&sf_err.jerr);
    sf_err.jerr.error_exit = sf_jpeg_error_exit;
    if (setjmp(sf_err.longjmp_buffer)) {
        jpeg_destroy_compress(&cinfo);
        fclose(f);
        return -1;
    }

    jpeg_create_compress(&cinfo);
    jpeg_stdio_dest(&cinfo, f);

    cinfo.image_width = width;
    cinfo.image_height = height;
    cinfo.input_components = 3;
    cinfo.in_color_space = JCS_RGB;

    jpeg_set_defaults(&cinfo);
    jpeg_set_quality(&cinfo, 80, TRUE);

    jpeg_start_compress(&cinfo, TRUE);

    for (int row = 0; row < height; row++) {
        uint16_t *src = (uint16_t *)(frame + row * width * 2);
        uint8_t *dst = row_data;
        for (int col = 0; col < width; col++) {
            dst[0] = from565to8(*src, 11, 5);
            dst[1] = from565to8(*src, 5, 6);
            dst[2] = from565to8(*src, 0, 5);
            dst += 3;
            src++;
        }
        jpeg_write_scanlines(&cinfo, &row_pointer, 1);
    }

    jpeg_finish_compress(&cinfo);
    jpeg_destroy_compress(&cinfo);

    fclose(f);
    return 0;
}
+6 −0
Original line number Diff line number Diff line
#ifndef _STAGEFRIGHT_JPEG_H_
#define _STAGEFRIGHT_JPEG_H_

int writeJpegFile(const char *filename, uint8_t *frame, int width, int height);

#endif
+4 −12
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@
#include <string.h>
#include <unistd.h>

#include "jpeg.h"
#include "SineSource.h"

#include <binder/IServiceManager.h>
@@ -49,8 +50,6 @@
#include <media/stagefright/MPEG4Writer.h>

#include <private/media/VideoFrame.h>
#include <SkBitmap.h>
#include <SkImageEncoder.h>

#include <fcntl.h>

@@ -787,16 +786,9 @@ int main(int argc, char **argv) {

                VideoFrame *frame = (VideoFrame *)mem->pointer();

                SkBitmap bitmap;
                bitmap.setConfig(
                        SkBitmap::kRGB_565_Config, frame->mWidth, frame->mHeight);

                bitmap.setPixels((uint8_t *)frame + sizeof(VideoFrame));

                CHECK(SkImageEncoder::EncodeFile(
                            "/sdcard/out.jpg", bitmap,
                            SkImageEncoder::kJPEG_Type,
                            SkImageEncoder::kDefaultQuality));
                CHECK_EQ(writeJpegFile("/sdcard/out.jpg",
                            (uint8_t *)frame + sizeof(VideoFrame),
                            frame->mWidth, frame->mHeight), 0);
            }

            {
+0 −1
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@
#include <stdint.h>
#include <sys/types.h>
#include <binder/Parcel.h>
#include <SkBitmap.h>
#include <media/IMediaMetadataRetriever.h>
#include <utils/String8.h>